Add todo section;
authorJuriy Zaytsev <kangax@gmail.com>
Fri, 5 Feb 2010 23:32:41 +0000 (18:32 -0500)
committerJuriy Zaytsev <kangax@gmail.com>
Fri, 5 Feb 2010 23:32:41 +0000 (18:32 -0500)
Add warning about draft state of minifier;
Rearrange UI slightly;
Whitepaces are now collapsed to 0 characters by default (instead of 1);
Make sure tags and attribute names match in a case-insensitive manner.

index.html
master.css
master.js

index 726219f..e506f77 100644 (file)
               </label>
             </li>
           </ul>
-          <p><button type="button" id="convert-btn">Convert</button></p>
         </div>
       </div>
+      <p><button type="button" id="convert-btn">Convert</button></p>
       <textarea rows="8" cols="40" id="output" readonly></textarea>
       <p id="stats"></p>
+      <p id="warning">
+        Minifier is <strong>very draft</strong> and is <strong>not yet thoroughly tested</strong>. Use at your own risk. 
+      </p>
+      <div id="todo">
+        TODO:
+        <ul>
+          <li>Detect empty elements/attributes</li>
+          <li>Detect smells like "javascript:" in event attributes</li>
+          <li>Report deprecated (or presentational) attributes (e.g.: <code>&lt;td width="..." height="..."></code>)</li>
+          <li>Add option to collapse all whitespace to 1 character, instead of completely removing it (to preserve empty text nodes)</li>
+          <li>Figure out when it is safe to remove optional closing tags, so that it doesn't affect document tree</li>
+          <li>Replace NAME attributes with IDs when they serve as anchors (e.g. on <code>A</code> elements)</li>
+        </ul>
+      </div>
       <p class="quiet" style="font-style:italic;">
-        Minifier is made by <a href="http://twitter.com/kangax/">kangax</a>, 
+        Minifier is made by <a href="http://perfectionkills.com/">kangax</a>, 
         using tweaked version of HTML parser by <a href="http://ejohn.org/">John Resig</a> 
         (which, in its turn, is based on work of <a href="http://erik.eae.net/">Erik Arvidsson</a>).
       </p>
index bd5bfc9..ee4402e 100644 (file)
@@ -1,15 +1,19 @@
 body { font-family: "Cambria", Georgia, Times, "Times New Roman", serif; }
 textarea { height: 20em; }
 h1 { margin-top: 0.5em; font-size: 1.25em; }
+button { font-weight: bold; width: 100px; }
 
 #wrapper { overflow: hidden; min-width: 900px; }
-#input { width: 65%; margin-bottom: 1em; }
-#output { width: 100%; height: 18em; }
+#input { width: 65%; }
+#output { width: 100%; height: 18em; margin-bottom: 2em; }
 #options { float: right; width: 33%; padding-left: 1em; }
 #options ul { list-style: none; padding: 0.5em; overflow: hidden; background: #ffe; margin-top: 0; }
 #options ul li { float: left; clear: both; padding-bottom: 0.5em; }
 #options label, #options input { float: left; }
 #options input { margin-right: 0.5em; }
+#stats { margin-bottom: 2em; }
+#todo { font-family: monospace; }
+#warning { background: #fcc; padding: 0.25em; display: inline-block; }
 
 .success { color: green; }
 .failure { color: red; }
index 64f9123..3948cd2 100644 (file)
--- a/master.js
+++ b/master.js
@@ -29,7 +29,7 @@
     return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
   }
   function collapseWhitespace(str) {
-    return str.replace(/^\s+/, ' ').replace(/\s+$/, ' ');
+    return str.replace(/^\s+/, '').replace(/\s+$/, '');
   }
   function canRemoveAttributeQuotes(value) {
     // http://www.w3.org/TR/html4/intro/sgmltut.html#attributes
   }
   function isAttributeRedundant(tag, attributeName, attributeValue) {
     return (
-        (tag === 'script' && 
-        attributeName === 'language' && 
+        (/^script$/i.test(tag) && 
+        /^language$/i.test(attributeName) && 
         /^javascript$/i.test(attributeValue)) ||
         
-        (tag === 'form' && 
-        attributeName === 'method' && 
+        (/^form$/i.test(tag) && 
+        /^method$/i.test(attributeName) && 
         /^get$/i.test(attributeValue)) ||
         
-        (tag === 'input' && 
-        attributeName === 'type' && 
+        (/^input$/i.test(tag) && 
+        /^type$/i.test(attributeName) &&
         /^text$/i.test(attributeValue))
     );
   }