twbs_less_rails 2.5.1 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/Gemfile.lock +1 -1
  4. data/Rakefile +55 -21
  5. data/lib/twbs_less_rails/version.rb +1 -1
  6. data/vendor/assets/javascripts/respond.js +209 -211
  7. data/vendor/assets/javascripts/twbs/bootstrap/affix.js +1 -1
  8. data/vendor/assets/javascripts/twbs/bootstrap/alert.js +1 -1
  9. data/vendor/assets/javascripts/twbs/bootstrap/button.js +11 -5
  10. data/vendor/assets/javascripts/twbs/bootstrap/carousel.js +5 -5
  11. data/vendor/assets/javascripts/twbs/bootstrap/collapse.js +1 -1
  12. data/vendor/assets/javascripts/twbs/bootstrap/dropdown.js +5 -5
  13. data/vendor/assets/javascripts/twbs/bootstrap/modal.js +1 -1
  14. data/vendor/assets/javascripts/twbs/bootstrap/popover.js +1 -1
  15. data/vendor/assets/javascripts/twbs/bootstrap/scrollspy.js +2 -2
  16. data/vendor/assets/javascripts/twbs/bootstrap/tab.js +1 -1
  17. data/vendor/assets/javascripts/twbs/bootstrap/tooltip.js +1 -1
  18. data/vendor/assets/javascripts/twbs/bootstrap/transition.js +1 -1
  19. data/vendor/assets/stylesheets/twbs/bootstrap/badges.less +6 -6
  20. data/vendor/assets/stylesheets/twbs/bootstrap/button-groups.less +7 -33
  21. data/vendor/assets/stylesheets/twbs/bootstrap/buttons.less +2 -5
  22. data/vendor/assets/stylesheets/twbs/bootstrap/carousel.less +1 -0
  23. data/vendor/assets/stylesheets/twbs/bootstrap/dropdowns.less +3 -8
  24. data/vendor/assets/stylesheets/twbs/bootstrap/forms.less +11 -0
  25. data/vendor/assets/stylesheets/twbs/bootstrap/glyphicons.less +1 -1
  26. data/vendor/assets/stylesheets/twbs/bootstrap/grid.less +12 -26
  27. data/vendor/assets/stylesheets/twbs/bootstrap/input-groups.less +1 -1
  28. data/vendor/assets/stylesheets/twbs/bootstrap/jumbotron.less +8 -2
  29. data/vendor/assets/stylesheets/twbs/bootstrap/labels.less +6 -0
  30. data/vendor/assets/stylesheets/twbs/bootstrap/mixins.less +37 -50
  31. data/vendor/assets/stylesheets/twbs/bootstrap/modals.less +2 -5
  32. data/vendor/assets/stylesheets/twbs/bootstrap/navbar.less +41 -53
  33. data/vendor/assets/stylesheets/twbs/bootstrap/navs.less +0 -20
  34. data/vendor/assets/stylesheets/twbs/bootstrap/panels.less +11 -1
  35. data/vendor/assets/stylesheets/twbs/bootstrap/progress-bars.less +0 -12
  36. data/vendor/assets/stylesheets/twbs/bootstrap/tables.less +5 -18
  37. data/vendor/assets/stylesheets/twbs/bootstrap/thumbnails.less +9 -3
  38. data/vendor/assets/stylesheets/twbs/bootstrap/type.less +54 -52
  39. data/vendor/assets/stylesheets/twbs/bootstrap/variables.less +15 -10
  40. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d4a8c8ce4d544c30154681fc534f4c0cb0e9b6b
4
- data.tar.gz: e3c289a8b3565d8d9b70aa191eecac79ffde903b
3
+ metadata.gz: 5ed81f61795e7a0eb4530dfd8671f7db00d68285
4
+ data.tar.gz: fd94424cd8f3d0c7e03397ce1ce33531e19ad855
5
5
  SHA512:
