PageSourceSearch

https://www.lbs.edu.ng/wp-content/plugins/yith-faq-plugin-for-word…/jquery-jseldom/jquery.jseldom.js?ver=0.0.2

js lbs.edu.ng collected 2026-09-24 09:40:57 UTC 7,787 bytes, 281 lines download raw bytes

1/**
2Copyright (c) 2010, All Right Reserved, Wong Shek Hei @ [email protected]
3License: GNU Lesser General Public License (http://www.gnu.org/licenses/lgpl.html)
4 **/
5(function($) {
6	expr = /[.#\w].([\S]*)/g,
7		classexpr = /(\.)([^.#[]+)/g,
8		idexpr = /(#)[^.#[]+/,
9		tagexpr = /^[\w]+/,
10		varexpr = /(\w+?)=(['"])([^\2$]*?)\2/,
11		simpleselector = /^[\w]+$/,
12		rTrimmer = /^[\s]*[\"\']?|[\"\']?[\s]*$/g,
13		rSpaceTrim = /^[\s]+|[\s]+$/g;
14	if ( !String.prototype.trim) {
15		String.prototype.trim = function() {
16			return this.replace(rSpaceTrim, '');
17		}
18	}
19	function parseSelector( selector ) {
20		//var buffer = [];
21		var buffer = {sel:"",val:[]},
22			arr = [],
23			isVar = false,
24			quote,
25			varbuff = "",
26			pc = '', c = '', i,
27			selLen = selector.length;
28		for ( i = 0; i < selLen; i++ ) {
29			pc = c;
30			c = selector.charAt(i);
31			if ( isVar ) {
32				if ( c === '\\' && i+1 < selLen ) {
33					varbuff += selector.charAt(++i);
34				}
35				else if ( quote === c ) {
36					quote = undefined;
37					varbuff += c;
38				}
39				else if ((c === '\'' || c === '\"') && quote === undefined ) {
40					quote = c;
41					varbuff += c;
42				}
43				else if ( c === ']' && quote === undefined ) {
44					buffer.val.push(varbuff);
45					varbuff = "";
46					isVar = false;
47				}
48				else if ( c !== ']' || quote !== undefined ) {
49					if ( quote === undefined && c === ',' ) {
50						buffer.val.push(varbuff);
51						varbuff = "";
52					}
53					else {
54						varbuff += c;
55					}
56				}
57			}
58			else if ( c === '\\' && i+1 < selLen ) {
59				if ( isVar ) {
60					varbuff += selector.charAt(++i);
61				}
62			}
63			else if ( c === '[' && quote === undefined) {
64				isVar = true;
65			}
66			else if ( c === ' ' || c === '+' || c === "<" ) {   // end of a tag, or as a sibling element
67				// now lets peek forward
68				if ( c === " " ) {
69					for ( ; c === " " && i < selLen; i++ ) {
70						c = selector.charAt(i);
71					}
72					if ( i < selLen ) {
73						--i;
74						c = selector.charAt(i);
75					}
76				}
77				arr.push(buffer);
78				if ( c === '+' || c === '<') {
79					arr.push({sel:c, val:''});
80					while ( i < selLen && ( c = selector.charAt(++i) ) === " " ) {}
81					if ( i < selLen ) {
82						c = selector.charAt(--i);
83					}
84				}
85				buffer = {sel:"",val:[]};
86			}
87			else if ( c !== ' ' && c !== ']' ) {
88				buffer.sel+= c;
89			}
90		}
91		if ( buffer.sel.length != 0 || buffer.val.length != 0 ) {
92			arr.push(buffer);
93		}
94		var len = arr.length
95		for ( i = 0; i < len; i++ ) {
96			var sel = arr[i].sel, temp ={};
97
98			if ( sel === '+' || sel ==="<") {
99				temp.tag = sel;
100			}
101			else {
102				temp.tag = tagexpr.exec(sel);
103				temp.id = idexpr.exec(sel);
104				if ( temp.id && $.isArray(temp.id) ) {
105					temp.id = temp.id[0].substr(1);
106				}
107				if ( !temp.tag ) {
108					temp.tag = 'div';
109				}
110				temp.vars = [];
111				var classes = [];
112				for ( var j = 0; j < arr[i].val.length; j++ ) {
113					var index = arr[i].val[j].indexOf('=');
114					var key = arr[i].val[j].substr(0, index).trim();
115					var val = arr[i].val[j].substr(index+1);
116					val = val.replace(rTrimmer, '');
117					if ( key === "text" ) {
118						temp.text = val;
119					} else if ( key === "class" && val.trim().length ) {
120						classes.push(val);
121					}else {
122						temp.vars.push([key,val]);
123					}
124				}
125				var arr2 = sel.match(classexpr);
126				if ( arr2 ) {
127					for ( var j = 0; j < arr2.length; j++ ) {
128						classes.push(arr2[j].substr(1));
129					}
130					temp.className = classes.join(" ");
131				}
132			}
133
134			arr[i] = temp;
135		}
136		return arr;
137	};
138	function nonArrVer(selector, count) {
139		var arr = [], newel = [];
140		if ( simpleselector.test(selector) ) {
141			arr = [ { tag: selector } ];    //if it is just a simple tag selector, then there is no need to parse it, makes it much more efficient
142		}
143		else {
144			arr = parseSelector(selector);
145		}
146
147		if ( typeof count === "undefined" ) {
148			count = 1;
149		}
150		var returns = $();
151		var parent = [];
152		var lastparent = [];
153		var tempholder = document.createElement('div');
154		//var buff = [];
155		var depth = 0, i = 0, x = 0, len = arr.length;
156		for ( i = 0; i < len; i++ ) {
157			if ( arr[i].tag == '+' || arr[i].tag === '<' ) { parent = lastparent.slice(); --depth;}
158			else {
159				for ( x = 0; x < count; x++ ) {
160
161					if ( arr[i].tag == 'input' ) { // special case, needs to create tag by html
162						var html = [];
163						html.push( "<"+arr[i].tag);
164						if ( arr[i].id) {
165							html.push( "id=\'"+arr[i].id+"\'");
166						}
167						if ( arr[i].className || (arr[i].vars && "class" in arr[i].vars)) {
168							var val = [];
169							if ( arr[i].className ) { val.push(arr[i].className); }
170							if ( arr[i].vals["class"] ) { val.push(arr[i].vars["class"]); }
171							html.push( "class=\'"+val.join(" ") );
172							html.push( "\'");
173						}
174						if ( arr[i].vars ) {
175							for ( var j = 0; j < arr[i].vars.length; j++ ) {
176								html.push(arr[i].vars[j][0]+"=\'"+arr[i].vars[j][1]+"\'");
177							}
178						}
179						if ( arr[i].text ) {
180							html.push("value=\'"+arr[i].text+"\'");
181						}
182						html.push("/>");
183						lastparent[x] = parent[x];
184						if ( !parent[x] ) {
185							tempholder.innerHTML = html.join(" ");
186							parent[x] = tempholder.removeChild(tempholder.firstChild);
187						} else {
188							parent[x].innerHTML = parent[x].innerHTML+html.join(" ");
189							parent[x]=parent[x].lastChild;
190						}
191					}
192					else {
193						var buff = document.createElement(arr[i].tag);
194						if ( arr[i].vars ) {
195							for ( var j = 0; j < arr[i].vars.length; j++ ) {
196								buff.setAttribute(arr[i].vars[j][0], arr[i].vars[j][1]);
197							}
198						}
199						if ( arr[i].id ) {
200							buff.id = arr[i].id;
201						}
202						if ( arr[i].className ) {
203							buff.className = arr[i].className;
204						}
205						if ( arr[i].text ) {
206							buff.appendChild(document.createTextNode(arr[i].text));
207						}
208						lastparent[x] = parent[x];
209						if ( parent[x] ) {
210							parent[x] = parent[x].appendChild(buff);
211						} else {
212							parent[x] = buff;
213						}
214					}
215				}
216				if ( !depth++ ) {
217					Array.prototype.push.apply(returns, parent);
218				}
219			}
220			Array.prototype.push.apply( newel, parent );
221		}
222		return returns;
223	};
224	function arrVer(sel, arr, count ) {
225		var regex = /{[^}]*}/g;
226		var vars = sel.match(regex) || [];
227		var newel = $();
228		for ( var i = 0; i < arr.length; i++ ) {
229			var tsel = sel;
230			for ( var j = 0; j < vars.length; j++ ) {
231				var vname = vars[j].substr(1,vars[j].length-2).split('.'),
232					val = arr[i][vname[0]], oldval;
233				if ( vname[0].trim() === "" ) {
234					val = arr[i].toString();
235				} else {
236					for ( var x = 1; x < vname.length; x++ ) {
237						oldval = val;
238						val = val[vname[x]];
239						if (!val) {
240							val = "";
241							break;
242						}
243						if ( typeof val === "function" ) {
244							val = val.call(oldval)
245						}
246					}
247				}
248				if ( $.isArray(val) ) { val = val.join(","); }
249				if ( typeof val === "string" ) {
250					val = val.replace(/\\['"\\]|['"]/g, function (s) {
251						return "\\"+s;
252					});
253				} else if ( typeof val === "function" ) {
254					val = val.call(oldval)
255				}
256				val = val || "";
257				tsel = tsel.replace(vars[j], val);
258			}
259			Array.prototype.push.apply(newel, nonArrVer(tsel, count));
260			// newel = newel.pushStack(nonArrVer(tsel, count));
261		}
262
263		return newel;
264	};
265	var isArray = Array.isArray || function(arr){return toString.call(arr) === "[object Array]";}
266	$.jseldom = function(selector) {
267		if ( arguments.length == 2 && $.isPlainObject(arguments[1])) {
268			return arrVer.apply(this, [arguments[0], [arguments[1]]]);
269		}
270		else if ( arguments.length == 1 || (arguments.length == 2 && !isArray(arguments[1]))) {
271			return nonArrVer.apply( this, arguments );
272		}
273		else if ( arguments.length == 2 ) {
274			return arrVer.apply( this, arguments);
275		}
276	}
277	$.jseldomf = function(selector) {
278		var args = [selector, [Array.prototype.slice.call(arguments,1)]];
279		return arrVer.apply(this, args);
280	}
281})(jQuery);

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.