Advertisement
Guest User

utilis.js

a guest
Nov 28th, 2019
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 42.95 KB | None | 0 0
  1. /**
  2. * Javascript utilities
  3. *
  4. * @package WordPress
  5. * @subpackage NIOBE
  6. * @since NIOBE 1.0
  7. */
  8.  
  9. /* global jQuery:false */
  10. /* global NIOBE_STORAGE:false */
  11.  
  12. /* Global variables manipulations
  13. ---------------------------------------------------------------- */
  14.  
  15. (function(){
  16. "use strict";
  17.  
  18. // Global variables storage
  19. if (typeof NIOBE_STORAGE == 'undefined') window.NIOBE_STORAGE = {};
  20.  
  21. // Get global variable
  22. window.niobe_storage_get = function(var_name) {
  23. return niobe_isset(NIOBE_STORAGE[var_name]) ? NIOBE_STORAGE[var_name] : '';
  24. };
  25.  
  26. // Set global variable
  27. window.niobe_storage_set = function(var_name, value) {
  28. NIOBE_STORAGE[var_name] = value;
  29. };
  30.  
  31. // Inc/Dec global variable with specified value
  32. window.niobe_storage_inc = function(var_name) {
  33. var value = arguments[1]===undefined ? 1 : arguments[1];
  34. NIOBE_STORAGE[var_name] += value;
  35. };
  36.  
  37. // Concatenate global variable with specified value
  38. window.niobe_storage_concat = function(var_name, value) {
  39. NIOBE_STORAGE[var_name] += ''+value;
  40. };
  41.  
  42. // Get global array element
  43. window.niobe_storage_get_array = function(var_name, key) {
  44. return niobe_isset(NIOBE_STORAGE[var_name][key]) ? NIOBE_STORAGE[var_name][key] : '';
  45. };
  46.  
  47. // Set global array element
  48. window.niobe_storage_set_array = function(var_name, key, value) {
  49. if (!niobe_isset(NIOBE_STORAGE[var_name])) NIOBE_STORAGE[var_name] = {};
  50. NIOBE_STORAGE[var_name][key] = value;
  51. };
  52.  
  53. // Inc/Dec global array element with specified value
  54. window.niobe_storage_inc_array = function(var_name, key) {
  55. var value = arguments[2]===undefined ? 1 : arguments[2];
  56. NIOBE_STORAGE[var_name][key] += value;
  57. };
  58.  
  59. // Concatenate global array element with specified value
  60. window.niobe_storage_concat_array = function(var_name, key, value) {
  61. NIOBE_STORAGE[var_name][key] += ''+value;
  62. };
  63.  
  64.  
  65.  
  66. /* PHP-style functions
  67. ---------------------------------------------------------------- */
  68. window.niobe_isset = function(obj) {
  69. return typeof(obj) != 'undefined';
  70. };
  71.  
  72. window.niobe_empty = function(obj) {
  73. return typeof(obj) == 'undefined' || (typeof(obj)=='object' && obj == null) || (typeof(obj)=='array' && obj.length == 0) || (typeof(obj)=='string' && niobe_alltrim(obj)=='') || obj===0;
  74. };
  75.  
  76. window.niobe_is_array = function(obj) {
  77. return typeof(obj)=='array';
  78. };
  79.  
  80. window.niobe_is_object = function(obj) {
  81. return typeof(obj)=='object';
  82. };
  83.  
  84. window.niobe_clone_object = function(obj) {
  85. if (obj == null || typeof(obj) != 'object') {
  86. return obj;
  87. }
  88. var temp = {};
  89. for (var key in obj) {
  90. temp[key] = niobe_clone_object(obj[key]);
  91. }
  92. return temp;
  93. };
  94.  
  95. window.niobe_merge_objects = function(obj1, obj2) {
  96. for (var i in obj2) obj1[i] = obj2[i];
  97. return obj1;
  98. };
  99.  
  100. // Generates a storable representation of a value
  101. window.niobe_serialize = function(mixed_val) {
  102. var obj_to_array = arguments.length==1 || argument[1]===true;
  103.  
  104. switch (typeof(mixed_val)) {
  105.  
  106. case "number":
  107. if (isNaN(mixed_val) || !isFinite(mixed_val))
  108. return false;
  109. else
  110. return (Math.floor(mixed_val) == mixed_val ? "i" : "d") + ":" + mixed_val + ";";
  111.  
  112. case "string":
  113. return "s:" + mixed_val.length + ":\"" + mixed_val + "\";";
  114.  
  115. case "boolean":
  116. return "b:" + (mixed_val ? "1" : "0") + ";";
  117.  
  118. case "object":
  119. if (mixed_val == null)
  120. return "N;";
  121. else if (mixed_val instanceof Array) {
  122. var idxobj = { idx: -1 };
  123. var map = [];
  124. for (var i=0; i < mixed_val.length; i++) {
  125. idxobj.idx++;
  126. var ser = niobe_serialize(mixed_val[i]);
  127. if (ser)
  128. map.push(niobe_serialize(idxobj.idx) + ser);
  129. }
  130. return "a:" + mixed_val.length + ":{" + map.join("") + "}";
  131. } else {
  132. var class_name = niobe_get_class(mixed_val);
  133. if (class_name == undefined)
  134. return false;
  135. var props = new Array();
  136. for (var prop in mixed_val) {
  137. var ser = niobe_serialize(mixed_val[prop]);
  138. if (ser)
  139. props.push(niobe_serialize(prop) + ser);
  140. }
  141. if (obj_to_array)
  142. return "a:" + props.length + ":{" + props.join("") + "}";
  143. else
  144. return "O:" + class_name.length + ":\"" + class_name + "\":" + props.length + ":{" + props.join("") + "}";
  145. }
  146.  
  147. case "undefined":
  148. return "N;";
  149. }
  150. return false;
  151. };
  152.  
  153. // Returns the name of the class of an object
  154. window.niobe_get_class = function(obj) {
  155. if (obj instanceof Object && !(obj instanceof Array) && !(obj instanceof Function) && obj.constructor) {
  156. var arr = obj.constructor.toString().match(/function\s*(\w+)/);
  157. if (arr && arr.length == 2) return arr[1];
  158. }
  159. return false;
  160. };
  161.  
  162.  
  163. /* String functions
  164. ---------------------------------------------------------------- */
  165.  
  166. window.niobe_in_list = function(str, list) {
  167. var delim = arguments[2]!==undefined ? arguments[2] : '|';
  168. var icase = arguments[3]!==undefined ? arguments[3] : true;
  169. var retval = false;
  170. if (icase) {
  171. if (typeof(str)=='string') str = str.toLowerCase();
  172. list = list.toLowerCase();
  173. }
  174. var parts = list.split(delim);
  175. for (var i=0; i < parts.length; i++) {
  176. if (parts[i]==str) {
  177. retval=true;
  178. break;
  179. }
  180. }
  181. return retval;
  182. };
  183.  
  184. window.niobe_alltrim = function(str) {
  185. var dir = arguments[1]!==undefined ? arguments[1] : 'a';
  186. var rez = '';
  187. var i, start = 0, end = str.length-1;
  188. if (dir=='a' || dir=='l') {
  189. for (i=0; i < str.length; i++) {
  190. if (str.substr(i,1)!=' ') {
  191. start = i;
  192. break;
  193. }
  194. }
  195. }
  196. if (dir=='a' || dir=='r') {
  197. for (i=str.length-1; i >= 0; i--) {
  198. if (str.substr(i,1)!=' ') {
  199. end = i;
  200. break;
  201. }
  202. }
  203. }
  204. return str.substring(start, end+1);
  205. };
  206.  
  207. window.niobe_ltrim = function(str) {
  208. return niobe_alltrim(str, 'l');
  209. };
  210.  
  211. window.niobe_rtrim = function(str) {
  212. return niobe_alltrim(str, 'r');
  213. };
  214.  
  215. window.niobe_padl = function(str, len) {
  216. var ch = arguments[2]!==undefined ? arguments[2] : ' ';
  217. var rez = str.substr(0,len);
  218. if (rez.length < len) {
  219. for (var i=0; i < len-str.length; i++)
  220. rez += ch;
  221. }
  222. return rez;
  223. };
  224.  
  225. window.niobe_padr = function(str, len) {
  226. var ch = arguments[2]!==undefined ? arguments[2] : ' ';
  227. var rez = str.substr(0,len);
  228. if (rez.length < len) {
  229. for (var i=0; i < len-str.length; i++)
  230. rez = ch + rez;
  231. }
  232. return rez;
  233. };
  234.  
  235. window.niobe_padc = function(str, len) {
  236. var ch = arguments[2]!==undefined ? arguments[2] : ' ';
  237. var rez = str.substr(0,len);
  238. if (rez.length < len) {
  239. for (var i=0; i < Math.floor((len-str.length)/2); i++)
  240. rez = ch + rez + ch;
  241. }
  242. return rez+(rez.length<len ? ch : '');
  243. };
  244.  
  245. window.niobe_replicate = function(str, num) {
  246. var rez = '';
  247. for (var i=0; i < num; i++) {
  248. rez += str;
  249. }
  250. return rez;
  251. };
  252.  
  253. window.niobe_prepare_macros = function(str) {
  254. return str
  255. .replace(/\{\{/g, "<i>")
  256. .replace(/\}\}/g, "</i>")
  257. .replace(/\(\(/g, "<b>")
  258. .replace(/\)\)/g, "</b>")
  259. .replace(/\|\|/g, "<br>");
  260. };
  261.  
  262.  
  263.  
  264. /* Numbers functions
  265. ---------------------------------------------------------------- */
  266.  
  267. // Round number to specified precision.
  268. // For example: num=1.12345, prec=2, rounded=1.12
  269. // num=12345, prec=-2, rounded=12300
  270. window.niobe_round_number = function(num) {
  271. var precision = arguments[1]!==undefined ? arguments[1] : 0;
  272. var p = Math.pow(10, precision);
  273. return Math.round(num*p)/p;
  274. };
  275.  
  276. // Clear number from any characters and append it with 0 to desired precision
  277. // For example: num=test1.12dd, prec=3, cleared=1.120
  278. window.niobe_clear_number = function(num) {
  279. var precision = arguments[1]!==undefined ? arguments[1] : 0;
  280. var defa = arguments[2]!==undefined ? arguments[2] : 0;
  281. var res = '';
  282. var decimals = -1;
  283. num = ""+num;
  284. if (num=="") num=""+defa;
  285. for (var i=0; i < num.length; i++) {
  286. if (decimals==0) break;
  287. else if (decimals>0) decimals--;
  288. var ch = num.substr(i,1);
  289. if (ch=='.') {
  290. if (precision>0) {
  291. res += ch;
  292. }
  293. decimals = precision;
  294. } else if ((ch>=0 && ch<=9) || (ch=='-' && i==0))
  295. res+=ch;
  296. }
  297. if (precision>0 && decimals!=0) {
  298. if (decimals==-1) {
  299. res += '.';
  300. decimals = precision;
  301. }
  302. for (i=decimals; i > 0; i--)
  303. res +='0';
  304. }
  305. //if (isNaN(res)) res = clearNumber(defa, precision, defa);
  306. return res;
  307. };
  308.  
  309. // Convert number from decimal to hex
  310. window.niobe_dec2hex = function(n) {
  311. return Number(n).toString(16);
  312. };
  313.  
  314. // Convert number from hex to decimal
  315. window.niobe_hex2dec = function(hex) {
  316. return parseInt(hex,16);
  317. };
  318.  
  319.  
  320.  
  321. /* Array manipulations
  322. ---------------------------------------------------------------- */
  323.  
  324. window.niobe_in_array = function(val, thearray) {
  325. var rez = false;
  326. for (var i=0; i < thearray.length-1; i++) {
  327. if (thearray[i] == val) {
  328. rez = true;
  329. break;
  330. }
  331. }
  332. return rez;
  333. };
  334.  
  335. window.niobe_sort_array = function(thearray) {
  336. var caseSensitive = arguments[1]!==undefined ? arguments[1] : false;
  337. var tmp = '';
  338. for (var x=0; x < thearray.length-1; x++) {
  339. for (var y=(x+1); y < thearray.length; y++) {
  340. if (caseSensitive) {
  341. if (thearray[x] > thearray[y]) {
  342. tmp = thearray[x];
  343. thearray[x] = thearray[y];
  344. thearray[y] = tmp;
  345. }
  346. } else {
  347. if (thearray[x].toLowerCase() > thearray[y].toLowerCase()) {
  348. tmp = thearray[x];
  349. thearray[x] = thearray[y];
  350. thearray[y] = tmp;
  351. }
  352. }
  353. }
  354. }
  355. return thearray;
  356. };
  357.  
  358.  
  359.  
  360. /* Date manipulations
  361. ---------------------------------------------------------------- */
  362.  
  363. // Return array[Year, Month, Day, Hours, Minutes, Seconds]
  364. // from string: Year[-/.]Month[-/.]Day[T ]Hours:Minutes:Seconds
  365. window.niobe_parse_date = function(dt) {
  366. dt = dt.replace(/\//g, '-').replace(/\./g, '-').replace(/T/g, ' ').split('+')[0];
  367. var dt2 = dt.split(' ');
  368. var d = dt2[0].split('-');
  369. var t = dt2[1].split(':');
  370. d.push(t[0], t[1], t[2]);
  371. return d;
  372. };
  373.  
  374. // Return difference string between two dates
  375. window.niobe_get_date_difference = function(dt1) {
  376. var dt2 = arguments[1]!==undefined ? arguments[1] : '';
  377. var short_date = arguments[2]!==undefined ? arguments[2] : true;
  378. var sec = arguments[3]!==undefined ? arguments[3] : false;
  379. var a1 = niobe_parse_date(dt1);
  380. dt1 = Date.UTC(a1[0], a1[1], a1[2], a1[3], a1[4], a1[5]);
  381. if (dt2 == '') {
  382. dt2 = new Date();
  383. var a2 = [dt2.getFullYear(), dt2.getMonth()+1, dt2.getDate(), dt2.getHours(), dt2.getMinutes(), dt2.getSeconds()];
  384. } else
  385. var a2 = niobe_parse_date(dt2);
  386. dt2 = Date.UTC(a2[0], a2[1], a2[2], a2[3], a2[4], a2[5]);
  387. var diff = Math.round((dt2 - dt1)/1000);
  388. var days = Math.floor(diff / (24*3600));
  389. diff -= days * 24 * 3600;
  390. var hours = Math.floor(diff / 3600);
  391. diff -= hours * 3600;
  392. var minutes = Math.floor(diff / 60);
  393. diff -= minutes * 60;
  394. var rez = '';
  395. if (days > 0)
  396. rez += (rez!='' ? ' ' : '') + days + ' day' + (days > 1 ? 's' : '');
  397. if ((!short_date || rez=='') && hours > 0)
  398. rez += (rez!='' ? ' ' : '') + hours + ' hour' + (hours > 1 ? 's' : '');
  399. if ((!short_date || rez=='') && minutes > 0)
  400. rez += (rez!='' ? ' ' : '') + minutes + ' minute' + (minutes > 1 ? 's' : '');
  401. if (sec || rez=='')
  402. rez += rez!='' || sec ? (' ' + diff + ' second' + (diff > 1 ? 's' : '')) : 'less then minute';
  403. return rez;
  404. };
  405.  
  406.  
  407.  
  408. /* Colors functions
  409. ---------------------------------------------------------------- */
  410.  
  411. window.niobe_hex2rgb = function(hex) {
  412. hex = parseInt(((hex.indexOf('#') > -1) ? hex.substring(1) : hex), 16);
  413. return {r: hex >> 16, g: (hex & 0x00FF00) >> 8, b: (hex & 0x0000FF)};
  414. };
  415.  
  416. window.niobe_hex2rgba = function(hex, alpha) {
  417. var rgb = niobe_hex2rgb(hex);
  418. return 'rgba('+rgb.r+','+rgb.g+','+rgb.b+','+alpha+')';
  419. };
  420.  
  421. window.niobe_rgb2hex = function(color) {
  422. var aRGB;
  423. color = color.replace(/\s/g,"").toLowerCase();
  424. if (color=='rgba(0,0,0,0)' || color=='rgba(0%,0%,0%,0%)')
  425. color = 'transparent';
  426. if (color.indexOf('rgba(')==0)
  427. aRGB = color.match(/^rgba\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i);
  428. else
  429. aRGB = color.match(/^rgb\((\d{1,3}[%]?),(\d{1,3}[%]?),(\d{1,3}[%]?)\)$/i);
  430.  
  431. if(aRGB) {
  432. color = '';
  433. for (var i=1; i <= 3; i++)
  434. color += Math.round((aRGB[i][aRGB[i].length-1]=="%"?2.55:1)*parseInt(aRGB[i])).toString(16).replace(/^(.)$/,'0$1');
  435. } else
  436. color = color.replace(/^#?([\da-f])([\da-f])([\da-f])$/i, '$1$1$2$2$3$3');
  437. return (color.substr(0,1)!='#' ? '#' : '') + color;
  438. };
  439.  
  440. window.niobe_components2hex = function(r,g,b) {
  441. return '#'+
  442. Number(r).toString(16).toUpperCase().replace(/^(.)$/,'0$1') +
  443. Number(g).toString(16).toUpperCase().replace(/^(.)$/,'0$1') +
  444. Number(b).toString(16).toUpperCase().replace(/^(.)$/,'0$1');
  445. };
  446.  
  447. window.niobe_rgb2components = function(color) {
  448. color = niobe_rgb2hex(color);
  449. var matches = color.match(/^#?([\dabcdef]{2})([\dabcdef]{2})([\dabcdef]{2})$/i);
  450. if (!matches) return false;
  451. for (var i=1, rgb = new Array(3); i <= 3; i++)
  452. rgb[i-1] = parseInt(matches[i],16);
  453. return rgb;
  454. };
  455.  
  456. window.niobe_hex2hsb = function(hex) {
  457. var h = arguments[1]!==undefined ? arguments[1] : 0;
  458. var s = arguments[2]!==undefined ? arguments[2] : 0;
  459. var b = arguments[3]!==undefined ? arguments[3] : 0;
  460. var hsb = niobe_rgb2hsb(niobe_hex2rgb(hex));
  461. hsb.h = Math.min(359, hsb.h + h);
  462. hsb.s = Math.min(100, hsb.s + s);
  463. hsb.b = Math.min(100, hsb.b + b);
  464. return hsb;
  465. };
  466.  
  467. window.niobe_hsb2hex = function(hsb) {
  468. var rgb = niobe_hsb2rgb(hsb);
  469. return niobe_components2hex(rgb.r, rgb.g, rgb.b);
  470. };
  471.  
  472. window.niobe_rgb2hsb = function(rgb) {
  473. var hsb = {};
  474. hsb.b = Math.max(Math.max(rgb.r,rgb.g),rgb.b);
  475. hsb.s = (hsb.b <= 0) ? 0 : Math.round(100*(hsb.b - Math.min(Math.min(rgb.r,rgb.g),rgb.b))/hsb.b);
  476. hsb.b = Math.round((hsb.b /255)*100);
  477. if ((rgb.r==rgb.g) && (rgb.g==rgb.b)) hsb.h = 0;
  478. else if (rgb.r>=rgb.g && rgb.g>=rgb.b) hsb.h = 60*(rgb.g-rgb.b)/(rgb.r-rgb.b);
  479. else if (rgb.g>=rgb.r && rgb.r>=rgb.b) hsb.h = 60 + 60*(rgb.g-rgb.r)/(rgb.g-rgb.b);
  480. else if (rgb.g>=rgb.b && rgb.b>=rgb.r) hsb.h = 120 + 60*(rgb.b-rgb.r)/(rgb.g-rgb.r);
  481. else if (rgb.b>=rgb.g && rgb.g>=rgb.r) hsb.h = 180 + 60*(rgb.b-rgb.g)/(rgb.b-rgb.r);
  482. else if (rgb.b>=rgb.r && rgb.r>=rgb.g) hsb.h = 240 + 60*(rgb.r-rgb.g)/(rgb.b-rgb.g);
  483. else if (rgb.r>=rgb.b && rgb.b>=rgb.g) hsb.h = 300 + 60*(rgb.r-rgb.b)/(rgb.r-rgb.g);
  484. else hsb.h = 0;
  485. hsb.h = Math.round(hsb.h);
  486. return hsb;
  487. };
  488.  
  489. window.niobe_hsb2rgb = function(hsb) {
  490. var rgb = {};
  491. var h = Math.round(hsb.h);
  492. var s = Math.round(hsb.s*255/100);
  493. var v = Math.round(hsb.b*255/100);
  494. if (s == 0) {
  495. rgb.r = rgb.g = rgb.b = v;
  496. } else {
  497. var t1 = v;
  498. var t2 = (255-s)*v/255;
  499. var t3 = (t1-t2)*(h%60)/60;
  500. if (h==360) h = 0;
  501. if (h<60) { rgb.r=t1; rgb.b=t2; rgb.g=t2+t3; }
  502. else if (h<120) { rgb.g=t1; rgb.b=t2; rgb.r=t1-t3; }
  503. else if (h<180) { rgb.g=t1; rgb.r=t2; rgb.b=t2+t3; }
  504. else if (h<240) { rgb.b=t1; rgb.r=t2; rgb.g=t1-t3; }
  505. else if (h<300) { rgb.b=t1; rgb.g=t2; rgb.r=t2+t3; }
  506. else if (h<360) { rgb.r=t1; rgb.g=t2; rgb.b=t1-t3; }
  507. else { rgb.r=0; rgb.g=0; rgb.b=0; }
  508. }
  509. return { r:Math.round(rgb.r), g:Math.round(rgb.g), b:Math.round(rgb.b) };
  510. };
  511.  
  512. window.niobe_color_picker = function(){
  513. var id = arguments[0]!==undefined ? arguments[0] : "iColorPicker"+Math.round(Math.random()*1000);
  514. var colors = arguments[1]!==undefined ? arguments[1] :
  515. '#f00,#ff0,#0f0,#0ff,#00f,#f0f,#fff,#ebebeb,#e1e1e1,#d7d7d7,#cccccc,#c2c2c2,#b7b7b7,#acacac,#a0a0a0,#959595,'
  516. +'#ee1d24,#fff100,#00a650,#00aeef,#2f3192,#ed008c,#898989,#7d7d7d,#707070,#626262,#555,#464646,#363636,#262626,#111,#000,'
  517. +'#f7977a,#fbad82,#fdc68c,#fff799,#c6df9c,#a4d49d,#81ca9d,#7bcdc9,#6ccff7,#7ca6d8,#8293ca,#8881be,#a286bd,#bc8cbf,#f49bc1,#f5999d,'
  518. +'#f16c4d,#f68e54,#fbaf5a,#fff467,#acd372,#7dc473,#39b778,#16bcb4,#00bff3,#438ccb,#5573b7,#5e5ca7,#855fa8,#a763a9,#ef6ea8,#f16d7e,'
  519. +'#ee1d24,#f16522,#f7941d,#fff100,#8fc63d,#37b44a,#00a650,#00a99e,#00aeef,#0072bc,#0054a5,#2f3192,#652c91,#91278f,#ed008c,#ee105a,'
  520. +'#9d0a0f,#a1410d,#a36209,#aba000,#588528,#197b30,#007236,#00736a,#0076a4,#004a80,#003370,#1d1363,#450e61,#62055f,#9e005c,#9d0039,'
  521. +'#790000,#7b3000,#7c4900,#827a00,#3e6617,#045f20,#005824,#005951,#005b7e,#003562,#002056,#0c004b,#30004a,#4b0048,#7a0045,#7a0026';
  522. var colorsList = colors.split(',');
  523. var tbl = '<table class="colorPickerTable"><thead>';
  524. for (var i=0; i < colorsList.length; i++) {
  525. if (i%16==0) tbl += (i>0 ? '</tr>' : '') + '<tr>';
  526. tbl += '<td style="background-color:'+colorsList[i]+'">&nbsp;</td>';
  527. }
  528. tbl += '</tr></thead><tbody>'
  529. + '<tr class="height_60">'
  530. + '<td colspan="8" id="'+id+'_colorPreview" class="colorpicker_td_extra_style">'
  531. + '<input class="colorpicker_input_extra_style" maxlength="7" />'
  532. + '<a href="#" id="'+id+'_moreColors" class="iColorPicker_moreColors"></a>'
  533. + '</td>'
  534. + '<td colspan="8" id="'+id+'_colorOriginal">'
  535. + '<input class="colorpicker_input_extra_style" readonly="readonly" />'
  536. + '</td>'
  537. + '</tr></tbody></table>';
  538.  
  539. jQuery(document.createElement("div"))
  540. .attr("id", id)
  541. .css('display','none')
  542. .html(tbl)
  543. .appendTo("body")
  544. .addClass("iColorPickerTable")
  545. .on('mouseover', 'thead td', function(){
  546. var aaa = niobe_rgb2hex(jQuery(this).css('background-color'));
  547. jQuery('#'+id+'_colorPreview').css('background',aaa);
  548. jQuery('#'+id+'_colorPreview input').val(aaa);
  549. })
  550. .on('keypress', '#'+id+'_colorPreview input', function(key){
  551. var aaa = jQuery(this).val();
  552. if (aaa.length<7 && ((key.which>=48 && key.which<=57) || (key.which>=97 && key.which<=102) || (key.which===35 || aaa.length===0))) {
  553. aaa += String.fromCharCode(key.which);
  554. } else if (key.which == 8 && aaa.length>0) {
  555. aaa = aaa.substring(0, aaa.length-1);
  556. } else if (key.which===13 && (aaa.length===4 || aaa.length===7)) {
  557. var fld = jQuery('#'+id).data('field');
  558. var func = jQuery('#'+id).data('func');
  559. if (func!=null && func!='undefined') {
  560. func(fld, aaa);
  561. } else {
  562. fld.val(aaa).css('backgroundColor', aaa).trigger('change');
  563. }
  564. jQuery('#'+id+'_Bg').fadeOut(500);
  565. jQuery('#'+id).fadeOut(500);
  566.  
  567. } else {
  568. key.preventDefault();
  569. return false;
  570. }
  571. if (aaa.substr(0,1)==='#' && (aaa.length===4 || aaa.length===7)) {
  572. jQuery('#'+id+'_colorPreview').css('background',aaa);
  573. }
  574. })
  575. .on('click', 'thead td', function(e){
  576. var fld = jQuery('#'+id).data('field');
  577. var func = jQuery('#'+id).data('func');
  578. var aaa = niobe_rgb2hex(jQuery(this).css('background-color'));
  579. if (func!=null && func!='undefined') {
  580. func(fld, aaa);
  581. } else {
  582. fld.val(aaa).css('backgroundColor', aaa).trigger('change');
  583. }
  584. jQuery('#'+id+'_Bg').fadeOut(500);
  585. jQuery('#'+id).fadeOut(500);
  586. e.preventDefault();
  587. return false;
  588. })
  589. .on('click', 'tbody .iColorPicker_moreColors', function(e){
  590. var thead = jQuery(this).parents('table').find('thead');
  591. var out = '';
  592. if (thead.hasClass('more_colors')) {
  593. for (var i=0; i < colorsList.length; i++) {
  594. if (i%16==0) out += (i>0 ? '</tr>' : '') + '<tr>';
  595. out += '<td style="background-color:'+colorsList[i]+'">&nbsp;</td>';
  596. }
  597. thead.removeClass('more_colors').empty().html(out+'</tr>');
  598. jQuery('#'+id+'_colorPreview').attr('colspan', 8);
  599. jQuery('#'+id+'_colorOriginal').attr('colspan', 8);
  600. } else {
  601. var rgb=[0,0,0], i=0, j=-1; // Set j=-1 or j=0 - show 2 different colors layouts
  602. while (rgb[0]<0xF || rgb[1]<0xF || rgb[2]<0xF) {
  603. if (i%18==0) out += (i>0 ? '</tr>' : '') + '<tr>';
  604. i++;
  605. out += '<td style="background-color:'+niobe_components2hex(rgb[0]*16+rgb[0],rgb[1]*16+rgb[1],rgb[2]*16+rgb[2])+'">&nbsp;</td>';
  606. rgb[2]+=3;
  607. if (rgb[2]>0xF) {
  608. rgb[1]+=3;
  609. if (rgb[1]>(j===0 ? 6 : 0xF)) {
  610. rgb[0]+=3;
  611. if (rgb[0]>0xF) {
  612. if (j===0) {
  613. j=1;
  614. rgb[0]=0;
  615. rgb[1]=9;
  616. rgb[2]=0;
  617. } else {
  618. break;
  619. }
  620. } else {
  621. rgb[1]=(j < 1 ? 0 : 9);
  622. rgb[2]=0;
  623. }
  624. } else {
  625. rgb[2]=0;
  626. }
  627. }
  628. }
  629. thead.addClass('more_colors').empty().html(out+'<td class="bg_color_white" colspan="8">&nbsp;</td></tr>');
  630. jQuery('#'+id+'_colorPreview').attr('colspan', 9);
  631. jQuery('#'+id+'_colorOriginal').attr('colspan', 9);
  632. }
  633. jQuery('#'+id+' table.colorPickerTable thead td')
  634. .css({
  635. 'width':'12px',
  636. 'height':'14px',
  637. 'border':'1px solid #000',
  638. 'cursor':'pointer'
  639. });
  640. e.preventDefault();
  641. return false;
  642. });
  643. jQuery(document.createElement("div"))
  644. .attr("id", id+"_Bg")
  645. .on('click', function(e) {
  646. jQuery("#"+id+"_Bg").fadeOut(500);
  647. jQuery("#"+id).fadeOut(500);
  648. e.preventDefault();
  649. return false;
  650. })
  651. .appendTo("body");
  652. jQuery('#'+id+' table.colorPickerTable thead td')
  653. .css({
  654. 'width':'12px',
  655. 'height':'14px',
  656. 'border':'1px solid #000',
  657. 'cursor':'pointer'
  658. });
  659. jQuery('#'+id+' table.colorPickerTable')
  660. .css({'border-collapse':'collapse'});
  661. jQuery('#'+id)
  662. .css({
  663. 'border':'1px solid #ccc',
  664. 'background':'#333',
  665. 'padding':'5px',
  666. 'color':'#fff'
  667. });
  668. jQuery('#'+id+'_colorPreview')
  669. .css({'height':'50px'});
  670. return id;
  671. };
  672.  
  673. window.niobe_color_picker_show = function(id, fld, func) {
  674. if (id===null || id==='') {
  675. id = jQuery('.iColorPickerTable').attr('id');
  676. }
  677. var eICP = fld.offset();
  678. var w = jQuery('#'+id).width();
  679. var h = jQuery('#'+id).height();
  680. var l = eICP.left + w < jQuery(window).width()-10 ? eICP.left : jQuery(window).width()-10 - w;
  681. var t = eICP.top + fld.outerHeight() + h < jQuery(document).scrollTop() + jQuery(window).height()-10 ? eICP.top + fld.outerHeight() : eICP.top - h - 13;
  682. jQuery("#"+id)
  683. .data({field: fld, func: func})
  684. .css({
  685. 'top':t+"px",
  686. 'left':l+"px",
  687. 'position':'absolute',
  688. 'z-index':999999
  689. })
  690. .fadeIn(500);
  691. jQuery("#"+id+"_Bg")
  692. .css({
  693. 'position':'fixed',
  694. 'z-index':999998,
  695. 'top':0,
  696. 'left':0,
  697. 'width':'100%',
  698. 'height':'100%'
  699. })
  700. .fadeIn(500);
  701. var def = fld.val().substr(0, 1)=='#' ? fld.val() : niobe_rgb2hex(fld.css('backgroundColor'));
  702. jQuery('#'+id+'_colorPreview input,#'+id+'_colorOriginal input').val(def);
  703. jQuery('#'+id+'_colorPreview,#'+id+'_colorOriginal').css('background',def);
  704. };
  705.  
  706.  
  707.  
  708. /* Cookies manipulations
  709. ---------------------------------------------------------------- */
  710.  
  711. window.niobe_get_cookie = function(name) {
  712. var defa = arguments[1]!==undefined ? arguments[1] : null;
  713. var start = document.cookie.indexOf(name + '=');
  714. var len = start + name.length + 1;
  715. if ((!start) && (name != document.cookie.substring(0, name.length))) {
  716. return defa;
  717. }
  718. if (start == -1)
  719. return defa;
  720. var end = document.cookie.indexOf(';', len);
  721. if (end == -1)
  722. end = document.cookie.length;
  723. return unescape(document.cookie.substring(len, end));
  724. };
  725.  
  726.  
  727. window.niobe_set_cookie = function(name, value) {
  728. var expires = arguments[2]!==undefined ? arguments[2] : 0;
  729. var path = arguments[3]!==undefined ? arguments[3] : '/';
  730. var domain = arguments[4]!==undefined ? arguments[4] : '';
  731. var secure = arguments[5]!==undefined ? arguments[5] : '';
  732. var today = new Date();
  733. today.setTime(today.getTime());
  734. if (expires) {
  735. expires = expires * 1000 * 60 * 60 * 24;
  736. }
  737. var expires_date = new Date(today.getTime() + (expires));
  738. document.cookie = name + '='
  739. + escape(value)
  740. + ((expires) ? ';expires=' + expires_date.toGMTString() : '')
  741. + ((path) ? ';path=' + path : '')
  742. + ((domain) ? ';domain=' + domain : '')
  743. + ((secure) ? ';secure' : '');
  744. };
  745.  
  746.  
  747. window.niobe_del_cookie = function(name, path, domain) {
  748. var path = arguments[1]!==undefined ? arguments[1] : '/';
  749. var domain = arguments[2]!==undefined ? arguments[2] : '';
  750. if (niobe_get_cookie(name))
  751. document.cookie = name + '=' + ((path) ? ';path=' + path : '')
  752. + ((domain) ? ';domain=' + domain : '')
  753. + ';expires=Thu, 01-Jan-1970 00:00:01 GMT';
  754. };
  755.  
  756.  
  757.  
  758. /* ListBox and ComboBox manipulations
  759. ---------------------------------------------------------------- */
  760.  
  761. window.niobe_clear_listbox = function(box) {
  762. for (var i=box.options.length-1; i >= 0; i--)
  763. box.options[i] = null;
  764. };
  765.  
  766. window.niobe_add_listbox_item = function(box, val, text) {
  767. var item = new Option();
  768. item.value = val;
  769. item.text = text;
  770. box.options.add(item);
  771. };
  772.  
  773. window.niobe_del_listbox_item_by_value = function(box, val) {
  774. for (var i=0; i < box.options.length; i++) {
  775. if (box.options[i].value == val) {
  776. box.options[i] = null;
  777. break;
  778. }
  779. }
  780. };
  781.  
  782. window.niobe_del_listbox_item_by_text = function(box, txt) {
  783. for (var i=0; i < box.options.length; i++) {
  784. if (box.options[i].text == txt) {
  785. box.options[i] = null;
  786. break;
  787. }
  788. }
  789. };
  790.  
  791. window.niobe_find_listbox_item_by_value = function(box, val) {
  792. var idx = -1;
  793. for (var i=0; i < box.options.length; i++) {
  794. if (box.options[i].value == val) {
  795. idx = i;
  796. break;
  797. }
  798. }
  799. return idx;
  800. };
  801.  
  802. window.niobe_find_listbox_item_by_text = function(box, txt) {
  803. var idx = -1;
  804. for (var i=0; i < box.options.length; i++) {
  805. if (box.options[i].text == txt) {
  806. idx = i;
  807. break;
  808. }
  809. }
  810. return idx;
  811. };
  812.  
  813. window.niobe_select_listbox_item_by_value = function(box, val) {
  814. for (var i = 0; i < box.options.length; i++) {
  815. box.options[i].selected = (val == box.options[i].value);
  816. }
  817. };
  818.  
  819. window.niobe_select_listbox_item_by_text = function(box, txt) {
  820. for (var i = 0; i < box.options.length; i++) {
  821. box.options[i].selected = (txt == box.options[i].text);
  822. }
  823. };
  824.  
  825. window.niobe_get_listbox_values = function(box) {
  826. var delim = arguments[1]!==undefined ? arguments[1] : ',';
  827. var str = '';
  828. for (var i=0; i < box.options.length; i++) {
  829. str += (str ? delim : '') + box.options[i].value;
  830. }
  831. return str;
  832. };
  833.  
  834. window.niobe_get_listbox_texts = function(box) {
  835. var delim = arguments[1]!==undefined ? arguments[1] : ',';
  836. var str = '';
  837. for (var i=0; i < box.options.length; i++) {
  838. str += (str ? delim : '') + box.options[i].text;
  839. }
  840. return str;
  841. };
  842.  
  843. window.niobe_sort_listbox = function(box) {
  844. var temp_opts = new Array();
  845. var temp = new Option();
  846. for(var i=0; i<box.options.length; i++) {
  847. temp_opts[i] = box.options[i].clone();
  848. }
  849. for(var x=0; x<temp_opts.length-1; x++) {
  850. for(var y=(x+1); y<temp_opts.length; y++) {
  851. if(temp_opts[x].text > temp_opts[y].text) {
  852. temp = temp_opts[x];
  853. temp_opts[x] = temp_opts[y];
  854. temp_opts[y] = temp;
  855. }
  856. }
  857. }
  858. for(var i=0; i<box.options.length; i++) {
  859. box.options[i] = temp_opts[i].clone();
  860. }
  861. };
  862.  
  863. window.niobe_get_listbox_selected_index = function(box) {
  864. for (var i = 0; i < box.options.length; i++) {
  865. if (box.options[i].selected)
  866. return i;
  867. }
  868. return -1;
  869. };
  870.  
  871. window.niobe_get_listbox_selected_value = function(box) {
  872. for (var i = 0; i < box.options.length; i++) {
  873. if (box.options[i].selected) {
  874. return box.options[i].value;
  875. }
  876. }
  877. return null;
  878. };
  879.  
  880. window.niobe_get_listbox_selected_text = function(box) {
  881. for (var i = 0; i < box.options.length; i++) {
  882. if (box.options[i].selected) {
  883. return box.options[i].text;
  884. }
  885. }
  886. return null;
  887. };
  888.  
  889. window.niobe_get_listbox_selected_option = function(box) {
  890. for (var i = 0; i < box.options.length; i++) {
  891. if (box.options[i].selected) {
  892. return box.options[i];
  893. }
  894. }
  895. return null;
  896. };
  897.  
  898.  
  899.  
  900. /* Radio buttons manipulations
  901. ---------------------------------------------------------------- */
  902.  
  903. window.niobe_get_radio_value = function(radioGroupObj) {
  904. for (var i=0; i < radioGroupObj.length; i++)
  905. if (radioGroupObj[i].checked) return radioGroupObj[i].value;
  906. return null;
  907. };
  908.  
  909. window.niobe_set_radio_checked_by_num = function(radioGroupObj, num) {
  910. for (var i=0; i < radioGroupObj.length; i++)
  911. if (radioGroupObj[i].checked && i!=num) radioGroupObj[i].checked=false;
  912. else if (i==num) radioGroupObj[i].checked=true;
  913. };
  914.  
  915. window.niobe_set_radio_checked_by_value = function(radioGroupObj, val) {
  916. for (var i=0; i < radioGroupObj.length; i++)
  917. if (radioGroupObj[i].checked && radioGroupObj[i].value!=val) radioGroupObj[i].checked=false;
  918. else if (radioGroupObj[i].value==val) radioGroupObj[i].checked=true;
  919. };
  920.  
  921.  
  922.  
  923. /* Form manipulations
  924. ---------------------------------------------------------------- */
  925.  
  926. /*
  927. // Usage example:
  928. var error = niobe_form_validate(jQuery(form_selector), { // -------- Options ---------
  929. error_message_show: true, // Display or not error message
  930. error_message_time: 5000, // Time to display error message
  931. error_message_class: 'messagebox messagebox_style_error', // Class, appended to error message block
  932. error_message_text: 'Global error text', // Global error message text (if don't write message in checked field)
  933. error_fields_class: 'error_field', // Class, appended to error fields
  934. exit_after_first_error: false, // Cancel validation and exit after first error
  935. rules: [
  936. {
  937. field: 'author', // Checking field name
  938. min_length: { value: 1, message: 'The author name can\'t be empty' }, // Min character count (0 - don't check), message - if error occurs
  939. max_length: { value: 60, message: 'Too long author name'} // Max character count (0 - don't check), message - if error occurs
  940. },
  941. {
  942. field: 'email',
  943. min_length: { value: 7, message: 'Too short (or empty) email address' },
  944. max_length: { value: 60, message: 'Too long email address'},
  945. mask: { value: '^([a-z0-9_\\-]+\\.)*[a-z0-9_\\-]+@[a-z0-9_\\-]+(\\.[a-z0-9_\\-]+)*\\.[a-z]{2,6}$', message: 'Invalid email address'}
  946. },
  947. {
  948. field: 'comment',
  949. min_length: { value: 1, message: 'The comment text can\'t be empty' },
  950. max_length: { value: 200, message: 'Too long comment'}
  951. },
  952. {
  953. field: 'pwd1',
  954. min_length: { value: 5, message: 'The password can\'t be less then 5 characters' },
  955. max_length: { value: 20, message: 'Too long password'}
  956. },
  957. {
  958. field: 'pwd2',
  959. equal_to: { value: 'pwd1', message: 'The passwords in both fields must be equals' }
  960. }
  961. ]
  962. });
  963. */
  964.  
  965. window.niobe_form_validate = function(form, opt) {
  966. var error_msg = '';
  967. form.find(":input").each(function() {
  968. if (error_msg!='' && opt.exit_after_first_error) return;
  969. for (var i = 0; i < opt.rules.length; i++) {
  970. if (jQuery(this).attr("name") == opt.rules[i].field) {
  971. var val = jQuery(this).val();
  972. var error = false;
  973. if (typeof(opt.rules[i].min_length) == 'object') {
  974. if (opt.rules[i].min_length.value > 0 && val.length < opt.rules[i].min_length.value) {
  975. if (error_msg=='') jQuery(this).get(0).focus();
  976. 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>';
  977. error = true;
  978. }
  979. }
  980. if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].max_length) == 'object') {
  981. if (opt.rules[i].max_length.value > 0 && val.length > opt.rules[i].max_length.value) {
  982. if (error_msg=='') jQuery(this).get(0).focus();
  983. 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>';
  984. error = true;
  985. }
  986. }
  987. if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].mask) == 'object') {
  988. if (opt.rules[i].mask.value != '') {
  989. var regexp = new RegExp(opt.rules[i].mask.value);
  990. if (!regexp.test(val)) {
  991. if (error_msg=='') jQuery(this).get(0).focus();
  992. error_msg += '<p class="error_item">' + (typeof(opt.rules[i].mask.message)!='undefined' ? opt.rules[i].mask.message : opt.error_message_text ) + '</p>';
  993. error = true;
  994. }
  995. }
  996. }
  997. if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].state) == 'object') {
  998. if (opt.rules[i].state.value=='checked' && !jQuery(this).get(0).checked) {
  999. if (error_msg=='') jQuery(this).get(0).focus();
  1000. error_msg += '<p class="error_item">' + (typeof(opt.rules[i].state.message)!='undefined' ? opt.rules[i].state.message : opt.error_message_text ) + '</p>';
  1001. error = true;
  1002. }
  1003. }
  1004. if ((!error || !opt.exit_after_first_error) && typeof(opt.rules[i].equal_to) == 'object') {
  1005. if (opt.rules[i].equal_to.value != '' && val!=jQuery(jQuery(this).get(0).form[opt.rules[i].equal_to.value]).val()) {
  1006. if (error_msg=='') jQuery(this).get(0).focus();
  1007. 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>';
  1008. error = true;
  1009. }
  1010. }
  1011. if (opt.error_fields_class != '') jQuery(this).toggleClass(opt.error_fields_class, error);
  1012. }
  1013. }
  1014. });
  1015. if (error_msg!='' && opt.error_message_show) {
  1016. var error_message_box = form.find(".result");
  1017. if (error_message_box.length == 0) error_message_box = form.parent().find(".result");
  1018. if (error_message_box.length == 0) {
  1019. form.append('<div class="result"></div>');
  1020. error_message_box = form.find(".result");
  1021. }
  1022. if (opt.error_message_class) error_message_box.toggleClass(opt.error_message_class, true);
  1023. error_message_box.html(error_msg).fadeIn();
  1024. setTimeout(function() { error_message_box.fadeOut(); }, opt.error_message_time);
  1025. }
  1026. return error_msg!='';
  1027. };
  1028.  
  1029.  
  1030.  
  1031. /* Document manipulations
  1032. ---------------------------------------------------------------- */
  1033.  
  1034. // Animated scroll to selected id
  1035. window.niobe_document_animate_to = function(id, callback) {
  1036. var oft = !isNaN(id) ? Number(id) : 0;
  1037. if (isNaN(id)) {
  1038. if (id.indexOf('#')==-1) id = '#' + id;
  1039. var obj = jQuery(id).eq(0);
  1040. if (obj.length == 0) return;
  1041. oft = obj.offset().top;
  1042. }
  1043. var st = jQuery(window).scrollTop();
  1044. var oft2 = Math.max(0, oft - niobe_fixed_rows_height());
  1045. var speed = Math.min(1200, Math.max(300, Math.round(Math.abs(oft2-st) / jQuery(window).height() * 300)));
  1046. if (st == 0) {
  1047. setTimeout(function() {
  1048. if (isNaN(id)) oft = obj.offset().top;
  1049. oft2 = Math.max(0, oft - niobe_fixed_rows_height());
  1050. jQuery('body,html').stop(true).animate( {scrollTop: oft2}, Math.floor(speed/2), 'linear', callback );
  1051. }, Math.floor(speed/2));
  1052. }
  1053. jQuery('body,html').stop(true).animate( {scrollTop: oft2}, speed, 'linear', callback );
  1054. };
  1055.  
  1056. // Detect fixed rows height
  1057. window.niobe_fixed_rows_height = function() {
  1058. var with_admin_bar = arguments.length>0 ? arguments[0] : true;
  1059. var with_fixed_rows = arguments.length>1 ? arguments[1] : true;
  1060. var oft = 0;
  1061. // Admin bar height (if visible and fixed)
  1062. if (with_admin_bar) {
  1063. var admin_bar = jQuery('#wpadminbar');
  1064. oft += admin_bar.length > 0 && admin_bar.css('display')!='none' && admin_bar.css('position')=='fixed'
  1065. ? admin_bar.height()
  1066. : 0;
  1067. }
  1068. // Fixed rows height
  1069. if (with_fixed_rows) {
  1070. jQuery('.sc_layouts_row_fixed_on').each(function() {
  1071. if (jQuery(this).css('position')=='fixed')
  1072. oft += jQuery(this).height();
  1073. });
  1074. }
  1075. return oft;
  1076. };
  1077.  
  1078. // Change browser address without reload page
  1079. window.niobe_document_set_location = function(curLoc){
  1080. try {
  1081. history.pushState(null, null, curLoc);
  1082. return;
  1083. } catch(e) {}
  1084. location.href = curLoc;
  1085. };
  1086.  
  1087. // Add/Change arguments to the url address
  1088. window.niobe_add_to_url = function(loc, prm) {
  1089. var ignore_empty = arguments[2]!==undefined ? arguments[2] : true;
  1090. var q = loc.indexOf('?');
  1091. var attr = {};
  1092. if (q > 0) {
  1093. var qq = loc.substr(q+1).split('&');
  1094. var parts = '';
  1095. for (var i=0; i < qq.length; i++) {
  1096. var parts = qq[i].split('=');
  1097. attr[parts[0]] = parts.length>1 ? parts[1] : '';
  1098. }
  1099. }
  1100. for (var p in prm) {
  1101. attr[p] = prm[p];
  1102. }
  1103. loc = (q > 0 ? loc.substr(0, q) : loc) + '?';
  1104. var i = 0;
  1105. for (p in attr) {
  1106. if (ignore_empty && attr[p]=='') continue;
  1107. loc += (i++ > 0 ? '&' : '') + p + '=' + attr[p];
  1108. }
  1109. return loc;
  1110. };
  1111.  
  1112. // Check if url is page-inner (local) link
  1113. window.niobe_is_local_link = function(url) {
  1114. var rez = url!==undefined;
  1115. if (rez) {
  1116. var url_pos = url.indexOf('#');
  1117. if (url_pos == 0 && url.length == 1)
  1118. rez = false;
  1119. else {
  1120. if (url_pos < 0) url_pos = url.length;
  1121. var loc = window.location.href;
  1122. var loc_pos = loc.indexOf('#');
  1123. if (loc_pos > 0) loc = loc.substring(0, loc_pos);
  1124. rez = url_pos==0;
  1125. if (!rez) rez = loc == url.substring(0, url_pos);
  1126. }
  1127. }
  1128. return rez;
  1129. };
  1130.  
  1131.  
  1132.  
  1133. /* Browsers detection
  1134. ---------------------------------------------------------------- */
  1135.  
  1136. window.niobe_browser_is_mobile = function() {
  1137. var check = false;
  1138. (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);
  1139. return check;
  1140. };
  1141.  
  1142. window.niobe_browser_is_ios = function() {
  1143. return navigator.userAgent.match(/iPad|iPhone|iPod/i) != null;
  1144. };
  1145.  
  1146. window.niobe_is_retina = function() {
  1147. 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)';
  1148. return (window.devicePixelRatio > 1) || (window.matchMedia && window.matchMedia(mediaQuery).matches);
  1149. };
  1150.  
  1151.  
  1152.  
  1153. /* File functions
  1154. ---------------------------------------------------------------- */
  1155.  
  1156. window.niobe_get_file_name = function(path) {
  1157. path = path.replace(/\\/g, '/');
  1158. var pos = path.lastIndexOf('/');
  1159. if (pos >= 0)
  1160. path = path.substr(pos+1);
  1161. return path;
  1162. };
  1163.  
  1164. window.niobe_get_file_ext = function(path) {
  1165. var pos = path.lastIndexOf('.');
  1166. path = pos >= 0 ? path.substr(pos+1) : '';
  1167. return path;
  1168. };
  1169.  
  1170.  
  1171.  
  1172. /* Image functions
  1173. ---------------------------------------------------------------- */
  1174.  
  1175. // Return true, if all images in the specified container are loaded
  1176. window.niobe_check_images_complete = function(cont) {
  1177. var complete = true;
  1178. cont.find('img').each(function() {
  1179. if (!complete) return;
  1180. if (!jQuery(this).get(0).complete) complete = false;
  1181. });
  1182. return complete;
  1183. };
  1184.  
  1185.  
  1186. /* Debug functions
  1187. ---------------------------------------------------------------- */
  1188. window.niobe_debug_object = function(obj) {
  1189. var recursive = arguments[1] ? arguments[1] : 0; // Show inner objects (arrays) in depth
  1190. var showMethods = arguments[2] ? arguments[2] : false; // Show object's methods
  1191. var level = arguments[3] ? arguments[3] : 0; // Nesting level (for internal usage only)
  1192. var dispStr = "";
  1193. var addStr = "";
  1194. var curStr = "";
  1195. if (level > 0) {
  1196. dispStr += (obj===null ? "null" : typeof(obj)) + "\n";
  1197. addStr = niobe_replicate(' ', level*2);
  1198. }
  1199. if (obj!==null && (typeof(obj)=='object' || typeof(obj)=='array')) {
  1200. for (var prop in obj) {
  1201. if (!showMethods && typeof(obj[prop])=='function') // || prop=='innerHTML' || prop=='outerHTML' || prop=='innerText' || prop=='outerText')
  1202. continue;
  1203. if (level<recursive && (typeof(obj[prop])=='object' || typeof(obj[prop])=='array') && obj[prop]!=obj)
  1204. dispStr += addStr + prop + '=' + niobe_debug_object(obj[prop], recursive, showMethods, level+1);
  1205. else {
  1206. try {
  1207. curStr = "" + obj[prop];
  1208. } catch (e) {
  1209. curStr = "--- Not evaluate ---";
  1210. }
  1211. dispStr += addStr+prop+'='+(typeof(obj[prop])=='string' ? '"' : '')+curStr+(typeof(obj[prop])=='string' ? '"' : '')+"\n";
  1212. }
  1213. }
  1214. } else if (typeof(obj)!='function')
  1215. dispStr += addStr+(typeof(obj)=='string' ? '"' : '')+obj+(typeof(obj)=='string' ? '"' : '')+"\n";
  1216.  
  1217. return dispStr; //decodeURI(dispStr);
  1218. };
  1219.  
  1220.  
  1221. window.niobe_debug_log = function(s, clr) {
  1222. if (NIOBE_STORAGE['user_logged_in']) {
  1223. if (jQuery('#debug_log').length == 0) {
  1224. jQuery('body').append('<div id="debug_log"><span id="debug_log_close">x</span><pre id="debug_log_content"></pre></div>');
  1225. jQuery("#debug_log_close").on('click', function(e) {
  1226. jQuery('#debug_log').hide();
  1227. e.preventDefault();
  1228. return false;
  1229. });
  1230. }
  1231. if (clr) jQuery('#debug_log_content').empty();
  1232. jQuery('#debug_log_content').prepend(s+' ');
  1233. jQuery('#debug_log').show();
  1234. }
  1235. };
  1236.  
  1237. window.dcl===undefined && (window.dcl = function(s) { console.log(s); });
  1238. window.dco===undefined && (window.dco = function(s,r) { console.log(niobe_debug_object(s,r)); });
  1239. window.dal===undefined && (window.dal = function(s) { if (NIOBE_STORAGE['user_logged_in']) alert(s); });
  1240. window.dao===undefined && (window.dao = function(s,r) { if (NIOBE_STORAGE['user_logged_in']) alert(niobe_debug_object(s,r)); });
  1241. window.ddl===undefined && (window.ddl = function(s,c) { niobe_debug_log(s,c); });
  1242. window.ddo===undefined && (window.ddo = function(s,r,c) { niobe_debug_log(niobe_debug_object(s,r),c); });
  1243.  
  1244. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement