PageSourceSearch

https://www.bulley.com/wp-content/themes/bulley/js/vendor/selectivizr.js?ver=7.0.5

js bulley.com collected 2026-09-29 06:56:59 UTC 18,985 bytes, 563 lines download raw bytes

1/*
2selectivizr v1.0.3b - (c) Keith Clark, freely distributable under the terms 
3of the MIT license.
4
5selectivizr.com
6*/
7/* 
8  
9Notes about this source
10-----------------------
11
12 * The #DEBUG_START and #DEBUG_END comments are used to mark blocks of code
13   that will be removed prior to building a final release version (using a
14   pre-compression script)
15  
16  
17References:
18-----------
19 
20 * CSS Syntax          : http://www.w3.org/TR/2003/WD-css3-syntax-20030813/#style
21 * Selectors           : http://www.w3.org/TR/css3-selectors/#selectors
22 * IE Compatability    : http://msdn.microsoft.com/en-us/library/cc351024(VS.85).aspx
23 * W3C Selector Tests  : http://www.w3.org/Style/CSS/Test/CSS3/Selectors/current/html/tests/
24 
25*/
26
27(function(win) {
28
29	// Determine IE version and stop execution if browser isn't IE. This
30	// handles the script being loaded by non IE browsers because the
31	// developer didn't use conditional comments.
32	var ieUserAgent = navigator.userAgent.match(/MSIE (\d+)/);
33	if (!ieUserAgent) {
34		return false;
35	}
36
37	// =========================== Init Objects ============================
38
39	var doc = document;
40	var root = doc.documentElement;
41	var xhr = getXHRObject();
42	var ieVersion = ieUserAgent[1];
vendor: 17,726 bytes, lines 43-563
43
44	// If were not in standards mode, IE is too old / new or we can't create
45	// an XMLHttpRequest object then we should get out now.
46	if (doc.compatMode != 'CSS1Compat' || ieVersion<6 || ieVersion>8 || !xhr) {
47		return;
48	}
49	
50	
51	// ========================= Common Objects ============================
52
53	// Compatiable selector engines in order of CSS3 support. Note: '*' is
54	// a placholder for the object key name. (basically, crude compression)
55	var selectorEngines = {
56		"NW"								: "*.Dom.select",
57		"MooTools"							: "$$",
58		"DOMAssistant"						: "*.$", 
59		"Prototype"							: "$$",
60		"YAHOO"								: "*.util.Selector.query",
61		"Sizzle"							: "*", 
62		"jQuery"							: "*",
63		"dojo"								: "*.query"
64	};
65
66	var selectorMethod;
67	var enabledWatchers 					= [];     // array of :enabled/:disabled elements to poll
68	var domPatches							= [];
69	var ie6PatchID 							= 0;      // used to solve ie6's multiple class bug
70	var patchIE6MultipleClasses				= true;   // if true adds class bloat to ie6
71	var namespace 							= "slvzr";
72
73	// Stylesheet parsing regexp's
74	var RE_COMMENT							= /(\/\*[^*]*\*+([^\/][^*]*\*+)*\/)\s*?/g;
75	var RE_IMPORT							= /@import\s*(?:(?:(?:url\(\s*(['"]?)(.*)\1)\s*\))|(?:(['"])(.*)\3))\s*([^;]*);/g;
76	var RE_ASSET_URL 						= /(behavior\s*?:\s*)?\burl\(\s*(["']?)(?!data:)([^"')]+)\2\s*\)/g;
77	var RE_PSEUDO_STRUCTURAL				= /^:(empty|(first|last|only|nth(-last)?)-(child|of-type))$/;
78	var RE_PSEUDO_ELEMENTS					= /:(:first-(?:line|letter))/g;
79	var RE_SELECTOR_GROUP					= /((?:^|(?:\s*})+)(?:\s*@media[^{]+{)?)\s*([^\{]*?[\[:][^{]+)/g;
80	var RE_SELECTOR_PARSE					= /([ +~>])|(:[a-z-]+(?:\(.*?\)+)?)|(\[.*?\])/g; 
81	var RE_LIBRARY_INCOMPATIBLE_PSEUDOS		= /(:not\()?:(hover|enabled|disabled|focus|checked|target|active|visited|first-line|first-letter)\)?/g;
82	var RE_PATCH_CLASS_NAME_REPLACE			= /[^\w-]/g;
83	
84	// HTML UI element regexp's
85	var RE_INPUT_ELEMENTS					= /^(INPUT|SELECT|TEXTAREA|BUTTON)$/;
86	var RE_INPUT_CHECKABLE_TYPES			= /^(checkbox|radio)$/;
87
88	// Broken attribute selector implementations (IE7/8 native [^=""], [$=""] and [*=""])
89	var BROKEN_ATTR_IMPLEMENTATIONS			= ieVersion>6 ? /[\$\^*]=(['"])\1/ : null;
90
91	// Whitespace normalization regexp's
92	var RE_TIDY_TRAILING_WHITESPACE			= /([(\[+~])\s+/g;
93	var RE_TIDY_LEADING_WHITESPACE			= /\s+([)\]+~])/g;
94	var RE_TIDY_CONSECUTIVE_WHITESPACE		= /\s+/g;
95	var RE_TIDY_TRIM_WHITESPACE				= /^\s*((?:[\S\s]*\S)?)\s*$/;
96	
97	// String constants
98	var EMPTY_STRING						= "";
99	var SPACE_STRING						= " ";
100	var PLACEHOLDER_STRING					= "$1";
101
102	// =========================== Patching ================================
103
104	// --[ patchStyleSheet() ]----------------------------------------------
105	// Scans the passed cssText for selectors that require emulation and
106	// creates one or more patches for each matched selector.
107	function patchStyleSheet( cssText ) {
108		return cssText.replace(RE_PSEUDO_ELEMENTS, PLACEHOLDER_STRING).
109			replace(RE_SELECTOR_GROUP, function(m, prefix, selectorText) {	
110    			var selectorGroups = selectorText.split(",");
111    			for (var c = 0, cs = selectorGroups.length; c < cs; c++) {
112    				var selector = normalizeSelectorWhitespace(selectorGroups[c]) + SPACE_STRING;
113    				var patches = [];
114    				selectorGroups[c] = selector.replace(RE_SELECTOR_PARSE, 
115    					function(match, combinator, pseudo, attribute, index) {
116    						if (combinator) {
117    							if (patches.length>0) {
118    								domPatches.push( { selector: selector.substring(0, index), patches: patches } )
119    								patches = [];
120    							}
121    							return combinator;
122    						}		
123    						else {
124    							var patch = (pseudo) ? patchPseudoClass( pseudo ) : patchAttribute( attribute );
125    							if (patch) {
126    								patches.push(patch);
127    								return "." + patch.className;
128    							}
129    							return match;
130    						}
131    					}
132    				);
133    			}
134    			return prefix + selectorGroups.join(",");
135    		});
136	};
137
138	// --[ patchAttribute() ]-----------------------------------------------
139	// returns a patch for an attribute selector.
140	function patchAttribute( attr ) {
141		return (!BROKEN_ATTR_IMPLEMENTATIONS || BROKEN_ATTR_IMPLEMENTATIONS.test(attr)) ? 
142			{ className: createClassName(attr), applyClass: true } : null;
143	};
144
145	// --[ patchPseudoClass() ]---------------------------------------------
146	// returns a patch for a pseudo-class
147	function patchPseudoClass( pseudo ) {
148
149		var applyClass = true;
150		var className = createClassName(pseudo.slice(1));
151		var isNegated = pseudo.substring(0, 5) == ":not(";
152		var activateEventName;
153		var deactivateEventName;
154
155		// if negated, remove :not() 
156		if (isNegated) {
157			pseudo = pseudo.slice(5, -1);
158		}
159		
160		// bracket contents are irrelevant - remove them
161		var bracketIndex = pseudo.indexOf("(")
162		if (bracketIndex > -1) {
163			pseudo = pseudo.substring(0, bracketIndex);
164		}		
165		
166		// check we're still dealing with a pseudo-class
167		if (pseudo.charAt(0) == ":") {
168			switch (pseudo.slice(1)) {
169
170				case "root":
171					applyClass = function(e) {
172						return isNegated ? e != root : e == root;
173					}
174					break;
175
176				case "target":
177					// :target is only supported in IE8
178					if (ieVersion == 8) {
179						applyClass = function(e) {
180							var handler = function() { 
181								var hash = location.hash;
182								var hashID = hash.slice(1);
183								return isNegated ? (hash == EMPTY_STRING || e.id != hashID) : (hash != EMPTY_STRING && e.id == hashID);
184							};
185							addEvent( win, "hashchange", function() {
186								toggleElementClass(e, className, handler());
187							})
188							return handler();
189						}
190						break;
191					}
192					return false;
193				
194				case "checked":
195					applyClass = function(e) { 
196						if (RE_INPUT_CHECKABLE_TYPES.test(e.type)) {
197							addEvent( e, "propertychange", function() {
198								if (event.propertyName == "checked") {
199									toggleElementClass( e, className, e.checked !== isNegated );
200								} 							
201							})
202						}
203						return e.checked !== isNegated;
204					}
205					break;
206					
207				case "disabled":
208					isNegated = !isNegated;
209
210				case "enabled":
211					applyClass = function(e) { 
212						if (RE_INPUT_ELEMENTS.test(e.tagName)) {
213							addEvent( e, "propertychange", function() {
214								if (event.propertyName == "$disabled") {
215									toggleElementClass( e, className, e.$disabled === isNegated );
216								} 
217							});
218							enabledWatchers.push(e);
219							e.$disabled = e.disabled;
220							return e.disabled === isNegated;
221						}
222						return pseudo == ":enabled" ? isNegated : !isNegated;
223					}
224					break;
225					
226				case "focus":
227					activateEventName = "focus";
228					deactivateEventName = "blur";
229								
230				case "hover":
231					if (!activateEventName) {
232						activateEventName = "mouseenter";
233						deactivateEventName = "mouseleave";
234					}
235					applyClass = function(e) {
236						addEvent( e, isNegated ? deactivateEventName : activateEventName, function() {
237							toggleElementClass( e, className, true );
238						})
239						addEvent( e, isNegated ? activateEventName : deactivateEventName, function() {
240							toggleElementClass( e, className, false );
241						})
242						return isNegated;
243					}
244					break;
245					
246				// everything else
247				default:
248					// If we don't support this pseudo-class don't create 
249					// a patch for it
250					if (!RE_PSEUDO_STRUCTURAL.test(pseudo)) {
251						return false;
252					}
253					break;
254			}
255		}
256		return { className: className, applyClass: applyClass };
257	};
258
259	// --[ applyPatches() ]-------------------------------------------------
260	function applyPatches() {
261		var elms, selectorText, patches, domSelectorText;
262
263		for (var c=0; c<domPatches.length; c++) {
264			selectorText = domPatches[c].selector;
265			patches = domPatches[c].patches;
266
267			// Although some selector libraries can find :checked :enabled etc.
268			// we need to find all elements that could have that state because
269			// it can be changed by the user.
270			domSelectorText = selectorText.replace(RE_LIBRARY_INCOMPATIBLE_PSEUDOS, EMPTY_STRING);
271
272			// If the dom selector equates to an empty string or ends with
273			// whitespace then we need to append a universal selector (*) to it.
274			if (domSelectorText == EMPTY_STRING || domSelectorText.charAt(domSelectorText.length - 1) == SPACE_STRING) {
275				domSelectorText += "*";
276			}
277
278			// Ensure we catch errors from the selector library
279			try {
280				elms = selectorMethod( domSelectorText );
281			} catch (ex) {
282				// #DEBUG_START
283				log( "Selector '" + selectorText + "' threw exception '" + ex + "'" );
284				// #DEBUG_END
285			}
286
287
288			if (elms) {
289				for (var d = 0, dl = elms.length; d < dl; d++) {
290					var elm = elms[d];
291					var cssClasses = elm.className;
292					for (var f = 0, fl = patches.length; f < fl; f++) {
293						var patch = patches[f];
294						if (!hasPatch(elm, patch)) {
295							if (patch.applyClass && (patch.applyClass === true || patch.applyClass(elm) === true)) {
296								cssClasses = toggleClass(cssClasses, patch.className, true );
297							}
298						}
299					}
300					elm.className = cssClasses;
301				}
302			}
303		}
304	};
305
306	// --[ hasPatch() ]-----------------------------------------------------
307	// checks for the exsistence of a patch on an element
308	function hasPatch( elm, patch ) {
309		return new RegExp("(^|\\s)" + patch.className + "(\\s|$)").test(elm.className);
310	};
311	
312	
313	// =========================== Utility =================================
314	
315	function createClassName( className ) {
316		return namespace + "-" + ((ieVersion == 6 && patchIE6MultipleClasses) ?
317			ie6PatchID++
318		:
319			className.replace(RE_PATCH_CLASS_NAME_REPLACE, function(a) { return a.charCodeAt(0) }));
320	};
321
322	// --[ log() ]----------------------------------------------------------
323	// #DEBUG_START
324	function log( message ) {
325		if (win.console) {
326			win.console.log(message);
327		}
328	};
329	// #DEBUG_END
330
331	// --[ trim() ]---------------------------------------------------------
332	// removes leading, trailing whitespace from a string
333	function trim( text ) {
334		return text.replace(RE_TIDY_TRIM_WHITESPACE, PLACEHOLDER_STRING);
335	};
336
337	// --[ normalizeWhitespace() ]------------------------------------------
338	// removes leading, trailing and consecutive whitespace from a string
339	function normalizeWhitespace( text ) {
340		return trim(text).replace(RE_TIDY_CONSECUTIVE_WHITESPACE, SPACE_STRING);
341	};
342
343	// --[ normalizeSelectorWhitespace() ]----------------------------------
344	// tidies whitespace around selector brackets and combinators
345	function normalizeSelectorWhitespace( selectorText ) {
346		return normalizeWhitespace(selectorText.
347			replace(RE_TIDY_TRAILING_WHITESPACE, PLACEHOLDER_STRING).
348			replace(RE_TIDY_LEADING_WHITESPACE, PLACEHOLDER_STRING)
349		);
350	};
351
352	// --[ toggleElementClass() ]-------------------------------------------
353	// toggles a single className on an element
354	function toggleElementClass( elm, className, on ) {
355		var oldClassName = elm.className;
356		var newClassName = toggleClass(oldClassName, className, on);
357		if (newClassName != oldClassName) {
358			elm.className = newClassName;
359			elm.parentNode.className += EMPTY_STRING;
360		}
361	};
362
363	// --[ toggleClass() ]--------------------------------------------------
364	// adds / removes a className from a string of classNames. Used to 
365	// manage multiple class changes without forcing a DOM redraw
366	function toggleClass( classList, className, on ) {
367		var re = RegExp("(^|\\s)" + className + "(\\s|$)");
368		var classExists = re.test(classList);
369		if (on) {
370			return classExists ? classList : classList + SPACE_STRING + className;
371		} else {
372			return classExists ? trim(classList.replace(re, PLACEHOLDER_STRING)) : classList;
373		}
374	};
375	
376	// --[ addEvent() ]-----------------------------------------------------
377	function addEvent(elm, eventName, eventHandler) {
378		elm.attachEvent("on" + eventName, eventHandler);
379	};
380
381	// --[ getXHRObject() ]-------------------------------------------------
382	function getXHRObject() {
383		if (win.XMLHttpRequest) {
384			return new XMLHttpRequest;
385		}
386		try	{ 
387			return new ActiveXObject('Microsoft.XMLHTTP');
388		} catch(e) { 
389			return null;
390		}
391	};
392
393	// --[ loadStyleSheet() ]-----------------------------------------------
394	function loadStyleSheet( url ) {
395		xhr.open("GET", url, false);
396		xhr.send();
397		return (xhr.status==200) ? xhr.responseText : EMPTY_STRING;	
398	};
399	
400	// --[ resolveUrl() ]---------------------------------------------------
401	// Converts a URL fragment to a fully qualified URL using the specified
402	// context URL. Returns null if same-origin policy is broken
403	function resolveUrl( url, contextUrl, ignoreSameOriginPolicy ) {
404
405		function getProtocol( url ) {
406			return url.substring(0, url.indexOf("//"));
407		};
408
409		function getProtocolAndHost( url ) {
410			return url.substring(0, url.indexOf("/", 8));
411		};
412
413		if (!contextUrl) {
414			contextUrl = baseUrl;
415		}
416
417		// protocol-relative path
418		if (url.substring(0,2)=="//") {
419			url = getProtocol(contextUrl) + url;
420		}
421
422		// absolute path
423		if (/^https?:\/\//i.test(url)) {
424			return !ignoreSameOriginPolicy && getProtocolAndHost(contextUrl) != getProtocolAndHost(url) ? null : url ;
425		}
426
427		// root-relative path
428		if (url.charAt(0)=="/")	{
429			return getProtocolAndHost(contextUrl) + url;
430		}
431
432		// relative path
433		var contextUrlPath = contextUrl.split(/[?#]/)[0]; // ignore query string in the contextUrl	
434		if (url.charAt(0) != "?" && contextUrlPath.charAt(contextUrlPath.length - 1) != "/") {
435			contextUrlPath = contextUrlPath.substring(0, contextUrlPath.lastIndexOf("/") + 1);
436		}
437
438		return contextUrlPath + url;
439	};
440	
441	// --[ parseStyleSheet() ]----------------------------------------------
442	// Downloads the stylesheet specified by the URL, removes it's comments
443	// and recursivly replaces @import rules with their contents, ultimately
444	// returning the full cssText.
445	function parseStyleSheet( url ) {
446		if (url) {
447			return loadStyleSheet(url).replace(RE_COMMENT, EMPTY_STRING).
448			replace(RE_IMPORT, function( match, quoteChar, importUrl, quoteChar2, importUrl2, media ) {
449				var cssText = parseStyleSheet(resolveUrl(importUrl || importUrl2, url));
450				return (media) ? "@media " + media + " {" + cssText + "}" : cssText;
451			}).
452			replace(RE_ASSET_URL, function( match, isBehavior, quoteChar, assetUrl ) { 
453				quoteChar = quoteChar || EMPTY_STRING;
454				return isBehavior ? match : " url(" + quoteChar + resolveUrl(assetUrl, url, true) + quoteChar + ") "; 
455			});
456		}
457		return EMPTY_STRING;
458	};
459
460	// --[ getStyleSheets() ]-----------------------------------------------
461	function getStyleSheets() {
462		var url, stylesheet;
463		for (var c = 0; c < doc.styleSheets.length; c++) {
464			stylesheet = doc.styleSheets[c];
465			if (stylesheet.href != EMPTY_STRING) {
466				url = resolveUrl(stylesheet.href);
467				if (url) {
468					stylesheet.cssText = stylesheet["rawCssText"] = patchStyleSheet( parseStyleSheet( url ) );
469				}
470			}
471		}
472	};
473
474	// --[ init() ]---------------------------------------------------------
475	function init() {
476		applyPatches();
477
478		// :enabled & :disabled polling script (since we can't hook 
479		// onpropertychange event when an element is disabled) 
480		if (enabledWatchers.length > 0) {
481			setInterval( function() {
482				for (var c = 0, cl = enabledWatchers.length; c < cl; c++) {
483					var e = enabledWatchers[c];
484					if (e.disabled !== e.$disabled) {
485						if (e.disabled) {
486							e.disabled = false;
487							e.$disabled = true;
488							e.disabled = true;
489						}
490						else {
491							e.$disabled = e.disabled;
492						}
493					}
494				}
495			}, 250)
496		}
497	};
498
499	// Determine the baseUrl and download the stylesheets
500	var baseTags = doc.getElementsByTagName("BASE");
501	var baseUrl = (baseTags.length > 0) ? baseTags[0].href : doc.location.href;
502	getStyleSheets();
503
504	// Bind selectivizr to the ContentLoaded event. 
505	ContentLoaded(win, function() {
506		// Determine the "best fit" selector engine
507		for (var engine in selectorEngines) {
508			var members, member, context = win;
509			if (win[engine]) {
510				members = selectorEngines[engine].replace("*", engine).split(".");
511				while ((member = members.shift()) && (context = context[member])) {}
512				if (typeof context == "function") {
513					selectorMethod = context;
514					init();
515					return;
516				}
517			}
518		}
519	});
520	
521
522	
523	/*!
524	 * ContentLoaded.js by Diego Perini, modified for IE<9 only (to save space)
525	 *
526	 * Author: Diego Perini (diego.perini at gmail.com)
527	 * Summary: cross-browser wrapper for DOMContentLoaded
528	 * Updated: 20101020
529	 * License: MIT
530	 * Version: 1.2
531	 *
532	 * URL:
533	 * http://javascript.nwbox.com/ContentLoaded/
534	 * http://javascript.nwbox.com/ContentLoaded/MIT-LICENSE
535	 *
536	 */
537
538	// @w window reference
539	// @f function reference
540	function ContentLoaded(win, fn) {
541
542		var done = false, top = true,
543		init = function(e) {
544			if (e.type == "readystatechange" && doc.readyState != "complete") return;
545			(e.type == "load" ? win : doc).detachEvent("on" + e.type, init, false);
546			if (!done && (done = true)) fn.call(win, e.type || e);
547		},
548		poll = function() {
549			try { root.doScroll("left"); } catch(e) { setTimeout(poll, 50); return; }
550			init('poll');
551		};
552
553		if (doc.readyState == "complete") fn.call(win, EMPTY_STRING);
554		else {
555			if (doc.createEventObject && root.doScroll) {
556				try { top = !win.frameElement; } catch(e) { }
557				if (top) poll();
558			}
559			addEvent(doc,"readystatechange", init);
560			addEvent(win,"load", init);
561		}
562	};
563})(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.