diff --git a/js/panel.js b/js/panel.js index e5bdb75..54d8a55 100644 --- a/js/panel.js +++ b/js/panel.js @@ -23,6 +23,7 @@ combineSameRulesInput = $('#combine-same-rules'), fixHTMLIndentationInput = $('#fix-html-indentation'), includeAncestors = $('#include-ancestors'), + retainClasses = $('#retain-classes'), idPrefix = $('#id-prefix'), htmlTextarea = $('#html'), @@ -67,6 +68,7 @@ fixHTMLIndentationInput.on('change', persistSettingAndProcessSnapshot); combineSameRulesInput.on('change', persistSettingAndProcessSnapshot); includeAncestors.on('change', persistSettingAndProcessSnapshot); + retainClasses.on('change', persistSettingAndProcessSnapshot); createButton.on('click', makeSnapshot); @@ -175,13 +177,39 @@ var styles = lastSnapshot.css, html = lastSnapshot.html, - prefix = ""; + prefix = "", + htmlCleanOptions = { + removeAttrs: ['class'], + allowedAttributes: [ + ['id'], + ['placeholder', ['input', 'textarea']], + ['disabled', ['input', 'textarea', 'select', 'option', 'button']], + ['value', ['input', 'button']], + ['readonly', ['input', 'textarea', 'option']], + ['label', ['option']], + ['selected', ['option']], + ['checked', ['input']] + ], + format: true, + replace: [], + replaceStyles: [], + allowComments: true + }; if (includeAncestors.is(':checked')) { styles = lastSnapshot.ancestorCss.concat(styles); html = lastSnapshot.leadingAncestorHtml + html + lastSnapshot.trailingAncestorHtml; } + if (retainClasses.is(':checked')) { + for (var index in htmlCleanOptions.removeAttrs) { + var value = htmlCleanOptions.removeAttrs[index]; + if (value === 'class') { + htmlCleanOptions.removeAttrs.splice(index, 1); + } + } + } + loader.addClass('processing'); if (removeDefaultValuesInput.is(':checked')) { @@ -199,23 +227,7 @@ } if (fixHTMLIndentationInput.is(':checked')) { - html = $.htmlClean(html, { - removeAttrs: ['class'], - allowedAttributes: [ - ['id'], - ['placeholder', ['input', 'textarea']], - ['disabled', ['input', 'textarea', 'select', 'option', 'button']], - ['value', ['input', 'button']], - ['readonly', ['input', 'textarea', 'option']], - ['label', ['option']], - ['selected', ['option']], - ['checked', ['input']] - ], - format: true, - replace: [], - replaceStyles: [], - allowComments: true - }); + html = $.htmlClean(html, htmlCleanOptions); } styles = cssStringifier.process(styles); diff --git a/js/tools/CSSStringifier.js b/js/tools/CSSStringifier.js index 7758293..34b65c7 100644 --- a/js/tools/CSSStringifier.js +++ b/js/tools/CSSStringifier.js @@ -40,6 +40,16 @@ function CSSStringifier() { return output.join(', '); } + function generateStyle(selector, node) { + var output = ""; + + output += selector + ' {\n'; + output += propertiesToString(node); + output += '}/*' + selector + '*/\n\n'; + + return output; + } + this.process = function (styles) { var i, l, style, @@ -48,20 +58,14 @@ function CSSStringifier() { 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'; + output += generateStyle(printIDs(style.id), style.node); if (style.after) { - output += printIDs(style.id, ':after') + ' {\n'; - output += propertiesToString(style.after); - output += '}/*' + printIDs(style.id, ':after') + '*/\n\n'; + output += generateStyle(printIDs(style.id, ':after'), style.after); } if (style.before) { - output += printIDs(style.id, ':before') + ' {\n'; - output += propertiesToString(style.before); - output += '}/*' + printIDs(style.id, ':before') + '*/\n\n'; + output += generateStyle(printIDs(style.id, ':before'), style.before); } } diff --git a/panel.html b/panel.html index a077613..8e60f17 100644 --- a/panel.html +++ b/panel.html @@ -69,6 +69,9 @@