forked from webismymind/editablegrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
editablegrid_utils.js
786 lines (705 loc) · 24.6 KB
/
editablegrid_utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
EditableGrid.prototype._convertOptions = function(optionValues)
{
// option values should be an *ordered* array of value/label pairs, but to stay compatible with existing enum providers
if (optionValues !== null && (!(optionValues instanceof Array)) && typeof optionValues == 'object') {
var _converted = [];
for (var value in optionValues) {
if (typeof optionValues[value] == 'object') _converted.push({ label : value, values: this._convertOptions(optionValues[value])}); // group
else _converted.push({ value : value, label: optionValues[value]});
}
optionValues = _converted;
}
return optionValues;
};
EditableGrid.prototype.setCookie = function(c_name, value, exdays)
{
var exdate = new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
document.cookie = c_name + "=" + c_value;
};
EditableGrid.prototype.getCookie = function(c_name)
{
var _cookies = document.cookie.split(";");
for (var i = 0; i < _cookies.length; i++) {
var x = _cookies[i].substr(0, _cookies[i].indexOf("="));
var y = _cookies[i].substr(_cookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x == c_name) return unescape(y);
}
return null;
};
EditableGrid.prototype.has_local_storage = function()
{
try { return 'localStorage' in window && window['localStorage'] !== null; } catch(e) { return false; }
};
EditableGrid.prototype._localset = function(key, value)
{
if (this.has_local_storage()) localStorage.setItem(key, value);
else this.setCookie(key, value, null);
};
EditableGrid.prototype._localunset = function(key)
{
if (this.has_local_storage()) localStorage.removeItem(key);
else this.setCookie(key, null, null);
};
EditableGrid.prototype._localget = function(key)
{
if (this.has_local_storage()) return localStorage.getItem(key);
return this.getCookie(key);
};
EditableGrid.prototype._localisset = function(key)
{
if (this.has_local_storage()) return localStorage.getItem(key) !== null && localStorage.getItem(key) != 'undefined';
return this.getCookie(key) !== null;
};
EditableGrid.prototype.localset = function(key, value)
{
if (this.enableStore) return this._localset(this.name + '_' + key, value);
};
EditableGrid.prototype.localunset = function(key)
{
if (this.enableStore) return this._localunset(this.name + '_' + key, value);
};
EditableGrid.prototype.localget = function(key)
{
return this.enableStore ? this._localget(this.name + '_' + key) : null;
};
EditableGrid.prototype.localisset = function(key)
{
return this.enableStore ? this._localget(this.name + '_' + key) !== null : false;
};
EditableGrid.prototype.unsort = function(a,b)
{
// at index 2 we have the originalIndex
aa = isNaN(a[2]) ? 0 : parseFloat(a[2]);
bb = isNaN(b[2]) ? 0 : parseFloat(b[2]);
return aa-bb;
};
/**
* returns a sort function which further sorts according to the original index
* this ensures the sort will always be stable
* used to sort a tree where only the first level is actually sorted
*/
EditableGrid.prototype.sort_stable = function(sort_function, descending)
{
return function (a, b) {
var sort = descending ? sort_function(b, a) : sort_function(a, b);
if (sort != 0) return sort;
return EditableGrid.prototype.unsort(a, b);
};
};
EditableGrid.prototype.sort_numeric = function(a,b)
{
aa = isNaN(parseFloat(a[0])) ? 0 : parseFloat(a[0]);
bb = isNaN(parseFloat(b[0])) ? 0 : parseFloat(b[0]);
return aa-bb;
};
EditableGrid.prototype.sort_boolean = function(a,b)
{
aa = !a[0] || a[0] == "false" ? 0 : 1;
bb = !b[0] || b[0] == "false" ? 0 : 1;
return aa-bb;
};
EditableGrid.prototype.sort_alpha = function(a,b)
{
if (!a[0] && !b[0]) return 0;
if (a[0] && !b[0]) return 1;
if (!a[0] && b[0]) return -1;
if (a[0].toLowerCase()==b[0].toLowerCase()) return 0;
return a[0].toLowerCase().localeCompare(b[0].toLowerCase());
};
EditableGrid.prototype.sort_date = function(a,b)
{
date = EditableGrid.prototype.checkDate(a[0]);
aa = typeof date == "object" ? date.sortDate : 0;
date = EditableGrid.prototype.checkDate(b[0]);
bb = typeof date == "object" ? date.sortDate : 0;
return aa-bb;
};
/**
* Returns computed style property for element
* @private
*/
EditableGrid.prototype.getStyle = function(element, stylePropCamelStyle, stylePropCSSStyle)
{
stylePropCSSStyle = stylePropCSSStyle || stylePropCamelStyle;
if (element.currentStyle) return element.currentStyle[stylePropCamelStyle];
else if (window.getComputedStyle) return document.defaultView.getComputedStyle(element,null).getPropertyValue(stylePropCSSStyle);
return element.style[stylePropCamelStyle];
};
/**
* Returns true if the element has a static positioning
* @private
*/
EditableGrid.prototype.isStatic = function (element)
{
var position = this.getStyle(element, 'position');
return (!position || position == "static");
};
EditableGrid.prototype.verticalAlign = function (element)
{
return this.getStyle(element, "verticalAlign", "vertical-align");
};
EditableGrid.prototype.paddingLeft = function (element)
{
var padding = parseInt(this.getStyle(element, "paddingLeft", "padding-left"));
return isNaN(padding) ? 0 : Math.max(0, padding);
};
EditableGrid.prototype.paddingRight = function (element)
{
var padding = parseInt(this.getStyle(element, "paddingRight", "padding-right"));
return isNaN(padding) ? 0 : Math.max(0, padding);
};
EditableGrid.prototype.paddingTop = function (element)
{
var padding = parseInt(this.getStyle(element, "paddingTop", "padding-top"));
return isNaN(padding) ? 0 : Math.max(0, padding);
};
EditableGrid.prototype.paddingBottom = function (element)
{
var padding = parseInt(this.getStyle(element, "paddingBottom", "padding-bottom"));
return isNaN(padding) ? 0 : Math.max(0, padding);
};
EditableGrid.prototype.borderLeft = function (element)
{
var border_l = parseInt(this.getStyle(element, "borderRightWidth", "border-right-width"));
var border_r = parseInt(this.getStyle(element, "borderLeftWidth", "border-left-width"));
border_l = isNaN(border_l) ? 0 : border_l;
border_r = isNaN(border_r) ? 0 : border_r;
return Math.max(border_l, border_r);
};
EditableGrid.prototype.borderRight = function (element)
{
return this.borderLeft(element);
};
EditableGrid.prototype.borderTop = function (element)
{
var border_t = parseInt(this.getStyle(element, "borderTopWidth", "border-top-width"));
var border_b = parseInt(this.getStyle(element, "borderBottomWidth", "border-bottom-width"));
border_t = isNaN(border_t) ? 0 : border_t;
border_b = isNaN(border_b) ? 0 : border_b;
return Math.max(border_t, border_b);
};
EditableGrid.prototype.borderBottom = function (element)
{
return this.borderTop(element);
};
/**
* Returns auto width for editor
* @private
*/
EditableGrid.prototype.autoWidth = function (element)
{
return element.offsetWidth - this.paddingLeft(element) - this.paddingRight(element) - this.borderLeft(element) - this.borderRight(element);
};
/**
* Returns auto height for editor
* @private
*/
EditableGrid.prototype.autoHeight = function (element)
{
return element.offsetHeight - this.paddingTop(element) - this.paddingBottom(element) - this.borderTop(element) - this.borderBottom(element);
};
/**
* Detects the directory when the js sources can be found
* @private
*/
EditableGrid.prototype.detectDir = function()
{
var base = location.href;
var e = document.getElementsByTagName('base');
for (var i=0; i<e.length; i++) if(e[i].href) base = e[i].href;
e = document.getElementsByTagName('script');
for (var i=0; i<e.length; i++) {
if (e[i].src && /(^|\/)editablegrid[^\/]*\.js([?#].*)?$/i.test(e[i].src)) {
var src = new URI(e[i].src);
var srcAbs = src.toAbsolute(base);
srcAbs.path = srcAbs.path.replace(/[^\/]+$/, ''); // remove filename
srcAbs.path = srcAbs.path.replace(/\/$/, ''); // remove trailing slash
delete srcAbs.query;
delete srcAbs.fragment;
return srcAbs.toString();
}
}
return false;
};
/**
* Detect is 2 values are exactly the same (type and value). Numeric NaN are considered the same.
* @param v1
* @param v2
* @return boolean
*/
EditableGrid.prototype.isSame = function(v1, v2)
{
if (v1 === v2) return true;
if (typeof v1 == 'number' && isNaN(v1) && typeof v2 == 'number' && isNaN(v2)) return true;
if (v1 === '' && v2 === null) return true;
if (v2 === '' && v1 === null) return true;
return false;
};
/**
* class name manipulation
* @private
*/
EditableGrid.prototype.strip = function(str) { return str.replace(/^\s+/, '').replace(/\s+$/, ''); };
EditableGrid.prototype.hasClassName = function(element, className) { return (element.className.length > 0 && (element.className == className || new RegExp("(^|\\s)" + className.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&") + "(\\s|$)").test(element.className))); };
EditableGrid.prototype.addClassName = function(element, className) { if (!this.hasClassName(element, className)) element.className += (element.className ? ' ' : '') + className; };
EditableGrid.prototype.removeClassName = function(element, className) { element.className = this.strip(element.className.replace(new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' ')); };
/**
* Useful string methods
* @private
*/
String.prototype.trim = function() { return (this.replace(/^[\s\xA0]+/, "").replace(/[\s\xA0]+$/, "")); };
String.prototype.contains = function(str) { return (this.match(str)==str); };
String.prototype.startsWith = function(str) { return (this.match("^"+str)==str); };
String.prototype.endsWith = function(str) { return (this.match(str+"$")==str); };
//Accepted formats: (for EU just switch month and day)
//mm-dd-yyyy
//mm/dd/yyyy
//mm.dd.yyyy
//mm dd yyyy
//mmm dd yyyy
//mmddyyyy
//m-d-yyyy
//m/d/yyyy
//m.d.yyyy,
//m d yyyy
//mmm d yyyy
////m-d-yy
////m/d/yy
////m.d.yy
////m d yy,
////mmm d yy (yy is 20yy)
/**
* Checks validity of a date string
* @private
*/
EditableGrid.prototype.checkDate = function(strDate, strDatestyle)
{
strDatestyle = strDatestyle || this.dateFormat;
strDatestyle = strDatestyle || "EU";
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
var err = 0;
var strMonthArray = this.shortMonthNames;
strMonthArray = strMonthArray || ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
if (!strDate || strDate.length < 1) return 0;
for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
strDateArray = strDate.split(strSeparatorArray[intElementNr]);
if (strDateArray.length != 3) return 1;
else {
strDay = strDateArray[0];
strMonth = strDateArray[1];
strYear = strDateArray[2];
}
booFound = true;
}
}
if (booFound == false) {
if (strDate.length <= 5) return 1;
strDay = strDate.substr(0, 2);
strMonth = strDate.substr(2, 2);
strYear = strDate.substr(4);
}
// if (strYear.length == 2) strYear = '20' + strYear;
// US style
if (strDatestyle == "US") {
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
}
// get and check day
intday = parseInt(strDay, 10);
if (isNaN(intday)) return 2;
// get and check month
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
}
}
if (isNaN(intMonth)) return 3;
}
if (intMonth>12 || intMonth<1) return 5;
// get and check year
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) return 4;
if (intYear < 70) { intYear = 2000 + intYear; strYear = '' + intYear; } // 70 become 1970, 69 becomes 1969, as with PHP's date_parse_from_format
if (intYear < 100) { intYear = 1900 + intYear; strYear = '' + intYear; }
if (intYear < 1900 || intYear > 2100) return 11;
// check day in month
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) return 6;
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) return 7;
if (intMonth == 2) {
if (intday < 1) return 8;
if (LeapYear(intYear) == true) { if (intday > 29) return 9; }
else if (intday > 28) return 10;
}
// return formatted date
return {
formattedDate: (strDatestyle == "US" ? strMonthArray[intMonth-1] + " " + intday+" " + strYear : intday + " " + strMonthArray[intMonth-1]/*.toLowerCase()*/ + " " + strYear),
sortDate: Date.parse(intMonth + "/" + intday + "/" + intYear),
dbDate: intYear + "-" + intMonth + "-" + intday
};
};
function LeapYear(intYear)
{
if (intYear % 100 == 0) { if (intYear % 400 == 0) return true; }
else if ((intYear % 4) == 0) return true;
return false;
}
//See RFC3986
URI = function(uri)
{
this.scheme = null;
this.authority = null;
this.path = '';
this.query = null;
this.fragment = null;
this.parse = function(uri) {
var m = uri.match(/^(([A-Za-z][0-9A-Za-z+.-]*)(:))?((\/\/)([^\/?#]*))?([^?#]*)((\?)([^#]*))?((#)(.*))?/);
this.scheme = m[3] ? m[2] : null;
this.authority = m[5] ? m[6] : null;
this.path = m[7];
this.query = m[9] ? m[10] : null;
this.fragment = m[12] ? m[13] : null;
return this;
};
this.toString = function() {
var result = '';
if(this.scheme != null) result = result + this.scheme + ':';
if(this.authority != null) result = result + '//' + this.authority;
if(this.path != null) result = result + this.path;
if(this.query != null) result = result + '?' + this.query;
if(this.fragment != null) result = result + '#' + this.fragment;
return result;
};
this.toAbsolute = function(base) {
var base = new URI(base);
var r = this;
var t = new URI;
if(base.scheme == null) return false;
if(r.scheme != null && r.scheme.toLowerCase() == base.scheme.toLowerCase()) {
r.scheme = null;
}
if(r.scheme != null) {
t.scheme = r.scheme;
t.authority = r.authority;
t.path = removeDotSegments(r.path);
t.query = r.query;
} else {
if(r.authority != null) {
t.authority = r.authority;
t.path = removeDotSegments(r.path);
t.query = r.query;
} else {
if(r.path == '') {
t.path = base.path;
if(r.query != null) {
t.query = r.query;
} else {
t.query = base.query;
}
} else {
if(r.path.substr(0,1) == '/') {
t.path = removeDotSegments(r.path);
} else {
if(base.authority != null && base.path == '') {
t.path = '/'+r.path;
} else {
t.path = base.path.replace(/[^\/]+$/,'')+r.path;
}
t.path = removeDotSegments(t.path);
}
t.query = r.query;
}
t.authority = base.authority;
}
t.scheme = base.scheme;
}
t.fragment = r.fragment;
return t;
};
function removeDotSegments(path) {
var out = '';
while(path) {
if(path.substr(0,3)=='../' || path.substr(0,2)=='./') {
path = path.replace(/^\.+/,'').substr(1);
} else if(path.substr(0,3)=='/./' || path=='/.') {
path = '/'+path.substr(3);
} else if(path.substr(0,4)=='/../' || path=='/..') {
path = '/'+path.substr(4);
out = out.replace(/\/?[^\/]*$/, '');
} else if(path=='.' || path=='..') {
path = '';
} else {
var rm = path.match(/^\/?[^\/]*/)[0];
path = path.substr(rm.length);
out = out + rm;
}
}
return out;
}
if(uri) {
this.parse(uri);
}
};
function get_html_translation_table (table, quote_style) {
// http://kevin.vanzonneveld.net
// + original by: Philip Peterson
// + revised by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfixed by: noname
// + bugfixed by: Alex
// + bugfixed by: Marco
// + bugfixed by: madipta
// + improved by: KELAN
// + improved by: Brett Zamir (http://brett-zamir.me)
// + bugfixed by: Brett Zamir (http://brett-zamir.me)
// + input by: Frank Forte
// + bugfixed by: T.Wild
// + input by: Ratheous
// % note: It has been decided that we're not going to add global
// % note: dependencies to php.js, meaning the constants are not
// % note: real constants, but strings instead. Integers are also supported if someone
// % note: chooses to create the constants themselves.
// * example 1: get_html_translation_table('HTML_SPECIALCHARS');
// * returns 1: {'"': '"', '&': '&', '<': '<', '>': '>'}
var entities = {}, hash_map = {}, decimal = 0, symbol = '';
var constMappingTable = {}, constMappingQuoteStyle = {};
var useTable = {}, useQuoteStyle = {};
// Translate arguments
constMappingTable[0] = 'HTML_SPECIALCHARS';
constMappingTable[1] = 'HTML_ENTITIES';
constMappingQuoteStyle[0] = 'ENT_NOQUOTES';
constMappingQuoteStyle[2] = 'ENT_COMPAT';
constMappingQuoteStyle[3] = 'ENT_QUOTES';
useTable = !isNaN(table) ? constMappingTable[table] : table ? table.toUpperCase() : 'HTML_SPECIALCHARS';
useQuoteStyle = !isNaN(quote_style) ? constMappingQuoteStyle[quote_style] : quote_style ? quote_style.toUpperCase() : 'ENT_COMPAT';
if (useTable !== 'HTML_SPECIALCHARS' && useTable !== 'HTML_ENTITIES') {
throw new Error("Table: "+useTable+' not supported');
// return false;
}
if (useTable === 'HTML_ENTITIES') {
entities['160'] = ' ';
entities['161'] = '¡';
entities['162'] = '¢';
entities['163'] = '£';
entities['164'] = '¤';
entities['165'] = '¥';
entities['166'] = '¦';
entities['167'] = '§';
entities['168'] = '¨';
entities['169'] = '©';
entities['170'] = 'ª';
entities['171'] = '«';
entities['172'] = '¬';
entities['173'] = '­';
entities['174'] = '®';
entities['175'] = '¯';
entities['176'] = '°';
entities['177'] = '±';
entities['178'] = '²';
entities['179'] = '³';
entities['180'] = '´';
entities['181'] = 'µ';
entities['182'] = '¶';
entities['183'] = '·';
entities['184'] = '¸';
entities['185'] = '¹';
entities['186'] = 'º';
entities['187'] = '»';
entities['188'] = '¼';
entities['189'] = '½';
entities['190'] = '¾';
entities['191'] = '¿';
entities['192'] = 'À';
entities['193'] = 'Á';
entities['194'] = 'Â';
entities['195'] = 'Ã';
entities['196'] = 'Ä';
entities['197'] = 'Å';
entities['198'] = 'Æ';
entities['199'] = 'Ç';
entities['200'] = 'È';
entities['201'] = 'É';
entities['202'] = 'Ê';
entities['203'] = 'Ë';
entities['204'] = 'Ì';
entities['205'] = 'Í';
entities['206'] = 'Î';
entities['207'] = 'Ï';
entities['208'] = 'Ð';
entities['209'] = 'Ñ';
entities['210'] = 'Ò';
entities['211'] = 'Ó';
entities['212'] = 'Ô';
entities['213'] = 'Õ';
entities['214'] = 'Ö';
entities['215'] = '×';
entities['216'] = 'Ø';
entities['217'] = 'Ù';
entities['218'] = 'Ú';
entities['219'] = 'Û';
entities['220'] = 'Ü';
entities['221'] = 'Ý';
entities['222'] = 'Þ';
entities['223'] = 'ß';
entities['224'] = 'à';
entities['225'] = 'á';
entities['226'] = 'â';
entities['227'] = 'ã';
entities['228'] = 'ä';
entities['229'] = 'å';
entities['230'] = 'æ';
entities['231'] = 'ç';
entities['232'] = 'è';
entities['233'] = 'é';
entities['234'] = 'ê';
entities['235'] = 'ë';
entities['236'] = 'ì';
entities['237'] = 'í';
entities['238'] = 'î';
entities['239'] = 'ï';
entities['240'] = 'ð';
entities['241'] = 'ñ';
entities['242'] = 'ò';
entities['243'] = 'ó';
entities['244'] = 'ô';
entities['245'] = 'õ';
entities['246'] = 'ö';
entities['247'] = '÷';
entities['248'] = 'ø';
entities['249'] = 'ù';
entities['250'] = 'ú';
entities['251'] = 'û';
entities['252'] = 'ü';
entities['253'] = 'ý';
entities['254'] = 'þ';
entities['255'] = 'ÿ';
}
if (useQuoteStyle !== 'ENT_NOQUOTES') {
entities['34'] = '"';
}
if (useQuoteStyle === 'ENT_QUOTES') {
entities['39'] = ''';
}
entities['60'] = '<';
entities['62'] = '>';
// ascii decimals to real symbols
for (decimal in entities) {
symbol = String.fromCharCode(decimal);
hash_map[symbol] = entities[decimal];
}
return hash_map;
}
function html_entity_decode(string, quote_style)
{
var hash_map = {}, symbol = '', tmp_str = '';
tmp_str = string.toString();
if (false === (hash_map = get_html_translation_table('HTML_ENTITIES', quote_style))) return false;
hash_map["'"] = ''';
for (symbol in hash_map) tmp_str = tmp_str.split(hash_map[symbol]).join(symbol);
return tmp_str;
}
function htmlentities(string, quote_style)
{
var hash_map = {}, symbol = '', tmp_str = '';
tmp_str = string.toString();
if (false === (hash_map = get_html_translation_table('HTML_ENTITIES', quote_style))) return false;
tmp_str = tmp_str.split('&').join('&'); // replace & first, otherwise & in htlm codes will be replaced too!
hash_map["'"] = ''';
for (symbol in hash_map) tmp_str = tmp_str.split(symbol).join(hash_map[symbol]);
return tmp_str;
}
function htmlspecialchars(string, quote_style)
{
var hash_map = {}, symbol = '', tmp_str = '';
tmp_str = string.toString();
if (false === (hash_map = get_html_translation_table('HTML_SPECIALCHARS', quote_style))) return false;
tmp_str = tmp_str.split('&').join('&'); // replace & first, otherwise & in htlm codes will be replaced too!
for (symbol in hash_map) tmp_str = tmp_str.split(symbol).join(hash_map[symbol]);
return tmp_str;
}
function number_format (number, decimals, dec_point, thousands_sep) {
// http://kevin.vanzonneveld.net
// + original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfix by: Michael White (http://getsprink.com)
// + bugfix by: Benjamin Lupton
// + bugfix by: Allan Jensen (http://www.winternet.no)
// + revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
// + bugfix by: Howard Yeend
// + revised by: Luke Smith (http://lucassmith.name)
// + bugfix by: Diogo Resende
// + bugfix by: Rival
// + input by: Kheang Hok Chin (http://www.distantia.ca/)
// + improved by: davook
// + improved by: Brett Zamir (http://brett-zamir.me)
// + input by: Jay Klehr
// + improved by: Brett Zamir (http://brett-zamir.me)
// + input by: Amir Habibi (http://www.residence-mixte.com/)
// + bugfix by: Brett Zamir (http://brett-zamir.me)
// + improved by: Theriault
// + input by: Amirouche
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// * example 1: number_format(1234.56);
// * returns 1: '1,235'
// * example 2: number_format(1234.56, 2, ',', ' ');
// * returns 2: '1 234,56'
// * example 3: number_format(1234.5678, 2, '.', '');
// * returns 3: '1234.57'
// * example 4: number_format(67, 2, ',', '.');
// * returns 4: '67,00'
// * example 5: number_format(1000);
// * returns 5: '1,000'
// * example 6: number_format(67.311, 2);
// * returns 6: '67.31'
// * example 7: number_format(1000.55, 1);
// * returns 7: '1,000.6'
// * example 8: number_format(67000, 5, ',', '.');
// * returns 8: '67.000,00000'
// * example 9: number_format(0.9, 0);
// * returns 9: '1'
// * example 10: number_format('1.20', 2);
// * returns 10: '1.20'
// * example 11: number_format('1.20', 4);
// * returns 11: '1.2000'
// * example 12: number_format('1.2000', 3);
// * returns 12: '1.200'
// * example 13: number_format('1 000,50', 2, '.', ' ');
// * returns 13: '100 050.00'
// Strip all characters but numerical ones.
number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
var n = !isFinite(+number) ? 0 : +number,
prec = !isFinite(+decimals) ? 0 : /*Math.abs(*/decimals/*)*/,
sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
s = '',
toFixedFix = function (n, prec) {
var k = Math.pow(10, prec);
return '' + Math.round(n * k) / k;
};
// Fix for IE parseFloat(0.55).toFixed(0) = 0;
s = (prec < 0 ? ('' + n) : (prec ? toFixedFix(n, prec) : '' + Math.round(n))).split('.');
if (s[0].length > 3) {
s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
}
if ((s[1] || '').length < prec) {
s[1] = s[1] || '';
s[1] += new Array(prec - s[1].length + 1).join('0');
}
return s.join(dec);
}