From b5d67e1d163211f6f74aee733e55113073f344a5 Mon Sep 17 00:00:00 2001 From: panjiachen Date: Tue, 16 Dec 2014 13:05:20 +0800 Subject: [PATCH 1/2] fix css path contain query string bug --- cross-domain/respond.proxy.js | 2 +- dest/respond.src.js | 2 +- src/respond.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cross-domain/respond.proxy.js b/cross-domain/respond.proxy.js index 9322a354..0d2fbf95 100644 --- a/cross-domain/respond.proxy.js +++ b/cross-domain/respond.proxy.js @@ -103,7 +103,7 @@ for( var i = 0, linkl = links.length; i < linkl; i++ ){ var thislink = links[i], - href = links[i].href, + href = links[i].href.split('?')[0], extreg = (/^([a-zA-Z:]*\/\/(www\.)?)/).test( href ), ext = (baseElem && !extreg) || extreg; diff --git a/dest/respond.src.js b/dest/respond.src.js index 640f0183..adc09fa2 100644 --- a/dest/respond.src.js +++ b/dest/respond.src.js @@ -203,7 +203,7 @@ } }, ripCSS = function() { for (var i = 0; i < links.length; i++) { - var sheet = links[i], href = sheet.href, media = sheet.media, isCSS = sheet.rel && sheet.rel.toLowerCase() === "stylesheet"; + var sheet = links[i], href = sheet.href.split('?')[0], media = sheet.media, isCSS = sheet.rel && sheet.rel.toLowerCase() === "stylesheet"; if (!!href && isCSS && !parsedSheets[href]) { if (sheet.styleSheet && sheet.styleSheet.rawCssText) { translate(sheet.styleSheet.rawCssText, href, media); diff --git a/src/respond.js b/src/respond.js index 58883e4b..16570c4e 100644 --- a/src/respond.js +++ b/src/respond.js @@ -303,7 +303,7 @@ for( var i = 0; i < links.length; i++ ){ var sheet = links[ i ], - href = sheet.href, + href = sheet.href.split('?')[0], media = sheet.media, isCSS = sheet.rel && sheet.rel.toLowerCase() === "stylesheet"; From 508081959d0930f6806f5b9e1530f35a66590f1e Mon Sep 17 00:00:00 2001 From: panjiachen Date: Wed, 17 Dec 2014 10:24:07 +0800 Subject: [PATCH 2/2] fork --- cross-domain/respond-proxy.html | 136 ++++++------ cross-domain/respond.proxy.js | 239 ++++++++++----------- dest/respond.min.js | 362 +++++++++++++++++++++++++++++++- dest/respond.src.js | 23 +- src/respond.js | 27 +-- 5 files changed, 541 insertions(+), 246 deletions(-) diff --git a/cross-domain/respond-proxy.html b/cross-domain/respond-proxy.html index f828a0a5..2edff248 100644 --- a/cross-domain/respond-proxy.html +++ b/cross-domain/respond-proxy.html @@ -7,90 +7,74 @@ \ No newline at end of file diff --git a/cross-domain/respond.proxy.js b/cross-domain/respond.proxy.js index 0d2fbf95..978d2669 100644 --- a/cross-domain/respond.proxy.js +++ b/cross-domain/respond.proxy.js @@ -1,129 +1,112 @@ -/*! Respond.js: min/max-width media query polyfill. Remote proxy (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */ +/*! Respond.js: min/max-width media query polyfill. Remote proxy (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */ (function(win, doc, undefined){ - var docElem = doc.documentElement, - proxyURL = doc.getElementById("respond-proxy").href, - redirectURL = (doc.getElementById("respond-redirect") || location).href, - baseElem = doc.getElementsByTagName("base")[0], - urls = [], - refNode; - - function encode(url){ - return win.encodeURIComponent(url); - } - - function fakejax( url, callback ){ - - var iframe, - AXO; - - // All hail Google http://j.mp/iKMI19 - // Behold, an iframe proxy without annoying clicky noises. - if ( "ActiveXObject" in win ) { - AXO = new ActiveXObject( "htmlfile" ); - AXO.open(); - AXO.write( '' ); - AXO.close(); - iframe = AXO.getElementById( "x" ); - } else { - iframe = doc.createElement( "iframe" ); - iframe.style.cssText = "position:absolute;top:-99em"; - docElem.insertBefore(iframe, docElem.firstElementChild || docElem.firstChild ); - } - - iframe.src = checkBaseURL(proxyURL) + "?url=" + encode(redirectURL) + "&css=" + encode(checkBaseURL(url)); - - function checkFrameName() { - var cssText; - - try { - cssText = iframe.contentWindow.name; - } - catch (e) { } - - if (cssText) { - // We've got what we need. Stop the iframe from loading further content. - iframe.src = "about:blank"; - iframe.parentNode.removeChild(iframe); - iframe = null; - - - // Per http://j.mp/kn9EPh, not taking any chances. Flushing the ActiveXObject - if (AXO) { - AXO = null; - - if (win.CollectGarbage) { - win.CollectGarbage(); - } - } - - callback(cssText); - } - else{ - win.setTimeout(checkFrameName, 100); - } - } - - win.setTimeout(checkFrameName, 500); - } - - // http://stackoverflow.com/a/472729 - function checkBaseURL(href) { - var el = document.createElement('div'), - escapedURL = href.split('&').join('&'). - split('<').join('<'). - split('"').join('"'); - - el.innerHTML = 'x'; - return el.firstChild.href; - } - - function checkRedirectURL() { - // IE6 & IE7 don't build out absolute urls in attributes. - // So respond.proxy.gif remains relative instead of http://example.com/respond.proxy.gif. - // This trickery resolves that issue. - if (~ !redirectURL.indexOf(location.host)) { - - var fakeLink = doc.createElement("div"); - - fakeLink.innerHTML = ''; - docElem.insertBefore(fakeLink, docElem.firstElementChild || docElem.firstChild ); - - // Grab the parsed URL from that dummy object - redirectURL = fakeLink.firstChild.href; - - // Clean up - fakeLink.parentNode.removeChild(fakeLink); - fakeLink = null; - } - } - - function buildUrls(){ - var links = doc.getElementsByTagName( "link" ); - - for( var i = 0, linkl = links.length; i < linkl; i++ ){ - - var thislink = links[i], - href = links[i].href.split('?')[0], - extreg = (/^([a-zA-Z:]*\/\/(www\.)?)/).test( href ), - ext = (baseElem && !extreg) || extreg; - - //make sure it's an external stylesheet - if( thislink.rel.indexOf( "stylesheet" ) >= 0 && ext ){ - (function( link ){ - fakejax( href, function( css ){ - link.styleSheet.rawCssText = css; - respond.update(); - } ); - })( thislink ); - } - } - - - } - - if( !respond.mediaQueriesSupported ){ - checkRedirectURL(); - buildUrls(); - } - -})( window, document ); +var docElem = doc.documentElement, +proxyURL = doc.getElementById("respond-proxy").href, +redirectURL = (doc.getElementById("respond-redirect") || location).href, +urls = [], +refNode; + +function fakejax( url, callback ){ + +var iframe, +AXO; + +// All hail Google http://j.mp/iKMI19 +// Behold, an iframe proxy without annoying clicky noises. +if ( "ActiveXObject" in win ) { +AXO = new ActiveXObject( "htmlfile" ); +AXO.open(); +AXO.write( '' ); +AXO.close(); +iframe = AXO.getElementById( "x" ); +} else { +iframe = doc.createElement( "iframe" ); +iframe.style.cssText = "position:absolute;top:-99em"; +docElem.insertBefore(iframe, docElem.firstElementChild || docElem.firstChild ); +} + +iframe.src = proxyURL + "?url=" + redirectURL + "&css=" + url; + +function checkFrameName() { +var cssText; + +try { +cssText = iframe.contentWindow.name; +} +catch (e) { } + +if (cssText) { +// We've got what we need. Stop the iframe from loading further content. +iframe.src = "about:blank"; +iframe.parentNode.removeChild(iframe); +iframe = null; + + +// Per http://j.mp/kn9EPh, not taking any chances. Flushing the ActiveXObject +if (AXO) { +AXO = null; + +if (win.CollectGarbage) { +win.CollectGarbage(); +} +} + +callback(cssText); +} +else{ +win.setTimeout(checkFrameName, 100); +} +} + +win.setTimeout(checkFrameName, 500); +} + +function checkRedirectURL() { +// IE6 & IE7 don't build out absolute urls in attributes. +// So respond.proxy.gif remains relative instead of http://example.com/respond.proxy.gif. +// This trickery resolves that issue. +if (~ !redirectURL.indexOf(location.host)) { + +// Inject an attribute, with the redirectURL +var fakeLink = doc.createElement("div"); + +fakeLink.innerHTML = ''; +docElem.insertBefore(fakeLink, docElem.firstElementChild || docElem.firstChild ); + +// Grab the parsed URL from that dummy object +redirectURL = fakeLink.firstChild.href; + +// Clean up +fakeLink.parentNode.removeChild(fakeLink); +fakeLink = null; +} +} + +function buildUrls(){ +var links = doc.getElementsByTagName( "link" ); + +for( var i = 0, linkl = links.length; i < linkl; i++ ){ +var thislink = links[i], +href = links[i].href.split('?')[0], +ext = /^([a-zA-Z]+?:(\/\/)?(www\.)?)/; + +//make sure it's an external stylesheet +if( thislink.rel.indexOf( "stylesheet" ) >= 0 && ext.test( href ) ){ +(function( link ){ +fakejax( href, function( css ){ +link.styleSheet.rawCssText = css; +respond.update(); +} ); +})( thislink ); +} +} + + +} + +if( !respond.mediaQueriesSupported ){ +checkRedirectURL(); +buildUrls(); +} + +})( window, document ); \ No newline at end of file diff --git a/dest/respond.min.js b/dest/respond.min.js index e8d6207f..fdab352a 100644 --- a/dest/respond.min.js +++ b/dest/respond.min.js @@ -1,6 +1,358 @@ -/*! Respond.js v1.4.2: min/max-width media query polyfill - * Copyright 2014 Scott Jehl - * Licensed under MIT - * http://j.mp/respondjs */ +/* Respond.js: min/max-width media query polyfill. (c) Scott Jehl. MIT Lic. j.mp/respondjs */ +(function( w ){ -!function(a){"use strict";a.matchMedia=a.matchMedia||function(a){var b,c=a.documentElement,d=c.firstElementChild||c.firstChild,e=a.createElement("body"),f=a.createElement("div");return f.id="mq-test-1",f.style.cssText="position:absolute;top:-100em",e.style.background="none",e.appendChild(f),function(a){return f.innerHTML='­',c.insertBefore(e,d),b=42===f.offsetWidth,c.removeChild(e),{matches:b,media:a}}}(a.document)}(this),function(a){"use strict";function b(){v(!0)}var c={};a.respond=c,c.update=function(){};var d=[],e=function(){var b=!1;try{b=new a.XMLHttpRequest}catch(c){b=new a.ActiveXObject("Microsoft.XMLHTTP")}return function(){return b}}(),f=function(a,b){var c=e();c&&(c.open("GET",a,!0),c.onreadystatechange=function(){4!==c.readyState||200!==c.status&&304!==c.status||b(c.responseText)},4!==c.readyState&&c.send(null))},g=function(a){return a.replace(c.regex.minmaxwh,"").match(c.regex.other)};if(c.ajax=f,c.queue=d,c.unsupportedmq=g,c.regex={media:/@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi,keyframes:/@(?:\-(?:o|moz|webkit)\-)?keyframes[^\{]+\{(?:[^\{\}]*\{[^\}\{]*\})+[^\}]*\}/gi,comments:/\/\*[^*]*\*+([^/][^*]*\*+)*\//gi,urls:/(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,findStyles:/@media *([^\{]+)\{([\S\s]+?)$/,only:/(only\s+)?([a-zA-Z]+)\s?/,minw:/\(\s*min\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/,maxw:/\(\s*max\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/,minmaxwh:/\(\s*m(in|ax)\-(height|width)\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/gi,other:/\([^\)]*\)/g},c.mediaQueriesSupported=a.matchMedia&&null!==a.matchMedia("only all")&&a.matchMedia("only all").matches,!c.mediaQueriesSupported){var h,i,j,k=a.document,l=k.documentElement,m=[],n=[],o=[],p={},q=30,r=k.getElementsByTagName("head")[0]||l,s=k.getElementsByTagName("base")[0],t=r.getElementsByTagName("link"),u=function(){var a,b=k.createElement("div"),c=k.body,d=l.style.fontSize,e=c&&c.style.fontSize,f=!1;return b.style.cssText="position:absolute;font-size:1em;width:1em",c||(c=f=k.createElement("body"),c.style.background="none"),l.style.fontSize="100%",c.style.fontSize="100%",c.appendChild(b),f&&l.insertBefore(c,l.firstChild),a=b.offsetWidth,f?l.removeChild(c):c.removeChild(b),l.style.fontSize=d,e&&(c.style.fontSize=e),a=j=parseFloat(a)},v=function(b){var c="clientWidth",d=l[c],e="CSS1Compat"===k.compatMode&&d||k.body[c]||d,f={},g=t[t.length-1],p=(new Date).getTime();if(b&&h&&q>p-h)return a.clearTimeout(i),i=a.setTimeout(v,q),void 0;h=p;for(var s in m)if(m.hasOwnProperty(s)){var w=m[s],x=w.minw,y=w.maxw,z=null===x,A=null===y,B="em";x&&(x=parseFloat(x)*(x.indexOf(B)>-1?j||u():1)),y&&(y=parseFloat(y)*(y.indexOf(B)>-1?j||u():1)),w.hasquery&&(z&&A||!(z||e>=x)||!(A||y>=e))||(f[w.media]||(f[w.media]=[]),f[w.media].push(n[w.rules]))}for(var C in o)o.hasOwnProperty(C)&&o[C]&&o[C].parentNode===r&&r.removeChild(o[C]);o.length=0;for(var D in f)if(f.hasOwnProperty(D)){var E=k.createElement("style"),F=f[D].join("\n");E.type="text/css",E.media=D,r.insertBefore(E,g.nextSibling),E.styleSheet?E.styleSheet.cssText=F:E.appendChild(k.createTextNode(F)),o.push(E)}},w=function(a,b,d){var e=a.replace(c.regex.comments,"").replace(c.regex.keyframes,"").match(c.regex.media),f=e&&e.length||0;b=b.substring(0,b.lastIndexOf("/"));var h=function(a){return a.replace(c.regex.urls,"$1"+b+"$2$3")},i=!f&&d;b.length&&(b+="/"),i&&(f=1);for(var j=0;f>j;j++){var k,l,o,p;i?(k=d,n.push(h(a))):(k=e[j].match(c.regex.findStyles)&&RegExp.$1,n.push(RegExp.$2&&h(RegExp.$2))),o=k.split(","),p=o.length;for(var q=0;p>q;q++)l=o[q],g(l)||m.push({media:l.split("(")[0].match(c.regex.only)&&RegExp.$2||"all",rules:n.length-1,hasquery:l.indexOf("(")>-1,minw:l.match(c.regex.minw)&&parseFloat(RegExp.$1)+(RegExp.$2||""),maxw:l.match(c.regex.maxw)&&parseFloat(RegExp.$1)+(RegExp.$2||"")})}v()},x=function(){if(d.length){var b=d.shift();f(b.href,function(c){w(c,b.href,b.media),p[b.href]=!0,a.setTimeout(function(){x()},0)})}},y=function(){for(var b=0;b -1 ? ( eminpx || getEmValue() ) : 1 ); + } + if( !!max ){ + max = parseFloat( max ) * ( max.indexOf( em ) > -1 ? ( eminpx || getEmValue() ) : 1 ); + } + + // if there's no media query at all (the () part), or min or max is not null, and if either is present, they're true + if( !thisstyle.hasquery || ( !minnull || !maxnull ) && ( minnull || currWidth >= min ) && ( maxnull || currWidth <= max ) ){ + if( !styleBlocks[ thisstyle.media ] ){ + styleBlocks[ thisstyle.media ] = []; + } + styleBlocks[ thisstyle.media ].push( rules[ thisstyle.rules ] ); + } + } + } + + //remove any existing respond style element(s) + for( var j in appendedEls ){ + if( appendedEls.hasOwnProperty( j ) ){ + if( appendedEls[ j ] && appendedEls[ j ].parentNode === head ){ + head.removeChild( appendedEls[ j ] ); + } + } + } + appendedEls.length = 0; + + //inject active styles, grouped by media type + for( var k in styleBlocks ){ + if( styleBlocks.hasOwnProperty( k ) ){ + var ss = doc.createElement( "style" ), + css = styleBlocks[ k ].join( "\n" ); + + ss.type = "text/css"; + ss.media = k; + + //originally, ss was appended to a documentFragment and sheets were appended in bulk. + //this caused crashes in IE in a number of circumstances, such as when the HTML element had a bg image set, so appending beforehand seems best. Thanks to @dvelyk for the initial research on this one! + head.insertBefore( ss, lastLink.nextSibling ); + + if ( ss.styleSheet ){ + ss.styleSheet.cssText = css; + } + else { + ss.appendChild( doc.createTextNode( css ) ); + } + + //push to appendedEls to track for later removal + appendedEls.push( ss ); + } + } + }, + //find media blocks in css text, convert to style blocks + translate = function( styles, href, media ){ + var qs = styles.replace( respond.regex.comments, '' ) + .replace( respond.regex.keyframes, '' ) + .match( respond.regex.media ), + ql = qs && qs.length || 0; + + //try to get CSS path + href = href.substring( 0, href.lastIndexOf( "/" ) ); + + var repUrls = function( css ){ + return css.replace( respond.regex.urls, "$1" + href + "$2$3" ); + }, + useMedia = !ql && media; + + //if path exists, tack on trailing slash + if( href.length ){ href += "/"; } + + //if no internal queries exist, but media attr does, use that + //note: this currently lacks support for situations where a media attr is specified on a link AND + //its associated stylesheet has internal CSS media queries. + //In those cases, the media attribute will currently be ignored. + if( useMedia ){ + ql = 1; + } + + for( var i = 0; i < ql; i++ ){ + var fullq, thisq, eachq, eql; + + //media attr + if( useMedia ){ + fullq = media; + rules.push( repUrls( styles ) ); + } + //parse for styles + else{ + fullq = qs[ i ].match( respond.regex.findStyles ) && RegExp.$1; + rules.push( RegExp.$2 && repUrls( RegExp.$2 ) ); + } + + eachq = fullq.split( "," ); + eql = eachq.length; + + for( var j = 0; j < eql; j++ ){ + thisq = eachq[ j ]; + + if( isUnsupportedMediaQuery( thisq ) ) { + continue; + } + + mediastyles.push( { + media : thisq.split( "(" )[ 0 ].match( respond.regex.only ) && RegExp.$2 || "all", + rules : rules.length - 1, + hasquery : thisq.indexOf("(") > -1, + minw : thisq.match( respond.regex.minw ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" ), + maxw : thisq.match( respond.regex.maxw ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" ) + } ); + } + } + + applyMedia(); + }, + + //recurse through request queue, get css text + makeRequests = function(){ + // alert(requestQueue.length); + if( requestQueue.length ){ + + var thisRequest = requestQueue.shift(); + ajax( thisRequest.href, function( styles ){ + translate( styles, thisRequest.href, thisRequest.media ); + parsedSheets[ thisRequest.href ] = true; + + // by wrapping recursive function call in setTimeout + // we prevent "Stack overflow" error in IE7 + w.setTimeout(function(){ makeRequests(); },0); + } ); + } + }, + + //loop stylesheets, send text content to translate + ripCSS = function(){ + + for( var i = 0; i < links.length; i++ ){ + var sheet = links[ i ], + href = sheet.href.split('?')[0], + media = sheet.media, + isCSS = sheet.rel && sheet.rel.toLowerCase() === "stylesheet"; + //only links plz and prevent re-parsing + if( !!href && isCSS && !parsedSheets[ href ] ){ + // selectivizr exposes css through the rawCssText expando + // alert(sheet.styleSheet.rawCssText); + if (sheet.styleSheet && sheet.styleSheet.rawCssText) { + translate( sheet.styleSheet.rawCssText, href, media ); + + parsedSheets[ href ] = true; + // alert(href); + } else { + + if( (!/^([a-zA-Z:]*\/\/)/.test( href ) && !base) || + href.replace( RegExp.$1, "" ).split( "/" )[0] === w.location.host ){ + + // IE7 doesn't handle urls that start with '//' for ajax request + // manually add in the protocol + + if ( href.substring(0,2) === "//" ) { href = w.location.protocol + href; } + requestQueue.push( { + href: href, + media: media + } ); + } + } + } + } + makeRequests(); + }; + + //translate CSS + ripCSS(); + + //expose update for re-running respond later on + respond.update = ripCSS; + + //expose getEmValue + respond.getEmValue = getEmValue; + + //adjust on resize + function callMedia(){ + applyMedia( true ); + } + + if( w.addEventListener ){ + w.addEventListener( "resize", callMedia, false ); + } + else if( w.attachEvent ){ + w.attachEvent( "onresize", callMedia ); + } +})(this); \ No newline at end of file diff --git a/dest/respond.src.js b/dest/respond.src.js index adc09fa2..b1298d07 100644 --- a/dest/respond.src.js +++ b/dest/respond.src.js @@ -1,8 +1,3 @@ -/*! Respond.js v1.4.2: min/max-width media query polyfill - * Copyright 2014 Scott Jehl - * Licensed under MIT - * http://j.mp/respondjs */ - /*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */ /*! NOTE: If you're already including a window.matchMedia polyfill via Modernizr or otherwise, you don't need this part */ (function(w) { @@ -26,6 +21,7 @@ }(w.document); })(this); +/*! Respond.js v1.4.0: min/max-width media query polyfill. (c) Scott Jehl. MIT Lic. j.mp/respondjs */ (function(w) { "use strict"; var respond = {}; @@ -57,23 +53,17 @@ return; } req.send(null); - }, isUnsupportedMediaQuery = function(query) { - return query.replace(respond.regex.minmaxwh, "").match(respond.regex.other); }; respond.ajax = ajax; respond.queue = requestQueue; - respond.unsupportedmq = isUnsupportedMediaQuery; respond.regex = { media: /@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi, keyframes: /@(?:\-(?:o|moz|webkit)\-)?keyframes[^\{]+\{(?:[^\{\}]*\{[^\}\{]*\})+[^\}]*\}/gi, - comments: /\/\*[^*]*\*+([^/][^*]*\*+)*\//gi, urls: /(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g, findStyles: /@media *([^\{]+)\{([\S\s]+?)$/, only: /(only\s+)?([a-zA-Z]+)\s?/, - minw: /\(\s*min\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/, - maxw: /\(\s*max\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/, - minmaxwh: /\(\s*m(in|ax)\-(height|width)\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/gi, - other: /\([^\)]*\)/g + minw: /\([\s]*min\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/, + maxw: /\([\s]*max\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/ }; respond.mediaQueriesSupported = w.matchMedia && w.matchMedia("only all") !== null && w.matchMedia("only all").matches; if (respond.mediaQueriesSupported) { @@ -153,7 +143,7 @@ } } }, translate = function(styles, href, media) { - var qs = styles.replace(respond.regex.comments, "").replace(respond.regex.keyframes, "").match(respond.regex.media), ql = qs && qs.length || 0; + var qs = styles.replace(respond.regex.keyframes, "").match(respond.regex.media), ql = qs && qs.length || 0; href = href.substring(0, href.lastIndexOf("/")); var repUrls = function(css) { return css.replace(respond.regex.urls, "$1" + href + "$2$3"); @@ -177,9 +167,6 @@ eql = eachq.length; for (var j = 0; j < eql; j++) { thisq = eachq[j]; - if (isUnsupportedMediaQuery(thisq)) { - continue; - } mediastyles.push({ media: thisq.split("(")[0].match(respond.regex.only) && RegExp.$2 || "all", rules: rules.length - 1, @@ -203,7 +190,7 @@ } }, ripCSS = function() { for (var i = 0; i < links.length; i++) { - var sheet = links[i], href = sheet.href.split('?')[0], media = sheet.media, isCSS = sheet.rel && sheet.rel.toLowerCase() === "stylesheet"; + var sheet = links[i], href = sheet.href, media = sheet.media, isCSS = sheet.rel && sheet.rel.toLowerCase() === "stylesheet"; if (!!href && isCSS && !parsedSheets[href]) { if (sheet.styleSheet && sheet.styleSheet.rawCssText) { translate(sheet.styleSheet.rawCssText, href, media); diff --git a/src/respond.js b/src/respond.js index 16570c4e..ecf2707d 100644 --- a/src/respond.js +++ b/src/respond.js @@ -1,4 +1,4 @@ -/* Respond.js: min/max-width media query polyfill. (c) Scott Jehl. MIT Lic. j.mp/respondjs */ +/*! Respond.js v1.4.0: min/max-width media query polyfill. (c) Scott Jehl. MIT Lic. j.mp/respondjs */ (function( w ){ "use strict"; @@ -42,26 +42,21 @@ return; } req.send( null ); - }, - isUnsupportedMediaQuery = function( query ) { - return query.replace( respond.regex.minmaxwh, '' ).match( respond.regex.other ); }; //expose for testing respond.ajax = ajax; respond.queue = requestQueue; - respond.unsupportedmq = isUnsupportedMediaQuery; + + // expose for testing respond.regex = { media: /@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi, keyframes: /@(?:\-(?:o|moz|webkit)\-)?keyframes[^\{]+\{(?:[^\{\}]*\{[^\}\{]*\})+[^\}]*\}/gi, - comments: /\/\*[^*]*\*+([^/][^*]*\*+)*\//gi, urls: /(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g, findStyles: /@media *([^\{]+)\{([\S\s]+?)$/, only: /(only\s+)?([a-zA-Z]+)\s?/, - minw: /\(\s*min\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/, - maxw: /\(\s*max\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/, - minmaxwh: /\(\s*m(in|ax)\-(height|width)\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/gi, - other: /\([^\)]*\)/g + minw: /\([\s]*min\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/, + maxw: /\([\s]*max\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/ }; //expose media query support flag for external use @@ -221,13 +216,12 @@ }, //find media blocks in css text, convert to style blocks translate = function( styles, href, media ){ - var qs = styles.replace( respond.regex.comments, '' ) - .replace( respond.regex.keyframes, '' ) - .match( respond.regex.media ), + var qs = styles.replace( respond.regex.keyframes, '' ).match( respond.regex.media ), ql = qs && qs.length || 0; //try to get CSS path href = href.substring( 0, href.lastIndexOf( "/" ) ); + var repUrls = function( css ){ return css.replace( respond.regex.urls, "$1" + href + "$2$3" ); @@ -264,11 +258,6 @@ for( var j = 0; j < eql; j++ ){ thisq = eachq[ j ]; - - if( isUnsupportedMediaQuery( thisq ) ) { - continue; - } - mediastyles.push( { media : thisq.split( "(" )[ 0 ].match( respond.regex.only ) && RegExp.$2 || "all", rules : rules.length - 1, @@ -303,7 +292,7 @@ for( var i = 0; i < links.length; i++ ){ var sheet = links[ i ], - href = sheet.href.split('?')[0], + href = sheet.href, media = sheet.media, isCSS = sheet.rel && sheet.rel.toLowerCase() === "stylesheet";