PageSourceSearch

https://www.generacionsavia.org/Scripts/respond.js

js generacionsavia.org collected 2026-10-02 12:21:18 UTC 9,853 bytes, 327 lines download raw bytes

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