UNPKG

@progress/kendo-ui

Version:

This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.

1,510 lines (1,280 loc) 196 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var kendo_licensing = require('./kendo.licensing.js'); require('@progress/kendo-licensing'); let breakpoints; const EVENT = "change"; const defaultBreakpoints = { small: "(max-width: 500px)", medium: "(min-width: 500.1px) and (max-width: 768px)", large: "(min-width: 768.1px)", }; function createMediaQuery(query) { let mediaQueryList = window.matchMedia(query); let onEnterCallbacks = []; let onLeaveCallbacks = []; let onChangeHandlers = []; let kendoMediaQuery = { mediaQueryList }; const onChangeHandler = (ev) => { onChangeHandlers.forEach((cb) => cb(ev)); if (ev.matches) { onEnterCallbacks.forEach((cb) => cb(ev)); } else { onLeaveCallbacks.forEach((cb) => cb(ev)); } }; mediaQueryList.addEventListener(EVENT, onChangeHandler); const onChange = (cb) => { onChangeHandlers.push(cb); return kendoMediaQuery; }; const onEnter = (cb) => { onEnterCallbacks.push(cb); if (mediaQueryList.matches) { const media = mediaQueryList.media; const matches = true; const ev = new MediaQueryListEvent(EVENT, { media, matches, }); cb(ev); } return kendoMediaQuery; }; const onLeave = (cb) => { onLeaveCallbacks.push(cb); return kendoMediaQuery; }; const destroy = () => { if (mediaQueryList) { mediaQueryList.removeEventListener(EVENT, onChangeHandler); } onEnterCallbacks = null; onLeaveCallbacks = null; onChangeHandlers = null; mediaQueryList = null; kendoMediaQuery = null; }; kendoMediaQuery.onChange = onChange; kendoMediaQuery.onEnter = onEnter; kendoMediaQuery.onLeave = onLeave; kendoMediaQuery.destroy = destroy; return kendoMediaQuery; } function mediaQuery(query) { if (!query) { return; } breakpoints = breakpoints || Object.assign({}, defaultBreakpoints, kendo.defaults.breakpoints); if (query in breakpoints) { query = breakpoints[query]; } return createMediaQuery(query); } function fromESClass(ESClass) { class ExtendedClass extends ESClass { static extend(proto) { const subclass = class extends ExtendedClass { constructor() { super(); if (proto && proto.init) { proto.init.apply(this, arguments); } } }; // Copy the prototype so that the constructor is not overwritten Object.assign(subclass.prototype, proto); addInstanceGetter(subclass.prototype); // Apply the prototype to fn to allow for chaining subclass.fn = subclass.prototype; return subclass; } } addInstanceGetter(ExtendedClass.prototype); // Apply the prototype to fn to allow for chaining ExtendedClass.fn = ExtendedClass.prototype; return ExtendedClass; } function addInstanceGetter(proto) { Object.defineProperty(proto, '_instance', { get: function() { return this; } }); } const __meta__ = { id: "core", name: "Core", category: "framework", description: "The core of the Kendo framework.", depends: ["licensing"], }; (function($, window, undefined$1) { var kendo = window.kendo = window.kendo || { cultures: {} }, extend = $.extend, each = $.each, isArray = Array.isArray, noop = $.noop, math = Math, crypto = window.crypto, Template, JSON = window.JSON || {}, support = {}, percentRegExp = /%/, formatRegExp = /\{(\d+)(:[^\}]+)?\}/g, boxShadowRegExp = /(\d+(?:\.?)\d*)px\s*(\d+(?:\.?)\d*)px\s*(\d+(?:\.?)\d*)px\s*(\d+)?/i, numberRegExp = /^(\+|-?)\d+(\.?)\d*$/, MONTH = "month", HOUR = "hour", ZONE = "zone", WEEKDAY = "weekday", QUARTER = "quarter", DATE_FIELD_MAP = { "G": "era", "y": "year", "q": QUARTER, "Q": QUARTER, "M": MONTH, "L": MONTH, "d": "day", "E": WEEKDAY, "c": WEEKDAY, "e": WEEKDAY, "h": HOUR, "H": HOUR, "k": HOUR, "K": HOUR, "m": "minute", "s": "second", "a": "dayperiod", "t": "dayperiod", "x": ZONE, "X": ZONE, "z": ZONE, "Z": ZONE }, NAME_TYPES = { month: { type: "months", minLength: 3, standAlone: "L" }, quarter: { type: "quarters", minLength: 3, standAlone: "q" }, weekday: { type: "days", minLength: { E: 0, c: 3, e: 3 }, standAlone: "c" }, dayperiod: { type: "dayPeriods", minLength: 0 }, era: { type: "eras", minLength: 0 } }, FUNCTION = "function", STRING = "string", NUMBER = "number", OBJECT = "object", NULL = "null", BOOLEAN = "boolean", UNDEFINED = "undefined", PREFIX = "prefix", ARIA_LABELLEDBY = "aria-labelledby", ARIA_LABEL = "aria-label", LABELIDPART = "_label", getterCache = {}, setterCache = {}, slice = [].slice, cssPropertiesNames = [ "themeColor", "fillMode", "shape", "size", "rounded", "positionMode" ], // avoid extending the depricated properties in latest verions of jQuery noDepricateExtend = function() { var src, copyIsArray, copy, name, options, clone, target = arguments[ 0 ] || {}, i = 1, length = arguments.length, deep = false; // Handle a deep copy situation if ( typeof target === "boolean" ) { deep = target; // skip the boolean and the target target = arguments[ i ] || {}; i++; } // Handle case when target is a string or something (possible in deep copy) if ( typeof target !== "object" && typeof target !== "function") { target = {}; } // extend jQuery itself if only one argument is passed if ( i === length ) { target = this; i--; } for ( ; i < length; i++ ) { // Only deal with non-null/undefined values if ( ( options = arguments[ i ] ) != null ) { // Extend the base object for ( name in options ) { // filters, concat and : properties are depricated in the jQuery 3.3.0 // cssNumber is deprecated in jQuery 4.0.0 // accessing these properties throw a warning when jQuery migrate is included if (name == "filters" || name == "concat" || name == ":" || name == "cssNumber") { continue; } src = target[ name ]; copy = options[ name ]; // Prevent never-ending loop if ( target === copy ) { continue; } // Recurse if we're merging plain objects or arrays if ( deep && copy && ( jQuery.isPlainObject( copy ) || ( copyIsArray = Array.isArray( copy ) ) ) ) { if ( copyIsArray ) { copyIsArray = false; clone = src && Array.isArray( src ) ? src : []; } else { clone = src && jQuery.isPlainObject( src ) ? src : {}; } // Never move original objects, clone them target[ name ] = noDepricateExtend( deep, clone, copy ); // Don't bring in undefined values } else if ( copy !== undefined$1 ) { target[ name ] = copy; } } } } // Return the modified object return target; }; kendo.version = kendo_licensing.packageMetadata.version; function Class() {} Class.extend = function(proto) { var base = function() {}, member, that = this, subclass = proto && proto.init ? proto.init : function() { that.apply(this, arguments); }, fn; base.prototype = that.prototype; fn = subclass.fn = subclass.prototype = new base(); for (member in proto) { if (proto[member] != null && proto[member].constructor === Object) { // Merge object members fn[member] = extend(true, {}, base.prototype[member], proto[member]); } else { fn[member] = proto[member]; } } fn.constructor = subclass; subclass.extend = that.extend; return subclass; }; Class.prototype._initOptions = function(options) { this.options = deepExtend({}, this.options, options); }; kendo.createProxyMember = function(proto, name) { proto.fn[name] = function() { var instance = this._instance; if (instance) { return instance[name].apply(instance, arguments); } }; }; kendo.getBaseClass = function(targetClass) { if (targetClass instanceof Function) { let baseClass = targetClass; const newBaseClass = Object.getPrototypeOf(baseClass); if (newBaseClass && newBaseClass !== Object && newBaseClass.name) { return newBaseClass; } } return null; }; kendo.getAllMethods = function(targetClass) { const allStatic = Object.getOwnPropertyNames(targetClass) .filter(prop => typeof targetClass[prop] === "function"); const allNonStatic = Object.getOwnPropertyNames(Object.getPrototypeOf(new targetClass({}))) .filter(prop => prop !== "constructor"); return allStatic.concat(allNonStatic); }; kendo.convertPromiseToDeferred = function(promise) { let deferred = $.Deferred(); promise.finally(deferred.always).then(deferred.resolve).catch(deferred.reject); return deferred.promise(); }; kendo.ConvertClass = fromESClass; kendo.isPresent = (value) => value !== null && value !== undefined$1; kendo.isBlank = (value) => value === null || value === undefined$1; kendo.isEmpty = (value) => value.length === 0; kendo.isString = (value) => typeof value === 'string'; kendo.isInteger = (value) => Number.isInteger(value); kendo.isNumeric = (value) => !isNaN(value - parseFloat(value)); kendo.isDate = (value) => value && value.getTime; const isFunction = kendo.isFunction = (value) => typeof value === 'function'; var preventDefault = function() { this._defaultPrevented = true; }; var isDefaultPrevented = function() { return this._defaultPrevented === true; }; var Observable = Class.extend({ init: function() { this._events = {}; }, bind: function(eventName, handlers, one) { var that = this, idx, eventNames = typeof eventName === STRING ? [eventName] : eventName, length, original, handler, handlersIsFunction = typeof handlers === FUNCTION, events; if (handlers === undefined$1) { for (idx in eventName) { that.bind(idx, eventName[idx]); } return that; } for (idx = 0, length = eventNames.length; idx < length; idx++) { eventName = eventNames[idx]; handler = handlersIsFunction ? handlers : handlers[eventName]; if (handler) { if (one) { original = handler; handler = function() { that.unbind(eventName, handler); original.apply(that, arguments); }; handler.original = original; } events = that._events[eventName] = that._events[eventName] || []; events.push(handler); } } return that; }, one: function(eventNames, handlers) { return this.bind(eventNames, handlers, true); }, first: function(eventName, handlers) { var that = this, idx, eventNames = typeof eventName === STRING ? [eventName] : eventName, length, handler, handlersIsFunction = typeof handlers === FUNCTION, events; for (idx = 0, length = eventNames.length; idx < length; idx++) { eventName = eventNames[idx]; handler = handlersIsFunction ? handlers : handlers[eventName]; if (handler) { events = that._events[eventName] = that._events[eventName] || []; events.unshift(handler); } } return that; }, trigger: function(eventName, e) { var that = this, events = that._events[eventName], idx, length; if (events) { e = e || {}; e.sender = that; e._defaultPrevented = false; e.preventDefault = preventDefault; e.isDefaultPrevented = isDefaultPrevented; events = events.slice(); for (idx = 0, length = events.length; idx < length; idx++) { events[idx].call(that, e); } return e._defaultPrevented === true; } return false; }, unbind: function(eventName, handler) { var that = this, events = that._events[eventName], idx; if (eventName === undefined$1) { that._events = {}; } else if (events) { if (handler) { for (idx = events.length - 1; idx >= 0; idx--) { if (events[idx] === handler || events[idx].original === handler) { events.splice(idx, 1); } } } else { that._events[eventName] = []; } } return that; } }); function compilePart(part, stringPart) { if (stringPart) { return "'" + part.split("'").join("\\'") .split('\\"').join('\\\\\\"') .replace(/\n/g, "\\n") .replace(/\r/g, "\\r") .replace(/\t/g, "\\t") + "'"; } else { var first = part.charAt(0), rest = part.substring(1); if (first === "=") { return "+(" + rest + ")+"; } else if (first === ":") { return "+$kendoHtmlEncode(" + rest + ")+"; } else { return ";" + part + ";$kendoOutput+="; } } } var argumentNameRegExp = /^\w+/, encodeRegExp = /\$\{([^}]*)\}/g, escapedCurlyRegExp = /\\\}/g, curlyRegExp = /__CURLY__/g, escapedSharpRegExp = /\\#/g, sharpRegExp = /__SHARP__/g, zeros = ["", "0", "00", "000", "0000"]; Template = { paramName: "data", // name of the parameter of the generated template useWithBlock: true, // whether to wrap the template in a with() block render: function(template, data) { var idx, length, html = ""; for (idx = 0, length = data.length; idx < length; idx++) { html += template(data[idx]); } return html; }, compile: function(template, options) { var settings = extend({}, this, options), paramName = settings.paramName, argumentName = paramName.match(argumentNameRegExp)[0], useWithBlock = settings.useWithBlock, functionBody = "var $kendoOutput, $kendoHtmlEncode = kendo.htmlEncode;", fn, parts, idx; if (isFunction(template)) { return template; } functionBody += useWithBlock ? "with(" + paramName + "){" : ""; functionBody += "$kendoOutput="; parts = template .replace(escapedCurlyRegExp, "__CURLY__") .replace(encodeRegExp, "#=$kendoHtmlEncode($1)#") .replace(curlyRegExp, "}") .replace(escapedSharpRegExp, "__SHARP__") .split("#"); for (idx = 0; idx < parts.length; idx ++) { functionBody += compilePart(parts[idx], idx % 2 === 0); } functionBody += useWithBlock ? ";}" : ";"; functionBody += "return $kendoOutput;"; functionBody = functionBody.replace(sharpRegExp, "#"); try { // This function evaluation is required for legacy support of the Kendo Template syntax - non CSP compliant. fn = new Function(argumentName, functionBody); fn._slotCount = Math.floor(parts.length / 2); return fn; } catch (e) { if (kendo.debugTemplates) { window.console.warn(`Invalid template:'${template}' Generated code:'${functionBody}'`); } else { throw new Error(kendo.format("Invalid template:'{0}' Generated code:'{1}'", template, functionBody)); } } } }; function pad(number, digits, end) { number = number + ""; digits = digits || 2; end = digits - number.length; if (end) { return zeros[digits].substring(0, end) + number; } return number; } //JSON stringify (function() { var escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, gap, indent, meta = { "\b": "\\b", "\t": "\\t", "\n": "\\n", "\f": "\\f", "\r": "\\r", "\"": '\\"', "\\": "\\\\" }, rep, toString = {}.toString; if (typeof Date.prototype.toJSON !== FUNCTION) { Date.prototype.toJSON = function() { var that = this; return isFinite(that.valueOf()) ? pad(that.getUTCFullYear(), 4) + "-" + pad(that.getUTCMonth() + 1) + "-" + pad(that.getUTCDate()) + "T" + pad(that.getUTCHours()) + ":" + pad(that.getUTCMinutes()) + ":" + pad(that.getUTCSeconds()) + "Z" : null; }; String.prototype.toJSON = Number.prototype.toJSON = Boolean.prototype.toJSON = function() { return this.valueOf(); }; } function quote(string) { escapable.lastIndex = 0; return escapable.test(string) ? "\"" + string.replace(escapable, function(a) { var c = meta[a]; return typeof c === STRING ? c : "\\u" + ("0000" + a.charCodeAt(0).toString(16)).slice(-4); }) + "\"" : "\"" + string + "\""; } function str(key, holder) { var i, k, v, length, mind = gap, partial, value = holder[key], type; if (value && typeof value === OBJECT && typeof value.toJSON === FUNCTION) { value = value.toJSON(key); } if (typeof rep === FUNCTION) { value = rep.call(holder, key, value); } type = typeof value; if (type === STRING) { return quote(value); } else if (type === NUMBER) { return isFinite(value) ? String(value) : NULL; } else if (type === BOOLEAN || type === NULL) { return String(value); } else if (type === OBJECT) { if (!value) { return NULL; } gap += indent; partial = []; if (toString.apply(value) === "[object Array]") { length = value.length; for (i = 0; i < length; i++) { partial[i] = str(i, value) || NULL; } v = partial.length === 0 ? "[]" : gap ? "[\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "]" : "[" + partial.join(",") + "]"; gap = mind; return v; } if (rep && typeof rep === OBJECT) { length = rep.length; for (i = 0; i < length; i++) { if (typeof rep[i] === STRING) { k = rep[i]; v = str(k, value); if (v) { partial.push(quote(k) + (gap ? ": " : ":") + v); } } } } else { for (k in value) { if (Object.hasOwnProperty.call(value, k)) { v = str(k, value); if (v) { partial.push(quote(k) + (gap ? ": " : ":") + v); } } } } v = partial.length === 0 ? "{}" : gap ? "{\n" + gap + partial.join(",\n" + gap) + "\n" + mind + "}" : "{" + partial.join(",") + "}"; gap = mind; return v; } } if (typeof JSON.stringify !== FUNCTION) { JSON.stringify = function(value, replacer, space) { var i; gap = ""; indent = ""; if (typeof space === NUMBER) { for (i = 0; i < space; i += 1) { indent += " "; } } else if (typeof space === STRING) { indent = space; } rep = replacer; if (replacer && typeof replacer !== FUNCTION && (typeof replacer !== OBJECT || typeof replacer.length !== NUMBER)) { throw new Error("JSON.stringify"); } return str("", { "": value }); }; } })(); // Date and Number formatting (function() { var dateFormatRegExp = /EEEE|dddd|ddd|dd|d|MMMM|MMM|MM|M|yyyy|yy|HH|H|hh|h|mm|m|fff|ff|f|tt|ss|s|zzz|zz|z|"[^"]*"|'[^']*'/g, standardFormatRegExp = /^(n|c|p|e)(\d*)$/i, literalRegExp = /(\\.)|(['][^']*[']?)|(["][^"]*["]?)/g, commaRegExp = /\,/g, EMPTY = "", POINT = ".", COMMA = ",", SHARP = "#", ZERO = "0", PLACEHOLDER = "??", EN = "en-US", objectToString = {}.toString; //cultures kendo.cultures = kendo.cultures || {}; // Ensure cultures object exists kendo.cultures["en-US"] = { name: EN, numberFormat: { pattern: ["-n"], decimals: 2, ",": ",", ".": ".", groupSize: [3], percent: { pattern: ["-n %", "n %"], decimals: 2, ",": ",", ".": ".", groupSize: [3], symbol: "%" }, currency: { name: "US Dollar", abbr: "USD", pattern: ["($n)", "$n"], decimals: 2, ",": ",", ".": ".", groupSize: [3], symbol: "$" } }, calendars: { standard: { days: { names: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], namesAbbr: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], namesShort: [ "Su", "Mo", "Tu", "We", "Th", "Fr", "Sa" ] }, months: { names: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], namesAbbr: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] }, AM: [ "AM", "am", "AM" ], PM: [ "PM", "pm", "PM" ], patterns: { d: "M/d/yyyy", D: "dddd, MMMM dd, yyyy", F: "dddd, MMMM dd, yyyy h:mm:ss tt", g: "M/d/yyyy h:mm tt", G: "M/d/yyyy h:mm:ss tt", m: "MMMM dd", M: "MMMM dd", s: "yyyy'-'MM'-'ddTHH':'mm':'ss", t: "h:mm tt", T: "h:mm:ss tt", u: "yyyy'-'MM'-'dd HH':'mm':'ss'Z'", y: "MMMM, yyyy", Y: "MMMM, yyyy" }, "/": "/", ":": ":", firstDay: 0, twoDigitYearMax: 2029 } } }; function kendoCultureToIntl(kendoCulture) { kendoCulture = getCulture(kendoCulture) || kendo.cultures.current; let currencies = {}; currencies[kendoCulture.numberFormat.currency.abbr] = kendoCulture.numberFormat.currency; const localeInfoAll = {}; // Extract the name and split into language and territory if possible const [language, territory] = kendoCulture.name.split('-'); localeInfoAll.name = language; localeInfoAll.identity = { language }; if (territory) { localeInfoAll.territory = territory; } // Map number format symbols if (kendoCulture.numberFormat) { localeInfoAll.numbers = { symbols: { decimal: kendoCulture.numberFormat["."], group: kendoCulture.numberFormat[","], percentSign: kendoCulture.numberFormat.percent?.symbol || "%" }, decimal: { patterns: kendoCulture.numberFormat.pattern, groupSize: kendoCulture.numberFormat.groupSize }, currency: { patterns: kendoCulture.numberFormat.currency?.pattern, groupSize: kendoCulture.numberFormat.currency?.groupSize }, percent: { patterns: kendoCulture.numberFormat.percent?.pattern, groupSize: kendoCulture.numberFormat.percent?.groupSize, decimals: kendoCulture.numberFormat.percent?.decimals } }; // Map currency information if available if (kendoCulture.numberFormat.currency) { localeInfoAll.numbers.currencies = { [kendoCulture.numberFormat.currency.abbr]: kendoCulture.numberFormat.currency }; localeInfoAll.numbers.localeCurrency = kendoCulture.numberFormat.currency.abbr; } } // Map calendar information if (kendoCulture.calendars && kendoCulture.calendars.standard) { const standardCalendar = kendoCulture.calendars.standard; localeInfoAll.calendar = { patterns: { d: standardCalendar.patterns.d, D: standardCalendar.patterns.D, F: standardCalendar.patterns.F, g: standardCalendar.patterns.g, G: standardCalendar.patterns.G, m: standardCalendar.patterns.m, M: standardCalendar.patterns.M, s: standardCalendar.patterns.s, t: standardCalendar.patterns.t, T: standardCalendar.patterns.T, u: standardCalendar.patterns.u, y: standardCalendar.patterns.y, Y: standardCalendar.patterns.Y }, days: { format: { wide: standardCalendar.days.names, abbreviated: standardCalendar.days.namesAbbr, short: standardCalendar.days.namesShort }, "stand-alone": { wide: standardCalendar.days.names, abbreviated: standardCalendar.days.namesAbbr, short: standardCalendar.days.namesShort } }, months: { format: { wide: standardCalendar.months.names, abbreviated: standardCalendar.months.namesAbbr, narrow: standardCalendar.months.namesAbbr.map(name => name.charAt(0)) }, "stand-alone": { wide: standardCalendar.months.names, abbreviated: standardCalendar.months.namesAbbr, narrow: standardCalendar.months.namesAbbr.map(name => name.charAt(0)) } }, dayPeriods: { format: { abbreviated: { am: standardCalendar.AM[0], pm: standardCalendar.PM[0] }, narrow: { am: standardCalendar.AM[1], pm: standardCalendar.PM[1] }, wide: { am: standardCalendar.AM[0], pm: standardCalendar.PM[0] } }, "stand-alone": { abbreviated: { am: standardCalendar.AM[0], pm: standardCalendar.PM[0] }, narrow: { am: standardCalendar.AM[1], pm: standardCalendar.PM[1] }, wide: { am: standardCalendar.AM[0], pm: standardCalendar.PM[0] } } } }; // Include firstDay if defined if ('firstDay' in standardCalendar) { localeInfoAll.firstDay = standardCalendar.firstDay; } } return { localeInfo: () => ({ numbers: { localeCurrency: kendoCulture.numberFormat.currency.abbr, currencies: currencies, symbols: { group: kendoCulture.numberFormat[','], decimal: kendoCulture.numberFormat['.'], percentSign: kendoCulture.numberFormat.percent.symbol, } }, calendar: { patterns: kendoCulture.calendars.standard.patterns, months: { format: { wide: kendoCulture.calendars.standard.months.names, abbreviated: kendoCulture.calendars.standard.months.namesAbbr } }, days: { format: { wide: kendoCulture.calendars.standard.days.names, abbreviated: kendoCulture.calendars.standard.days.namesAbbr } } } }), parseDate: (value, fmt) => kendo.parseExactDate(value, fmt), toString: (value, fmt) => toString(value, fmt), format: (fmt, ...values) => kendo.format(fmt, values) }; } function findCulture(culture) { if (culture) { if (culture.numberFormat) { return culture; } if (typeof culture === STRING) { var cultures = kendo.cultures; return cultures[culture] || cultures[culture.split("-")[0]] || null; } return null; } return null; } function getCulture(culture) { if (culture) { culture = findCulture(culture); } return culture || kendo.cultures.current; } function appendDesignatorsToCultures(calendars) { // Don't ask. It's temporary. if ((calendars.standard.AM && calendars.standard.AM.length) && (calendars.standard.PM && calendars.standard.PM.length) && (calendars.standard.AM.indexOf("PMA0") < 0) && (calendars.standard.AM.indexOf("AM") > -1 || calendars.standard.PM.indexOf("PM") > -1)) { calendars.standard.AM.push("a", "A", "PMa", "PMA", "PMa0", "PMA0"); calendars.standard.PM.push("p", "P", "AMp", "AMP", "AMp0", "AMP0"); } } kendo.culture = function(cultureName) { var cultures = kendo.cultures, culture; if (cultureName !== undefined$1) { culture = findCulture(cultureName) || cultures[EN]; culture.calendar = culture.calendars.standard; cultures.current = culture; } else { appendDesignatorsToCultures(cultures.current.calendars); return cultures.current; } }; kendo.findCulture = findCulture; kendo.getCulture = getCulture; kendo.kendoCultureToIntl = kendoCultureToIntl; //set current culture to en-US. kendo.culture(EN); function formatDate(date, format, culture) { culture = getCulture(culture); var calendar = culture.calendars.standard, days = calendar.days, months = calendar.months; format = format.pattern || calendar.patterns[format] || format; return format.replace(dateFormatRegExp, function(match) { var minutes; var result; var sign; if (match === "d") { result = date.getDate(); } else if (match === "dd") { result = pad(date.getDate()); } else if (match === "ddd") { result = days.namesAbbr[date.getDay()]; } else if (match === "dddd" || match === "EEEE") { result = days.names[date.getDay()]; } else if (match === "M") { result = date.getMonth() + 1; } else if (match === "MM") { result = pad(date.getMonth() + 1); } else if (match === "MMM") { result = months.namesAbbr[date.getMonth()]; } else if (match === "MMMM") { result = months.names[date.getMonth()]; } else if (match === "yy") { result = pad(date.getFullYear() % 100); } else if (match === "yyyy") { result = pad(date.getFullYear(), 4); } else if (match === "h" ) { result = date.getHours() % 12 || 12; } else if (match === "hh") { result = pad(date.getHours() % 12 || 12); } else if (match === "H") { result = date.getHours(); } else if (match === "HH") { result = pad(date.getHours()); } else if (match === "m") { result = date.getMinutes(); } else if (match === "mm") { result = pad(date.getMinutes()); } else if (match === "s") { result = date.getSeconds(); } else if (match === "ss") { result = pad(date.getSeconds()); } else if (match === "f") { result = math.floor(date.getMilliseconds() / 100); } else if (match === "ff") { result = date.getMilliseconds(); if (result > 99) { result = math.floor(result / 10); } result = pad(result); } else if (match === "fff") { result = pad(date.getMilliseconds(), 3); } else if (match === "tt" || match === "aa") { result = date.getHours() < 12 ? calendar.AM[0] : calendar.PM[0]; } else if (match === "zzz") { minutes = date.getTimezoneOffset(); sign = minutes < 0; result = math.abs(minutes / 60).toString().split(".")[0]; minutes = math.abs(minutes) - (result * 60); result = (sign ? "+" : "-") + pad(result); result += ":" + pad(minutes); } else if (match === "zz" || match === "z") { result = date.getTimezoneOffset() / 60; sign = result < 0; result = math.abs(result).toString().split(".")[0]; result = (sign ? "+" : "-") + (match === "zz" ? pad(result) : result); } return result !== undefined$1 ? result : match.slice(1, match.length - 1); }); } //number formatting function formatNumber(number, format, culture) { culture = getCulture(culture); var numberFormat = culture.numberFormat, decimal = numberFormat[POINT], precision = numberFormat.decimals, pattern = numberFormat.pattern[0], literals = [], symbol, isCurrency, isPercent, customPrecision, formatAndPrecision, negative = number < 0, integer, fraction, integerLength, replacement = EMPTY, value = EMPTY, idx, length, ch, hasGroup, hasNegativeFormat, decimalIndex, sharpIndex, zeroIndex, hasZero, hasSharp, percentIndex, currencyIndex, start = -1, end; //return empty string if no number if (number === undefined$1) { return EMPTY; } if (!isFinite(number)) { return number; } //if no format then return number.toString() or number.toLocaleString() if culture.name is not defined if (!format) { return culture.name.length ? number.toLocaleString() : number.toString(); } formatAndPrecision = standardFormatRegExp.exec(format); // standard formatting if (formatAndPrecision) { format = formatAndPrecision[1].toLowerCase(); isCurrency = format === "c"; isPercent = format === "p"; if (isCurrency || isPercent) { //get specific number format information if format is currency or percent numberFormat = isCurrency ? numberFormat.currency : numberFormat.percent; decimal = numberFormat[POINT]; precision = numberFormat.decimals; symbol = numberFormat.symbol; pattern = numberFormat.pattern[negative ? 0 : 1]; } customPrecision = formatAndPrecision[2]; if (customPrecision) { precision = +customPrecision; } //return number in exponential format if (format === "e") { var exp = customPrecision ? number.toExponential(precision) : number.toExponential(); // toExponential() and toExponential(undefined) differ in FF #653438. return exp.replace(POINT, numberFormat[POINT]); } // multiply if format is percent if (isPercent) { number *= 100; } number = round(number, precision); negative = number < 0; number = number.split(POINT); integer = number[0]; fraction = number[1]; //exclude "-" if number is negative. if (negative) { integer = integer.substring(1); } value = groupInteger(integer, 0, integer.length, numberFormat); if (fraction) { value += decimal + fraction; } if (format === "n" && !negative) { return value; } number = EMPTY; for (idx = 0, length = pattern.length; idx < length; idx++) { ch = pattern.charAt(idx); if (ch === "n") { number += value; } else if (ch === "$" || ch === "%") { number += symbol; } else { number += ch; } } return number; } //custom formatting // //separate format by sections. if (format.indexOf("'") > -1 || format.indexOf("\"") > -1 || format.indexOf("\\") > -1) { format = format.replace(literalRegExp, function(match) { var quoteChar = match.charAt(0).replace("\\", ""), literal = match.slice(1).replace(quoteChar, ""); literals.push(literal); return PLACEHOLDER; }); } format = format.split(";"); if (negative && format[1]) { //get negative format format = format[1]; hasNegativeFormat = true; } else if (number === 0 && format[2]) { //format for zeros format = format[2]; if (format.indexOf(SHARP) == -1 && format.indexOf(ZERO) == -1) { //return format if it is string constant. return format; } } else { format = format[0]; } percentIndex = format.indexOf("%"); currencyIndex = format.indexOf("$"); isPercent = percentIndex != -1; isCurrency = currencyIndex != -1; //multiply number if the format has percent if (isPercent) { number *= 100; } if (isCurrency && format[currencyIndex - 1] === "\\") { format = format.split("\\").join(""); isCurrency = false; } if (isCurrency || isPercent) { //get specific number format information if format is currency or percent numberFormat = isCurrency ? numberFormat.currency : numberFormat.percent; decimal = numberFormat[POINT]; precision = numberFormat.decimals; symbol = numberFormat.symbol; } hasGroup = format.indexOf(COMMA) > -1; if (hasGroup) { format = format.replace(commaRegExp, EMPTY); } decimalIndex = format.indexOf(POINT); length = format.length; if (decimalIndex != -1) { fraction = number.toString().split("e"); if (fraction[1]) { fraction = round(number, Math.abs(fraction[1])); } else { fraction = fraction[0]; } fraction = fraction.split(POINT)[1] || EMPTY; zeroIndex = format.lastIndexOf(ZERO) - decimalIndex; sharpIndex = format.lastIndexOf(SHARP) - decimalIndex; hasZero = zeroIndex > -1; hasSharp = sharpIndex > -1; idx = fraction.length; if (!hasZero && !hasSharp) { format = format.substring(0, decimalIndex) + format.substring(decimalIndex + 1); length = format.length; decimalIndex = -1; idx = 0; } if (hasZero && zeroIndex > sharpIndex) { idx = zeroIndex; } else if (sharpIndex > zeroIndex) { if (hasSharp && idx > sharpIndex) { var rounded = round(number, sharpIndex, negative); while (rounded.charAt(rounded.length - 1) === ZERO && sharpIndex > 0 && sharpIndex > zeroIndex) { sharpIndex--; rounded = round(number, sharpIndex, negative); } idx = sharpIndex; } else if (hasZero && idx < zeroIndex) { idx = zeroIndex; } } } number = round(number, idx, negative); sharpIndex = format.indexOf(SHARP); zeroIndex = format.indexOf(ZERO); //define the index of the first digit placeholder if (sharpIndex == -1 && zeroIndex != -1) { start = zeroIndex; } else if (sharpIndex != -1 && zeroIndex == -1) { start = sharpIndex; } else { start = sharpIndex > zeroIndex ? zeroIndex : sharpIndex; } sharpIndex = format.lastIndexOf(SHARP); zeroIndex = format.lastIndexOf(ZERO); //define the index of the last digit placeholder if (sharpIndex == -1 && zeroIndex != -1) { end = zeroIndex; } else if (sharpIndex != -1 && zeroIndex == -1) { end = sharpIndex; } else { end = sharpIndex > zeroIndex ? sharpIndex : zeroIndex; } if (start == length) { end = start; } if (start != -1) { value = number.toString().split(POINT); integer = value[0]; fraction = value[1] || EMPTY; integerLength = integer.length; fraction.length; if (negative && (number * -1) >= 0) { negative = false; } number = format.substring(0, start); if (negative && !hasNegativeFormat) { number += "-"; } idx = start; while (idx < length) { ch = format.charAt(idx); if (decimalIndex == -1) { if (end - idx < integerLength) { number += integer; break; } } else { if (zeroIndex != -1 && zeroIndex < idx) { replacement = EMPTY; } if ((decimalIndex - idx) <= integerLength && decimalIndex - idx > -1) { number += integer; idx = decimalIndex; } if (decimalIndex === idx) { number += (fraction ? decimal : EMPTY) + fraction; idx += end - decimalIndex + 1; continue; } } if (ch === ZERO) { number += ch; replacement = ch; } else if (ch === SHARP) { number += replacement; } idx++; } if (hasGroup) { number = groupInteger(number, start + (negative && !hasNegativeFormat ? 1 : 0), Math.max(end, (integerLength + start)), numberFormat); } if (end >= start) { number += format.substring(end + 1); } //replace symbol placeholders if (isCurrency || isPercent) { value = EMPTY; for (idx = 0, length = number.length; idx < length; idx++) { ch = number.charAt(idx); value += (ch === "$" || ch === "%") ? symbol : ch; } number = value; } length = literals.length; if (length) { for (idx = 0; idx < length; idx++) { number = number.replace(PLACEHOLDER, literals[idx]); } } } return number; } var groupInteger = function(number, start, end, numberFormat) { var decimalIndex = number.indexOf(numberFormat[POINT]); var groupSizes = numberFormat.groupSize.slice(); var groupSize = groupSizes.shift(); var integer, integerLength; var idx, parts, value; var newGroupSize; end = decimalIndex !== -1 ? decimalIndex : end + 1; integer = number.substring(start, end); integerLength = integer.length; if