6
- metadata.gz: 55724dc2da835566732be4fd44eed40aba31ddbc745673a5637300cd22b1172ca66774a8865bf84ef465165778bda02ecce4dd57f6de61e3e53de7efc309559c
7
- data.tar.gz: 51f56d031bd9c7028dd6d387f0cccfa5d2a3d6f7a436dd05bc9f92712b27c3f78f3b10e8884a01256cf508a56c708c79f1add103820366bf660228f1a53ffdce
6
+ metadata.gz: e53d3813b24781e1b8d842d458daf9e18a8c2d3724a418aed5e4965339f1a0ab738add3b5c106d5c63723a9bcfb5fbdff4fc710779be6089383cfcdb1cfc610b
7
+ data.tar.gz: 3334a3a1e71a66043d71524a67cb5d8a8c5475dc5e163638474b59929dbf40812040de1e873d262d6dbfe64fe36419c917a39e483e6d97e04a3ee924dfa3510a
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ 2.6.0
5
+ -----
6
+ * Bootstrap v3.0.3
7
+ * Respond.js 1.4.1
8
+ * Submodules locked to tags instead of master branch
9
+
4
10
  2.5.1
5
11
  -----
6
12
  * Rails 4.0.2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- twbs_less_rails (2.5.1)
4
+ twbs_less_rails (2.6.0)
5
5
  less-rails
6
6
  rails (>= 3.2.16)
7
7
  therubyracer
data/Rakefile CHANGED
@@ -27,6 +27,24 @@ end
27
27
 
28
28
  task default: :test
29
29
 
