From: alexlamsl Date: Thu, 7 Apr 2016 17:13:16 +0000 (+0800) Subject: update online minifier X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=87d228391e030dccac5af5e7f45e0aa25cf947b7;p=html-minifier.git update online minifier ease maintenance by using a single source for listing all available options --- diff --git a/README.md b/README.md index a486ad7..ccf50c1 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ How does HTMLMinifier compare to other solutions — [HTML Minifier from Will Pe | `caseSensitive` | Treat attributes in case sensitive manner (useful for custom HTML tags) | `false` | | `collapseBooleanAttributes` | [Omit attribute values from boolean attributes](http://perfectionkills.com/experimenting-with-html-minifier/#collapse_boolean_attributes) | `false` | | `collapseInlineTagWhitespace` | Don't leave any spaces between `display:inline;` elements when collapsing. Must be used in conjunction with `collapseWhitespace=true` | `false` | -| `collapseWhitespace` | [Collapse white space that contributes to text nodes in a document tree.](http://perfectionkills.com/experimenting-with-html-minifier/#collapse_whitespace) | `false` | +| `collapseWhitespace` | [Collapse white space that contributes to text nodes in a document tree](http://perfectionkills.com/experimenting-with-html-minifier/#collapse_whitespace) | `false` | | `conservativeCollapse` | Always collapse to 1 space (never remove it entirely). Must be used in conjunction with `collapseWhitespace=true` | `false` | | `customAttrAssign` | Arrays of regex'es that allow to support custom attribute assign expressions (e.g. `'
'`) | `[ ]` | | `customAttrCollapse` | Regex that specifies custom attribute to strip newlines from (e.g. `/ng\-class/`) | | diff --git a/assets/master.css b/assets/master.css index dcccfc2..875753e 100644 --- a/assets/master.css +++ b/assets/master.css @@ -18,7 +18,6 @@ button { font-weight: bold; width: 100px; } #options input { margin-right: 0.5em; } #stats { margin-bottom: 2em; overflow: hidden; margin-top: 0; } #todo { font-family: monospace; margin-bottom: 2em; } -#warning { background: #fee; padding: 0.25em; display: inline-block; margin-top: 0; font-size: 0.85em; } #lint-report { font-family: monospace; } #report { margin-bottom: 5em; } #report ul { margin: 0.5em; padding-left: 1em; list-style: none; } @@ -33,7 +32,7 @@ button { font-weight: bold; width: 100px; } .controls a:focus, .controls a:hover { text-decoration: none; } .deprecated-element, .deprecated-attribute { color: red; } -.presentational-element, .presentational-attribute, .inaccessible-attribute { color: #FF8C00; } +.presentational-element, .presentational-attribute, .inaccessible-attribute, .repeating-attribute { color: #FF8C00; } .unsafe { color: #f33; } diff --git a/assets/master.js b/assets/master.js index 50afd4e..22f5064 100644 --- a/assets/master.js +++ b/assets/master.js @@ -12,30 +12,43 @@ return (str + '').replace(/&/g, '&').replace(//g, '>'); } + function forEachOption(fn) { + [].forEach.call(byId('options').getElementsByTagName('input'), fn); + } + function getOptions() { - return { - removeComments: byId('remove-comments').checked, - collapseWhitespace: byId('collapse-whitespace').checked, - conservativeCollapse: byId('conservative-collapse').checked, - collapseBooleanAttributes: byId('collapse-boolean-attributes').checked, - removeTagWhitespace: byId('remove-tag-whitespace').checked, - removeAttributeQuotes: byId('remove-attribute-quotes').checked, - removeRedundantAttributes: byId('remove-redundant-attributes').checked, - useShortDoctype: byId('use-short-doctype').checked, - removeEmptyAttributes: byId('remove-empty-attributes').checked, - removeEmptyElements: byId('remove-empty-elements').checked, - removeOptionalTags: byId('remove-optional-tags').checked, - removeScriptTypeAttributes: byId('remove-script-type-attributes').checked, - removeStyleLinkTypeAttributes: byId('remove-style-link-type-attributes').checked, - caseSensitive: byId('case-sensitive').checked, - keepClosingSlash: byId('keep-closing-slash').checked, - minifyJS: byId('minify-js').checked, - processScripts: byId('minify-js-templates').checked ? byId('minify-js-templates-type').value : false, - minifyCSS: byId('minify-css').checked, - minifyURLs: byId('minify-urls').checked ? { site: byId('minify-urls-siteurl').value } : false, - lint: byId('use-htmllint').checked ? new HTMLLint() : null, - maxLineLength: parseInt(byId('max-line-length').value, 10) - }; + var options = {}; + forEachOption(function(element) { + var key = element.id; + var value; + if (element.type === 'checkbox') { + value = element.checked; + } + else { + value = element.value.replace(/^\s+|\s+$/, ''); + if (!value) { + return; + } + } + switch (key) { + case 'lint': + if (!value) { + return; + } + value = new HTMLLint(); + break; + case 'maxLineLength': + value = parseInt(value); + break; + case 'minifyURLs': + value = { site: value }; + break; + case 'processScripts': + value = value.split(/\s*,\s*/); + } + options[key] = value; + }); + return options; } function commify(str) { @@ -45,7 +58,7 @@ .split('').reverse().join(''); } - function minifyTextarea() { + byId('minify-btn').onclick = function() { try { var options = getOptions(), lint = options.lint, @@ -71,38 +84,37 @@ byId('output').value = ''; byId('stats').innerHTML = '' + escapeHTML(err) + ''; } - } - - byId('max-line-length').oninput = function() { minifyTextarea(); }; - byId('minify-btn').onclick = function() { minifyTextarea(); }; - - function setCheckedAttrOnCheckboxes(attrValue) { - var checkboxes = byId('options').getElementsByTagName('input'); - for (var i = checkboxes.length; i--;) { - checkboxes[i].checked = attrValue; - } - } + }; byId('select-all').onclick = function() { - setCheckedAttrOnCheckboxes(true); + forEachOption(function(element) { + if (element.type === 'checkbox') { + element.checked = true; + } + }); return false; }; byId('select-none').onclick = function() { - setCheckedAttrOnCheckboxes(false); + forEachOption(function(element) { + if (element.type === 'checkbox') { + element.checked = false; + } + else { + element.value = ''; + } + }); return false; }; - byId('select-safe').onclick = function() { - setCheckedAttrOnCheckboxes(true); - var inputEls = byId('options').getElementsByTagName('input'); - inputEls[10].checked = false; - inputEls[11].checked = false; - inputEls[13].checked = false; - inputEls[18].checked = false; + var defaultOptions = getOptions(); + byId('select-defaults').onclick = function() { + for (var key in defaultOptions) { + var element = byId(key); + element[element.type === 'checkbox' ? 'checked' : 'value'] = defaultOptions[key]; + } return false; }; - })(); /* eslint-disable */ var _gaq = _gaq || []; @@ -116,3 +128,14 @@ _gaq.push(['_trackPageview']); ga.src = (document.location.protocol === 'https:' ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; document.getElementsByTagName('head')[0].appendChild(ga); })(); + +(function(i){ + var s = document.getElementById(i); + var f = document.createElement('iframe'); + f.src = (document.location.protocol === 'https:' ? 'https' : 'http') + '://api.flattr.com/button/view/?uid=kangax&button=compact&url=' + encodeURIComponent(document.URL); + f.title = 'Flattr'; + f.height = 20; + f.width = 110; + f.style.borderWidth = 0; + s.parentNode.insertBefore(f, s); +})('wrapper'); diff --git a/index.html b/index.html index cb6e637..e612a33 100644 --- a/index.html +++ b/index.html @@ -6,244 +6,312 @@ -
-
- -
-

HTML Minifier (v1.4.0)

-

- Minifier is in beta and could be rough around the edges. - However, there's an extensive test suite. -

- -
- -
- - -

-
- LINT REPORT: -
-
+
+
+

HTML Minifier (v1.4.0)

+ +
+
-
-
    -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
    - <script language="Javascript" ...>
    - <form method="get" ...>
    - <input type="text" ...>
    - <script src="..." charset="...">
    - <a id="..." name="...">
    - <... onclick="javascript:..." ...> -
    -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
  • - - -
  • -
-
- Select: - All, - None, - Safe -
+ + +

+
+ LINT REPORT: +
- - + +