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