PageSourceSearch

https://leadgenic.ru/blog/mythemeblogy3/js/respond/respond.src.js

js leadgenic.ru collected 2026-10-04 00:19:07 UTC 9,628 bytes, 329 lines download raw bytes

vendor: 2,427 bytes, lines 1-75
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 */
3window.matchMedia = window.matchMedia || (function(doc, undefined){
4  
5  var bool,
6      docElem  = doc.documentElement,
7      refNode  = docElem.firstElementChild || docElem.firstChild,
8      // fakeBody required for <FF4 when executed in <head>
9      fakeBody = doc.createElement('body'),
10      div      = doc.createElement('div');
11  
12  div.id = 'mq-test-1';
13  div.style.cssText = "position:absolute;top:-100em";
14  fakeBody.appendChild(div);
15  
16  return function(q){
17    
18    div.innerHTML = '&shy;<style media="'+q+'"> #mq-test-1 { width: 42px; }</style>';
19    
20    docElem.insertBefore(fakeBody, refNode);
21    bool = div.offsetWidth == 42;  
22    docElem.removeChild(fakeBody);
23    
24    return { matches: bool, media: q };
25  };
26  
27})(document);
28
29
30
31
32/*! Respond.js v1.1.0: min/max-width media query polyfill. (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs  */
33(function( win ){
34	//exposed namespace
35	win.respond		= {};
36	
37	//define update even in native-mq-supporting browsers, to avoid errors
38	respond.update	= function(){};
39	
40	//expose media query support flag for external use
41	respond.mediaQueriesSupported	= win.matchMedia && win.matchMedia( "only all" ).matches;
42	
43	//if media queries are supported, exit here
44	if( respond.mediaQueriesSupported ){ return; }
45	
46	//define vars
47	var doc 			= win.document,
48		docElem 		= doc.documentElement,
49		mediastyles		= [],
50		rules			= [],
51		appendedEls 	= [],
52		parsedSheets 	= {},
53		resizeThrottle	= 30,
54		head 			= doc.getElementsByTagName( "head" )[0] || docElem,
55		base			= doc.getElementsByTagName( "base" )[0],
56		links			= head.getElementsByTagName( "link" ),
57		requestQueue	= [],
58		
59		//loop stylesheets, send text content to translate
60		ripCSS			= function(){
61			var sheets 	= links,
62				sl 		= sheets.length,
63				i		= 0,
64				//vars for loop:
65				sheet, href, media, isCSS;
66
67			for( ; i < sl; i++ ){
68				sheet	= sheets[ i ],
69				href	= sheet.href,
70				media	= sheet.media,
71				isCSS	= sheet.rel && sheet.rel.toLowerCase() === "stylesheet";
72
73                // BTP hack for ommiting unwanted stylesheets
74                if ( href.indexOf('respondjs=no') !== -1) {
75                    href = false;
76                }
77
78				//only links plz and prevent re-parsing
79				if( !!href && isCSS && !parsedSheets[ href ] ){
80					// selectivizr exposes css through the rawCssText expando
81					if (sheet.styleSheet && sheet.styleSheet.rawCssText) {
82						translate( sheet.styleSheet.rawCssText, href, media );
83						parsedSheets[ href ] = true;
84					} else {
85						if( (!/^([a-zA-Z:]*\/\/)/.test( href ) && !base)
86							|| href.replace( RegExp.$1, "" ).split( "/" )[0] === win.location.host ){
87							requestQueue.push( {
88								href: href,
89								media: media
90							} );
91						}
92					}
93				}
94			}
95			makeRequests();
96		},
97		
98		//recurse through request queue, get css text
99		makeRequests	= function(){
100			if( requestQueue.length ){
101				var thisRequest = requestQueue.shift();
102				
103				ajax( thisRequest.href, function( styles ){
104					translate( styles, thisRequest.href, thisRequest.media );
105					parsedSheets[ thisRequest.href ] = true;
106					makeRequests();
107				} );
108			}
109		},
110		
111		//find media blocks in css text, convert to style blocks
112		translate			= function( styles, href, media ){
113			var qs			= styles.match(  /@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi ),
114				ql			= qs && qs.length || 0,
115				//try to get CSS path
116				href		= href.substring( 0, href.lastIndexOf( "/" )),
117				repUrls		= function( css ){
118					return css.replace( /(url\()['"]?([^\/\)'"][^:\)'"]+)['"]?(\))/g, "$1" + href + "$2$3" );
119				},
120				useMedia	= !ql && media,
121				//vars used in loop
122				i			= 0,
123				j, fullq, thisq, eachq, eql;
124
125			//if path exists, tack on trailing slash
126			if( href.length ){ href += "/"; }	
127				
128			//if no internal queries exist, but media attr does, use that	
129			//note: this currently lacks support for situations where a media attr is specified on a link AND
130				//its associated stylesheet has internal CSS media queries.
131				//In those cases, the media attribute will currently be ignored.
132			if( useMedia ){
133				ql = 1;
134			}
135			
136
137			for( ; i < ql; i++ ){
138				j	= 0;
139				
140				//media attr
141				if( useMedia ){
142					fullq = media;
143					rules.push( repUrls( styles ) );
144				}
145				//parse for styles
146				else{
147					fullq	= qs[ i ].match( /@media *([^\{]+)\{([\S\s]+?)$/ ) && RegExp.$1;
148					rules.push( RegExp.$2 && repUrls( RegExp.$2 ) );
149				}
150				
151				eachq	= fullq.split( "," );
152				eql		= eachq.length;
153					
154				for( ; j < eql; j++ ){
155					thisq	= eachq[ j ];
156					mediastyles.push( { 
157						media	: thisq.split( "(" )[ 0 ].match( /(only\s+)?([a-zA-Z]+)\s?/ ) && RegExp.$2 || "all",
158						rules	: rules.length - 1,
159						hasquery: thisq.indexOf("(") > -1,
160						minw	: thisq.match( /\(min\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/ ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" ), 
161						maxw	: thisq.match( /\(max\-width:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/ ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" )
162					} );
163				}	
164			}
165
166			applyMedia();
167		},
168        	
169		lastCall,
170		
171		resizeDefer,
172		
173		// returns the value of 1em in pixels
174		getEmValue		= function() {
175			var ret,
176				div = doc.createElement('div'),
177				body = doc.body,
178				fakeUsed = false;
179									
180			div.style.cssText = "position:absolute;font-size:1em;width:1em";
181					
182			if( !body ){
183				body = fakeUsed = doc.createElement( "body" );
184			}
185					
186			body.appendChild( div );
187								
188			docElem.insertBefore( body, docElem.firstChild );
189								
190			ret = div.offsetWidth;
191								
192			if( fakeUsed ){
193				docElem.removeChild( body );
194			}
195			else {
196				body.removeChild( div );
197			}
198			
199			//also update eminpx before returning
200			ret = eminpx = parseFloat(ret);
201								
202			return ret;
203		},
204		
205		//cached container for 1em value, populated the first time it's needed 
206		eminpx,
207		
208		//enable/disable styles
209		applyMedia			= function( fromResize ){
210			var name		= "clientWidth",
211				docElemProp	= docElem[ name ],
212				currWidth 	= doc.compatMode === "CSS1Compat" && docElemProp || doc.body[ name ] || docElemProp,
213				styleBlocks	= {},
214				lastLink	= links[ links.length-1 ],
215				now 		= (new Date()).getTime();
216
217			//throttle resize calls	
218			if( fromResize && lastCall && now - lastCall < resizeThrottle ){
219				clearTimeout( resizeDefer );
220				resizeDefer = setTimeout( applyMedia, resizeThrottle );
221				return;
222			}
223			else {
224				lastCall	= now;
225			}
226										
227			for( var i in mediastyles ){
228				var thisstyle = mediastyles[ i ],
229					min = thisstyle.minw,
230					max = thisstyle.maxw,
231					minnull = min === null,
232					maxnull = max === null,
233					em = "em";
234				
235				if( !!min ){
236					min = parseFloat( min ) * ( min.indexOf( em ) > -1 ? ( eminpx || getEmValue() ) : 1 );
237				}
238				if( !!max ){
239					max = parseFloat( max ) * ( max.indexOf( em ) > -1 ? ( eminpx || getEmValue() ) : 1 );
240				}
241				
242				// 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
243				if( !thisstyle.hasquery || ( !minnull || !maxnull ) && ( minnull || currWidth >= min ) && ( maxnull || currWidth <= max ) ){
244						if( !styleBlocks[ thisstyle.media ] ){
245							styleBlocks[ thisstyle.media ] = [];
246						}
247						styleBlocks[ thisstyle.media ].push( rules[ thisstyle.rules ] );
248				}
249			}
250			
251			//remove any existing respond style element(s)
252			for( var i in appendedEls ){
253				if( appendedEls[ i ] && appendedEls[ i ].parentNode === head ){
254					head.removeChild( appendedEls[ i ] );
255				}
256			}
257			
258			//inject active styles, grouped by media type
259			for( var i in styleBlocks ){
260				var ss		= doc.createElement( "style" ),
261					css		= styleBlocks[ i ].join( "\n" );
262				
263				ss.type = "text/css";	
264				ss.media	= i;
265				
266				//originally, ss was appended to a documentFragment and sheets were appended in bulk.
267				//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!
268				head.insertBefore( ss, lastLink.nextSibling );
269				
270				if ( ss.styleSheet ){ 
271		        	ss.styleSheet.cssText = css;
272		        } 
273		        else {
274					ss.appendChild( doc.createTextNode( css ) );
275		        }
276		        
277				//push to appendedEls to track for later removal
278				appendedEls.push( ss );
279			}
280		},
281		//tweaked Ajax functions from Quirksmode
282		ajax = function( url, callback ) {
283			var req = xmlHttp();
284			if (!req){
285				return;
286			}	
287			req.open( "GET", url, true );
288			req.onreadystatechange = function () {
289				if ( req.readyState != 4 || req.status != 200 && req.status != 304 ){
290					return;
291				}
292				callback( req.responseText );
293			}
294			if ( req.readyState == 4 ){
295				return;
296			}
297			req.send( null );
298		},
299		//define ajax obj 
300		xmlHttp = (function() {
301			var xmlhttpmethod = false;	
302			try {
303				xmlhttpmethod = new XMLHttpRequest();
304			}
305			catch( e ){
306				xmlhttpmethod = new ActiveXObject( "Microsoft.XMLHTTP" );
307			}
308			return function(){
309				return xmlhttpmethod;
310			};
311		})();
312	
313	//translate CSS
314	ripCSS();
315	
316	//expose update for re-running respond later on
317	respond.update = ripCSS;
318	
319	//adjust on resize
320	function callMedia(){
321		applyMedia( true );
322	}
323	if( win.addEventListener ){
324		win.addEventListener( "resize", callMedia, false );
325	}
326	else if( win.attachEvent ){
327		win.attachEvent( "onresize", callMedia );
328	}
329})(this);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.