30
+ SUBMODULES = {
31
+ bootstrap: {
32
+ name: 'Bootstrap',
33
+ sample_version: 'v3.0.3',
34
+ folder: File.expand_path('src/twbs/bootstrap')
35
+ },
36
+ fontawesome: {
37
+ name: 'Font Awesome',
38
+ sample_version: 'v4.0.3',
39
+ folder: File.expand_path('src/FortAwesome/Font-Awesome')
40
+ },
41
+ respond_js: {
42
+ name: 'Respond.js',
43
+ sample_version: '1.4.1',
44
+ folder: File.expand_path('src/scottjehl/Respond')
45
+ }
46
+ }
47
+
30
48
  SOURCE_FILES = {
31
49
  bootstrap_stylesheets: File.expand_path('src/twbs/bootstrap/less/*.less'),
32
50
  bootstrap_javascripts: File.expand_path('src/twbs/bootstrap/js/*.js'),
@@ -43,33 +61,49 @@ DESTINATION_FOLDERS = {
43
61
  fontawesome_fonts: File.expand_path('app/assets/fonts'),
44
62
  }
45
63
 
46
- desc "Update assets"
47
- task :update_assets do
48
- # git submodule add https://github.com/FortAwesome/Font-Awesome.git src/FortAwesome/Font-Awesome/
49
- # git submodule add https://github.com/scottjehl/Respond.git src/scottjehl/Respond
50
- # git submodule add https://github.com/twbs/bootstrap.git src/twbs/bootstrap
64
+ namespace :update do
65
+ SUBMODULES.each do |submodule, v|
66
+ desc "Updates #{v[:name]} at specified tag"
67
+ task submodule, :tag do |t, args|
68
+ if args[:tag]
69
+ update_submodule(SUBMODULES[submodule], args[:tag])
70
+ else
71
+ puts "Please specify a tag, e.g: rake #{t}[#{SUBMODULES[submodule][:sample_version]}]"
72
+ end
73
+ end
74
+ end
75
+
76
+ desc "Update assets"
77
+ task :assets do
78
+ # git submodule add https://github.com/FortAwesome/Font-Awesome.git src/FortAwesome/Font-Awesome/
79
+ # git submodule add https://github.com/scottjehl/Respond.git src/scottjehl/Respond
80
+ # git submodule add https://github.com/twbs/bootstrap.git src/twbs/bootstrap
51
81
 
52
- puts 'Updating submodules...'
53
- `git submodule update --init`
54
- `git submodule foreach git pull origin master`
82
+ puts 'Preparing destination folders...'
83
+ remove_content_from_destination_folders
55
84
 
56
- puts 'Preparing destination folders...'
57
- remove_content_from_destination_folders
85
+ puts 'Copying new assets...'
86
+ copy_source_files_to_destination_folders
58
87
 
59
- puts 'Copying new assets...'
60
- copy_source_files_to_destination_folders
88
+ puts 'Adding respond.js...'
89
+ FileUtils.cp File.expand_path('src/scottjehl/Respond/src/respond.js'), File.expand_path('vendor/assets/javascripts/respond.js')
61
90
 
62
- puts 'Adding respond.js...'
63
- FileUtils.cp File.expand_path('src/scottjehl/Respond/respond.src.js'), File.expand_path('vendor/assets/javascripts/respond.js')
91
+ puts 'Updating font paths...'
92
+ update_fontawesome_paths
93
+ update_glyphicons_paths
64
94
 
65
- puts 'Updating font paths...'
66
- update_fontawesome_paths
67
- update_glyphicons_paths
95
+ puts 'Disabling glyphicons...'
96
+ disable_glyphicons
68
97
 
69
- puts 'Disabling glyphicons...'
70
- disable_glyphicons
98
+ puts 'Done. RUN TESTS NOW!'
99
+ end
100
+ end
71
101
 
72
- puts 'Done. RUN TESTS NOW!'
102
+ private
103
+ def update_submodule(submodule, tag)
104
+ return unless tag
105
+ puts "Updating #{submodule[:name]} at #{tag}..."
106
+ `cd #{submodule[:folder]} && exec git pull origin #{tag}`
73
107
  end
74
108
 
75
109
  def remove_content_from_destination_folders
@@ -98,7 +132,7 @@ def update_glyphicons_paths
98
132
  icon_font_name = File.read("#{DESTINATION_FOLDERS[:bootstrap_stylesheets]}/variables.less").match(/@icon\-font\-name:\s+"([^\"]+)"/)[1]
99
133
  file_name = "#{DESTINATION_FOLDERS[:bootstrap_stylesheets]}/glyphicons.less"
100
134
  text = File.read(file_name)
101
- text.gsub! /url\(\'@{icon-font-path}@{icon-font-name}/, "asset-url('#{icon_font_name}"
135
+ text.gsub! /~\"url\(\'@{icon-font-path}@{icon-font-name}(.*)\"/, "asset-url('#{icon_font_name}\\1"
102
136
  File.open(file_name, 'w') { |file| file.puts text }
103
137
  end
104
138
 
@@ -1,3 +1,3 @@
1
1
  module TwbsLessRails
2
- VERSION = "2.5.1"
2
+ VERSION = "2.6.0"
3
3
  end
@@ -1,65 +1,74 @@
1
- /*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */
2
- /*! NOTE: If you're already including a window.matchMedia polyfill via Modernizr or otherwise, you don't need this part */
1
+ /*! Respond.js v1.4.0: min/max-width media query polyfill. (c) Scott Jehl. MIT Lic. j.mp/respondjs */
2
+ (function( w ){
3
3
 
4
- window.matchMedia = window.matchMedia || (function( doc, undefined ) {
5
-
6
- "use strict";
7
-
8
- var bool,
9
- docElem = doc.documentElement,
10
- refNode = docElem.firstElementChild || docElem.firstChild,
11
- // fakeBody required for <FF4 when executed in <head>
12
- fakeBody = doc.createElement( "body" ),
13
- div = doc.createElement( "div" );
14
-
15
- div.id = "mq-test-1";
16
- div.style.cssText = "position:absolute;top:-100em";
17
- fakeBody.style.background = "none";
18
- fakeBody.appendChild(div);
19
-
20
- return function(q){
21
-
22
- div.innerHTML = "&shy;<style media=\"" + q + "\"> #mq-test-1 { width: 42px; }</style>";
23
-
24
- docElem.insertBefore( fakeBody, refNode );
25
- bool = div.offsetWidth === 42;
26
- docElem.removeChild( fakeBody );
27
-
28
- return {
29
- matches: bool,
30
- media: q
31
- };
32
-
33
- };
34
-
35
- }( document ));
4
+ "use strict";
36
5
 
6
+ //exposed namespace
7
+ var respond = {};
8
+ w.respond = respond;
37
9
 
10
+ //define update even in native-mq-supporting browsers, to avoid errors
11
+ respond.update = function(){};
38
12
 
13
+ //define ajax obj
14
+ var requestQueue = [],
15
+ xmlHttp = (function() {
16
+ var xmlhttpmethod = false;
17
+ try {
18
+ xmlhttpmethod = new w.XMLHttpRequest();
19
+ }
20
+ catch( e ){
21
+ xmlhttpmethod = new w.ActiveXObject( "Microsoft.XMLHTTP" );
22
+ }
23
+ return function(){
24
+ return xmlhttpmethod;
25
+ };
26
+ })(),
39
27
 
28
+ //tweaked Ajax functions from Quirksmode
29
+ ajax = function( url, callback ) {
30
+ var req = xmlHttp();
31
+ if (!req){
32
+ return;
33
+ }
34
+ req.open( "GET", url, true );
35
+ req.onreadystatechange = function () {
36
+ if ( req.readyState !== 4 || req.status !== 200 && req.status !== 304 ){
37
+ return;
38
+ }
39
+ callback( req.responseText );
40
+ };
41
+ if ( req.readyState === 4 ){
42
+ return;
43
+ }
44
+ req.send( null );
45
+ };
40
46
 
41
- /*! Respond.js v1.3.0: min/max-width media query polyfill. (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */
42
- (function( win ){
47
+ //expose for testing
48
+ respond.ajax = ajax;
49
+ respond.queue = requestQueue;
43
50
 
44
- "use strict";
51
+ // expose for testing
52
+ respond.regex = {
53
+ media: /@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi,
54
+ keyframes: /@.*keyframes[^\{]+\{(?:[^\{\}]*\{[^\}\{]*\})+[^\}]+\}/gi,
55
+ urls: /(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g,
56
+ findStyles: /@media *([^\{]+)\{([\S\s]+?)$/,
57
+ only: /(only\s+)?([a-zA-Z]+)\s?/,
58
+ minw: /\([\s]*min\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/,
59
+ maxw: /\([\s]*max\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/
60
+ };
45
61
 
46
- //exposed namespace
47
- var respond = {};
48
- win.respond = respond;
49
-
50
- //define update even in native-mq-supporting browsers, to avoid errors
51
- respond.update = function(){};
52
-
53
62
  //expose media query support flag for external use
54
- respond.mediaQueriesSupported = win.matchMedia && win.matchMedia( "only all" ).matches;
55
-
63
+ respond.mediaQueriesSupported = w.matchMedia && w.matchMedia( "only all" ) !== null && w.matchMedia( "only all" ).matches;
64
+
56
65
  //if media queries are supported, exit here
57
66
  if( respond.mediaQueriesSupported ){
58
67
  return;
59
68
  }
60
-
69
+
61
70
  //define vars
62
- var doc = win.document,
71
+ var doc = w.document,
63
72
  docElem = doc.documentElement,
64
73
  mediastyles = [],
65
74
  rules = [],
@@ -69,149 +78,62 @@ window.matchMedia = window.matchMedia || (function( doc, undefined ) {
69
78
  head = doc.getElementsByTagName( "head" )[0] || docElem,
70
79
  base = doc.getElementsByTagName( "base" )[0],
71
80
  links = head.getElementsByTagName( "link" ),
72
- requestQueue = [],
73
-
74
- //loop stylesheets, send text content to translate
75
- ripCSS = function(){
76
81
 
77
- for( var i = 0; i < links.length; i++ ){
78
- var sheet = links[ i ],
79
- href = sheet.href,
80
- media = sheet.media,
81
- isCSS = sheet.rel && sheet.rel.toLowerCase() === "stylesheet";
82
-
83
- //only links plz and prevent re-parsing
84
- if( !!href && isCSS && !parsedSheets[ href ] ){
85
- // selectivizr exposes css through the rawCssText expando
86
- if (sheet.styleSheet && sheet.styleSheet.rawCssText) {
87
- translate( sheet.styleSheet.rawCssText, href, media );
88
- parsedSheets[ href ] = true;
89
- } else {
90
- if( (!/^([a-zA-Z:]*\/\/)/.test( href ) && !base) ||
91
- href.replace( RegExp.$1, "" ).split( "/" )[0] === win.location.host ){
92
- requestQueue.push( {
93
- href: href,
94
- media: media
95
- } );
96
- }
97
- }
98
- }
99
- }
100
- makeRequests();
101
- },
102
-
103
- //recurse through request queue, get css text
104
- makeRequests = function(){
105
- if( requestQueue.length ){
106
- var thisRequest = requestQueue.shift();
107
-
108
- ajax( thisRequest.href, function( styles ){
109
- translate( styles, thisRequest.href, thisRequest.media );
110
- parsedSheets[ thisRequest.href ] = true;
111
-
112
- // by wrapping recursive function call in setTimeout
113
- // we prevent "Stack overflow" error in IE7
114
- win.setTimeout(function(){ makeRequests(); },0);
115
- } );
116
- }
117
- },
118
-
119
- //find media blocks in css text, convert to style blocks
120
- translate = function( styles, href, media ){
121
- var qs = styles.match( /@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi ),
122
- ql = qs && qs.length || 0;
123
-
124
- //try to get CSS path
125
- href = href.substring( 0, href.lastIndexOf( "/" ) );
126
-
127
- var repUrls = function( css ){
128
- return css.replace( /(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g, "$1" + href + "$2$3" );
129
- },
130
- useMedia = !ql && media;
131
-
132
- //if path exists, tack on trailing slash
133
- if( href.length ){ href += "/"; }
134
-
135
- //if no internal queries exist, but media attr does, use that
136
- //note: this currently lacks support for situations where a media attr is specified on a link AND
137
- //its associated stylesheet has internal CSS media queries.
138
- //In those cases, the media attribute will currently be ignored.
139
- if( useMedia ){
140
- ql = 1;
141
- }
142
-
143
- for( var i = 0; i < ql; i++ ){
144
- var fullq, thisq, eachq, eql;
145
-
146
- //media attr
147
- if( useMedia ){
148
- fullq = media;
149
- rules.push( repUrls( styles ) );
150
- }
151
- //parse for styles
152
- else{
153
- fullq = qs[ i ].match( /@media *([^\{]+)\{([\S\s]+?)$/ ) && RegExp.$1;
154
- rules.push( RegExp.$2 && repUrls( RegExp.$2 ) );
155
- }
156
-
157
- eachq = fullq.split( "," );
158
- eql = eachq.length;
159
-
160
- for( var j = 0; j < eql; j++ ){
161
- thisq = eachq[ j ];
162
- mediastyles.push( {
163
- media : thisq.split( "(" )[ 0 ].match( /(only\s+)?([a-zA-Z]+)\s?/ ) && RegExp.$2 || "all",
164
- rules : rules.length - 1,
165
- hasquery : thisq.indexOf("(") > -1,
166
- minw : thisq.match( /\(\s*min\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/ ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" ),
167
- maxw : thisq.match( /\(\s*max\-width\s*:\s*(\s*[0-9\.]+)(px|em)\s*\)/ ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" )
168
- } );
169
- }
170
- }
171
-
172
- applyMedia();
173
- },
174
-
175
82
  lastCall,
176
-
177
83
  resizeDefer,
178
-
84
+
85
+ //cached container for 1em value, populated the first time it's needed
86
+ eminpx,
87
+
179
88
  // returns the value of 1em in pixels
180
89
  getEmValue = function() {
181
90
  var ret,
182
91
  div = doc.createElement('div'),
183
92
  body = doc.body,
93
+ originalHTMLFontSize = docElem.style.fontSize,
94
+ originalBodyFontSize = body && body.style.fontSize,
184
95
  fakeUsed = false;
185
-
96
+
186
97
  div.style.cssText = "position:absolute;font-size:1em;width:1em";
187
-
98
+
188
99
  if( !body ){
189
100
  body = fakeUsed = doc.createElement( "body" );
190
101
  body.style.background = "none";
191
102
  }
192
-
103
+
104
+ // 1em in a media query is the value of the default font size of the browser
105
+ // reset docElem and body to ensure the correct value is returned
106
+ docElem.style.fontSize = "100%";
107
+ body.style.fontSize = "100%";
108
+
193
109
  body.appendChild( div );
194
-
195
- docElem.insertBefore( body, docElem.firstChild );
196
-
110
+
111
+ if( fakeUsed ){
112
+ docElem.insertBefore( body, docElem.firstChild );
113
+ }
114
+
197
115
  ret = div.offsetWidth;
198
-
116
+
199
117
  if( fakeUsed ){
200
118
  docElem.removeChild( body );
201
119
  }
202
120
  else {
203
121
  body.removeChild( div );
204
122
  }
205
-
123
+
124
+ // restore the original values
125
+ docElem.style.fontSize = originalHTMLFontSize;
126
+ if( originalBodyFontSize ) {
127
+ body.style.fontSize = originalBodyFontSize;
128
+ }
129
+
130
+
206
131
  //also update eminpx before returning
207
132
  ret = eminpx = parseFloat(ret);
208
-
133
+
209
134
  return ret;
210
135
  },
211
-
212
- //cached container for 1em value, populated the first time it's needed
213
- eminpx,
214
-
136
+
215
137
  //enable/disable styles
216
138
  applyMedia = function( fromResize ){
217
139
  var name = "clientWidth",
@@ -221,16 +143,16 @@ window.matchMedia = window.matchMedia || (function( doc, undefined ) {
221
143
  lastLink = links[ links.length-1 ],
222
144
  now = (new Date()).getTime();
223
145
 
224
- //throttle resize calls
146
+ //throttle resize calls
225
147
  if( fromResize && lastCall && now - lastCall < resizeThrottle ){
226
- win.clearTimeout( resizeDefer );
227
- resizeDefer = win.setTimeout( applyMedia, resizeThrottle );
148
+ w.clearTimeout( resizeDefer );
149
+ resizeDefer = w.setTimeout( applyMedia, resizeThrottle );
228
150
  return;
229
151
  }
230
152
  else {
231
153
  lastCall = now;
232
154
  }
233
-
155
+
234
156
  for( var i in mediastyles ){
235
157
  if( mediastyles.hasOwnProperty( i ) ){
236
158
  var thisstyle = mediastyles[ i ],
@@ -239,14 +161,14 @@ window.matchMedia = window.matchMedia || (function( doc, undefined ) {
239
161
  minnull = min === null,
240
162
  maxnull = max === null,
241
163
  em = "em";
242
-
164
+
243
165
  if( !!min ){
244
166
  min = parseFloat( min ) * ( min.indexOf( em ) > -1 ? ( eminpx || getEmValue() ) : 1 );
245
167
  }
246
168
  if( !!max ){
247
169
  max = parseFloat( max ) * ( max.indexOf( em ) > -1 ? ( eminpx || getEmValue() ) : 1 );
248
170
  }
249
-
171
+
250
172
  // 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
251
173
  if( !thisstyle.hasquery || ( !minnull || !maxnull ) && ( minnull || currWidth >= min ) && ( maxnull || currWidth <= max ) ){
252
174
  if( !styleBlocks[ thisstyle.media ] ){
@@ -256,7 +178,7 @@ window.matchMedia = window.matchMedia || (function( doc, undefined ) {
256
178
  }
257
179
  }
258
180
  }
259
-
181
+
260
182
  //remove any existing respond style element(s)
261
183
  for( var j in appendedEls ){
262
184
  if( appendedEls.hasOwnProperty( j ) ){
@@ -265,21 +187,21 @@ window.matchMedia = window.matchMedia || (function( doc, undefined ) {
265
187
  }
266
188
  }
267
189
  }
268
-
190
+
269
191
  //inject active styles, grouped by media type
270
192
  for( var k in styleBlocks ){
271
193
  if( styleBlocks.hasOwnProperty( k ) ){
272
194
  var ss = doc.createElement( "style" ),
273
195
  css = styleBlocks[ k ].join( "\n" );
274
-
275
- ss.type = "text/css";
196
+
197
+ ss.type = "text/css";
276
198
  ss.media = k;
277
-
199
+
278
200
  //originally, ss was appended to a documentFragment and sheets were appended in bulk.
279
201
  //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!
280
202
  head.insertBefore( ss, lastLink.nextSibling );
281
-
282
- if ( ss.styleSheet ){
203
+
204
+ if ( ss.styleSheet ){
283
205
  ss.styleSheet.cssText = css;
284
206
  }
285
207
  else {
@@ -291,52 +213,128 @@ window.matchMedia = window.matchMedia || (function( doc, undefined ) {
291
213
  }
292
214
  }
293
215
  },
294
- //tweaked Ajax functions from Quirksmode
295
- ajax = function( url, callback ) {
296
- var req = xmlHttp();
297
- if (!req){
298
- return;
299
- }
300
- req.open( "GET", url, true );
301
- req.onreadystatechange = function () {
302
- if ( req.readyState !== 4 || req.status !== 200 && req.status !== 304 ){
303
- return;
216
+ //find media blocks in css text, convert to style blocks
217
+ translate = function( styles, href, media ){
218
+ var qs = styles.replace( respond.regex.keyframes, '' ).match( respond.regex.media ),
219
+ ql = qs && qs.length || 0;
220
+
221
+ //try to get CSS path
222
+ href = href.substring( 0, href.lastIndexOf( "/" ) );
223
+
224
+ var repUrls = function( css ){
225
+ return css.replace( respond.regex.urls, "$1" + href + "$2$3" );
226
+ },
227
+ useMedia = !ql && media;
228
+
229
+ //if path exists, tack on trailing slash
230
+ if( href.length ){ href += "/"; }
231
+
232
+ //if no internal queries exist, but media attr does, use that
233
+ //note: this currently lacks support for situations where a media attr is specified on a link AND
234
+ //its associated stylesheet has internal CSS media queries.
235
+ //In those cases, the media attribute will currently be ignored.
236
+ if( useMedia ){
237
+ ql = 1;
238
+ }
239
+
240
+ for( var i = 0; i < ql; i++ ){
241
+ var fullq, thisq, eachq, eql;
242
+
243
+ //media attr
244
+ if( useMedia ){
245
+ fullq = media;
246
+ rules.push( repUrls( styles ) );
247
+ }
248
+ //parse for styles
249
+ else{
250
+ fullq = qs[ i ].match( respond.regex.findStyles ) && RegExp.$1;
251
+ rules.push( RegExp.$2 && repUrls( RegExp.$2 ) );
252
+ }
253
+
254
+ eachq = fullq.split( "," );
255
+ eql = eachq.length;
256
+
257
+ for( var j = 0; j < eql; j++ ){
258
+ thisq = eachq[ j ];
259
+ mediastyles.push( {
260
+ media : thisq.split( "(" )[ 0 ].match( respond.regex.only ) && RegExp.$2 || "all",
261
+ rules : rules.length - 1,
262
+ hasquery : thisq.indexOf("(") > -1,
263
+ minw : thisq.match( respond.regex.minw ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" ),
264
+ maxw : thisq.match( respond.regex.maxw ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" )
265
+ } );
304
266
  }
305
- callback( req.responseText );
306
- };
307
- if ( req.readyState === 4 ){
308
- return;
309
267
  }
310
- req.send( null );
268
+
269
+ applyMedia();
311
270
  },
312
- //define ajax obj
313
- xmlHttp = (function() {
314
- var xmlhttpmethod = false;
315
- try {
316
- xmlhttpmethod = new win.XMLHttpRequest();
271
+
272
+ //recurse through request queue, get css text
273
+ makeRequests = function(){
274
+ if( requestQueue.length ){
275
+ var thisRequest = requestQueue.shift();
276
+
277
+ ajax( thisRequest.href, function( styles ){
278
+ translate( styles, thisRequest.href, thisRequest.media );
279
+ parsedSheets[ thisRequest.href ] = true;
280
+
281
+ // by wrapping recursive function call in setTimeout
282
+ // we prevent "Stack overflow" error in IE7
283
+ w.setTimeout(function(){ makeRequests(); },0);
284
+ } );
317
285
  }
318
- catch( e ){
319
- xmlhttpmethod = new win.ActiveXObject( "Microsoft.XMLHTTP" );
286
+ },
287
+
288
+ //loop stylesheets, send text content to translate
289
+ ripCSS = function(){
290
+
291
+ for( var i = 0; i < links.length; i++ ){
292
+ var sheet = links[ i ],
293
+ href = sheet.href,
294
+ media = sheet.media,
295
+ isCSS = sheet.rel && sheet.rel.toLowerCase() === "stylesheet";
296
+
297
+ //only links plz and prevent re-parsing
298
+ if( !!href && isCSS && !parsedSheets[ href ] ){
299
+ // selectivizr exposes css through the rawCssText expando
300
+ if (sheet.styleSheet && sheet.styleSheet.rawCssText) {
301
+ translate( sheet.styleSheet.rawCssText, href, media );
302
+ parsedSheets[ href ] = true;
303
+ } else {
304
+ if( (!/^([a-zA-Z:]*\/\/)/.test( href ) && !base) ||
305
+ href.replace( RegExp.$1, "" ).split( "/" )[0] === w.location.host ){
306
+ // IE7 doesn't handle urls that start with '//' for ajax request
307
+ // manually add in the protocol
308
+ if ( href.substring(0,2) === "//" ) { href = w.location.protocol + href; }
309
+ requestQueue.push( {
310
+ href: href,
311
+ media: media
312
+ } );
313
+ }
314
+ }
315
+ }
320
316
  }
321
- return function(){
322
- return xmlhttpmethod;
323
- };
324
- })();
325
-
317
+ makeRequests();
318
+ };
319
+
326
320
  //translate CSS
327
321
  ripCSS();
328
-
322
+
329
323
  //expose update for re-running respond later on
330
324
  respond.update = ripCSS;
331
-
325
+
326
+ //expose getEmValue
327
+ respond.getEmValue = getEmValue;
328
+
332
329
  //adjust on resize
333
330
  function callMedia(){
334
331
  applyMedia( true );
335
332
  }
336
- if( win.addEventListener ){
337
- win.addEventListener( "resize", callMedia, false );
333
+
334
+ if( w.addEventListener ){
335
+ w.addEventListener( "resize", callMedia, false );
338
336
  }
339
- else if( win.attachEvent ){
340
- win.attachEvent( "onresize", callMedia );
337
+ else if( w.attachEvent ){
338
+ w.attachEvent( "onresize", callMedia );
341
339
  }
342
340
  })(this);