Skip to content

Commit

Permalink
Update Respond.js to improved, comment-free version. Remove the CSS c…
Browse files Browse the repository at this point in the history
…omments that the old version of Respond required.
  • Loading branch information
necolas committed Jun 2, 2011
1 parent 4504c11 commit ab3abb6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 36 deletions.
4 changes: 2 additions & 2 deletions css/style.css
Expand Up @@ -214,12 +214,12 @@ h1, h2, h3, h4, h5, h6 { font-weight: bold; }
@media only screen and (min-width: 480px) {
/* Style adjustments for viewports 480px and over go here */

}/*/mediaquery*/
}

@media only screen and (min-width: 768px) {
/* Style adjustments for viewports 768px and over go here */

}/*/mediaquery*/
}



Expand Down
54 changes: 27 additions & 27 deletions js/libs/respond.js
@@ -1,9 +1,4 @@
/*
* respond.js - A small and fast polyfill for min/max-width CSS3 Media Queries
* Copyright 2011, Scott Jehl, scottjehl.com
* Dual licensed under the MIT or GPL Version 2 licenses.
* Usage: Check out the readme file or github.com/scottjehl/respond
*/
/*! Respond.js: min/max-width media query polyfill. (c) Scott Jehl. MIT Lic. j.mp/respondjs */
(function( win, mqSupported ){
//exposed namespace
win.respond = {};
Expand Down Expand Up @@ -32,13 +27,16 @@
//loop stylesheets, send text content to translate
ripCSS = function(){
var sheets = links,
sl = sheets.length;
sl = sheets.length,
i = 0,
//vars for loop:
sheet, href, media, isCSS;

for( var i = 0; i < sl; i++ ){
var sheet = sheets[ i ],
href = sheet.href,
media = sheet.media,
isCSS = sheet.rel && sheet.rel.toLowerCase() === "stylesheet";
for( ; i < sl; i++ ){
sheet = sheets[ i ],
href = sheet.href,
media = sheet.media,
isCSS = sheet.rel && sheet.rel.toLowerCase() === "stylesheet";

//only links plz and prevent re-parsing
if( !!href && isCSS && !parsedSheets[ href ] ){
Expand Down Expand Up @@ -72,15 +70,18 @@
},

//find media blocks in css text, convert to style blocks
translate = function( styles, href, media ){
var qs = styles.match( /@media ([^\{]+)\{((?!@media)[\s\S])*(?=\}[\s]*\/\*\/mediaquery\*\/)/gmi ),
ql = qs && qs.length || 0,
translate = function( styles, href, media ){
var qs = styles.match( /@media[^\{]+\{([^\{\}]+\{[^\}\{]+\})+/gi ),
ql = qs && qs.length || 0,
//try to get CSS path
href = href.substring( 0, href.lastIndexOf( "/" )),
repUrls = function( css ){
href = href.substring( 0, href.lastIndexOf( "/" )),
repUrls = function( css ){
return css.replace( /(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g, "$1" + href + "$2$3" );
},
useMedia = !ql && media;
useMedia = !ql && media,
//vars used in loop
i = 0,
j, fullq, thisq, eachq, eql;

//if path exists, tack on trailing slash
if( href.length ){ href += "/"; }
Expand All @@ -94,8 +95,8 @@
}


for( var i = 0; i < ql; i++ ){
var fullq;
for( ; i < ql; i++ ){
j = 0;

//media attr
if( useMedia ){
Expand All @@ -107,12 +108,13 @@
fullq = qs[ i ].match( /@media ([^\{]+)\{([\S\s]+?)$/ ) && RegExp.$1;
rules.push( RegExp.$2 && repUrls( RegExp.$2 ) );
}

var eachq = fullq.split( "," ),
eql = eachq.length;

eachq = fullq.split( "," );
eql = eachq.length;


for( var j = 0; j < eql; j++ ){
var thisq = eachq[ j ];
for( ; j < eql; j++ ){
thisq = eachq[ j ];
mediastyles.push( {
media : thisq.match( /(only\s+)?([a-zA-Z]+)(\sand)?/ ) && RegExp.$2,
rules : rules.length - 1,
Expand Down Expand Up @@ -212,8 +214,6 @@
var xmlhttpmethod = false,
attempts = [
function(){ return new ActiveXObject("Microsoft.XMLHTTP") },
function(){ return new ActiveXObject("Msxml3.XMLHTTP") },
function(){ return new ActiveXObject("Msxml2.XMLHTTP") },
function(){ return new XMLHttpRequest() }
],
al = attempts.length;
Expand Down
9 changes: 2 additions & 7 deletions js/libs/respond.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ab3abb6

Please sign in to comment.