todomvc
Version:
> Helping you select an MV\* framework
1,574 lines (1,324 loc) • 116 kB
JavaScript
/*
* Kendo UI Web v2013.3.1119 (http://kendoui.com)
* Copyright 2013 Telerik AD. All rights reserved.
*
* Kendo UI Web commercial licenses may be obtained at
* https://www.kendoui.com/purchase/license-agreement/kendo-ui-web-commercial.aspx
* If you do not own a commercial license, this file shall be governed by the
* GNU General Public License (GPL) version 3.
* For GPL requirements, please review: http://www.gnu.org/copyleft/gpl.html
*/
(function($, evil, undefined) {
var kendo = window.kendo = window.kendo || { cultures: {} },
extend = $.extend,
each = $.each,
isArray = $.isArray,
proxy = $.proxy,
noop = $.noop,
math = Math,
Template,
JSON = window.JSON || {},
support = {},
percentRegExp = /%/,
formatRegExp = /\{(\d+)(:[^\}]+)?\}/g,
boxShadowRegExp = /(\d+?)px\s*(\d+?)px\s*(\d+?)px\s*(\d+?)?/i,
numberRegExp = /^(\+|-?)\d+(\.?)\d*$/,
FUNCTION = "function",
STRING = "string",
NUMBER = "number",
OBJECT = "object",
NULL = "null",
BOOLEAN = "boolean",
UNDEFINED = "undefined",
getterCache = {},
setterCache = {},
slice = [].slice,
globalize = window.Globalize;
kendo.version = "2013.3.1119";
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 (typeof proto[member] === OBJECT && !(proto[member] instanceof Array) && proto[member] !== null) {
// 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);
};
var isFunction = kendo.isFunction = function(fn) {
return typeof fn === "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) {
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);
};
}
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) {
that._events = {};
} else if (events) {
if (handler) {
for (idx = events.length - 1; idx >= 0; idx--) {
if (events[idx] === 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 "+e(" + rest + ")+";
} else {
return ";" + part + ";o+=";
}
}
}
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 o,e=kendo.htmlEncode;",
fn,
parts,
idx;
if (isFunction(template)) {
if (template.length === 2) {
//looks like jQuery.template
return function(d) {
return template($, { data: d }).join("");
};
}
return template;
}
functionBody += useWithBlock ? "with(" + paramName + "){" : "";
functionBody += "o=";
parts = template
.replace(escapedCurlyRegExp, "__CURLY__")
.replace(encodeRegExp, "#=e($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 o;";
functionBody = functionBody.replace(sharpRegExp, "#");
try {
fn = new Function(argumentName, functionBody);
fn._slotCount = Math.floor(parts.length / 2);
return fn;
} catch(e) {
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 = /dddd|ddd|dd|d|MMMM|MMM|MM|M|yyyy|yy|HH|H|hh|h|mm|m|fff|ff|f|tt|ss|s|"[^"]*"|'[^']*'/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["en-US"] = {
name: EN,
numberFormat: {
pattern: ["-n"],
decimals: 2,
",": ",",
".": ".",
groupSize: [3],
percent: {
pattern: ["-n %", "n %"],
decimals: 2,
",": ",",
".": ".",
groupSize: [3],
symbol: "%"
},
currency: {
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 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 expandNumberFormat(numberFormat) {
numberFormat.groupSizes = numberFormat.groupSize;
numberFormat.percent.groupSizes = numberFormat.percent.groupSize;
numberFormat.currency.groupSizes = numberFormat.currency.groupSize;
}
kendo.culture = function(cultureName) {
var cultures = kendo.cultures, culture;
if (cultureName !== undefined) {
culture = findCulture(cultureName) || cultures[EN];
culture.calendar = culture.calendars.standard;
cultures.current = culture;
if (globalize) {
expandNumberFormat(culture.numberFormat);
}
} else {
return cultures.current;
}
};
kendo.findCulture = findCulture;
kendo.getCulture = getCulture;
//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 = calendar.patterns[format] || format;
return format.replace(dateFormatRegExp, function (match) {
var result;
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") {
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 = math.floor(date.getMilliseconds() / 10);
} else if (match === "fff") {
result = date.getMilliseconds();
} else if (match === "tt") {
result = date.getHours() < 12 ? calendar.AM[0] : calendar.PM[0];
}
return result !== undefined ? result : match.slice(1, match.length - 1);
});
}
//number formatting
function formatNumber(number, format, culture) {
culture = getCulture(culture);
var numberFormat = culture.numberFormat,
groupSize = numberFormat.groupSize[0],
groupSeparator = numberFormat[COMMA],
decimal = numberFormat[POINT],
precision = numberFormat.decimals,
pattern = numberFormat.pattern[0],
literals = [],
symbol,
isCurrency, isPercent,
customPrecision,
formatAndPrecision,
negative = number < 0,
integer,
fraction,
integerLength,
fractionLength,
replacement = EMPTY,
value = EMPTY,
idx,
length,
ch,
hasGroup,
hasNegativeFormat,
decimalIndex,
sharpIndex,
zeroIndex,
hasZero, hasSharp,
percentIndex,
currencyIndex,
startZeroIndex,
start = -1,
end;
//return empty string if no number
if (number === undefined) {
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;
groupSize = numberFormat.groupSize[0];
groupSeparator = numberFormat[COMMA];
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") {
return customPrecision ? number.toExponential(precision) : number.toExponential(); // toExponential() and toExponential(undefined) differ in FF #653438.
}
// multiply if format is percent
if (isPercent) {
number *= 100;
}
number = round(number, precision);
number = number.split(POINT);
integer = number[0];
fraction = number[1];
//exclude "-" if number is negative.
if (negative) {
integer = integer.substring(1);
}
value = integer;
integerLength = integer.length;
//add group separator to the number if it is longer enough
if (integerLength >= groupSize) {
value = EMPTY;
for (idx = 0; idx < integerLength; idx++) {
if (idx > 0 && (integerLength - idx) % groupSize === 0) {
value += groupSeparator;
}
value += integer.charAt(idx);
}
}
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.
//make number positive
if (negative) {
number = -number;
}
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 for zeros
format = format[2] || format[0];
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;
groupSize = numberFormat.groupSize[0];
groupSeparator = numberFormat[COMMA];
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) {
idx = sharpIndex;
} else if (hasZero && idx < zeroIndex) {
idx = zeroIndex;
}
}
if (idx > -1) {
number = round(number, idx);
}
} else {
number = round(number);
}
sharpIndex = format.indexOf(SHARP);
startZeroIndex = 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;
fractionLength = fraction.length;
//add group separator to the number if it is longer enough
if (hasGroup) {
if (integerLength === groupSize && integerLength < decimalIndex - startZeroIndex) {
integer = groupSeparator + integer;
} else if (integerLength > groupSize) {
value = EMPTY;
for (idx = 0; idx < integerLength; idx++) {
if (idx > 0 && (integerLength - idx) % groupSize === 0) {
value += groupSeparator;
}
value += integer.charAt(idx);
}
integer = value;
}
}
number = format.substring(0, start);
if (negative && !hasNegativeFormat) {
number += "-";
}
for (idx = start; idx < length; idx++) {
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;
}
}
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 round = function(value, precision) {
var power = Math.pow(10, precision || 0);
return (Math.round(value * power) / power).toFixed(precision);
};
var toString = function(value, fmt, culture) {
if (fmt) {
if (objectToString.call(value) === "[object Date]") {
return formatDate(value, fmt, culture);
} else if (typeof value === NUMBER) {
return formatNumber(value, fmt, culture);
}
}
return value !== undefined ? value : "";
};
if (globalize) {
toString = proxy(globalize.format, globalize);
}
kendo.format = function(fmt) {
var values = arguments;
return fmt.replace(formatRegExp, function(match, index, placeholderFormat) {
var value = values[parseInt(index, 10) + 1];
return toString(value, placeholderFormat ? placeholderFormat.substring(1) : "");
});
};
kendo._extractFormat = function (format) {
if (format.slice(0,3) === "{0:") {
format = format.slice(3, format.length - 1);
}
return format;
};
kendo._activeElement = function() {
try {
return document.activeElement;
} catch(e) {
return document.documentElement.activeElement;
}
};
kendo._round = round;
kendo.toString = toString;
})();
(function() {
var nonBreakingSpaceRegExp = /\u00A0/g,
exponentRegExp = /[eE][\-+]?[0-9]+/,
shortTimeZoneRegExp = /[+|\-]\d{1,2}/,
longTimeZoneRegExp = /[+|\-]\d{1,2}:\d{2}/,
dateRegExp = /^\/Date\((.*?)\)\/$/,
formatsSequence = ["G", "g", "d", "F", "D", "y", "m", "T", "t"],
numberRegExp = {
2: /^\d{1,2}/,
4: /^\d{4}/
},
objectToString = {}.toString;
function outOfRange(value, start, end) {
return !(value >= start && value <= end);
}
function designatorPredicate(designator) {
return designator.charAt(0);
}
function mapDesignators(designators) {
return $.map(designators, designatorPredicate);
}
//if date's day is different than the typed one - adjust
function adjustDST(date, hours) {
if (!hours && date.getHours() === 23) {
date.setHours(date.getHours() + 2);
}
}
function lowerArray(data) {
var idx = 0,
length = data.length,
array = [];
for (; idx < length; idx++) {
array[idx] = (data[idx] + "").toLowerCase();
}
return array;
}
function lowerLocalInfo(localInfo) {
var newLocalInfo = {}, property;
for (property in localInfo) {
newLocalInfo[property] = lowerArray(localInfo[property]);
}
return newLocalInfo;
}
function parseExact(value, format, culture) {
if (!value) {
return null;
}
var lookAhead = function (match) {
var i = 0;
while (format[idx] === match) {
i++;
idx++;
}
if (i > 0) {
idx -= 1;
}
return i;
},
getNumber = function(size) {
var rg = numberRegExp[size] || new RegExp('^\\d{1,' + size + '}'),
match = value.substr(valueIdx, size).match(rg);
if (match) {
match = match[0];
valueIdx += match.length;
return parseInt(match, 10);
}
return null;
},
getIndexByName = function (names, lower) {
var i = 0,
length = names.length,
name, nameLength,
subValue;
for (; i < length; i++) {
name = names[i];
nameLength = name.length;
subValue = value.substr(valueIdx, nameLength);
if (lower) {
subValue = subValue.toLowerCase();
}
if (subValue == name) {
valueIdx += nameLength;
return i + 1;
}
}
return null;
},
checkLiteral = function() {
var result = false;
if (value.charAt(valueIdx) === format[idx]) {
valueIdx++;
result = true;
}
return result;
},
calendar = culture.calendars.standard,
year = null,
month = null,
day = null,
hours = null,
minutes = null,
seconds = null,
milliseconds = null,
idx = 0,
valueIdx = 0,
literal = false,
date = new Date(),
twoDigitYearMax = calendar.twoDigitYearMax || 2029,
defaultYear = date.getFullYear(),
ch, count, length, pattern,
pmHour, UTC, ISO8601, matches,
amDesignators, pmDesignators,
hoursOffset, minutesOffset,
hasTime;
if (!format) {
format = "d"; //shord date format
}
//if format is part of the patterns get real format
pattern = calendar.patterns[format];
if (pattern) {
format = pattern;
}
format = format.split("");
length = format.length;
for (; idx < length; idx++) {
ch = format[idx];
if (literal) {
if (ch === "'") {
literal = false;
} else {
checkLiteral();
}
} else {
if (ch === "d") {
count = lookAhead("d");
if (!calendar._lowerDays) {
calendar._lowerDays = lowerLocalInfo(calendar.days);
}
day = count < 3 ? getNumber(2) : getIndexByName(calendar._lowerDays[count == 3 ? "namesAbbr" : "names"], true);
if (day === null || outOfRange(day, 1, 31)) {
return null;
}
} else if (ch === "M") {
count = lookAhead("M");
if (!calendar._lowerMonths) {
calendar._lowerMonths = lowerLocalInfo(calendar.months);
}
month = count < 3 ? getNumber(2) : getIndexByName(calendar._lowerMonths[count == 3 ? 'namesAbbr' : 'names'], true);
if (month === null || outOfRange(month, 1, 12)) {
return null;
}
month -= 1; //because month is zero based
} else if (ch === "y") {
count = lookAhead("y");
year = getNumber(count);
if (year === null) {
return null;
}
if (count == 2) {
if (typeof twoDigitYearMax === "string") {
twoDigitYearMax = defaultYear + parseInt(twoDigitYearMax, 10);
}
year = (defaultYear - defaultYear % 100) + year;
if (year > twoDigitYearMax) {
year -= 100;
}
}
} else if (ch === "h" ) {
lookAhead("h");
hours = getNumber(2);
if (hours == 12) {
hours = 0;
}
if (hours === null || outOfRange(hours, 0, 11)) {
return null;
}
} else if (ch === "H") {
lookAhead("H");
hours = getNumber(2);
if (hours === null || outOfRange(hours, 0, 23)) {
return null;
}
} else if (ch === "m") {
lookAhead("m");
minutes = getNumber(2);
if (minutes === null || outOfRange(minutes, 0, 59)) {
return null;
}
} else if (ch === "s") {
lookAhead("s");
seconds = getNumber(2);
if (seconds === null || outOfRange(seconds, 0, 59)) {
return null;
}
} else if (ch === "f") {
count = lookAhead("f");
milliseconds = getNumber(count);
if (milliseconds !== null && count > 3) {
milliseconds = parseInt(milliseconds.toString().substring(0, 3), 10);
}
if (milliseconds === null || outOfRange(milliseconds, 0, 999)) {
return null;
}
} else if (ch === "t") {
count = lookAhead("t");
amDesignators = calendar.AM;
pmDesignators = calendar.PM;
if (count === 1) {
amDesignators = mapDesignators(amDesignators);
pmDesignators = mapDesignators(pmDesignators);
}
pmHour = getIndexByName(pmDesignators);
if (!pmHour && !getIndexByName(amDesignators)) {
return null;
}
}
else if (ch === "z") {
UTC = true;
count = lookAhead("z");
if (value.substr(valueIdx, 1) === "Z") {
if (!ISO8601) {
return null;
}
checkLiteral();
continue;
}
matches = value.substr(valueIdx, 6)
.match(count > 2 ? longTimeZoneRegExp : shortTimeZoneRegExp);
if (!matches) {
return null;
}
matches = matches[0];
valueIdx = matches.length;
matches = matches.split(":");
hoursOffset = parseInt(matches[0], 10);
if (outOfRange(hoursOffset, -12, 13)) {
return null;
}
if (count > 2) {
minutesOffset = parseInt(matches[1], 10);
if (isNaN(minutesOffset) || outOfRange(minutesOffset, 0, 59)) {
return null;
}
}
} else if (ch === "T") {
ISO8601 = checkLiteral();
} else if (ch === "'") {
literal = true;
checkLiteral();
} else if (!checkLiteral()) {
return null;
}
}
}
hasTime = hours !== null || minutes !== null || seconds || null;
if (year === null && month === null && day === null && hasTime) {
year = defaultYear;
month = date.getMonth();
day = date.getDate();
} else {
if (year === null) {
year = defaultYear;
}
if (day === null) {
day = 1;
}
}
if (pmHour && hours < 12) {
hours += 12;
}
if (UTC) {
if (hoursOffset) {
hours += -hoursOffset;
}
if (minutesOffset) {
minutes += -minutesOffset;
}
value = new Date(Date.UTC(year, month, day, hours, minutes, seconds, milliseconds));
} else {
value = new Date(year, month, day, hours, minutes, seconds, milliseconds);
adjustDST(value, hours);
}
if (year < 100) {
value.setFullYear(year);
}
if (value.getDate() !== day && UTC === undefined) {
return null;
}
return value;
}
kendo.parseDate = function(value, formats, culture) {
if (objectToString.call(value) === "[object Date]") {
return value;
}
var idx = 0,
date = null,
length, patterns;
if (value && value.indexOf("/D") === 0) {
date = dateRegExp.exec(value);
if (date) {
return new Date(parseInt(date[1], 10));
}
}
culture = kendo.getCulture(culture);
if (!formats) {
formats = [];
patterns = culture.calendar.patterns;
length = formatsSequence.length;
for (; idx < length; idx++) {
formats[idx] = patterns[formatsSequence[idx]];
}
idx = 0;
formats.push(
"yyyy/MM/dd HH:mm:ss",
"yyyy/MM/dd HH:mm",
"yyyy/MM/dd",
"ddd MMM dd yyyy HH:mm:ss",
"yyyy-MM-ddTHH:mm:ss.fffffffzzz",
"yyyy-MM-ddTHH:mm:ss.fffzzz",
"yyyy-MM-ddTHH:mm:sszzz",
"yyyy-MM-ddTHH:mmzzz",
"yyyy-MM-ddTHH:mmzz",
"yyyy-MM-ddTHH:mm:ss",
"yyyy-MM-ddTHH:mm",
"yyyy-MM-dd HH:mm:ss",
"yyyy-MM-dd HH:mm",
"yyyy-MM-dd"
);
}
formats = isArray(formats) ? formats: [formats];
length = formats.length;
for (; idx < length; idx++) {
date = parseExact(value, formats[idx], culture);
if (date) {
return date;
}
}
return date;
};
kendo.parseInt = function(value, culture) {
var result = kendo.parseFloat(value, culture);
if (result) {
result = result | 0;
}
return result;
};
kendo.parseFloat = function(value, culture, format) {
if (!value && value !== 0) {
return null;
}
if (typeof value === NUMBER) {
return value;
}
value = value.toString();
culture = kendo.getCulture(culture);
var number = culture.numberFormat,
percent = number.percent,
currency = number.currency,
symbol = currency.symbol,
percentSymbol = percent.symbol,
negative = value.indexOf("-"),
parts, isPercent;
//handle exponential number
if (exponentRegExp.test(value)) {
value = parseFloat(value.replace(number["."], "."));
if (isNaN(value)) {
value = null;
}
return value;
}
if (negative > 0) {
return null;
} else {
negative = negative > -1;
}
if (value.indexOf(symbol) > -1 || (format && format.toLowerCase().indexOf("c") > -1)) {
number = currency;
parts = number.pattern[0].replace("$", symbol).split("n");
if (value.indexOf(parts[0]) > -1 && value.indexOf(parts[1]) > -1) {
value = value.replace(parts[0], "").replace(parts[1], "");
negative = true;
}
} else if (value.indexOf(percentSymbol) > -1) {
isPercent = true;
number = percent;
symbol = percentSymbol;
}
value = value.replace("-", "")
.replace(symbol, "")
.replace(nonBreakingSpaceRegExp, " ")
.split(number[","].replace(nonBreakingSpaceRegExp, " ")).join("")
.replace(number["."], ".");
value = parseFloat(value);
if (isNaN(value)) {
value = null;
} else if (negative) {
value *= -1;
}
if (value && isPercent) {
value /= 100;
}
return value;
};
if (globalize) {
kendo.parseDate = function (value, format, culture) {
if (objectToString.call(value) === "[object Date]") {
return value;
}
return globalize.parseDate(value, format, culture);
};
kendo.parseFloat = function (value, culture) {
if (typeof value === NUMBER) {
return value;
}
if (value === undefined || value === null) {
return null;
}
value = globalize.parseFloat(value, culture);
return isNaN(value) ? null : value;
};
}
})();
function wrap(element, autosize) {
var browser = support.browser,
percentage,
isRtl = element.css("direction") == "rtl";
if (!element.parent().hasClass("k-animation-container")) {
var shadow = element.css(kendo.support.transitions.css + "box-shadow") || element.css("box-shadow"),
radius = shadow ? shadow.match(boxShadowRegExp) || [ 0, 0, 0, 0, 0 ] : [ 0, 0, 0, 0, 0 ],