equation-admin-template
Version:
Booststrap 4 admin template made by equation
787 lines (705 loc) • 25.2 kB
JavaScript
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);
}