common.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. /*
  2. CalDavZAP - the open source CalDAV Web Client
  3. Copyright (C) 2011-2015
  4. Jan Mate <jan.mate@inf-it.com>
  5. Andrej Lezo <andrej.lezo@inf-it.com>
  6. Matej Mihalik <matej.mihalik@inf-it.com>
  7. This program is free software: you can redistribute it and/or modify
  8. it under the terms of the GNU Affero General Public License as
  9. published by the Free Software Foundation, either version 3 of the
  10. License, or (at your option) any later version.
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. GNU Affero General Public License for more details.
  15. You should have received a copy of the GNU Affero General Public License
  16. along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // Used to match XML element names with any namespace
  19. jQuery.fn.filterNsNode=function(nameOrRegex)
  20. {
  21. return this.filter(
  22. function()
  23. {
  24. if(nameOrRegex instanceof RegExp)
  25. return (this.nodeName.match(nameOrRegex) || this.nodeName.replace(RegExp('^[^:]+:',''),'').match(nameOrRegex));
  26. else
  27. return (this.nodeName===nameOrRegex || this.nodeName.replace(RegExp('^[^:]+:',''),'')===nameOrRegex);
  28. }
  29. );
  30. };
  31. // Escape jQuery selector
  32. function jqueryEscapeSelector(inputValue)
  33. {
  34. return (inputValue==undefined ? '' : inputValue).toString().replace(/([ !"#$%&'()*+,./:;<=>?@[\\\]^`{|}~])/g,'\\$1');
  35. }
  36. // Generate random string (UID)
  37. function generateUID()
  38. {
  39. uidChars='0123456789abcdefghijklmnopqrstuvwxyz';
  40. UID='';
  41. for(i=0;i<32;i++)
  42. {
  43. if(i==8 || i==12 || i==16 || i==20) UID+='-';
  44. UID+=uidChars.charAt(Math.floor(Math.random()*(uidChars.length-1)));
  45. }
  46. return UID;
  47. }
  48. // IE compatibility
  49. if (typeof window.btoa=='undefined' && typeof base64.encode!='undefined') window.btoa=base64.encode;
  50. // Create Basic auth string (for HTTP header)
  51. function basicAuth(user, password)
  52. {
  53. var tok=user+':'+password;
  54. var hash=btoa(tok);
  55. return 'Basic '+hash;
  56. }
  57. // multiply regex replace {'regex': value, 'regex': value}
  58. String.prototype.multiReplace=function(hash)
  59. {
  60. var str=this, key;
  61. for(key in hash)
  62. str=str.replace(new RegExp(key,'g'), hash[key]);
  63. return str;
  64. };
  65. // Used for sorting the contact and resource list ...
  66. String.prototype.customCompare=function(stringB, alphabet, dir, caseSensitive)
  67. {
  68. var stringA=this;
  69. if(alphabet==undefined || alphabet==null)
  70. return stringA.localeCompare(stringB);
  71. else
  72. {
  73. var pos=0,
  74. min=Math.min(stringA.length, stringB.length);
  75. dir=dir || 1;
  76. caseSensitive=caseSensitive || false;
  77. if(!caseSensitive)
  78. {
  79. stringA=stringA.toLowerCase();
  80. stringB=stringB.toLowerCase();
  81. }
  82. while(stringA.charAt(pos)===stringB.charAt(pos) && pos<min){pos++;}
  83. if(stringA.charAt(pos)=='')
  84. return -dir;
  85. else
  86. {
  87. var index1=alphabet.indexOf(stringA.charAt(pos));
  88. var index2=alphabet.indexOf(stringB.charAt(pos));
  89. if(index1==-1 || index2==-1)
  90. return stringA.localeCompare(stringB);
  91. else
  92. return (index1<index2 ? -dir : dir);
  93. }
  94. }
  95. };
  96. function customResourceCompare(objA, objB)
  97. {
  98. return objA.displayValue.customCompare(objB.displayValue, globalSortAlphabet, 1, false);
  99. }
  100. function checkColorBrightness(hex)
  101. {
  102. var R=parseInt(hex.substring(0, 2), 16);
  103. var G=parseInt(hex.substring(2, 4), 16);
  104. var B=parseInt(hex.substring(4, 6), 16);
  105. return Math.sqrt(0.241*R*R+0.691*G*G+0.068*B*B);
  106. }
  107. // Get unique values from array
  108. Array.prototype.unique=function()
  109. {
  110. var o={}, i, l=this.length, r=[];
  111. for(i=0;i<l;i++)
  112. o[this[i]]=this[i];
  113. for(i in o)
  114. r.push(o[i]);
  115. return r;
  116. };
  117. // Recursive replaceAll
  118. String.prototype.replaceAll=function(stringToFind,stringToReplace)
  119. {
  120. var temp=this;
  121. while(temp.indexOf(stringToFind)!=-1)
  122. temp=temp.replace(stringToFind,stringToReplace);
  123. return temp;
  124. };
  125. // Pad number with leading zeroes
  126. Number.prototype.pad=function(size){
  127. var s=String(this);
  128. while(s.length<size)
  129. s='0'+s;
  130. return s;
  131. };
  132. // Case insensitive search for attributes
  133. // Usage: $('#selector').find(':attrCaseInsensitive(data-type,"'+typeList[i]+'")')
  134. jQuery.expr[':'].attrCaseInsensitive=function(elem, index, match)
  135. {
  136. var matchParams=match[3].split(','),
  137. attribute=matchParams[0].replace(/^\s*|\s*$/g,''),
  138. value=matchParams[1].replace(/^\s*"|"\s*$/g,'').toLowerCase();
  139. return jQuery(elem)['attr'](attribute)!=undefined && jQuery(elem)['attr'](attribute)==value;
  140. };
  141. // Capitalize given string
  142. function capitalize(string)
  143. {
  144. return string.charAt(0).toUpperCase()+string.slice(1).toLowerCase();
  145. }
  146. var timezoneKeys = new Array();
  147. function populateTimezoneKeys()
  148. {
  149. for(var i in timezones)
  150. timezoneKeys.push(i);
  151. timezoneKeys.push('0local');
  152. timezoneKeys.push('1UTC');
  153. timezoneKeys.sort();
  154. timezoneKeys[0] = timezoneKeys[0].substring(1);
  155. timezoneKeys[1] = timezoneKeys[1].substring(1);
  156. jQuery.extend(timezones,{'UTC':{}});
  157. }
  158. Date.prototype.getWeekNo=function()
  159. {
  160. var today = this;
  161. Year = today.getFullYear();
  162. Month = today.getMonth();
  163. Day = today.getDate();
  164. now = Date.UTC(Year,Month,Day,0,0,0);
  165. var Firstday = new Date();
  166. Firstday.setYear(Year);
  167. Firstday.setMonth(0);
  168. Firstday.setDate(1);
  169. then = Date.UTC(Year,0,1,0,0,0);
  170. var Compensation = Firstday.getDay();
  171. if(((now-then)/86400000) > 3)
  172. NumberOfWeek = Math.round((((now-then)/86400000)+Compensation)/7);
  173. else
  174. {
  175. if(Firstday.getDay()>4 || Firstday.getDay()==0)
  176. NumberOfWeek = 53;
  177. }
  178. return NumberOfWeek;
  179. }
  180. function zeroPad(n) {
  181. return (n < 10 ? '0' : '') + n;
  182. }
  183. var dateFormatters = {
  184. s : function(d) {return d.getSeconds() },
  185. ss : function(d) {return zeroPad(d.getSeconds())},
  186. m : function(d) {return d.getMinutes()},
  187. mm : function(d) {return zeroPad(d.getMinutes())},
  188. h : function(d) {return d.getHours() % 12 || 12},
  189. hh : function(d) {return zeroPad(d.getHours() % 12 || 12)},
  190. H : function(d) {return d.getHours()},
  191. HH : function(d) {return zeroPad(d.getHours())},
  192. d : function(d) {return d.getDate()},
  193. dd : function(d) {return zeroPad(d.getDate())},
  194. ddd : function(d,o) {return o.dayNamesShort[d.getDay()]},
  195. dddd: function(d,o) {return o.dayNames[d.getDay()]},
  196. W : function(d) {return d.getWeekNo()},
  197. M : function(d) {return d.getMonth() + 1},
  198. MM : function(d) {return zeroPad(d.getMonth() + 1)},
  199. MMM : function(d,o) {return o.monthNamesShort[d.getMonth()]},
  200. MMMM: function(d,o) {return o.monthNames[d.getMonth()]},
  201. yy : function(d) {return (d.getFullYear()+'').substring(2)},
  202. yyyy: function(d) {return d.getFullYear()},
  203. t : function(d) {return d.getHours() < 12 ? 'a' : 'p'},
  204. tt : function(d) {return d.getHours() < 12 ? 'am' : 'pm'},
  205. T : function(d) {return d.getHours() < 12 ? 'A' : 'P'},
  206. TT : function(d) {return d.getHours() < 12 ? 'AM' : 'PM'},
  207. u : function(d) {return formatDates(d, null, "yyyy-MM-dd'T'HH:mm:ss'Z'")},
  208. S : function(d) {
  209. var date = d.getDate();
  210. if (date > 10 && date < 20) {
  211. return 'th';
  212. }
  213. return ['st', 'nd', 'rd'][date%10-1] || 'th';
  214. }
  215. };
  216. function formatDates(date1, date2, format, options) {
  217. options = options;
  218. var date = date1,
  219. otherDate = date2,
  220. i, len = format.length, c,
  221. i2, formatter,
  222. res = '';
  223. for (i=0; i<len; i++) {
  224. c = format.charAt(i);
  225. if (c == "'") {
  226. for (i2=i+1; i2<len; i2++) {
  227. if (format.charAt(i2) == "'") {
  228. if (date) {
  229. if (i2 == i+1) {
  230. res += "'";
  231. }else{
  232. res += format.substring(i+1, i2);
  233. }
  234. i = i2;
  235. }
  236. break;
  237. }
  238. }
  239. }
  240. else if (c == '(') {
  241. for (i2=i+1; i2<len; i2++) {
  242. if (format.charAt(i2) == ')') {
  243. var subres = formatDates(date, null, format.substring(i+1, i2), options);
  244. if (parseInt(subres.replace(/\D/, ''), 10)) {
  245. res += subres;
  246. }
  247. i = i2;
  248. break;
  249. }
  250. }
  251. }
  252. else if (c == '[') {
  253. for (i2=i+1; i2<len; i2++) {
  254. if (format.charAt(i2) == ']') {
  255. var subformat = format.substring(i+1, i2);
  256. var subres = formatDates(date, null, subformat, options);
  257. if (subres != formatDates(otherDate, null, subformat, options)) {
  258. res += subres;
  259. }
  260. i = i2;
  261. break;
  262. }
  263. }
  264. }
  265. else if (c == '{') {
  266. date = date2;
  267. otherDate = date1;
  268. }
  269. else if (c == '}') {
  270. date = date1;
  271. otherDate = date2;
  272. }
  273. else {
  274. for (i2=len; i2>i; i2--) {
  275. if (formatter = dateFormatters[format.substring(i, i2)]) {
  276. if (date) {
  277. res += formatter(date, options);
  278. }
  279. i = i2 - 1;
  280. break;
  281. }
  282. }
  283. if (i2 == i) {
  284. if (date) {
  285. res += c;
  286. }
  287. }
  288. }
  289. }
  290. return res;
  291. };
  292. function vObjectLineFolding(inputText)
  293. {
  294. var outputText='';
  295. var maxLineOctetLength=75;
  296. var count=0;
  297. for(var i=0; inputText[i]!=undefined; i++)
  298. {
  299. var currentChar=inputText.charCodeAt(i);
  300. var nextChar=inputText.charCodeAt(i+1);
  301. if(currentChar==0x000D && nextChar==0x000A)
  302. {
  303. count=0;
  304. outputText+='\r\n';
  305. i++;
  306. continue;
  307. }
  308. var surrogatePair=false;
  309. if(currentChar<0x0080)
  310. var charNum=1;
  311. else if(currentChar<0x0800)
  312. var charNum=2;
  313. else if(currentChar<0xd800 || currentChar>=0xe000)
  314. var charNum=3;
  315. else
  316. {
  317. // surrogate pair
  318. // UTF-16 encodes 0x10000-0x10FFFF by subtracting 0x10000 and splitting
  319. // the 20 bits of 0x0-0xFFFFF into two halves
  320. charNum=4;
  321. surrogatePair=true;
  322. }
  323. if(count>maxLineOctetLength-charNum)
  324. {
  325. outputText+='\r\n ';
  326. count=1;
  327. }
  328. outputText+=String.fromCharCode(currentChar);
  329. if(surrogatePair)
  330. {
  331. outputText+=String.fromCharCode(vCardText.charCodeAt(i+1));
  332. i++;
  333. }
  334. count+=charNum;
  335. }
  336. return outputText;
  337. }
  338. function rgbToHex(rgb)
  339. {
  340. rgb=rgb.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d*)?|(?:\.\d+)))?\)$/);
  341. function hex(x)
  342. {
  343. return ("0"+parseInt(x).toString(16)).slice(-2);
  344. }
  345. return "#"+hex(rgb[1])+hex(rgb[2])+hex(rgb[3]);
  346. }
  347. function hexToRgba(hex, transparency) {
  348. var bigint=parseInt(hex.substring(1), 16);
  349. var r=(bigint >> 16) & 255;
  350. var g=(bigint >> 8) & 255;
  351. var b=bigint & 255;
  352. return 'rgba('+r+','+g+','+b+','+transparency+')';
  353. }
  354. function rgbToRgba(rgb, transparency)
  355. {
  356. rgb=rgb.match(/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d*)?|(?:\.\d+)))?\)$/);
  357. return 'rgba('+rgb[1]+','+rgb[2]+','+rgb[3]+','+transparency+')';
  358. }
  359. function dataGetChecked(resourceListSelector)
  360. {
  361. var checkedArr=$(resourceListSelector).find('input[type=checkbox]:checked').not('.unloadCheck').filter('[data-id]').filter(function(){return this.indeterminate==false}).map(function(){return $(this).attr('data-id')}).get();
  362. for(i=checkedArr.length-1; i>=0; i--)
  363. if(checkedArr[i].match(new RegExp('[^/]$'))!=null && checkedArr.indexOf(checkedArr[i].replace(new RegExp('[^/]+$'), ''))!=-1)
  364. checkedArr.splice(i, 1);
  365. return checkedArr;
  366. }
  367. function resourceChBoxClick(obj, resourceListSelector, headerSelector, returnChecked)
  368. {
  369. $(obj).parent().nextUntil(headerSelector).find('input[type=checkbox]:visible').prop('checked', $(obj).prop('checked')).prop('indeterminate', false);
  370. if(returnChecked)
  371. return dataGetChecked(resourceListSelector);
  372. }
  373. function collectionChBoxClick(obj, resourceListSelector, headerSelector, collectionSelector, groupSelector, returnChecked)
  374. {
  375. if(collectionSelector.match('_item$'))
  376. {
  377. var tmp_coh=$(obj).parent().prevAll(headerSelector).first();
  378. var tmp_co_chbxs=tmp_coh.nextUntil(headerSelector).find('input[type=checkbox]:visible');
  379. }
  380. else
  381. {
  382. var tmp_coh=$(obj).parent().parent().prevAll(headerSelector).first();
  383. var tmp_co_chbxs=tmp_coh.nextUntil(headerSelector).find(collectionSelector).find('input[type=checkbox]:visible');
  384. }
  385. if(groupSelector!=null)
  386. {
  387. if($(obj).prop('checked')==false && $(obj).prop('indeterminate')==false && $(obj).attr('data-ind')=='false' &&
  388. $(obj).parent().next(groupSelector).height()>0/* note: ':visible' is not working! */)
  389. {
  390. $(obj).prop('indeterminate', true);
  391. $(obj).prop('checked', true);
  392. $(obj).attr('data-ind', 'true');
  393. tmp_coh.find('input[type=checkbox]:visible').prop('indeterminate', true).prop('checked', false);
  394. if(returnChecked)
  395. return dataGetChecked(resourceListSelector);
  396. return true;
  397. }
  398. else if($(obj).attr('data-ind')=='true')
  399. $(obj).attr('data-ind', 'false');
  400. $(obj).parent().next(groupSelector).find('input[type=checkbox]').prop('checked', $(obj).prop('checked'));
  401. }
  402. if(tmp_co_chbxs.length==tmp_co_chbxs.filter(':checked').length)
  403. tmp_coh.find('input[type=checkbox]:visible').prop('checked', true).prop('indeterminate', false);
  404. else if(tmp_co_chbxs.filter(':checked').length==0 && tmp_co_chbxs.filter(function(){return this.indeterminate==true}).length==0)
  405. tmp_coh.find('input[type=checkbox]:visible').prop('checked', false).prop('indeterminate', false);
  406. else
  407. tmp_coh.find('input[type=checkbox]:visible').prop('indeterminate', true).prop('checked', false);
  408. if(returnChecked)
  409. return dataGetChecked(resourceListSelector);
  410. }
  411. function groupChBoxClick(obj, resourceListSelector, headerSelector, collectionSelector, groupSelector, returnChecked)
  412. {
  413. var tmp_cg=$(obj).closest(groupSelector);
  414. var tmp_cg_chbxs=tmp_cg.find('input[type=checkbox]:visible');
  415. var tmp_co_chbxs=tmp_cg.prev().find('input[type=checkbox]:visible');
  416. if(tmp_cg_chbxs.filter(':checked').length==0)
  417. tmp_co_chbxs.prop('checked', false).prop('indeterminate', false);
  418. else
  419. tmp_co_chbxs.prop('indeterminate', true).prop('checked', false);
  420. return collectionChBoxClick(tmp_co_chbxs, resourceListSelector, headerSelector, collectionSelector, null, returnChecked);
  421. }
  422. function loadResourceChBoxClick(obj, resourceListSelector, headerSelector, collectionSelector, resourceItemSelector)
  423. {
  424. if(collectionSelector.match('_item$'))
  425. {
  426. var firstCollection=$(obj).parent().nextUntil(headerSelector).first();
  427. if($(obj).prop('checked'))
  428. $(obj).parent().nextUntil(headerSelector).addBack().removeClass('unloaded');
  429. else
  430. $(obj).parent().nextUntil(headerSelector).addBack().addClass('unloaded');
  431. }
  432. else
  433. {
  434. var firstCollection=$(obj).parent().nextUntil(headerSelector).first().find(collectionSelector);
  435. if($(obj).prop('checked'))
  436. {
  437. $(obj).parent().nextUntil(headerSelector).find(collectionSelector).removeClass('unloaded');
  438. $(obj).parent().removeClass('unloaded');
  439. }
  440. else
  441. {
  442. $(obj).parent().nextUntil(headerSelector).find(collectionSelector).addClass('unloaded');
  443. $(obj).parent().addClass('unloaded');
  444. }
  445. }
  446. $(resourceListSelector).find(headerSelector).find('.unloadCheckHeader:checked').prop('disabled',false);
  447. $(resourceListSelector).find(collectionSelector).find('.unloadCheck:checked').prop('disabled',false);
  448. if(!$(resourceListSelector).find(headerSelector).find('.unloadCheckHeader').filter(function(){return $(this).prop('checked') || $(this).prop('indeterminate');}).length)
  449. {
  450. $(obj).prop({'checked':false,'indeterminate':true});
  451. $(obj).parent().removeClass('unloaded');
  452. $(obj).parent().nextUntil(headerSelector).find('.unloadCheck').prop({'checked':false,'indeterminate':false});
  453. firstCollection.removeClass('unloaded').find('.unloadCheck').prop({'checked':true,'indeterminate':false,'disabled':true});
  454. }
  455. else
  456. {
  457. $(obj).parent().nextUntil(headerSelector).find('.unloadCheck').prop({'checked':$(obj).prop('checked'),'indeterminate':false});
  458. var checkedCollections=$(resourceListSelector).find(collectionSelector).find('.unloadCheck:checked');
  459. if(checkedCollections.length==1)
  460. {
  461. var collection=checkedCollections.parents(resourceItemSelector);
  462. if(!collection.prev().hasClass(resourceItemSelector.slice(1)) && !collection.next().hasClass(resourceItemSelector.slice(1)))
  463. collection.prev().find('.unloadCheckHeader').prop('disabled',true);
  464. checkedCollections.prop('disabled',true);
  465. }
  466. }
  467. }
  468. function loadCollectionChBoxClick(obj, resourceListSelector, headerSelector, collectionSelector, resourceItemSelector)
  469. {
  470. if($(obj).prop('checked'))
  471. $(obj).parent().removeClass('unloaded');
  472. else
  473. $(obj).parent().addClass('unloaded');
  474. var checkedCollections=$(resourceListSelector).find(collectionSelector).find('.unloadCheck:checked');
  475. if(checkedCollections.length==1)
  476. {
  477. var collection=checkedCollections.parents(resourceItemSelector);
  478. if(!collection.prev().hasClass(resourceItemSelector.slice(1)) && !collection.next().hasClass(resourceItemSelector.slice(1)))
  479. collection.prev().find('.unloadCheckHeader').prop('disabled',true);
  480. checkedCollections.prop('disabled',true);
  481. }
  482. else
  483. {
  484. $(resourceListSelector).find(headerSelector).find('.unloadCheckHeader:checked').prop('disabled',false);
  485. checkedCollections.prop('disabled',false);
  486. }
  487. if(collectionSelector.match('_item$'))
  488. {
  489. var tmp_coh=$(obj).parent().prevAll(headerSelector).first();
  490. var tmp_co_chbxs=tmp_coh.nextUntil(headerSelector).find('.unloadCheck');
  491. }
  492. else
  493. {
  494. var tmp_coh=$(obj).parent().parent().prevAll(headerSelector).first();
  495. var tmp_co_chbxs=tmp_coh.nextUntil(headerSelector).find(collectionSelector).find('.unloadCheck');
  496. }
  497. if(tmp_co_chbxs.length==tmp_co_chbxs.filter(':checked').length)
  498. tmp_coh.removeClass('unloaded').find('.unloadCheckHeader').prop('checked', true).prop('indeterminate', false);
  499. else if(tmp_co_chbxs.filter(':checked').length==0 && tmp_co_chbxs.filter(function(){return this.indeterminate==true}).length==0)
  500. tmp_coh.addClass('unloaded').find('.unloadCheckHeader').prop('checked', false).prop('indeterminate', false);
  501. else
  502. tmp_coh.removeClass('unloaded').find('.unloadCheckHeader').prop('indeterminate', true).prop('checked', false);
  503. }
  504. // Escape vCalendar value - RFC2426 (Section 2.4.2)
  505. function vcalendarEscapeValue(inputValue)
  506. {
  507. return (inputValue==undefined ? '' : inputValue).replace(vCalendar.pre['escapeRex'],"\\$1").replace(vCalendar.pre['escapeRex2'],'\\n');
  508. }
  509. // Unescape vCalendar value - RFC2426 (Section 2.4.2)
  510. function vcalendarUnescapeValue(inputValue)
  511. {
  512. var outputValue='';
  513. if(inputValue!=undefined)
  514. {
  515. for(var i=0;i<inputValue.length;i++)
  516. if(inputValue[i]=='\\' && i+1<inputValue.length)
  517. {
  518. if(inputValue[++i]=='n')
  519. outputValue+='\n';
  520. else
  521. outputValue+=inputValue[i];
  522. }
  523. else
  524. outputValue+=inputValue[i];
  525. }
  526. return outputValue;
  527. }
  528. // Split parameters and remove double quotes from values (if parameter values are quoted)
  529. function vcalendarSplitParam(inputValue)
  530. {
  531. var result=vcalendarSplitValue(inputValue, ';');
  532. var index;
  533. for(var i=0;i<result.length;i++)
  534. {
  535. index=result[i].indexOf('=');
  536. if(index!=-1 && index+1<result[i].length && result[i][index+1]=='"' && result[i][result[i].length-1]=='"')
  537. result[i]=result[i].substring(0,index+1)+result[i].substring(index+2,result[i].length-1);
  538. }
  539. return result;
  540. }
  541. // Split string by separator (but not '\' escaped separator)
  542. function vcalendarSplitValue(inputValue, inputDelimiter)
  543. {
  544. var outputArray=new Array();
  545. var i=0;
  546. var j=0;
  547. for(i=0;i<inputValue.length;i++)
  548. {
  549. if(inputValue[i]==inputDelimiter)
  550. {
  551. if(outputArray[j]==undefined)
  552. outputArray[j]='';
  553. ++j;
  554. continue;
  555. }
  556. outputArray[j]=(outputArray[j]==undefined ? '' : outputArray[j])+inputValue[i];
  557. if(inputValue[i]=='\\' && i+1<inputValue.length)
  558. outputArray[j]=outputArray[j]+inputValue[++i];
  559. }
  560. return outputArray;
  561. }
  562. function dateFormatJqToFc(input)
  563. {
  564. return input.replaceAll('DD','dddd').replaceAll('D','ddd').replace(/(MM|M)/g, '$1MM').replaceAll('m','M').replace(/y/g,'yy');
  565. }