diff --git a/bubbly.js b/bubbly.js index bf6f1f1..937e638 100644 --- a/bubbly.js +++ b/bubbly.js @@ -1,7 +1,13 @@ +function changeValue(who){ + if(who=='picker') picker_color.value = color.value; + if(who=='color') color.value = picker_color.value; + update(); +} + function update() { var side = getRadioValue('side'), triangle = getRadioValue('triangle'); - + code.textContent = bubbleCSS('.speech-bubble', { side: side, triangle: triangle, @@ -9,10 +15,10 @@ function update() { color: color.value, ems: ems.checked }); - + // Update labels var labelCSS =''; - + ['top', 'right', 'bottom', 'left'].forEach(function(value) { labelCSS += bubbleCSS('label[for="side-' + value + '"]', { side: value, @@ -21,7 +27,7 @@ function update() { color: 'yellowgreen' }) + '\n\n'; }); - + ['symmetrical', 'right', 'left'].forEach(function(value) { labelCSS += bubbleCSS('label[for="triangle-' + value + '"]', { side: side, @@ -30,17 +36,17 @@ function update() { color: 'deeppink' }) + '\n\n'; }); - + labels.textContent = labelCSS; } function bubbleCSS(selector, settings) { var props = {}, propsBefore = {}; - + props['position'] = 'relative'; props['background'] = settings.color; props['border-radius'] = '.4em'; - + var side = settings.side, triangle = settings.triangle, isHorizontal = side == 'top' || side == 'bottom', @@ -51,61 +57,61 @@ function bubbleCSS(selector, settings) { 'left': 'right' }[side], offset = isHorizontal? 'left' : 'top'; - + propsBefore['content'] = "''"; propsBefore['position'] = 'absolute'; propsBefore[side] = '0'; propsBefore[offset] = '50%'; - + propsBefore['width'] = '0'; propsBefore['height'] = '0'; - + propsBefore['border'] = getLength(settings.size, settings.ems) + ' solid transparent'; propsBefore['border-' + opposite + '-color'] = settings.color; propsBefore['border-' + side] = '0'; - + if (triangle != 'symmetrical') { propsBefore['border-' + (isHorizontal? triangle : (triangle == 'right'? 'top' : 'bottom'))] = '0'; } - + propsBefore['margin-' + offset] = getLength(-settings.size/(triangle == 'symmetrical'? 1 : 2), settings.ems); // to center it propsBefore['margin-' + side] = getLength(-settings.size, settings.ems); // to put it outside the box - + return cssRule(selector, props) + '\n\n' + cssRule(selector + ':after', propsBefore); } function getLength(px, useEms) { if (useEms) { var base = parseInt(getComputedStyle($('.speech-bubble')).fontSize); - + return Math.round(1000 * px/base)/1000 + 'em'; } - + return px + 'px'; } function cssRule(selector, props) { var css = selector + ' {\n'; - - + + $u.each(props, function (value, property) { css += ' ' + property + ': ' + value + ';\n'; }); - + css += '}'; - + return css; } function getRadioValue(name) { var radios = document.getElementsByName(name); - + for (var i=0, radio; radio = radios[i++];) { if (radio.checked) { return radio.value; } } - + return ''; } @@ -117,4 +123,4 @@ $$('input[type="radio"] + label').forEach(function (label) { label.title = label.textContent; }); -update(); \ No newline at end of file +update(); diff --git a/index.html b/index.html index 3c8db18..079a421 100644 --- a/index.html +++ b/index.html @@ -18,38 +18,38 @@