PageSourceSearch

https://mathlingo.com/wp-content/themes/kidsplanet/fw/js/core.utils.js

js mathlingo.com collected 2026-10-06 13:16:29 UTC 34,656 bytes, 1,076 lines download raw bytes

1/**
2 * ThemeREX Framework: global variables storage
3 *
4 * @package	themerex
5 * @since	themerex 1.0
6 */
7
8
9/* Global variables manipulations
10---------------------------------------------------------------- */
11
12// Global variables storage
13if (typeof THEMEREX_GLOBALS == 'undefined') var THEMEREX_GLOBALS = {};
14
15// Get global variable
16function themerex_get_global(var_name) {
17	return themerex_isset(THEMEREX_GLOBALS[var_name]) ? THEMEREX_GLOBALS[var_name] : '';
18}
19
20// Set global variable
21function themerex_set_global(var_name, value) {
22	THEMEREX_GLOBALS[var_name] = value;
23}
24
25// Inc/Dec global variable with specified value
26function themerex_inc_global(var_name) {
27	var value = arguments[1]==undefined ? 1 : arguments[1];
28	THEMEREX_GLOBALS[var_name] += value;
29}
30
31// Concatenate global variable with specified value
32function themerex_concat_global(var_name, value) {
33	THEMEREX_GLOBALS[var_name] += ''+value;
34}
35
36// Get global array element
37function themerex_get_global_array(var_name, key) {
38	return themerex_isset(THEMEREX_GLOBALS[var_name][key]) ? THEMEREX_GLOBALS[var_name][key] : '';
39}
40
41// Set global array element
42function themerex_set_global_array(var_name, key, value) {
43	if (!themerex_isset(THEMEREX_GLOBALS[var_name])) THEMEREX_GLOBALS[var_name] = {};
44	THEMEREX_GLOBALS[var_name][key] = value;
45}
46
47// Inc/Dec global array element with specified value
48function themerex_inc_global_array(var_name, key) {
49	var value = arguments[2]==undefined ? 1 : arguments[2];
50	THEMEREX_GLOBALS[var_name][key] += value;
51}
52
53// Concatenate global array element with specified value
54function themerex_concat_global_array(var_name, key, value) {
55	THEMEREX_GLOBALS[var_name][key] += ''+value;
56}
57
58
59
60/* PHP-style functions
61---------------------------------------------------------------- */
62function themerex_isset(obj) {
63	return typeof(obj) != 'undefined';
64}
65
66function themerex_empty(obj) {
67	return typeof(obj) == 'undefined' || (typeof(obj)=='object' && obj == null) || (typeof(obj)=='array' && obj.length == 0) || (typeof(obj)=='string' && themerex_alltrim(obj)=='') || obj===0;
68}
69
70function themerex_is_array(obj)  {
71	"use strict";
72	return typeof(obj)=='array';
73}
74
75function themerex_is_object(obj)  {
76	"use strict";
77	return typeof(obj)=='object';
78}
79
80function themerex_clone_object(obj) {
81	if (obj == null || typeof(obj) != 'object') {
82		return obj;
83	}
84	var temp = {};
85	for (var key in obj) {
86		temp[key] = themerex_clone_object(obj[key]);
87	}
88	return temp;
89}
90
91function themerex_merge_objects(obj1, obj2)  {
92	"use strict";
93	for (var i in obj2) obj1[i] = obj2[i];
94	return obj1;
95}
96
97
98
99/* String functions
100---------------------------------------------------------------- */
101
102function themerex_in_list(str, list) {
103	"use strict";
104	var delim = arguments[2] ? arguments[2] : '|';
105	var icase = arguments[3] ? arguments[3] : true;
106	var retval = false;
107	if (icase) {
108		if (typeof(str)=='string') str = str.toLowerCase();
109		list = list.toLowerCase();
110	}
111	var parts = list.split(delim);
112	for (var i=0; i<parts.length; i++) {
113		if (parts[i]==str) {
114			retval=true;
115			break;
116		}
117	}
118	return retval;
119}
120
121function themerex_alltrim(str) {
122	"use strict";
123	var dir = arguments[1] ? arguments[1] : 'a';
124	var rez = '';
125	var i, start = 0, end = str.length-1;
126	if (dir=='a' || dir=='l') {
127		for (i=0; i<str.length; i++) {
128			if (str.substr(i,1)!=' ') {
129				start = i;
130				break;
131			}
132		}
133	}
134	if (dir=='a' || dir=='r') {
135		for (i=str.length-1; i>=0; i--) {
136			if (str.substr(i,1)!=' ') {
137				end = i;
138				break;
139			}
140		}
141	}
142	return str.substring(start, end+1);
143}
144
145function themerex_ltrim(str) {
146	"use strict";
147	return themerex_alltrim(str, 'l');
148}
149
150function themerex_rtrim(str) {
151	"use strict";
152	return themerex_alltrim(str, 'r');
153}
154
155function themerex_padl(str, len) {
156	"use strict";
157	var ch = arguments[2] ? arguments[2] : ' ';
158	var rez = str.substr(0,len);
159	if (rez.length < len) {
160		for (var i=0; i<len-str.length; i++)
161			rez += ch;
162	}
163	return rez;
164}
165
166function themerex_padr(str, len) {
167	"use strict";
168	var ch = arguments[2] ? arguments[2] : ' ';
169	var rez = str.substr(0,len);
170	if (rez.length < len) {
171		for (var i=0; i<len-str.length; i++)
172			rez = ch + rez;
173	}
174	return rez;
175}
176
177function themerex_padc(str, len) {
178	"use strict";
179	var ch = arguments[2] ? arguments[2] : ' ';
180	var rez = str.substr(0,len);
181	if (rez.length < len) {
182		for (var i=0; i<Math.floor((len-str.length)/2); i++)
183			rez = ch + rez + ch;
184	}
185	return rez+(rez.length<len ? ch : '');
186}
187
188function themerex_replicate(str, num) {
189	"use strict";
190	var rez = '';
191	for (var i=0; i<num; i++) {
192		rez += str;
193	}
194	return rez;
195}
196
197
198
199/* Numbers functions
200---------------------------------------------------------------- */
201
202// Round number to specified precision. 
203// For example: num=1.12345, prec=2,  rounded=1.12
204//              num=12345,   prec=-2, rounded=12300
205function themerex_round_number(num) {
206	"use strict";
207	var precision = arguments[1] ? arguments[1] : 0;
208	var p = Math.pow(10, precision);
209	return Math.round(num*p)/p;
210}
211
212// Clear number from any characters and append it with 0 to desired precision
213// For example: num=test1.12dd, prec=3, cleared=1.120
214function themerex_clear_number(num) {
215	"use strict";
216	var precision = arguments[1] ? arguments[1] : 0;
217	var defa = arguments[2] ? arguments[2] : 0;
218	var res = '';
219	var decimals = -1;
220	num = ""+num;
221	if (num=="") num=""+defa;
222	for (var i=0; i<num.length; i++) {
223		if (decimals==0) break;
224		else if (decimals>0) decimals--;
225		var ch = num.substr(i,1);
226		if (ch=='.') {
227			if (precision>0) {
228				res += ch;
229			}
230			decimals = precision;
231		} else if ((ch>=0 && ch<=9) || (ch=='-' && i==0))
232			res+=ch;
233	}
234	if (precision>0 && decimals!=0) {
235		if (decimals==-1) {
236			res += '.';
237			decimals = precision;
238		}
239		for (i=decimals; i>0; i--)
240			res +='0'; 
241	}
242	//if (isNaN(res)) res = clearNumber(defa, precision, defa);
243	return res;
244}
245
246// Convert number from decimal to hex
247function themerex_dec2hex(n) { 
248	"use strict";
249	return Number(n).toString(16);
250}
251
252// Convert number from hex to decimal
253function themerex_hex2dec(hex) {
254	"use strict";
255	return parseInt(hex,16); 
256}
257
258
259
260/* Array manipulations
261---------------------------------------------------------------- */
262
263function themerex_in_array(val, thearray)  {
264	"use strict";
265	var rez = false;
266	for (var i=0; i<thearray.length-1; i++)  {
267		if (thearray[i] == val)  {
268			rez = true;
269			break;
270		}
271	}
272	return rez;
273}
274
275function themerex_sort_array(thearray)  {
276	"use strict";
277	var caseSensitive = arguments[1] ? arguments[1] : false,
278		tmp;
279
280	for (var x=0; x<thearray.length-1; x++)  {
281		for (var y=(x+1); y<thearray.length; y++)  {
282			if (caseSensitive) {
283				if (thearray[x] > thearray[y])  {
284					tmp = thearray[x];
285					thearray[x] = thearray[y];
286					thearray[y] = tmp;
287				}  
288			} else {
289				if (thearray[x].toLowerCase() > thearray[y].toLowerCase())  {
290					tmp = thearray[x];
291					thearray[x] = thearray[y];
292					thearray[y] = tmp;
293				}  
294			}
295		}  
296	}
297	return thearray;
298}
299
300
301
302/* Date manipulations
303---------------------------------------------------------------- */
304
305// Return array[Year, Month, Day, Hours, Minutes, Seconds]
306// from string: Year[-/.]Month[-/.]Day[T ]Hours:Minutes:Seconds
307function themerex_parse_date(dt) {
308	"use strict";
309	dt = dt.replace(/\//g, '-').replace(/\./g, '-').replace(/T/g, ' ').split('+')[0];
310	var dt2 = dt.split(' ');
311	var d = dt2[0].split('-');
312	var t = dt2[1].split(':');
313	d.push(t[0], t[1], t[2]);
314	return d;
315}
316
317// Return difference string between two dates
318function themerex_get_date_difference(dt1) {
319	"use strict";
320	var dt2 = arguments[1]!==undefined ? arguments[1] : '';
321	var short_date = arguments[2]!==undefined ? arguments[2] : true;
322	var sec = arguments[3]!==undefined ? arguments[3] : false;
323	var a1 = themerex_parse_date(dt1);
324	dt1 = Date.UTC(a1[0], a1[1], a1[2], a1[3], a1[4], a1[5]);
325	if (dt2 == '') {
326		dt2 = new Date();
327		var a2 = [dt2.getFullYear(), dt2.getMonth()+1, dt2.getDate(), dt2.getHours(), dt2.getMinutes(), dt2.getSeconds()];
328	} else
329		var a2 = themerex_parse_date(dt2);
330	dt2 = Date.UTC(a2[0], a2[1], a2[2], a2[3], a2[4], a2[5]);
331	var diff = Math.round((dt2 - dt1)/1000);
332	var days = Math.floor(diff / (24*3600));
333	diff -= days * 24 * 3600;
334	var hours = Math.floor(diff / 3600);
335	diff -= hours * 3600;
336	var minutes = Math.floor(diff / 60);
337	diff -= minutes * 60;
338	var rez = '';
339	if (days > 0)
340		rez += (rez!='' ? ' ' : '') + days + ' day' + (days > 1 ? 's' : '');
341	if ((!short_date || rez=='') && hours > 0)
342		rez += (rez!='' ? ' ' : '') + hours + ' hour' + (hours > 1 ? 's' : '');
343	if ((!short_date || rez=='') && minutes > 0)
344		rez +=  (rez!='' ? ' ' : '') + minutes + ' minute' + (minutes > 1 ? 's' : '');
345	if (sec || rez=='')
346		rez +=  rez!='' || sec ? (' ' + diff + ' second' + (diff > 1 ? 's' : '')) : 'less then minute';
347	return rez;
348}
349
350
351
352/* Colors functions
353---------------------------------------------------------------- */
354
355function themerex_hex2rgb(hex) {
356	hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16);
357	return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)};
358}
359
360function themerex_rgb2hex(color) {
361	"use strict";
362	var aRGB;
363	color = color.replace(/\s/g,"").toLowerCase();
364	if (color=='rgba(0,0,0,0)' || color=='rgba(0%,0%,0%,0%)')
365		color = 'transparent';
366	if (color.indexOf('rgba(')==0)
367		aRGB = color.match(/^rgba\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i);
368	else	
369		aRGB = color.match(/^rgb\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i);
370	
371	if(aRGB) {
372		color = '';
373		for (var i=1; i<=3; i++) 
374			color += Math.round((aRGB[i][aRGB[i].length-1]=="%"?2.55:1)*parseInt(aRGB[i])).toString(16).replace(/^(.)$/,'0$1');
375	} else 
376		color = color.replace(/^#?([\da-f])([\da-f])([\da-f])$/i, '$1$1$2$2$3$3');
377	return (color.substr(0,1)!='#' ? '#' : '') + color;
378}
379
380function themerex_components2hex(r,g,b) {
381	"use strict";
382	return '#'+
383		Number(r).toString(16).toUpperCase().replace(/^(.)$/,'0$1') +
384		Number(g).toString(16).toUpperCase().replace(/^(.)$/,'0$1') +
385		Number(b).toString(16).toUpperCase().replace(/^(.)$/,'0$1');
386}
387
388function themerex_rgb2components(color) {
389	"use strict";
390	color = themerex_rgb2hex(color);
391	var matches = color.match(/^#?([\dabcdef]{2})([\dabcdef]{2})([\dabcdef]{2})$/i);
392	if (!matches) return false;
393	for (var i=1, rgb = new Array(3); i<=3; i++)
394		rgb[i-1] = parseInt(matches[i],16);
395	return rgb;
396}
397
398function themerex_hex2hsb(hex) {
399	"use strict";
400	return themerex_rgb2hsb(themerex_hex2rgb(hex));
401}
402
403function themerex_hsb2hex(hsb) {
404	var rgb = themerex_hsb2rgb(hsb);
405	return themerex_components2hex(rgb.r, rgb.g, rgb.b);
406}
407
408function themerex_rgb2hsb(rgb) {
409	"use strict";
410	var hsb = {};
411	hsb.b = Math.max(Math.max(rgb.r,rgb.g),rgb.b);
412	hsb.s = (hsb.b <= 0) ? 0 : Math.round(100*(hsb.b - Math.min(Math.min(rgb.r,rgb.g),rgb.b))/hsb.b);
413	hsb.b = Math.round((hsb.b /255)*100);
414	if ((rgb.r==rgb.g) && (rgb.g==rgb.b))  hsb.h = 0;
415	else if (rgb.r>=rgb.g && rgb.g>=rgb.b) hsb.h = 60*(rgb.g-rgb.b)/(rgb.r-rgb.b);
416	else if (rgb.g>=rgb.r && rgb.r>=rgb.b) hsb.h = 60  + 60*(rgb.g-rgb.r)/(rgb.g-rgb.b);
417	else if (rgb.g>=rgb.b && rgb.b>=rgb.r) hsb.h = 120 + 60*(rgb.b-rgb.r)/(rgb.g-rgb.r);
418	else if (rgb.b>=rgb.g && rgb.g>=rgb.r) hsb.h = 180 + 60*(rgb.b-rgb.g)/(rgb.b-rgb.r);
419	else if (rgb.b>=rgb.r && rgb.r>=rgb.g) hsb.h = 240 + 60*(rgb.r-rgb.g)/(rgb.b-rgb.g);
420	else if (rgb.r>=rgb.b && rgb.b>=rgb.g) hsb.h = 300 + 60*(rgb.r-rgb.b)/(rgb.r-rgb.g);
421	else 								   hsb.h = 0;
422	hsb.h = Math.round(hsb.h);
423	return hsb;
424}
425
426function themerex_hsb2rgb(hsb) {
427	var rgb = {};
428	var h = Math.round(hsb.h);
429	var s = Math.round(hsb.s*255/100);
430	var v = Math.round(hsb.b*255/100);
431	if (s == 0) {
432		rgb.r = rgb.g = rgb.b = v;
433	} else {
434		var t1 = v;
435		var t2 = (255-s)*v/255;
436		var t3 = (t1-t2)*(h%60)/60;
437		if (h==360) h = 0;
438		if (h<60) 		{ rgb.r=t1;	rgb.b=t2;   rgb.g=t2+t3; }
439		else if (h<120) { rgb.g=t1; rgb.b=t2;	rgb.r=t1-t3; }
440		else if (h<180) { rgb.g=t1; rgb.r=t2;	rgb.b=t2+t3; }
441		else if (h<240) { rgb.b=t1; rgb.r=t2;	rgb.g=t1-t3; }
442		else if (h<300) { rgb.b=t1; rgb.g=t2;	rgb.r=t2+t3; }
443		else if (h<360) { rgb.r=t1; rgb.g=t2;	rgb.b=t1-t3; }
444		else 			{ rgb.r=0;  rgb.g=0;	rgb.b=0;	 }
445	}
446	return { r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b) };
447}
448
449function themerex_color_picker(){
450	"use strict";
451	var id = arguments[0] ? arguments[0] : "iColorPicker"+Math.round(Math.random()*1000);
452	var colors = arguments[1] ? arguments[1] : 
453	'#f00,#ff0,#0f0,#0ff,#00f,#f0f,#fff,#ebebeb,#e1e1e1,#d7d7d7,#cccccc,#c2c2c2,#b7b7b7,#acacac,#a0a0a0,#959595,'
454	+'#ee1d24,#fff100,#00a650,#00aeef,#2f3192,#ed008c,#898989,#7d7d7d,#707070,#626262,#555,#464646,#363636,#262626,#111,#000,'
455	+'#f7977a,#fbad82,#fdc68c,#fff799,#c6df9c,#a4d49d,#81ca9d,#7bcdc9,#6ccff7,#7ca6d8,#8293ca,#8881be,#a286bd,#bc8cbf,#f49bc1,#f5999d,'
456	+'#f16c4d,#f68e54,#fbaf5a,#fff467,#acd372,#7dc473,#39b778,#16bcb4,#00bff3,#438ccb,#5573b7,#5e5ca7,#855fa8,#a763a9,#ef6ea8,#f16d7e,'
457	+'#ee1d24,#f16522,#f7941d,#fff100,#8fc63d,#37b44a,#00a650,#00a99e,#00aeef,#0072bc,#0054a5,#2f3192,#652c91,#91278f,#ed008c,#ee105a,'
458	+'#9d0a0f,#a1410d,#a36209,#aba000,#588528,#197b30,#007236,#00736a,#0076a4,#004a80,#003370,#1d1363,#450e61,#62055f,#9e005c,#9d0039,'
459	+'#790000,#7b3000,#7c4900,#827a00,#3e6617,#045f20,#005824,#005951,#005b7e,#003562,#002056,#0c004b,#30004a,#4b0048,#7a0045,#7a0026';
460	var colorsList = colors.split(',');
461	var tbl = '<table class="colorPickerTable"><thead>';
462	for (var i=0; i<colorsList.length; i++) {
463		if (i%16==0) tbl += (i>0 ? '</tr>' : '') + '<tr>';
464		tbl += '<td style="background-color:'+colorsList[i]+'">&nbsp;</td>';
465	}
466	tbl += '</tr></thead><tbody>'
467		+ '<tr style="height:60px;">'
468		+ '<td colspan="8" id="'+id+'_colorPreview" style="vertical-align:middle;text-align:center;border:1px solid #000;background:#fff;">'
469		+ '<input style="width:55px;color:#000;border:1px solid rgb(0, 0, 0);padding:5px;background-color:#fff;font:11px Arial, Helvetica, sans-serif;" maxlength="7" />'
470		+ '<a href="#" id="'+id+'_moreColors" class="iColorPicker_moreColors"></a>'
471		+ '</td>'
472		+ '<td colspan="8" id="'+id+'_colorOriginal" style="vertical-align:middle;text-align:center;border:1px solid #000;background:#fff;">'
473		+ '<input style="width:55px;color:#000;border:1px solid rgb(0, 0, 0);padding:5px;background-color:#fff;font:11px Arial, Helvetica, sans-serif;" readonly="readonly" />'
474		+ '</td>'
475		+ '</tr></tbody></table>';
476	//tbl += '<style>#iColorPicker input{margin:2px}</style>';
477
478	jQuery(document.createElement("div"))
479		.attr("id", id)
480		.css('display','none')
481		.html(tbl)
482		.appendTo("body")
483		.addClass("iColorPickerTable")
484		.on('mouseover', 'thead td', function(){
485			"use strict";
486			var aaa = themerex_rgb2hex(jQuery(this).css('background-color'));
487			jQuery('#'+id+'_colorPreview').css('background',aaa);
488			jQuery('#'+id+'_colorPreview input').val(aaa);
489		})
490		.on('keypress', '#'+id+'_colorPreview input', function(key){
491			"use strict";
492			var aaa = jQuery(this).val()
493			if (aaa.length<7 && ((key.which>=48 && key.which<=57) || (key.which>=97 && key.which<=102) || (key.which===35 || aaa.length===0))) {
494				aaa += String.fromCharCode(key.which);
495			} else if (key.which == 8 && aaa.length>0) {
496				aaa = aaa.substring(0, aaa.length-1);
497			} else if (key.which===13 && (aaa.length===4 || aaa.length===7)) {
498				var fld  = jQuery('#'+id).data('field');
499				var func = jQuery('#'+id).data('func');
500				if (func!=null && func!='undefined') {
501					func(fld, aaa);
502				} else {
503					fld.val(aaa).css('backgroundColor', aaa).trigger('change');
504				}
505				jQuery('#'+id+'_Bg').fadeOut(500);
506				jQuery('#'+id).fadeOut(500);
507				
508			} else {
509				key.preventDefault();
510				return false;
511			}
512			if (aaa.substr(0,1)==='#' && (aaa.length===4 || aaa.length===7)) {
513				jQuery('#'+id+'_colorPreview').css('background',aaa);
514			}
515		})
516		.on('click', 'thead td', function(e){
517			"use strict";
518			var fld  = jQuery('#'+id).data('field');
519			var func = jQuery('#'+id).data('func');
520			var aaa  = themerex_rgb2hex(jQuery(this).css('background-color'));
521			if (func!=null && func!='undefined') {
522				func(fld, aaa);
523			} else {
524				fld.val(aaa).css('backgroundColor', aaa).trigger('change');
525			}
526			jQuery('#'+id+'_Bg').fadeOut(500);
527			jQuery('#'+id).fadeOut(500);
528			e.preventDefault();
529			return false;
530		})
531		.on('click', 'tbody .iColorPicker_moreColors', function(e){
532			"use strict";
533			var thead  = jQuery(this).parents('table').find('thead');
534			var out = '';
535			if (thead.hasClass('more_colors')) {
536				for (var i=0; i<colorsList.length; i++) {
537					if (i%16==0) out += (i>0 ? '</tr>' : '') + '<tr>';
538					out += '<td style="background-color:'+colorsList[i]+'">&nbsp;</td>';
539				}
540				thead.removeClass('more_colors').empty().html(out+'</tr>');
541				jQuery('#'+id+'_colorPreview').attr('colspan', 8);
542				jQuery('#'+id+'_colorOriginal').attr('colspan', 8);
543			} else {
544				var rgb=[0,0,0], i=0, j=-1;	// Set j=-1 or j=0 - show 2 different colors layouts
545				while (rgb[0]<0xF || rgb[1]<0xF || rgb[2]<0xF) {
546					if (i%18==0) out += (i>0 ? '</tr>' : '') + '<tr>';
547					i++;
548					out += '<td style="background-color:'+themerex_components2hex(rgb[0]*16+rgb[0],rgb[1]*16+rgb[1],rgb[2]*16+rgb[2])+'">&nbsp;</td>';
549					rgb[2]+=3;
550					if (rgb[2]>0xF) {
551						rgb[1]+=3;
552						if (rgb[1]>(j===0 ? 6 : 0xF)) {
553							rgb[0]+=3;
554							if (rgb[0]>0xF) {
555								if (j===0) {
556									j=1;
557									rgb[0]=0;
558									rgb[1]=9;
559									rgb[2]=0;
560								} else {
561									break;
562								}
563							} else {
564								rgb[1]=(j < 1 ? 0 : 9);
565								rgb[2]=0;
566							}
567						} else {
568							rgb[2]=0;
569						}
570					}
571				}
572				thead.addClass('more_colors').empty().html(out+'<td  style="background-color:#ffffff" colspan="8">&nbsp;</td></tr>');
573				jQuery('#'+id+'_colorPreview').attr('colspan', 9);
574				jQuery('#'+id+'_colorOriginal').attr('colspan', 9);
575			}
576			jQuery('#'+id+' table.colorPickerTable thead td')
577				.css({
578					'width':'12px',
579					'height':'14px',
580					'border':'1px solid #000',
581					'cursor':'pointer'
582				});
583			e.preventDefault();
584			return false;
585		});
586	jQuery(document.createElement("div"))
587		.attr("id", id+"_Bg")
588		.click(function(e) {
589			"use strict";
590			jQuery("#"+id+"_Bg").fadeOut(500);
591			jQuery("#"+id).fadeOut(500);
592			e.preventDefault();
593			return false;
594		})
595		.appendTo("body");
596	jQuery('#'+id+' table.colorPickerTable thead td')
597		.css({
598			'width':'12px',
599			'height':'14px',
600			'border':'1px solid #000',
601			'cursor':'pointer'
602		});
603	jQuery('#'+id+' table.colorPickerTable')
604		.css({'border-collapse':'collapse'});
605	jQuery('#'+id)
606		.css({
607			'border':'1px solid #ccc',
608			'background':'#333',
609			'padding':'5px',
610			'color':'#fff',
611			'z-index':999999
612		});
613	jQuery('#'+id+'_colorPreview')
614		.css({'height':'50px'});
615	return id;
616}
617
618function themerex_color_picker_show(id, fld, func) { 
619	"use strict";
620	if (id===null || id==='') {
621		id = jQuery('.iColorPickerTable').attr('id');
622	}
623	var eICP = fld.offset();
624	var w = jQuery('#'+id).width();
625	var h = jQuery('#'+id).height();
626	var l = eICP.left + w < jQuery(window).width()-10 ? eICP.left : jQuery(window).width()-10 - w;
627	var t = eICP.top + fld.outerHeight() + h < jQuery(document).scrollTop() + jQuery(window).height()-10 ? eICP.top + fld.outerHeight() : eICP.top - h - 13;
628	jQuery("#"+id)
629		.data({field: fld, func: func})
630		.css({
631			'top':t+"px",
632			'left':l+"px",
633			'position':'absolute',
634			'z-index':100001
635		})
636		.fadeIn(500);
637	jQuery("#"+id+"_Bg")
638		.css({
639			'position':'fixed',
640			'z-index':100000,
641			'top':0,
642			'left':0,
643			'width':'100%',
644			'height':'100%'
645		})
646		.fadeIn(500);
647	var def = fld.val().substr(0, 1)=='#' ? fld.val() : themerex_rgb2hex(fld.css('backgroundColor'));
648	jQuery('#'+id+'_colorPreview input,#'+id+'_colorOriginal input').val(def);
649	jQuery('#'+id+'_colorPreview,#'+id+'_colorOriginal').css('background',def);
650}
651
652
653
654/* Cookies manipulations
655---------------------------------------------------------------- */
656
657function themerex_get_cookie(name) {
658	"use strict";
659	var defa = arguments[1]!=undefined ? arguments[1] : null;
660	var start = document.cookie.indexOf(name + '=');
661	var len = start + name.length + 1;
662	if ((!start) && (name != document.cookie.substring(0, name.length))) {
663		return defa;
664	}
665	if (start == -1)
666		return defa;
667	var end = document.cookie.indexOf(';', len);
668	if (end == -1)
669		end = document.cookie.length;
670	return unescape(document.cookie.substring(len, end));
671}
672
673
674function themerex_set_cookie(name, value, expires, path, domain, secure) {
675	"use strict";
676	var expires = arguments[2]!=undefined ? arguments[2] : 0;
677	var path    = arguments[3]!=undefined ? arguments[3] : '/';
678	var domain  = arguments[4]!=undefined ? arguments[4] : '';
679	var secure  = arguments[5]!=undefined ? arguments[5] : '';
680	var today = new Date();
681	today.setTime(today.getTime());
682	if (expires) {
683		expires = expires * 1000 * 60 * 60 * 24;
684	}
685	var expires_date = new Date(today.getTime() + (expires));
686	document.cookie = name + '='
687			+ escape(value)
688			+ ((expires) ? ';expires=' + expires_date.toGMTString() : '')
689			+ ((path)    ? ';path=' + path : '')
690			+ ((domain)  ? ';domain=' + domain : '')
691			+ ((secure)  ? ';secure' : '');
692}
693
694
695function themerex_del_cookie(name, path, domain) {
696	"use strict";
697	var path   = arguments[1]!=undefined ? arguments[1] : '/';
698	var domain = arguments[2]!=undefined ? arguments[2] : '';
699	if (themerex_get_cookie(name))
700		document.cookie = name + '=' + ((path) ? ';path=' + path : '')
701				+ ((domain) ? ';domain=' + domain : '')
702				+ ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
703}
704
705
706
707/* ListBox and ComboBox manipulations
708---------------------------------------------------------------- */
709
710function themerex_clear_listbox(box) {
711	"use strict";
712	for (var i=box.options.length-1; i>=0; i--)
713		box.options[i] = null;
714}
715
716function themerex_add_listbox_item(box, val, text) {
717	"use strict";
718	var item = new Option();
719	item.value = val;
720	item.text = text;
721    box.options.add(item);
722}
723
724function themerex_del_listbox_item_by_value(box, val) {
725	"use strict";
726	for (var i=0; i<box.options.length; i++) {
727		if (box.options[i].value == val) {
728			box.options[i] = null;
729			break;
730		}
731	}
732}
733
734function themerex_del_listbox_item_by_text(box, txt) {
735	"use strict";
736	for (var i=0; i<box.options.length; i++) {
737		if (box.options[i].text == txt) {
738			box.options[i] = null;
739			break;
740		}
741	}
742}
743
744function themerex_find_listbox_item_by_value(box, val) {
745	"use strict";
746	var idx = -1;
747	for (var i=0; i<box.options.length; i++) {
748		if (box.options[i].value == val) {
749			idx = i;
750			break;
751		}
752	}
753	return idx;
754}
755
756function themerex_find_listbox_item_by_text(box, txt) {
757	"use strict";
758	var idx = -1;
759	for (var i=0; i<box.options.length; i++) {
760		if (box.options[i].text == txt) {
761			idx = i;
762			break;
763		}
764	}
765	return idx;
766}
767
768function themerex_select_listbox_item_by_value(box, val) {
769	"use strict";
770	for (var i = 0; i < box.options.length; i++) {
771		box.options[i].selected = (val == box.options[i].value);
772	}
773}
774
775function themerex_select_listbox_item_by_text(box, txt) {
776	"use strict";
777	for (var i = 0; i < box.options.length; i++) {
778		box.options[i].selected = (txt == box.options[i].text);
779	}
780}
781
782function themerex_get_listbox_values(box) {
783	"use strict";
784	var delim = arguments[1] ? arguments[1] : ',';
785	var str = '';
786	for (var i=0; i<box.options.length; i++) {
787		str += (str ? delim : '') + box.options[i].value;
788	}
789	return str;
790}
791
792function themerex_get_listbox_texts(box) {
793	"use strict";
794	var delim = arguments[1] ? arguments[1] : ',';
795	var str = '';
796	for (var i=0; i<box.options.length; i++) {
797		str += (str ? delim : '') + box.options[i].text;
798	}
799	return str;
800}
801
802function themerex_sort_listbox(box)  {
803	"use strict";
804	var temp_opts = new Array();
805	var temp = new Option();
806	for(var i=0; i<box.options.length; i++)  {
807		temp_opts[i] = box.options[i].clone();
808	}
809	for(var x=0; x<temp_opts.length-1; x++)  {
810		for(var y=(x+1); y<temp_opts.length; y++)  {
811			if(temp_opts[x].text > temp_opts[y].text)  {
812				temp = temp_opts[x];
813				temp_opts[x] = temp_opts[y];
814				temp_opts[y] = temp;
815			}  
816		}  
817	}
818	for(var i=0; i<box.options.length; i++)  {
819		box.options[i] = temp_opts[i].clone();
820	}
821}
822
823function themerex_get_listbox_selected_index(box) {
824	"use strict";
825	for (var i = 0; i < box.options.length; i++) {
826		if (box.options[i].selected)
827			return i;
828	}
829	return -1;
830}
831
832function themerex_get_listbox_selected_value(box) {
833	"use strict";
834	for (var i = 0; i < box.options.length; i++) {
835		if (box.options[i].selected) {
836			return box.options[i].value;
837		}
838	}
839	return null;
840}
841
842function themerex_get_listbox_selected_text(box) {
843	"use strict";
844	for (var i = 0; i < box.options.length; i++) {
845		if (box.options[i].selected) {
846			return box.options[i].text;
847		}
848	}
849	return null;
850}
851
852function themerex_get_listbox_selected_option(box) {
853	"use strict";
854	for (var i = 0; i < box.options.length; i++) {
855		if (box.options[i].selected) {
856			return box.options[i];
857		}
858	}
859	return null;
860}
861
862
863
864/* Radio buttons manipulations
865---------------------------------------------------------------- */
866
867function themerex_get_radio_value(radioGroupObj) {
868	"use strict";
869	for (var i=0; i < radioGroupObj.length; i++)
870		if (radioGroupObj[i].checked) return radioGroupObj[i].value;
871	return null;
872}
873
874function themerex_set_radio_checked_by_num(radioGroupObj, num) {
875	"use strict";
876	for (var i=0; i < radioGroupObj.length; i++)
877		if (radioGroupObj[i].checked && i!=num) radioGroupObj[i].checked=false;
878		else if (i==num) radioGroupObj[i].checked=true;
879}
880
881function themerex_set_radio_checked_by_value(radioGroupObj, val) {
882	"use strict";
883	for (var i=0; i < radioGroupObj.length; i++)
884		if (radioGroupObj[i].checked && radioGroupObj[i].value!=val) radioGroupObj[i].checked=false;
885		else if (radioGroupObj[i].value==val) radioGroupObj[i].checked=true;
886}
887
888
889
890/* Form manipulations
891---------------------------------------------------------------- */
892
893/*
894// Usage example:
895var error = themerex_form_validate(jQuery(form_selector), {				// -------- Options ---------
896	error_message_show: true,									// Display or not error message
897	error_message_time: 5000,									// Time to display error message
898	error_message_class: 'sc_infobox sc_infobox_style_error',	// Class, appended to error message block
899	error_message_text: 'Global error text',					// Global error message text (if don't write message in checked field)
900	error_fields_class: 'error_fields_class',					// Class, appended to error fields
901	exit_after_first_error: false,								// Cancel validation and exit after first error
902	rules: [
903		{
904			field: 'author',																// Checking field name
905			min_length: { value: 1,	 message: 'The author name can\'t be empty' },			// Min character count (0 - don't check), message - if error occurs
906			max_length: { value: 60, message: 'Too long author name'}						// Max character count (0 - don't check), message - if error occurs
907		},
908		{
909			field: 'email',
910			min_length: { value: 7,	 message: 'Too short (or empty) email address' },
911			max_length: { value: 60, message: 'Too long email address'},
912			mask: { value: '^([a-z0-9_\\-]+\\.)*[a-z0-9_\\-]+@[a-z0-9_\\-]+(\\.[a-z0-9_\\-]+)*\\.[a-z]{2,6}$', message: 'Invalid email address'}
913		},
914		{
915			field: 'comment',
916			min_length: { value: 1,	 message: 'The comment text can\'t be empty' },
917			max_length: { value: 200, message: 'Too long comment'}
918		},
919		{
920			field: 'pwd1',
921			min_length: { value: 5,	 message: 'The password can\'t be less then 5 characters' },
922			max_length: { value: 20, message: 'Too long password'}
923		},
924		{
925			field: 'pwd2',
926			equal_to: { value: 'pwd1',	 message: 'The passwords in both fields must be equals' }
927		}
928	]
929});
930*/
931
932function themerex_form_validate(form, opt) {
933	"use strict";
934	var error_msg = '';
935	form.find(":input").each(function() {
936		"use strict";
937		if (error_msg!='' && opt.exit_after_first_error) return;
938		for (var i = 0; i < opt.rules.length; i++) {
939			if (jQuery(this).attr("name") == opt.rules[i].field) {
940				var val = jQuery(this).val();
941				var error = false;
942				if (typeof(opt.rules[i].min_length) == 'object') {
943					if (opt.rules[i].min_length.value > 0 && val.length < opt.rules[i].min_length.value) {
944						if (error_msg=='') jQuery(this).get(0).focus();
945						error_msg += '<p class="error_item">' + (typeof(opt.rules[i].min_length.message)!='undefined' ? opt.rules[i].min_length.message : opt.error_message_text ) + '</p>'
946						error = true;
947					}
948				}
949				if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].max_length) == 'object') {
950					if (opt.rules[i].max_length.value > 0 && val.length > opt.rules[i].max_length.value) {
951						if (error_msg=='') jQuery(this).get(0).focus();
952						error_msg += '<p class="error_item">' + (typeof(opt.rules[i].max_length.message)!='undefined' ? opt.rules[i].max_length.message : opt.error_message_text ) + '</p>'
953						error = true;
954					}
955				}
956				if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].mask) == 'object') {
957					if (opt.rules[i].mask.value != '') {
958						var regexp = new RegExp(opt.rules[i].mask.value);
959						if (!regexp.test(val)) {
960							if (error_msg=='') jQuery(this).get(0).focus();
961							error_msg += '<p class="error_item">' + (typeof(opt.rules[i].mask.message)!='undefined' ? opt.rules[i].mask.message : opt.error_message_text ) + '</p>'
962							error = true;
963						}
964					}
965				}
966				if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].equal_to) == 'object') {
967					if (opt.rules[i].equal_to.value != '' && val!=jQuery(jQuery(this).get(0).form[opt.rules[i].equal_to.value]).val()) {
968						if (error_msg=='') jQuery(this).get(0).focus();
969						error_msg += '<p class="error_item">' + (typeof(opt.rules[i].equal_to.message)!='undefined' ? opt.rules[i].equal_to.message : opt.error_message_text ) + '</p>'
970						error = true;
971					}
972				}
973				if (opt.error_fields_class != '') jQuery(this).toggleClass(opt.error_fields_class, error);
974			}
975		}
976	});
977	if (error_msg!='' && opt.error_message_show) {
978		var error_message_box = form.find(".result");
979		if (error_message_box.length == 0) error_message_box = form.parent().find(".result");
980		if (error_message_box.length == 0) {
981			form.append('<div class="result"></div>');
982			error_message_box = form.find(".result");
983		}
984		if (opt.error_message_class) error_message_box.toggleClass(opt.error_message_class, true);
985		error_message_box.html(error_msg).fadeIn();
986		setTimeout(function() { error_message_box.fadeOut(); }, opt.error_message_time);
987	}
988	return error_msg!='';
989}
990
991
992
993/* Document manipulations
994---------------------------------------------------------------- */
995
996// Animated scroll to selected id
997function themerex_document_animate_to(id) {
998	if (id.indexOf('#')==-1) id = '#' + id;
999	var obj = jQuery(id).eq(0);
1000	if (obj.length == 0) return;
1001	var oft = jQuery(id).offset().top;
1002	var st  = jQuery(window).scrollTop();
1003	var speed = Math.min(1600, Math.max(400, Math.round(Math.abs(oft-st) / jQuery(window).height() * 100)));
1004	jQuery('body,html').animate( {scrollTop: oft - jQuery('#wpadminbar').height() - jQuery('header.fixedTopMenu .topWrap').height()}, speed, 'swing');
1005}
1006
1007// Change browser address without reload page
1008function themerex_document_set_location(curLoc){
1009	try {
1010		history.pushState(null, null, curLoc);
1011		return;
1012	} catch(e) {}
1013	location.href = curLoc;
1014}
1015
1016// Add hidden elements init functions after tab, accordion, toggles activate
1017function themerex_add_hidden_elements_handler(key, handler) {
1018	themerex_set_global_array('init_hidden_elements', key, handler);
1019}
1020
1021// Init hidden elements after tab, accordion, toggles activate
1022function themerex_init_hidden_elements(cont) {
1023	if (THEMEREX_GLOBALS['init_hidden_elements']) {
1024		for (key in THEMEREX_GLOBALS['init_hidden_elements']) {
1025			THEMEREX_GLOBALS['init_hidden_elements'][key](cont);
1026		}
1027	}
1028}
1029
1030
1031
1032/* Browsers detection
1033---------------------------------------------------------------- */
1034
1035function themerex_browser_is_mobile() {
1036	var check = false;
1037	(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4)))check = true})(navigator.userAgent||navigator.vendor||window.opera);
1038	return check;
1039}
1040function themerex_browser_is_ios() {
1041	return navigator.userAgent.match(/iPad|iPhone|iPod/i) != null;
1042}
1043
1044
1045
1046/* File functions
1047---------------------------------------------------------------- */
1048
1049function themerex_get_file_name(path) {
1050	path = path.replace(/\\/g, '/');
1051	var pos = path.lastIndexOf('/');
1052	if (pos >= 0)
1053		path = path.substr(pos+1);
1054	return path;
1055}
1056
1057function themerex_get_file_ext(path) {
1058	var pos = path.lastIndexOf('.');
1059	path = pos >= 0 ? path.substr(pos+1) : '';
1060	return path;
1061}
1062
1063
1064
1065/* Image functions
1066---------------------------------------------------------------- */
1067
1068// Return true, if all images in the specified container are loaded
1069function themerex_check_images_complete(cont) {
1070	var complete = true;
1071	cont.find('img').each(function() {
1072		if (!complete) return;
1073		if (!jQuery(this).get(0).complete) complete = false;
1074	});
1075	return complete;
1076}

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.