diff --git a/js/panel.js b/js/panel.js index c956473..f3a8dfd 100644 --- a/js/panel.js +++ b/js/panel.js @@ -23,6 +23,7 @@ combineSameRulesInput = $('#combine-same-rules'), fixHTMLIndentationInput = $('#fix-html-indentation'), includeAncestors = $('#include-ancestors'), + embedCSS = $('#embed-css'), idPrefix = $('#id-prefix'), htmlTextarea = $('#html'), @@ -222,6 +223,11 @@ styles = cssStringifier.process(styles); + if (embedCSS.is(':checked')) { + html = '\n' + html; + styles = ''; + } + if (isValidPrefix(idPrefix.val())) { prefix = idPrefix.val(); } diff --git a/js/tools/EmbedCSS.js b/js/tools/EmbedCSS.js new file mode 100644 index 0000000..7758293 --- /dev/null +++ b/js/tools/EmbedCSS.js @@ -0,0 +1,70 @@ +/** + * Utility that transforms object representing CSS rules to actual CSS code. + * + * @constructor + */ +function CSSStringifier() { + "use strict"; + + function propertiesToString(properties) { + var propertyName, + output = ""; + + for (propertyName in properties) { + if (properties.hasOwnProperty(propertyName)) { + output += " " + propertyName + ": " + properties[propertyName] + ";\n"; + } + } + + return output; + } + + function printIDs(ids, pseudoElement) { + var i, l, + idString, + output = []; + + if (!(ids instanceof Array)) { + ids = [ids]; + } + + for (i = 0, l = ids.length; i < l; i++) { + idString = '#' + ids[i]; + if (pseudoElement) { + idString += pseudoElement; + } + + output.push(idString); + } + + return output.join(', '); + } + + this.process = function (styles) { + var i, l, + style, + output = ""; + + for (i = 0, l = styles.length; i < l; i++) { + style = styles[i]; + + output += printIDs(style.id) + ' {\n'; + output += propertiesToString(style.node); + output += '}/*' + printIDs(style.id) + '*/\n\n'; + + if (style.after) { + output += printIDs(style.id, ':after') + ' {\n'; + output += propertiesToString(style.after); + output += '}/*' + printIDs(style.id, ':after') + '*/\n\n'; + } + + if (style.before) { + output += printIDs(style.id, ':before') + ' {\n'; + output += propertiesToString(style.before); + output += '}/*' + printIDs(style.id, ':before') + '*/\n\n'; + } + } + + return output; + }; +} diff --git a/panel.html b/panel.html index e5fb273..396664a 100644 --- a/panel.html +++ b/panel.html @@ -69,6 +69,9 @@

  • +
  • Prefix all CSS IDs with