From e7d351015563f4a302def825ee492a844ff10e54 Mon Sep 17 00:00:00 2001 From: Chuck Carpenter Date: Sat, 21 Jun 2014 19:28:28 -0300 Subject: [PATCH] update the minified and cleanup some white space --- .jshintrc | 7 ++++++- js/rem.js | 34 +++++++++++++++++----------------- js/rem.min.js | 6 +++--- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/.jshintrc b/.jshintrc index 3cc877f..f153bce 100644 --- a/.jshintrc +++ b/.jshintrc @@ -17,5 +17,10 @@ "strict": false, "trailing": true, "smarttabs": true, - "globals": {"define": false} + "supernew": false, + "globals": { + "define": false, + "XDomainRequest": false, + "ActiveXObject": false + } } diff --git a/js/rem.js b/js/rem.js index a3fb20b..a58bf9d 100644 --- a/js/rem.js +++ b/js/rem.js @@ -122,16 +122,16 @@ try { var xhr = getXMLHttpRequest(), isOldIE = document.all; - + xhr.open( 'GET', url, true ); xhr.send(null); - + // Better way for IE versions detection: http://tanalin.com/en/articles/ie-version-js/ - + if ( !isOldIE || (isOldIE && window.XMLHttpRequest) ){ //If IE is greater than 6 // This targets modern browsers and modern versions of IE, // which don't need the "new" keyword. - xhr.onreadystatechange = function () { + xhr.onreadystatechange = function() { if ( xhr.readyState === 4 ){ callback(xhr, i); } // else { callback function on AJAX error } @@ -214,41 +214,41 @@ css = [], // initialize the array holding the parsed rules for use later fontSize = ''; - // Notice: rem is a "root em" that means that in case when html element size was changed by css - // or style we should not change document.documentElement.fontSize to 1em - only body size should be changed + // Notice: rem is a "root em" that means that in case when html element size was changed by css + // or style we should not change document.documentElement.fontSize to 1em - only body size should be changed // to 1em for calculation - + fontSize = (function () { var doc = document, docElement = doc.documentElement, body = doc.body || doc.createElement('body'), isFakeBody = !doc.body, - div = doc.createElement('div'), + div = doc.createElement('div'), currentSize = body.style.fontSize, size; - + if ( isFakeBody ) { docElement.appendChild( body ); } - - div.style.cssText = 'width:1em; position:absolute; visibility:hidden; padding: 0;'; - + + div.style.cssText = 'width:1em; position:absolute; visibility:hidden; padding: 0;'; + body.style.fontSize = '1em'; - + body.appendChild( div ); size = div.offsetWidth; - + if ( isFakeBody ) { docElement.removeChild( body ); } else { body.removeChild( div ); - body.style.fontSize = currentSize; + body.style.fontSize = currentSize; } - + return size; }()); - + processLinks(); } // else { do nothing, you are awesome and have REM support } diff --git a/js/rem.min.js b/js/rem.min.js index 4fc696c..526d096 100644 --- a/js/rem.min.js +++ b/js/rem.min.js @@ -1,7 +1,7 @@ /** - * Module: rem - v1.2.2 + * Module: rem - v1.2.4 * Description: A polyfill to parse CSS links and rewrite pixel equivalents into head for non supporting browsers - * Date Built: 2014-04-05 + * Date Built: 2014-06-21 * Copyright (c) 2014 | Chuck Carpenter ,Lucas Serven ; **/ -(function(window,undefined){var cssremunit=function(){var div=document.createElement("div");div.style.cssText="font-size: 1rem;";return/rem/.test(div.style.fontSize)},isStyleSheet=function(){var styles=document.getElementsByTagName("link"),filteredLinks=[];for(var i=0;i0){CSSLinks=[];preCSS=[];importLinks=[];processLinks()}else buildCSS()}},matchCSS=function(sheetCSS,link){var clean=removeComments(removeMediaQueries(sheetCSS)),pattern=/[\w\d\s\-\/\\\[\]:,.'"*()<>+~%#^$_=|@]+\{[\w\d\s\-\/\\%#:!;,.'"*()]+\d*\.?\d+rem[\w\d\s\-\/\\%#:!;,.'"*()]*\}/g,current=clean.match(pattern),remPattern=/\d*\.?\d+rem/g,remCurrent=clean.match(remPattern),sheetPathPattern=/(.*\/)/,sheetPath=sheetPathPattern.exec(link)[0],importPattern=/@import (?:url\()?['"]?([^'\)"]*)['"]?\)?[^;]*/gm,importStatement;while((importStatement=importPattern.exec(sheetCSS))!==null)importLinks.push(sheetPath+importStatement[1]);if(current!==null&¤t.length!==0){found=found.concat(current);foundProps=foundProps.concat(remCurrent)}},buildCSS=function(){var pattern=/[\w\d\s\-\/\\%#:,.'"*()]+\d*\.?\d+rem[\w\d\s\-\/\\%#:!,.'"*()]*[;}]/g;for(var i=0;i-1&&end>start){css=css.substring(0,start)+css.substring(end+2);start=css.search(/\/\*/);end=css.search(/\*\//)}return css},mediaQuery=function(){if(window.matchMedia||window.msMatchMedia)return true;return false},removeMediaQueries=function(css){if(!mediaQuery())css=css.replace(/@media[\s\S]*?\}\s*\}/g,"");return css},getXMLHttpRequest=function(){if(window.XMLHttpRequest)return new XMLHttpRequest;else try{return new ActiveXObject("MSXML2.XMLHTTP")}catch(e1){try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(e2){}}};if(!cssremunit()){var rules="",links=[],importLinks=[],found=[],foundProps=[],preCSS=[],CSSLinks=[],css=[],fontSize="";fontSize=function(){var doc=document,docElement=doc.documentElement,body=doc.body||doc.createElement("body"),isFakeBody=!doc.body,div=doc.createElement("div"),currentSize=body.style.fontSize,size;if(isFakeBody)docElement.appendChild(body);div.style.cssText="width:1em; position:absolute; visibility:hidden; padding: 0;";body.style.fontSize="1em";body.appendChild(div);size=div.offsetWidth;if(isFakeBody)docElement.removeChild(body);else{body.removeChild(div);body.style.fontSize=currentSize}return size}();processLinks()}})(window); +!function(a){"use strict";var b=function(){var a=document.createElement("div");return a.style.cssText="font-size: 1rem;",/rem/.test(a.style.fontSize)},c=function(){for(var a=document.getElementsByTagName("link"),b=[],c=0;c0?(u=[],t=[],q=[],d()):g()}},f=function(a,b){for(var c,d=k(m(a)),e=/[\w\d\s\-\/\\\[\]:,.'"*()<>+~%#^$_=|@]+\{[\w\d\s\-\/\\%#:!;,.'"*()]+\d*\.?\d+rem[\w\d\s\-\/\\%#:!;,.'"*()]*\}/g,f=d.match(e),g=/\d*\.?\d+rem/g,h=d.match(g),i=/(.*\/)/,j=i.exec(b)[0],l=/@import (?:url\()?['"]?([^'\)"]*)['"]?\)?[^;]*/gm;null!==(c=l.exec(a));)q.push(j+c[1]);null!==f&&0!==f.length&&(r=r.concat(f),s=s.concat(h))},g=function(){for(var a=/[\w\d\s\-\/\\%#:,.'"*()]+\d*\.?\d+rem[\w\d\s\-\/\\%#:!,.'"*()]*[;}]/g,b=0;b-1&&c>b;)a=a.substring(0,b)+a.substring(c+2),b=a.search(/\/\*/),c=a.search(/\*\//);return a},l=function(){return a.matchMedia||a.msMatchMedia?!0:!1},m=function(a){return l()||(a=a.replace(/@media[\s\S]*?\}\s*\}/g,"")),a},n=function(){if(a.XMLHttpRequest)return new XMLHttpRequest;try{return new ActiveXObject("MSXML2.XMLHTTP")}catch(b){try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(c){}}};if(!b()){var o="",p=[],q=[],r=[],s=[],t=[],u=[],v=[],w="";w=function(){var a,b=document,c=b.documentElement,d=b.body||b.createElement("body"),e=!b.body,f=b.createElement("div"),g=d.style.fontSize;return e&&c.appendChild(d),f.style.cssText="width:1em; position:absolute; visibility:hidden; padding: 0;",d.style.fontSize="1em",d.appendChild(f),a=f.offsetWidth,e?c.removeChild(d):(d.removeChild(f),d.style.fontSize=g),a}(),d()}}(window); \ No newline at end of file