PageSourceSearch

https://healthymontanakids.org/wp-content/themes/kidsplanet/fw/js/core.utils.js

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

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.