1/** 2 * Dentario Framework: Utilities 3 * 4 * @package dentario 5 * @since dentario 1.0 6 */ 7 8 9/* Global variables manipulations 10---------------------------------------------------------------- */ 11 12// Global variables storage 13if (typeof DENTARIO_STORAGE == 'undefined') var DENTARIO_STORAGE = {}; 14 15// Get global variable 16function dentario_storage_get(var_name) { 17 "use strict"; 18 return dentario_isset(DENTARIO_STORAGE[var_name]) ? DENTARIO_STORAGE[var_name] : ''; 19} 20 21// Set global variable 22function dentario_storage_set(var_name, value) { 23 "use strict"; 24 DENTARIO_STORAGE[var_name] = value; 25} 26 27// Inc/Dec global variable with specified value 28function dentario_storage_inc(var_name) { 29 "use strict"; 30 var value = arguments[1]==undefined ? 1 : arguments[1]; 31 DENTARIO_STORAGE[var_name] += value; 32} 33 34// Concatenate global variable with specified value 35function dentario_storage_concat(var_name, value) { 36 "use strict"; 37 DENTARIO_STORAGE[var_name] += ''+value; 38} 39 40// Get global array element 41function dentario_storage_get_array(var_name, key) { 42 "use strict"; 43 return dentario_isset(DENTARIO_STORAGE[var_name][key]) ? DENTARIO_STORAGE[var_name][key] : ''; 44} 45 46// Set global array element 47function dentario_storage_set_array(var_name, key, value) { 48 "use strict"; 49 if (!dentario_isset(DENTARIO_STORAGE[var_name])) DENTARIO_STORAGE[var_name] = {}; 50 DENTARIO_STORAGE[var_name][key] = value; 51} 52 53// Inc/Dec global array element with specified value 54function dentario_storage_inc_array(var_name, key) { 55 "use strict"; 56 var value = arguments[2]==undefined ? 1 : arguments[2]; 57 DENTARIO_STORAGE[var_name][key] += value; 58} 59 60// Concatenate global array element with specified value 61function dentario_storage_concat_array(var_name, key, value) { 62 "use strict"; 63 DENTARIO_STORAGE[var_name][key] += ''+value; 64} 65 66 67 68/* PHP-style functions 69---------------------------------------------------------------- */ 70function dentario_isset(obj) { 71 "use strict"; 72 return typeof(obj) != 'undefined'; 73} 74 75function dentario_empty(obj) { 76 "use strict"; 77 return typeof(obj) == 'undefined' || (typeof(obj)=='object' && obj == null) || (typeof(obj)=='array' && obj.length == 0) || (typeof(obj)=='string' && dentario_alltrim(obj)=='') || obj===0; 78} 79 80function dentario_is_array(obj) { 81 "use strict"; 82 return typeof(obj)=='array'; 83} 84 85function dentario_is_object(obj) { 86 "use strict"; 87 return typeof(obj)=='object'; 88} 89 90function dentario_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] = dentario_clone_object(obj[key]); 98 } 99 return temp; 100} 101 102function dentario_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 dentario_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 dentario_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 dentario_ltrim(str) { 157 "use strict"; 158 return dentario_alltrim(str, 'l'); 159} 160 161function dentario_rtrim(str) { 162 "use strict"; 163 return dentario_alltrim(str, 'r'); 164} 165 166function dentario_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 dentario_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 dentario_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 dentario_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.
214// For example: num=1.12345, prec=2, rounded=1.12 215// num=12345, prec=-2, rounded=12300 216function dentario_round_number(num) { 217 "use strict"; 218 var precision = arguments[1] ? arguments[1] : 0; 219 var p = Math.pow(10, precision); 220 return Math.round(num*p)/p; 221} 222 223// Clear number from any characters and append it with 0 to desired precision 224// For example: num=test1.12dd, prec=3, cleared=1.120 225function dentario_clear_number(num) { 226 "use strict"; 227 var precision = arguments[1] ? arguments[1] : 0; 228 var defa = arguments[2] ? arguments[2] : 0; 229 var res = ''; 230 var decimals = -1; 231 num = ""+num; 232 if (num=="") num=""+defa; 233 for (var i=0; i<num.length; i++) { 234 if (decimals==0) break; 235 else if (decimals>0) decimals--; 236 var ch = num.substr(i,1); 237 if (ch=='.') { 238 if (precision>0) { 239 res += ch; 240 } 241 decimals = precision; 242 } else if ((ch>=0 && ch<=9) || (ch=='-' && i==0)) 243 res+=ch; 244 } 245 if (precision>0 && decimals!=0) { 246 if (decimals==-1) { 247 res += '.'; 248 decimals = precision; 249 } 250 for (i=decimals; i>0; i--) 251 res +='0'; 252 } 253 //if (isNaN(res)) res = clearNumber(defa, precision, defa); 254 return res; 255} 256 257// Convert number from decimal to hex 258function dentario_dec2hex(n) { 259 "use strict"; 260 return Number(n).toString(16); 261} 262 263// Convert number from hex to decimal 264function dentario_hex2dec(hex) { 265 "use strict"; 266 return parseInt(hex,16); 267} 268 269 270 271/* Array manipulations 272---------------------------------------------------------------- */ 273 274function dentario_in_array(val, thearray) { 275 "use strict"; 276 var rez = false; 277 for (var i=0; i<thearray.length-1; i++) { 278 if (thearray[i] == val) { 279 rez = true; 280 break; 281 } 282 } 283 return rez; 284} 285 286function dentario_sort_array(thearray) { 287 "use strict"; 288 var caseSensitive = arguments[1] ? arguments[1] : false; 289 for (var x=0; x<thearray.length-1; x++) { 290 for (var y=(x+1); y<thearray.length; y++) { 291 if (caseSensitive) { 292 if (thearray[x] > thearray[y]) { 293 tmp = thearray[x]; 294 thearray[x] = thearray[y]; 295 thearray[y] = tmp; 296 } 297 } else { 298 if (thearray[x].toLowerCase() > thearray[y].toLowerCase()) { 299 tmp = thearray[x]; 300 thearray[x] = thearray[y]; 301 thearray[y] = tmp; 302 } 303 } 304 } 305 } 306 return thearray; 307} 308 309 310 311/* Date manipulations 312---------------------------------------------------------------- */ 313 314// Return array[Year, Month, Day, Hours, Minutes, Seconds] 315// from string: Year[-/.]Month[-/.]Day[T ]Hours:Minutes:Seconds 316function dentario_parse_date(dt) { 317 "use strict"; 318 dt = dt.replace(/\//g, '-').replace(/\./g, '-').replace(/T/g, ' ').split('+')[0]; 319 var dt2 = dt.split(' '); 320 var d = dt2[0].split('-'); 321 var t = dt2[1].split(':'); 322 d.push(t[0], t[1], t[2]); 323 return d; 324} 325 326// Return difference string between two dates 327function dentario_get_date_difference(dt1) { 328 "use strict"; 329 var dt2 = arguments[1]!==undefined ? arguments[1] : ''; 330 var short_date = arguments[2]!==undefined ? arguments[2] : true; 331 var sec = arguments[3]!==undefined ? arguments[3] : false; 332 var a1 = dentario_parse_date(dt1); 333 dt1 = Date.UTC(a1[0], a1[1], a1[2], a1[3], a1[4], a1[5]); 334 if (dt2 == '') { 335 dt2 = new Date(); 336 var a2 = [dt2.getFullYear(), dt2.getMonth()+1, dt2.getDate(), dt2.getHours(), dt2.getMinutes(), dt2.getSeconds()]; 337 } else 338 var a2 = dentario_parse_date(dt2); 339 dt2 = Date.UTC(a2[0], a2[1], a2[2], a2[3], a2[4], a2[5]); 340 var diff = Math.round((dt2 - dt1)/1000); 341 var days = Math.floor(diff / (24*3600)); 342 diff -= days * 24 * 3600; 343 var hours = Math.floor(diff / 3600); 344 diff -= hours * 3600; 345 var minutes = Math.floor(diff / 60); 346 diff -= minutes * 60; 347 rez = ''; 348 if (days > 0) 349 rez += (rez!='' ? ' ' : '') + days + ' day' + (days > 1 ? 's' : ''); 350 if ((!short_date || rez=='') && hours > 0) 351 rez += (rez!='' ? ' ' : '') + hours + ' hour' + (hours > 1 ? 's' : ''); 352 if ((!short_date || rez=='') && minutes > 0) 353 rez += (rez!='' ? ' ' : '') + minutes + ' minute' + (minutes > 1 ? 's' : ''); 354 if (sec || rez=='') 355 rez += rez!='' || sec ? (' ' + diff + ' second' + (diff > 1 ? 's' : '')) : 'less then minute'; 356 return rez; 357} 358 359 360 361/* Colors functions 362---------------------------------------------------------------- */ 363 364function dentario_hex2rgb(hex) { 365 "use strict"; 366 hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16); 367 return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)}; 368} 369 370function dentario_rgb2hex(color) { 371 "use strict"; 372 var aRGB; 373 color = color.replace(/\s/g,"").toLowerCase(); 374 if (color=='rgba(0,0,0,0)' || color=='rgba(0%,0%,0%,0%)') 375 color = 'transparent'; 376 if (color.indexOf('rgba(')==0) 377 aRGB = color.match(/^rgba\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i); 378 else 379 aRGB = color.match(/^rgb\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i); 380 381 if(aRGB) { 382 color = ''; 383 for (var i=1; i<=3; i++) 384 color += Math.round((aRGB[i][aRGB[i].length-1]=="%"?2.55:1)*parseInt(aRGB[i])).toString(16).replace(/^(.)$/,'0$1'); 385 } else 386 color = color.replace(/^#?([\da-f])([\da-f])([\da-f])$/i, '$1$1$2$2$3$3'); 387 return (color.substr(0,1)!='#' ? '#' : '') + color; 388} 389 390function dentario_components2hex(r,g,b) { 391 "use strict"; 392 return '#'+ 393 Number(r).toString(16).toUpperCase().replace(/^(.)$/,'0$1') + 394 Number(g).toString(16).toUpperCase().replace(/^(.)$/,'0$1') + 395 Number(b).toString(16).toUpperCase().replace(/^(.)$/,'0$1'); 396} 397 398function dentario_rgb2components(color) { 399 "use strict"; 400 color = dentario_rgb2hex(color); 401 var matches = color.match(/^#?([\dabcdef]{2})([\dabcdef]{2})([\dabcdef]{2})$/i); 402 if (!matches) return false;
403 for (var i=1, rgb = new Array(3); i<=3; i++) 404 rgb[i-1] = parseInt(matches[i],16); 405 return rgb; 406} 407 408function dentario_hex2hsb(hex) { 409 "use strict"; 410 return dentario_rgb2hsb(dentario_hex2rgb(hex)); 411} 412 413function dentario_hsb2hex(hsb) { 414 var rgb = dentario_hsb2rgb(hsb); 415 return dentario_components2hex(rgb.r, rgb.g, rgb.b); 416} 417 418function dentario_rgb2hsb(rgb) { 419 "use strict"; 420 var hsb = {}; 421 hsb.b = Math.max(Math.max(rgb.r,rgb.g),rgb.b); 422 hsb.s = (hsb.b <= 0) ? 0 : Math.round(100*(hsb.b - Math.min(Math.min(rgb.r,rgb.g),rgb.b))/hsb.b); 423 hsb.b = Math.round((hsb.b /255)*100); 424 if ((rgb.r==rgb.g) && (rgb.g==rgb.b)) hsb.h = 0; 425 else if (rgb.r>=rgb.g && rgb.g>=rgb.b) hsb.h = 60*(rgb.g-rgb.b)/(rgb.r-rgb.b); 426 else if (rgb.g>=rgb.r && rgb.r>=rgb.b) hsb.h = 60 + 60*(rgb.g-rgb.r)/(rgb.g-rgb.b); 427 else if (rgb.g>=rgb.b && rgb.b>=rgb.r) hsb.h = 120 + 60*(rgb.b-rgb.r)/(rgb.g-rgb.r); 428 else if (rgb.b>=rgb.g && rgb.g>=rgb.r) hsb.h = 180 + 60*(rgb.b-rgb.g)/(rgb.b-rgb.r); 429 else if (rgb.b>=rgb.r && rgb.r>=rgb.g) hsb.h = 240 + 60*(rgb.r-rgb.g)/(rgb.b-rgb.g); 430 else if (rgb.r>=rgb.b && rgb.b>=rgb.g) hsb.h = 300 + 60*(rgb.r-rgb.b)/(rgb.r-rgb.g); 431 else hsb.h = 0; 432 hsb.h = Math.round(hsb.h); 433 return hsb; 434} 435 436function dentario_hsb2rgb(hsb) { 437 "use strict"; 438 var rgb = {}; 439 var h = Math.round(hsb.h); 440 var s = Math.round(hsb.s*255/100); 441 var v = Math.round(hsb.b*255/100); 442 if (s == 0) { 443 rgb.r = rgb.g = rgb.b = v; 444 } else { 445 var t1 = v; 446 var t2 = (255-s)*v/255; 447 var t3 = (t1-t2)*(h%60)/60; 448 if (h==360) h = 0; 449 if (h<60) { rgb.r=t1; rgb.b=t2; rgb.g=t2+t3; } 450 else if (h<120) { rgb.g=t1; rgb.b=t2; rgb.r=t1-t3; } 451 else if (h<180) { rgb.g=t1; rgb.r=t2; rgb.b=t2+t3; } 452 else if (h<240) { rgb.b=t1; rgb.r=t2; rgb.g=t1-t3; } 453 else if (h<300) { rgb.b=t1; rgb.g=t2; rgb.r=t2+t3; } 454 else if (h<360) { rgb.r=t1; rgb.g=t2; rgb.b=t1-t3; } 455 else { rgb.r=0; rgb.g=0; rgb.b=0; } 456 } 457 return { r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b) }; 458} 459 460function dentario_color_picker(){ 461 "use strict"; 462 var id = arguments[0] ? arguments[0] : "iColorPicker"+Math.round(Math.random()*1000); 463 var colors = arguments[1] ? arguments[1] : 464 '#f00,#ff0,#0f0,#0ff,#00f,#f0f,#fff,#ebebeb,#e1e1e1,#d7d7d7,#cccccc,#c2c2c2,#b7b7b7,#acacac,#a0a0a0,#959595,' 465 +'#ee1d24,#fff100,#00a650,#00aeef,#2f3192,#ed008c,#898989,#7d7d7d,#707070,#626262,#555,#464646,#363636,#262626,#111,#000,' 466 +'#f7977a,#fbad82,#fdc68c,#fff799,#c6df9c,#a4d49d,#81ca9d,#7bcdc9,#6ccff7,#7ca6d8,#8293ca,#8881be,#a286bd,#bc8cbf,#f49bc1,#f5999d,' 467 +'#f16c4d,#f68e54,#fbaf5a,#fff467,#acd372,#7dc473,#39b778,#16bcb4,#00bff3,#438ccb,#5573b7,#5e5ca7,#855fa8,#a763a9,#ef6ea8,#f16d7e,' 468 +'#ee1d24,#f16522,#f7941d,#fff100,#8fc63d,#37b44a,#00a650,#00a99e,#00aeef,#0072bc,#0054a5,#2f3192,#652c91,#91278f,#ed008c,#ee105a,' 469 +'#9d0a0f,#a1410d,#a36209,#aba000,#588528,#197b30,#007236,#00736a,#0076a4,#004a80,#003370,#1d1363,#450e61,#62055f,#9e005c,#9d0039,' 470 +'#790000,#7b3000,#7c4900,#827a00,#3e6617,#045f20,#005824,#005951,#005b7e,#003562,#002056,#0c004b,#30004a,#4b0048,#7a0045,#7a0026'; 471 var colorsList = colors.split(','); 472 var tbl = '<table class="colorPickerTable"><thead>'; 473 for (var i=0; i<colorsList.length; i++) { 474 if (i%16==0) tbl += (i>0 ? '</tr>' : '') + '<tr>'; 475 tbl += '<td style="background-color:'+colorsList[i]+'"> </td>'; 476 } 477 tbl += '</tr></thead><tbody>' 478 + '<tr style="height:60px;">' 479 + '<td colspan="8" id="'+id+'_colorPreview" style="vertical-align:middle;text-align:center;border:1px solid #000;background:#fff;">' 480 + '<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" />' 481 + '<a href="#" id="'+id+'_moreColors" class="iColorPicker_moreColors"></a>' 482 + '</td>' 483 + '<td colspan="8" id="'+id+'_colorOriginal" style="vertical-align:middle;text-align:center;border:1px solid #000;background:#fff;">' 484 + '<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" />' 485 + '</td>' 486 + '</tr></tbody></table>'; 487 //tbl += '<style>#iColorPicker input{margin:2px}</style>'; 488 489 jQuery(document.createElement("div")) 490 .attr("id", id) 491 .css('display','none') 492 .html(tbl) 493 .appendTo("body") 494 .addClass("iColorPickerTable") 495 .on('mouseover', 'thead td', function(){ 496 "use strict"; 497 var aaa = dentario_rgb2hex(jQuery(this).css('background-color')); 498 jQuery('#'+id+'_colorPreview').css('background',aaa); 499 jQuery('#'+id+'_colorPreview input').val(aaa); 500 }) 501 .on('keypress', '#'+id+'_colorPreview input', function(key){ 502 "use strict"; 503 var aaa = jQuery(this).val()
504 if (aaa.length<7 && ((key.which>=48 && key.which<=57) || (key.which>=97 && key.which<=102) || (key.which===35 || aaa.length===0))) { 505 aaa += String.fromCharCode(key.which); 506 } else if (key.which == 8 && aaa.length>0) { 507 aaa = aaa.substring(0, aaa.length-1); 508 } else if (key.which===13 && (aaa.length===4 || aaa.length===7)) { 509 var fld = jQuery('#'+id).data('field'); 510 var func = jQuery('#'+id).data('func'); 511 if (func!=null && func!='undefined') { 512 func(fld, aaa); 513 } else { 514 fld.val(aaa).css('backgroundColor', aaa).trigger('change'); 515 } 516 jQuery('#'+id+'_Bg').fadeOut(500); 517 jQuery('#'+id).fadeOut(500); 518 519 } else { 520 key.preventDefault(); 521 return false; 522 } 523 if (aaa.substr(0,1)==='#' && (aaa.length===4 || aaa.length===7)) { 524 jQuery('#'+id+'_colorPreview').css('background',aaa); 525 } 526 }) 527 .on('click', 'thead td', function(e){ 528 "use strict"; 529 var fld = jQuery('#'+id).data('field'); 530 var func = jQuery('#'+id).data('func'); 531 var aaa = dentario_rgb2hex(jQuery(this).css('background-color')); 532 if (func!=null && func!='undefined') { 533 func(fld, aaa); 534 } else { 535 fld.val(aaa).css('backgroundColor', aaa).trigger('change'); 536 } 537 jQuery('#'+id+'_Bg').fadeOut(500); 538 jQuery('#'+id).fadeOut(500); 539 e.preventDefault(); 540 return false; 541 }) 542 .on('click', 'tbody .iColorPicker_moreColors', function(e){ 543 "use strict"; 544 var thead = jQuery(this).parents('table').find('thead'); 545 var out = ''; 546 if (thead.hasClass('more_colors')) { 547 for (var i=0; i<colorsList.length; i++) { 548 if (i%16==0) out += (i>0 ? '</tr>' : '') + '<tr>'; 549 out += '<td style="background-color:'+colorsList[i]+'"> </td>'; 550 } 551 thead.removeClass('more_colors').empty().html(out+'</tr>'); 552 jQuery('#'+id+'_colorPreview').attr('colspan', 8); 553 jQuery('#'+id+'_colorOriginal').attr('colspan', 8); 554 } else { 555 var rgb=[0,0,0], i=0, j=-1; // Set j=-1 or j=0 - show 2 different colors layouts 556 while (rgb[0]<0xF || rgb[1]<0xF || rgb[2]<0xF) { 557 if (i%18==0) out += (i>0 ? '</tr>' : '') + '<tr>'; 558 i++; 559 out += '<td style="background-color:'+dentario_components2hex(rgb[0]*16+rgb[0],rgb[1]*16+rgb[1],rgb[2]*16+rgb[2])+'"> </td>'; 560 rgb[2]+=3; 561 if (rgb[2]>0xF) { 562 rgb[1]+=3; 563 if (rgb[1]>(j===0 ? 6 : 0xF)) { 564 rgb[0]+=3; 565 if (rgb[0]>0xF) { 566 if (j===0) { 567 j=1; 568 rgb[0]=0; 569 rgb[1]=9; 570 rgb[2]=0; 571 } else { 572 break; 573 } 574 } else { 575 rgb[1]=(j < 1 ? 0 : 9); 576 rgb[2]=0; 577 } 578 } else { 579 rgb[2]=0; 580 } 581 } 582 } 583 thead.addClass('more_colors').empty().html(out+'<td style="background-color:#ffffff" colspan="8"> </td></tr>'); 584 jQuery('#'+id+'_colorPreview').attr('colspan', 9); 585 jQuery('#'+id+'_colorOriginal').attr('colspan', 9); 586 } 587 jQuery('#'+id+' table.colorPickerTable thead td') 588 .css({ 589 'width':'12px', 590 'height':'14px', 591 'border':'1px solid #000', 592 'cursor':'pointer' 593 }); 594 e.preventDefault(); 595 return false; 596 }); 597 jQuery(document.createElement("div")) 598 .attr("id", id+"_Bg") 599 .on('click', function(e) { 600 "use strict"; 601 jQuery("#"+id+"_Bg").fadeOut(500); 602 jQuery("#"+id).fadeOut(500); 603 e.preventDefault(); 604 return false; 605 }) 606 .appendTo("body"); 607 jQuery('#'+id+' table.colorPickerTable thead td') 608 .css({ 609 'width':'12px', 610 'height':'14px', 611 'border':'1px solid #000', 612 'cursor':'pointer' 613 }); 614 jQuery('#'+id+' table.colorPickerTable') 615 .css({'border-collapse':'collapse'}); 616 jQuery('#'+id) 617 .css({ 618 'border':'1px solid #ccc', 619 'background':'#333', 620 'padding':'5px', 621 'color':'#fff', 622 'z-index':999999 623 }); 624 jQuery('#'+id+'_colorPreview') 625 .css({'height':'50px'}); 626 return id; 627} 628 629function dentario_color_picker_show(id, fld, func) { 630 "use strict"; 631 if (id===null || id==='') { 632 id = jQuery('.iColorPickerTable').attr('id'); 633 } 634 var eICP = fld.offset(); 635 var w = jQuery('#'+id).width(); 636 var h = jQuery('#'+id).height(); 637 var l = eICP.left + w < jQuery(window).width()-10 ? eICP.left : jQuery(window).width()-10 - w; 638 var t = eICP.top + fld.outerHeight() + h < jQuery(document).scrollTop() + jQuery(window).height()-10 ? eICP.top + fld.outerHeight() : eICP.top - h - 13; 639 jQuery("#"+id) 640 .data({field: fld, func: func}) 641 .css({ 642 'top':t+"px", 643 'left':l+"px", 644 'position':'absolute', 645 'z-index':100001 646 }) 647 .fadeIn(500); 648 jQuery("#"+id+"_Bg") 649 .css({ 650 'position':'fixed', 651 'z-index':100000, 652 'top':0, 653 'left':0, 654 'width':'100%', 655 'height':'100%' 656 }) 657 .fadeIn(500); 658 var def = fld.val().substr(0, 1)=='#' ? fld.val() : dentario_rgb2hex(fld.css('backgroundColor')); 659 jQuery('#'+id+'_colorPreview input,#'+id+'_colorOriginal input').val(def); 660 jQuery('#'+id+'_colorPreview,#'+id+'_colorOriginal').css('background',def); 661} 662 663 664 665/* Cookies manipulations 666---------------------------------------------------------------- */ 667 668function dentario_get_cookie(name) { 669 "use strict";
670 var defa = arguments[1]!=undefined ? arguments[1] : null; 671 var start = document.cookie.indexOf(name + '='); 672 var len = start + name.length + 1; 673 if ((!start) && (name != document.cookie.substring(0, name.length))) { 674 return defa; 675 } 676 if (start == -1) 677 return defa; 678 var end = document.cookie.indexOf(';', len); 679 if (end == -1) 680 end = document.cookie.length; 681 return unescape(document.cookie.substring(len, end)); 682} 683 684 685function dentario_set_cookie(name, value, expires, path, domain, secure) { 686 "use strict"; 687 var expires = arguments[2]!=undefined ? arguments[2] : 0; 688 var path = arguments[3]!=undefined ? arguments[3] : '/'; 689 var domain = arguments[4]!=undefined ? arguments[4] : ''; 690 var secure = arguments[5]!=undefined ? arguments[5] : ''; 691 var today = new Date(); 692 today.setTime(today.getTime()); 693 if (expires) { 694 expires = expires * 1000 * 60 * 60 * 24; 695 } 696 var expires_date = new Date(today.getTime() + (expires)); 697 document.cookie = name + '=' 698 + escape(value) 699 + ((expires) ? ';expires=' + expires_date.toGMTString() : '') 700 + ((path) ? ';path=' + path : '') 701 + ((domain) ? ';domain=' + domain : '') 702 + ((secure) ? ';secure' : ''); 703} 704 705
706function dentario_del_cookie(name, path, domain) { 707 "use strict"; 708 var path = arguments[1]!=undefined ? arguments[1] : '/'; 709 var domain = arguments[2]!=undefined ? arguments[2] : ''; 710 if (dentario_get_cookie(name)) 711 document.cookie = name + '=' + ((path) ? ';path=' + path : '') 712 + ((domain) ? ';domain=' + domain : '') 713 + ';expires=Thu, 01-Jan-1970 00:00:01 GMT'; 714} 715 716 717 718/* ListBox and ComboBox manipulations 719---------------------------------------------------------------- */ 720 721function dentario_clear_listbox(box) { 722 "use strict"; 723 for (var i=box.options.length-1; i>=0; i--) 724 box.options[i] = null; 725} 726 727function dentario_add_listbox_item(box, val, text) { 728 "use strict"; 729 var item = new Option(); 730 item.value = val; 731 item.text = text; 732 box.options.add(item); 733} 734 735function dentario_del_listbox_item_by_value(box, val) { 736 "use strict"; 737 for (var i=0; i<box.options.length; i++) { 738 if (box.options[i].value == val) { 739 box.options[i] = null; 740 break; 741 } 742 } 743} 744 745function dentario_del_listbox_item_by_text(box, txt) { 746 "use strict"; 747 for (var i=0; i<box.options.length; i++) { 748 if (box.options[i].text == txt) { 749 box.options[i] = null; 750 break; 751 } 752 } 753} 754 755function dentario_find_listbox_item_by_value(box, val) { 756 "use strict"; 757 var idx = -1; 758 for (var i=0; i<box.options.length; i++) { 759 if (box.options[i].value == val) { 760 idx = i; 761 break; 762 } 763 } 764 return idx; 765} 766 767function dentario_find_listbox_item_by_text(box, txt) { 768 "use strict"; 769 var idx = -1; 770 for (var i=0; i<box.options.length; i++) { 771 if (box.options[i].text == txt) { 772 idx = i; 773 break; 774 } 775 } 776 return idx; 777} 778 779function dentario_select_listbox_item_by_value(box, val) { 780 "use strict"; 781 for (var i = 0; i < box.options.length; i++) { 782 box.options[i].selected = (val == box.options[i].value); 783 } 784} 785 786function dentario_select_listbox_item_by_text(box, txt) { 787 "use strict"; 788 for (var i = 0; i < box.options.length; i++) { 789 box.options[i].selected = (txt == box.options[i].text); 790 } 791} 792 793function dentario_get_listbox_values(box) { 794 "use strict"; 795 var delim = arguments[1] ? arguments[1] : ','; 796 var str = ''; 797 for (var i=0; i<box.options.length; i++) { 798 str += (str ? delim : '') + box.options[i].value; 799 } 800 return str; 801} 802 803function dentario_get_listbox_texts(box) { 804 "use strict"; 805 var delim = arguments[1] ? arguments[1] : ','; 806 var str = ''; 807 for (var i=0; i<box.options.length; i++) { 808 str += (str ? delim : '') + box.options[i].text; 809 } 810 return str; 811} 812 813function dentario_sort_listbox(box) { 814 "use strict"; 815 var temp_opts = new Array(); 816 var temp = new Option(); 817 for(var i=0; i<box.options.length; i++) { 818 temp_opts[i] = box.options[i].clone(); 819 } 820 for(var x=0; x<temp_opts.length-1; x++) { 821 for(var y=(x+1); y<temp_opts.length; y++) { 822 if(temp_opts[x].text > temp_opts[y].text) { 823 temp = temp_opts[x]; 824 temp_opts[x] = temp_opts[y]; 825 temp_opts[y] = temp; 826 } 827 } 828 } 829 for(var i=0; i<box.options.length; i++) { 830 box.options[i] = temp_opts[i].clone(); 831 } 832} 833 834function dentario_get_listbox_selected_index(box) { 835 "use strict"; 836 for (var i = 0; i < box.options.length; i++) { 837 if (box.options[i].selected) 838 return i; 839 } 840 return -1; 841} 842 843function dentario_get_listbox_selected_value(box) { 844 "use strict"; 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 dentario_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 dentario_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 dentario_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 dentario_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 dentario_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
904/* 905// Usage example: 906var error = dentario_form_validate(jQuery(form_selector), { // -------- Options --------- 907 error_message_show: true, // Display or not error message 908 error_message_time: 5000, // Time to display error message 909 error_message_class: 'sc_infobox sc_infobox_style_error', // Class, appended to error message block 910 error_message_text: 'Global error text', // Global error message text (if don't write message in checked field) 911 error_fields_class: 'error_fields_class', // Class, appended to error fields 912 exit_after_first_error: false, // Cancel validation and exit after first error 913 rules: [ 914 { 915 field: 'author', // Checking field name 916 min_length: { value: 1, message: 'The author name can\'t be empty' }, // Min character count (0 - don't check), message - if error occurs 917 max_length: { value: 60, message: 'Too long author name'} // Max character count (0 - don't check), message - if error occurs 918 }, 919 { 920 field: 'email', 921 min_length: { value: 7, message: 'Too short (or empty) email address' }, 922 max_length: { value: 60, message: 'Too long email address'}, 923 mask: { value: '^([a-z0-9_\\-]+\\.)*[a-z0-9_\\-]+@[a-z0-9_\\-]+(\\.[a-z0-9_\\-]+)*\\.[a-z]{2,6}$', message: 'Invalid email address'} 924 }, 925 { 926 field: 'comment', 927 min_length: { value: 1, message: 'The comment text can\'t be empty' }, 928 max_length: { value: 200, message: 'Too long comment'} 929 }, 930 { 931 field: 'pwd1', 932 min_length: { value: 5, message: 'The password can\'t be less then 5 characters' }, 933 max_length: { value: 20, message: 'Too long password'} 934 }, 935 { 936 field: 'pwd2', 937 equal_to: { value: 'pwd1', message: 'The passwords in both fields must be equals' } 938 } 939 ] 940}); 941*/ 942 943function dentario_form_validate(form, opt) { 944 "use strict"; 945 var error_msg = ''; 946 form.find(":input").each(function() { 947 "use strict"; 948 if (error_msg!='' && opt.exit_after_first_error) return; 949 for (var i = 0; i < opt.rules.length; i++) { 950 if (jQuery(this).attr("name") == opt.rules[i].field) { 951 var val = jQuery(this).val(); 952 var error = false; 953 if (typeof(opt.rules[i].min_length) == 'object') { 954 if (opt.rules[i].min_length.value > 0 && val.length < opt.rules[i].min_length.value) { 955 if (error_msg=='') jQuery(this).get(0).focus(); 956 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>' 957 error = true; 958 } 959 } 960 if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].max_length) == 'object') { 961 if (opt.rules[i].max_length.value > 0 && val.length > opt.rules[i].max_length.value) { 962 if (error_msg=='') jQuery(this).get(0).focus(); 963 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>' 964 error = true; 965 } 966 } 967 if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].mask) == 'object') { 968 if (opt.rules[i].mask.value != '') { 969 var regexp = new RegExp(opt.rules[i].mask.value); 970 if (!regexp.test(val)) { 971 if (error_msg=='') jQuery(this).get(0).focus(); 972 error_msg += '<p class="error_item">' + (typeof(opt.rules[i].mask.message)!='undefined' ? opt.rules[i].mask.message : opt.error_message_text ) + '</p>' 973 error = true; 974 } 975 } 976 } 977 if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].equal_to) == 'object') { 978 if (opt.rules[i].equal_to.value != '' && val!=jQuery(jQuery(this).get(0).form[opt.rules[i].equal_to.value]).val()) { 979 if (error_msg=='') jQuery(this).get(0).focus(); 980 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>' 981 error = true; 982 } 983 } 984 if (opt.error_fields_class != '') jQuery(this).toggleClass(opt.error_fields_class, error); 985 } 986 } 987 }); 988 if (error_msg!='' && opt.error_message_show) { 989 var error_message_box = form.find(".result"); 990 if (error_message_box.length == 0) error_message_box = form.parent().find(".result"); 991 if (error_message_box.length == 0) { 992 form.append('<div class="result"></div>'); 993 error_message_box = form.find(".result"); 994 } 995 if (opt.error_message_class) error_message_box.toggleClass(opt.error_message_class, true); 996 error_message_box.html(error_msg).fadeIn(); 997 setTimeout(function() { error_message_box.fadeOut(); }, opt.error_message_time); 998 } 999 return error_msg!=''; 1000} 1001 1002 1003 1004/* Document manipulations 1005---------------------------------------------------------------- */ 1006 1007// Animated scroll to selected id 1008function dentario_document_animate_to(id) { 1009 "use strict"; 1010 if (id.indexOf('#')==-1) id = '#' + id; 1011 var obj = jQuery(id).eq(0); 1012 if (obj.length == 0) return; 1013 var oft = jQuery(id).offset().top; 1014 var st = jQuery(window).scrollTop(); 1015 var speed = Math.min(1600, Math.max(400, Math.round(Math.abs(oft-st) / jQuery(window).height() * 100))); 1016 jQuery('body,html').animate( {scrollTop: oft - jQuery('#wpadminbar').height() - jQuery('header.fixedTopMenu .topWrap').height()}, speed, 'swing'); 1017} 1018 1019// Change browser address without reload page 1020function dentario_document_set_location(curLoc){ 1021 "use strict"; 1022 try { 1023 history.pushState(null, null, curLoc); 1024 return; 1025 } catch(e) {}
1026 location.href = curLoc; 1027} 1028 1029// Add hidden elements init functions after tab, accordion, toggles activate 1030function dentario_add_hidden_elements_handler(key, handler) { 1031 "use strict"; 1032 dentario_storage_set_array('init_hidden_elements', key, handler); 1033} 1034 1035// Init hidden elements after tab, accordion, toggles activate 1036function dentario_init_hidden_elements(cont) { 1037 "use strict"; 1038 if (DENTARIO_STORAGE['init_hidden_elements']) { 1039 for (key in DENTARIO_STORAGE['init_hidden_elements']) { 1040 DENTARIO_STORAGE['init_hidden_elements'][key](cont); 1041 } 1042 } 1043} 1044 1045 1046 1047/* Browsers detection 1048---------------------------------------------------------------- */ 1049 1050function dentario_browser_is_mobile() { 1051 "use strict"; 1052 var check = false; 1053 (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); 1054 return check; 1055} 1056function dentario_browser_is_ios() { 1057 "use strict"; 1058 return navigator.userAgent.match(/iPad|iPhone|iPod/i) != null; 1059} 1060function dentario_is_retina() { 1061 "use strict"; 1062 var mediaQuery = '(-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-resolution: 1.5dppx)'; 1063 return (window.devicePixelRatio > 1) || (window.matchMedia && window.matchMedia(mediaQuery).matches); 1064} 1065 1066 1067/* File functions 1068---------------------------------------------------------------- */ 1069 1070function dentario_get_file_name(path) { 1071 "use strict"; 1072 path = path.replace(/\\/g, '/'); 1073 var pos = path.lastIndexOf('/'); 1074 if (pos >= 0) 1075 path = path.substr(pos+1); 1076 return path; 1077} 1078 1079function dentario_get_file_ext(path) { 1080 "use strict"; 1081 var pos = path.lastIndexOf('.'); 1082 path = pos >= 0 ? path.substr(pos+1) : ''; 1083 return path; 1084} 1085 1086 1087 1088/* Image functions 1089---------------------------------------------------------------- */ 1090 1091// Return true, if all images in the specified container are loaded 1092function dentario_check_images_complete(cont) { 1093 "use strict"; 1094 var complete = true; 1095 cont.find('img').each(function() { 1096 if (!complete) return; 1097 if (!jQuery(this).get(0).complete) complete = false; 1098 }); 1099 return complete; 1100}
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.