/trunk/src/MyShop.UI.Web.MainSite/Scripts/MicrosoftAjax.debug.js
# · JavaScript · 6850 lines · 6072 code · 113 blank · 665 comment · 1453 complexity · 24cdbf995d405f5d448c89744ce431d7 MD5 · raw file
Large files are truncated click here to view the full file
- // Name: MicrosoftAjax.debug.js
- // Assembly: System.Web.Extensions
- // Version: 3.5.0.0
- // FileVersion: 3.5.30729.1
- //-----------------------------------------------------------------------
- // Copyright (C) Microsoft Corporation. All rights reserved.
- //-----------------------------------------------------------------------
- // MicrosoftAjax.js
- // Microsoft AJAX Framework.
-
- Function.__typeName = 'Function';
- Function.__class = true;
- Function.createCallback = function Function$createCallback(method, context) {
- /// <summary locid="M:J#Function.createCallback" />
- /// <param name="method" type="Function"></param>
- /// <param name="context" mayBeNull="true"></param>
- /// <returns type="Function"></returns>
- var e = Function._validateParams(arguments, [
- {name: "method", type: Function},
- {name: "context", mayBeNull: true}
- ]);
- if (e) throw e;
- return function() {
- var l = arguments.length;
- if (l > 0) {
- var args = [];
- for (var i = 0; i < l; i++) {
- args[i] = arguments[i];
- }
- args[l] = context;
- return method.apply(this, args);
- }
- return method.call(this, context);
- }
- }
- Function.createDelegate = function Function$createDelegate(instance, method) {
- /// <summary locid="M:J#Function.createDelegate" />
- /// <param name="instance" mayBeNull="true"></param>
- /// <param name="method" type="Function"></param>
- /// <returns type="Function"></returns>
- var e = Function._validateParams(arguments, [
- {name: "instance", mayBeNull: true},
- {name: "method", type: Function}
- ]);
- if (e) throw e;
- return function() {
- return method.apply(instance, arguments);
- }
- }
- Function.emptyFunction = Function.emptyMethod = function Function$emptyMethod() {
- /// <summary locid="M:J#Function.emptyMethod" />
- if (arguments.length !== 0) throw Error.parameterCount();
- }
- Function._validateParams = function Function$_validateParams(params, expectedParams) {
- var e;
- e = Function._validateParameterCount(params, expectedParams);
- if (e) {
- e.popStackFrame();
- return e;
- }
- for (var i=0; i < params.length; i++) {
- var expectedParam = expectedParams[Math.min(i, expectedParams.length - 1)];
- var paramName = expectedParam.name;
- if (expectedParam.parameterArray) {
- paramName += "[" + (i - expectedParams.length + 1) + "]";
- }
- e = Function._validateParameter(params[i], expectedParam, paramName);
- if (e) {
- e.popStackFrame();
- return e;
- }
- }
- return null;
- }
- Function._validateParameterCount = function Function$_validateParameterCount(params, expectedParams) {
- var maxParams = expectedParams.length;
- var minParams = 0;
- for (var i=0; i < expectedParams.length; i++) {
- if (expectedParams[i].parameterArray) {
- maxParams = Number.MAX_VALUE;
- }
- else if (!expectedParams[i].optional) {
- minParams++;
- }
- }
- if (params.length < minParams || params.length > maxParams) {
- var e = Error.parameterCount();
- e.popStackFrame();
- return e;
- }
- return null;
- }
- Function._validateParameter = function Function$_validateParameter(param, expectedParam, paramName) {
- var e;
- var expectedType = expectedParam.type;
- var expectedInteger = !!expectedParam.integer;
- var expectedDomElement = !!expectedParam.domElement;
- var mayBeNull = !!expectedParam.mayBeNull;
- e = Function._validateParameterType(param, expectedType, expectedInteger, expectedDomElement, mayBeNull, paramName);
- if (e) {
- e.popStackFrame();
- return e;
- }
- var expectedElementType = expectedParam.elementType;
- var elementMayBeNull = !!expectedParam.elementMayBeNull;
- if (expectedType === Array && typeof(param) !== "undefined" && param !== null &&
- (expectedElementType || !elementMayBeNull)) {
- var expectedElementInteger = !!expectedParam.elementInteger;
- var expectedElementDomElement = !!expectedParam.elementDomElement;
- for (var i=0; i < param.length; i++) {
- var elem = param[i];
- e = Function._validateParameterType(elem, expectedElementType,
- expectedElementInteger, expectedElementDomElement, elementMayBeNull,
- paramName + "[" + i + "]");
- if (e) {
- e.popStackFrame();
- return e;
- }
- }
- }
- return null;
- }
- Function._validateParameterType = function Function$_validateParameterType(param, expectedType, expectedInteger, expectedDomElement, mayBeNull, paramName) {
- var e;
- if (typeof(param) === "undefined") {
- if (mayBeNull) {
- return null;
- }
- else {
- e = Error.argumentUndefined(paramName);
- e.popStackFrame();
- return e;
- }
- }
- if (param === null) {
- if (mayBeNull) {
- return null;
- }
- else {
- e = Error.argumentNull(paramName);
- e.popStackFrame();
- return e;
- }
- }
- if (expectedType && expectedType.__enum) {
- if (typeof(param) !== 'number') {
- e = Error.argumentType(paramName, Object.getType(param), expectedType);
- e.popStackFrame();
- return e;
- }
- if ((param % 1) === 0) {
- var values = expectedType.prototype;
- if (!expectedType.__flags || (param === 0)) {
- for (var i in values) {
- if (values[i] === param) return null;
- }
- }
- else {
- var v = param;
- for (var i in values) {
- var vali = values[i];
- if (vali === 0) continue;
- if ((vali & param) === vali) {
- v -= vali;
- }
- if (v === 0) return null;
- }
- }
- }
- e = Error.argumentOutOfRange(paramName, param, String.format(Sys.Res.enumInvalidValue, param, expectedType.getName()));
- e.popStackFrame();
- return e;
- }
- if (expectedDomElement) {
- var val;
- if (typeof(param.nodeType) !== 'number') {
- var doc = param.ownerDocument || param.document || param;
- if (doc != param) {
- var w = doc.defaultView || doc.parentWindow;
- val = (w != param) && !(w.document && param.document && (w.document === param.document));
- }
- else {
- val = (typeof(doc.body) === 'undefined');
- }
- }
- else {
- val = (param.nodeType === 3);
- }
- if (val) {
- e = Error.argument(paramName, Sys.Res.argumentDomElement);
- e.popStackFrame();
- return e;
- }
- }
- if (expectedType && !expectedType.isInstanceOfType(param)) {
- e = Error.argumentType(paramName, Object.getType(param), expectedType);
- e.popStackFrame();
- return e;
- }
- if (expectedType === Number && expectedInteger) {
- if ((param % 1) !== 0) {
- e = Error.argumentOutOfRange(paramName, param, Sys.Res.argumentInteger);
- e.popStackFrame();
- return e;
- }
- }
- return null;
- }
-
- Error.__typeName = 'Error';
- Error.__class = true;
- Error.create = function Error$create(message, errorInfo) {
- /// <summary locid="M:J#Error.create" />
- /// <param name="message" type="String" optional="true" mayBeNull="true"></param>
- /// <param name="errorInfo" optional="true" mayBeNull="true"></param>
- /// <returns type="Error"></returns>
- var e = Function._validateParams(arguments, [
- {name: "message", type: String, mayBeNull: true, optional: true},
- {name: "errorInfo", mayBeNull: true, optional: true}
- ]);
- if (e) throw e;
- var e = new Error(message);
- e.message = message;
- if (errorInfo) {
- for (var v in errorInfo) {
- e[v] = errorInfo[v];
- }
- }
- e.popStackFrame();
- return e;
- }
- Error.argument = function Error$argument(paramName, message) {
- /// <summary locid="M:J#Error.argument" />
- /// <param name="paramName" type="String" optional="true" mayBeNull="true"></param>
- /// <param name="message" type="String" optional="true" mayBeNull="true"></param>
- /// <returns></returns>
- var e = Function._validateParams(arguments, [
- {name: "paramName", type: String, mayBeNull: true, optional: true},
- {name: "message", type: String, mayBeNull: true, optional: true}
- ]);
- if (e) throw e;
- var displayMessage = "Sys.ArgumentException: " + (message ? message : Sys.Res.argument);
- if (paramName) {
- displayMessage += "\n" + String.format(Sys.Res.paramName, paramName);
- }
- var e = Error.create(displayMessage, { name: "Sys.ArgumentException", paramName: paramName });
- e.popStackFrame();
- return e;
- }
- Error.argumentNull = function Error$argumentNull(paramName, message) {
- /// <summary locid="M:J#Error.argumentNull" />
- /// <param name="paramName" type="String" optional="true" mayBeNull="true"></param>
- /// <param name="message" type="String" optional="true" mayBeNull="true"></param>
- /// <returns></returns>
- var e = Function._validateParams(arguments, [
- {name: "paramName", type: String, mayBeNull: true, optional: true},
- {name: "message", type: String, mayBeNull: true, optional: true}
- ]);
- if (e) throw e;
- var displayMessage = "Sys.ArgumentNullException: " + (message ? message : Sys.Res.argumentNull);
- if (paramName) {
- displayMessage += "\n" + String.format(Sys.Res.paramName, paramName);
- }
- var e = Error.create(displayMessage, { name: "Sys.ArgumentNullException", paramName: paramName });
- e.popStackFrame();
- return e;
- }
- Error.argumentOutOfRange = function Error$argumentOutOfRange(paramName, actualValue, message) {
- /// <summary locid="M:J#Error.argumentOutOfRange" />
- /// <param name="paramName" type="String" optional="true" mayBeNull="true"></param>
- /// <param name="actualValue" optional="true" mayBeNull="true"></param>
- /// <param name="message" type="String" optional="true" mayBeNull="true"></param>
- /// <returns></returns>
- var e = Function._validateParams(arguments, [
- {name: "paramName", type: String, mayBeNull: true, optional: true},
- {name: "actualValue", mayBeNull: true, optional: true},
- {name: "message", type: String, mayBeNull: true, optional: true}
- ]);
- if (e) throw e;
- var displayMessage = "Sys.ArgumentOutOfRangeException: " + (message ? message : Sys.Res.argumentOutOfRange);
- if (paramName) {
- displayMessage += "\n" + String.format(Sys.Res.paramName, paramName);
- }
- if (typeof(actualValue) !== "undefined" && actualValue !== null) {
- displayMessage += "\n" + String.format(Sys.Res.actualValue, actualValue);
- }
- var e = Error.create(displayMessage, {
- name: "Sys.ArgumentOutOfRangeException",
- paramName: paramName,
- actualValue: actualValue
- });
- e.popStackFrame();
- return e;
- }
- Error.argumentType = function Error$argumentType(paramName, actualType, expectedType, message) {
- /// <summary locid="M:J#Error.argumentType" />
- /// <param name="paramName" type="String" optional="true" mayBeNull="true"></param>
- /// <param name="actualType" type="Type" optional="true" mayBeNull="true"></param>
- /// <param name="expectedType" type="Type" optional="true" mayBeNull="true"></param>
- /// <param name="message" type="String" optional="true" mayBeNull="true"></param>
- /// <returns></returns>
- var e = Function._validateParams(arguments, [
- {name: "paramName", type: String, mayBeNull: true, optional: true},
- {name: "actualType", type: Type, mayBeNull: true, optional: true},
- {name: "expectedType", type: Type, mayBeNull: true, optional: true},
- {name: "message", type: String, mayBeNull: true, optional: true}
- ]);
- if (e) throw e;
- var displayMessage = "Sys.ArgumentTypeException: ";
- if (message) {
- displayMessage += message;
- }
- else if (actualType && expectedType) {
- displayMessage +=
- String.format(Sys.Res.argumentTypeWithTypes, actualType.getName(), expectedType.getName());
- }
- else {
- displayMessage += Sys.Res.argumentType;
- }
- if (paramName) {
- displayMessage += "\n" + String.format(Sys.Res.paramName, paramName);
- }
- var e = Error.create(displayMessage, {
- name: "Sys.ArgumentTypeException",
- paramName: paramName,
- actualType: actualType,
- expectedType: expectedType
- });
- e.popStackFrame();
- return e;
- }
- Error.argumentUndefined = function Error$argumentUndefined(paramName, message) {
- /// <summary locid="M:J#Error.argumentUndefined" />
- /// <param name="paramName" type="String" optional="true" mayBeNull="true"></param>
- /// <param name="message" type="String" optional="true" mayBeNull="true"></param>
- /// <returns></returns>
- var e = Function._validateParams(arguments, [
- {name: "paramName", type: String, mayBeNull: true, optional: true},
- {name: "message", type: String, mayBeNull: true, optional: true}
- ]);
- if (e) throw e;
- var displayMessage = "Sys.ArgumentUndefinedException: " + (message ? message : Sys.Res.argumentUndefined);
- if (paramName) {
- displayMessage += "\n" + String.format(Sys.Res.paramName, paramName);
- }
- var e = Error.create(displayMessage, { name: "Sys.ArgumentUndefinedException", paramName: paramName });
- e.popStackFrame();
- return e;
- }
- Error.format = function Error$format(message) {
- /// <summary locid="M:J#Error.format" />
- /// <param name="message" type="String" optional="true" mayBeNull="true"></param>
- /// <returns></returns>
- var e = Function._validateParams(arguments, [
- {name: "message", type: String, mayBeNull: true, optional: true}
- ]);
- if (e) throw e;
- var displayMessage = "Sys.FormatException: " + (message ? message : Sys.Res.format);
- var e = Error.create(displayMessage, {name: 'Sys.FormatException'});
- e.popStackFrame();
- return e;
- }
- Error.invalidOperation = function Error$invalidOperation(message) {
- /// <summary locid="M:J#Error.invalidOperation" />
- /// <param name="message" type="String" optional="true" mayBeNull="true"></param>
- /// <returns></returns>
- var e = Function._validateParams(arguments, [
- {name: "message", type: String, mayBeNull: true, optional: true}
- ]);
- if (e) throw e;
- var displayMessage = "Sys.InvalidOperationException: " + (message ? message : Sys.Res.invalidOperation);
- var e = Error.create(displayMessage, {name: 'Sys.InvalidOperationException'});
- e.popStackFrame();
- return e;
- }
- Error.notImplemented = function Error$notImplemented(message) {
- /// <summary locid="M:J#Error.notImplemented" />
- /// <param name="message" type="String" optional="true" mayBeNull="true"></param>
- /// <returns></returns>
- var e = Function._validateParams(arguments, [
- {name: "message", type: String, mayBeNull: true, optional: true}
- ]);
- if (e) throw e;
- var displayMessage = "Sys.NotImplementedException: " + (message ? message : Sys.Res.notImplemented);
- var e = Error.create(displayMessage, {name: 'Sys.NotImplementedException'});
- e.popStackFrame();
- return e;
- }
- Error.parameterCount = function Error$parameterCount(message) {
- /// <summary locid="M:J#Error.parameterCount" />
- /// <param name="message" type="String" optional="true" mayBeNull="true"></param>
- /// <returns></returns>
- var e = Function._validateParams(arguments, [
- {name: "message", type: String, mayBeNull: true, optional: true}
- ]);
- if (e) throw e;
- var displayMessage = "Sys.ParameterCountException: " + (message ? message : Sys.Res.parameterCount);
- var e = Error.create(displayMessage, {name: 'Sys.ParameterCountException'});
- e.popStackFrame();
- return e;
- }
- Error.prototype.popStackFrame = function Error$popStackFrame() {
- /// <summary locid="M:J#checkParam" />
- if (arguments.length !== 0) throw Error.parameterCount();
- if (typeof(this.stack) === "undefined" || this.stack === null ||
- typeof(this.fileName) === "undefined" || this.fileName === null ||
- typeof(this.lineNumber) === "undefined" || this.lineNumber === null) {
- return;
- }
- var stackFrames = this.stack.split("\n");
- var currentFrame = stackFrames[0];
- var pattern = this.fileName + ":" + this.lineNumber;
- while(typeof(currentFrame) !== "undefined" &&
- currentFrame !== null &&
- currentFrame.indexOf(pattern) === -1) {
- stackFrames.shift();
- currentFrame = stackFrames[0];
- }
- var nextFrame = stackFrames[1];
- if (typeof(nextFrame) === "undefined" || nextFrame === null) {
- return;
- }
- var nextFrameParts = nextFrame.match(/@(.*):(\d+)$/);
- if (typeof(nextFrameParts) === "undefined" || nextFrameParts === null) {
- return;
- }
- this.fileName = nextFrameParts[1];
- this.lineNumber = parseInt(nextFrameParts[2]);
- stackFrames.shift();
- this.stack = stackFrames.join("\n");
- }
-
- Object.__typeName = 'Object';
- Object.__class = true;
- Object.getType = function Object$getType(instance) {
- /// <summary locid="M:J#Object.getType" />
- /// <param name="instance"></param>
- /// <returns type="Type"></returns>
- var e = Function._validateParams(arguments, [
- {name: "instance"}
- ]);
- if (e) throw e;
- var ctor = instance.constructor;
- if (!ctor || (typeof(ctor) !== "function") || !ctor.__typeName || (ctor.__typeName === 'Object')) {
- return Object;
- }
- return ctor;
- }
- Object.getTypeName = function Object$getTypeName(instance) {
- /// <summary locid="M:J#Object.getTypeName" />
- /// <param name="instance"></param>
- /// <returns type="String"></returns>
- var e = Function._validateParams(arguments, [
- {name: "instance"}
- ]);
- if (e) throw e;
- return Object.getType(instance).getName();
- }
-
- String.__typeName = 'String';
- String.__class = true;
- String.prototype.endsWith = function String$endsWith(suffix) {
- /// <summary locid="M:J#String.endsWith" />
- /// <param name="suffix" type="String"></param>
- /// <returns type="Boolean"></returns>
- var e = Function._validateParams(arguments, [
- {name: "suffix", type: String}
- ]);
- if (e) throw e;
- return (this.substr(this.length - suffix.length) === suffix);
- }
- String.prototype.startsWith = function String$startsWith(prefix) {
- /// <summary locid="M:J#String.startsWith" />
- /// <param name="prefix" type="String"></param>
- /// <returns type="Boolean"></returns>
- var e = Function._validateParams(arguments, [
- {name: "prefix", type: String}
- ]);
- if (e) throw e;
- return (this.substr(0, prefix.length) === prefix);
- }
- String.prototype.trim = function String$trim() {
- /// <summary locid="M:J#String.trim" />
- /// <returns type="String"></returns>
- if (arguments.length !== 0) throw Error.parameterCount();
- return this.replace(/^\s+|\s+$/g, '');
- }
- String.prototype.trimEnd = function String$trimEnd() {
- /// <summary locid="M:J#String.trimEnd" />
- /// <returns type="String"></returns>
- if (arguments.length !== 0) throw Error.parameterCount();
- return this.replace(/\s+$/, '');
- }
- String.prototype.trimStart = function String$trimStart() {
- /// <summary locid="M:J#String.trimStart" />
- /// <returns type="String"></returns>
- if (arguments.length !== 0) throw Error.parameterCount();
- return this.replace(/^\s+/, '');
- }
- String.format = function String$format(format, args) {
- /// <summary locid="M:J#String.format" />
- /// <param name="format" type="String"></param>
- /// <param name="args" parameterArray="true" mayBeNull="true"></param>
- /// <returns type="String"></returns>
- var e = Function._validateParams(arguments, [
- {name: "format", type: String},
- {name: "args", mayBeNull: true, parameterArray: true}
- ]);
- if (e) throw e;
- return String._toFormattedString(false, arguments);
- }
- String.localeFormat = function String$localeFormat(format, args) {
- /// <summary locid="M:J#String.localeFormat" />
- /// <param name="format" type="String"></param>
- /// <param name="args" parameterArray="true" mayBeNull="true"></param>
- /// <returns type="String"></returns>
- var e = Function._validateParams(arguments, [
- {name: "format", type: String},
- {name: "args", mayBeNull: true, parameterArray: true}
- ]);
- if (e) throw e;
- return String._toFormattedString(true, arguments);
- }
- String._toFormattedString = function String$_toFormattedString(useLocale, args) {
- var result = '';
- var format = args[0];
- for (var i=0;;) {
- var open = format.indexOf('{', i);
- var close = format.indexOf('}', i);
- if ((open < 0) && (close < 0)) {
- result += format.slice(i);
- break;
- }
- if ((close > 0) && ((close < open) || (open < 0))) {
- if (format.charAt(close + 1) !== '}') {
- throw Error.argument('format', Sys.Res.stringFormatBraceMismatch);
- }
- result += format.slice(i, close + 1);
- i = close + 2;
- continue;
- }
- result += format.slice(i, open);
- i = open + 1;
- if (format.charAt(i) === '{') {
- result += '{';
- i++;
- continue;
- }
- if (close < 0) throw Error.argument('format', Sys.Res.stringFormatBraceMismatch);
- var brace = format.substring(i, close);
- var colonIndex = brace.indexOf(':');
- var argNumber = parseInt((colonIndex < 0)? brace : brace.substring(0, colonIndex), 10) + 1;
- if (isNaN(argNumber)) throw Error.argument('format', Sys.Res.stringFormatInvalid);
- var argFormat = (colonIndex < 0)? '' : brace.substring(colonIndex + 1);
- var arg = args[argNumber];
- if (typeof(arg) === "undefined" || arg === null) {
- arg = '';
- }
- if (arg.toFormattedString) {
- result += arg.toFormattedString(argFormat);
- }
- else if (useLocale && arg.localeFormat) {
- result += arg.localeFormat(argFormat);
- }
- else if (arg.format) {
- result += arg.format(argFormat);
- }
- else
- result += arg.toString();
- i = close + 1;
- }
- return result;
- }
-
- Boolean.__typeName = 'Boolean';
- Boolean.__class = true;
- Boolean.parse = function Boolean$parse(value) {
- /// <summary locid="M:J#Boolean.parse" />
- /// <param name="value" type="String"></param>
- /// <returns type="Boolean"></returns>
- var e = Function._validateParams(arguments, [
- {name: "value", type: String}
- ]);
- if (e) throw e;
- var v = value.trim().toLowerCase();
- if (v === 'false') return false;
- if (v === 'true') return true;
- throw Error.argumentOutOfRange('value', value, Sys.Res.boolTrueOrFalse);
- }
-
- Date.__typeName = 'Date';
- Date.__class = true;
- Date._appendPreOrPostMatch = function Date$_appendPreOrPostMatch(preMatch, strBuilder) {
- var quoteCount = 0;
- var escaped = false;
- for (var i = 0, il = preMatch.length; i < il; i++) {
- var c = preMatch.charAt(i);
- switch (c) {
- case '\'':
- if (escaped) strBuilder.append("'");
- else quoteCount++;
- escaped = false;
- break;
- case '\\':
- if (escaped) strBuilder.append("\\");
- escaped = !escaped;
- break;
- default:
- strBuilder.append(c);
- escaped = false;
- break;
- }
- }
- return quoteCount;
- }
- Date._expandFormat = function Date$_expandFormat(dtf, format) {
- if (!format) {
- format = "F";
- }
- if (format.length === 1) {
- switch (format) {
- case "d":
- return dtf.ShortDatePattern;
- case "D":
- return dtf.LongDatePattern;
- case "t":
- return dtf.ShortTimePattern;
- case "T":
- return dtf.LongTimePattern;
- case "F":
- return dtf.FullDateTimePattern;
- case "M": case "m":
- return dtf.MonthDayPattern;
- case "s":
- return dtf.SortableDateTimePattern;
- case "Y": case "y":
- return dtf.YearMonthPattern;
- default:
- throw Error.format(Sys.Res.formatInvalidString);
- }
- }
- return format;
- }
- Date._expandYear = function Date$_expandYear(dtf, year) {
- if (year < 100) {
- var curr = new Date().getFullYear();
- year += curr - (curr % 100);
- if (year > dtf.Calendar.TwoDigitYearMax) {
- return year - 100;
- }
- }
- return year;
- }
- Date._getParseRegExp = function Date$_getParseRegExp(dtf, format) {
- if (!dtf._parseRegExp) {
- dtf._parseRegExp = {};
- }
- else if (dtf._parseRegExp[format]) {
- return dtf._parseRegExp[format];
- }
- var expFormat = Date._expandFormat(dtf, format);
- expFormat = expFormat.replace(/([\^\$\.\*\+\?\|\[\]\(\)\{\}])/g, "\\\\$1");
- var regexp = new Sys.StringBuilder("^");
- var groups = [];
- var index = 0;
- var quoteCount = 0;
- var tokenRegExp = Date._getTokenRegExp();
- var match;
- while ((match = tokenRegExp.exec(expFormat)) !== null) {
- var preMatch = expFormat.slice(index, match.index);
- index = tokenRegExp.lastIndex;
- quoteCount += Date._appendPreOrPostMatch(preMatch, regexp);
- if ((quoteCount%2) === 1) {
- regexp.append(match[0]);
- continue;
- }
- switch (match[0]) {
- case 'dddd': case 'ddd':
- case 'MMMM': case 'MMM':
- regexp.append("(\\D+)");
- break;
- case 'tt': case 't':
- regexp.append("(\\D*)");
- break;
- case 'yyyy':
- regexp.append("(\\d{4})");
- break;
- case 'fff':
- regexp.append("(\\d{3})");
- break;
- case 'ff':
- regexp.append("(\\d{2})");
- break;
- case 'f':
- regexp.append("(\\d)");
- break;
- case 'dd': case 'd':
- case 'MM': case 'M':
- case 'yy': case 'y':
- case 'HH': case 'H':
- case 'hh': case 'h':
- case 'mm': case 'm':
- case 'ss': case 's':
- regexp.append("(\\d\\d?)");
- break;
- case 'zzz':
- regexp.append("([+-]?\\d\\d?:\\d{2})");
- break;
- case 'zz': case 'z':
- regexp.append("([+-]?\\d\\d?)");
- break;
- }
- Array.add(groups, match[0]);
- }
- Date._appendPreOrPostMatch(expFormat.slice(index), regexp);
- regexp.append("$");
- var regexpStr = regexp.toString().replace(/\s+/g, "\\s+");
- var parseRegExp = {'regExp': regexpStr, 'groups': groups};
- dtf._parseRegExp[format] = parseRegExp;
- return parseRegExp;
- }
- Date._getTokenRegExp = function Date$_getTokenRegExp() {
- return /dddd|ddd|dd|d|MMMM|MMM|MM|M|yyyy|yy|y|hh|h|HH|H|mm|m|ss|s|tt|t|fff|ff|f|zzz|zz|z/g;
- }
- Date.parseLocale = function Date$parseLocale(value, formats) {
- /// <summary locid="M:J#Date.parseLocale" />
- /// <param name="value" type="String"></param>
- /// <param name="formats" parameterArray="true" optional="true" mayBeNull="true"></param>
- /// <returns type="Date"></returns>
- var e = Function._validateParams(arguments, [
- {name: "value", type: String},
- {name: "formats", mayBeNull: true, optional: true, parameterArray: true}
- ]);
- if (e) throw e;
- return Date._parse(value, Sys.CultureInfo.CurrentCulture, arguments);
- }
- Date.parseInvariant = function Date$parseInvariant(value, formats) {
- /// <summary locid="M:J#Date.parseInvariant" />
- /// <param name="value" type="String"></param>
- /// <param name="formats" parameterArray="true" optional="true" mayBeNull="true"></param>
- /// <returns type="Date"></returns>
- var e = Function._validateParams(arguments, [
- {name: "value", type: String},
- {name: "formats", mayBeNull: true, optional: true, parameterArray: true}
- ]);
- if (e) throw e;
- return Date._parse(value, Sys.CultureInfo.InvariantCulture, arguments);
- }
- Date._parse = function Date$_parse(value, cultureInfo, args) {
- var custom = false;
- for (var i = 1, il = args.length; i < il; i++) {
- var format = args[i];
- if (format) {
- custom = true;
- var date = Date._parseExact(value, format, cultureInfo);
- if (date) return date;
- }
- }
- if (! custom) {
- var formats = cultureInfo._getDateTimeFormats();
- for (var i = 0, il = formats.length; i < il; i++) {
- var date = Date._parseExact(value, formats[i], cultureInfo);
- if (date) return date;
- }
- }
- return null;
- }
- Date._parseExact = function Date$_parseExact(value, format, cultureInfo) {
- value = value.trim();
- var dtf = cultureInfo.dateTimeFormat;
- var parseInfo = Date._getParseRegExp(dtf, format);
- var match = new RegExp(parseInfo.regExp).exec(value);
- if (match === null) return null;
-
- var groups = parseInfo.groups;
- var year = null, month = null, date = null, weekDay = null;
- var hour = 0, min = 0, sec = 0, msec = 0, tzMinOffset = null;
- var pmHour = false;
- for (var j = 0, jl = groups.length; j < jl; j++) {
- var matchGroup = match[j+1];
- if (matchGroup) {
- switch (groups[j]) {
- case 'dd': case 'd':
- date = parseInt(matchGroup, 10);
- if ((date < 1) || (date > 31)) return null;
- break;
- case 'MMMM':
- month = cultureInfo._getMonthIndex(matchGroup);
- if ((month < 0) || (month > 11)) return null;
- break;
- case 'MMM':
- month = cultureInfo._getAbbrMonthIndex(matchGroup);
- if ((month < 0) || (month > 11)) return null;
- break;
- case 'M': case 'MM':
- var month = parseInt(matchGroup, 10) - 1;
- if ((month < 0) || (month > 11)) return null;
- break;
- case 'y': case 'yy':
- year = Date._expandYear(dtf,parseInt(matchGroup, 10));
- if ((year < 0) || (year > 9999)) return null;
- break;
- case 'yyyy':
- year = parseInt(matchGroup, 10);
- if ((year < 0) || (year > 9999)) return null;
- break;
- case 'h': case 'hh':
- hour = parseInt(matchGroup, 10);
- if (hour === 12) hour = 0;
- if ((hour < 0) || (hour > 11)) return null;
- break;
- case 'H': case 'HH':
- hour = parseInt(matchGroup, 10);
- if ((hour < 0) || (hour > 23)) return null;
- break;
- case 'm': case 'mm':
- min = parseInt(matchGroup, 10);
- if ((min < 0) || (min > 59)) return null;
- break;
- case 's': case 'ss':
- sec = parseInt(matchGroup, 10);
- if ((sec < 0) || (sec > 59)) return null;
- break;
- case 'tt': case 't':
- var upperToken = matchGroup.toUpperCase();
- pmHour = (upperToken === dtf.PMDesignator.toUpperCase());
- if (!pmHour && (upperToken !== dtf.AMDesignator.toUpperCase())) return null;
- break;
- case 'f':
- msec = parseInt(matchGroup, 10) * 100;
- if ((msec < 0) || (msec > 999)) return null;
- break;
- case 'ff':
- msec = parseInt(matchGroup, 10) * 10;
- if ((msec < 0) || (msec > 999)) return null;
- break;
- case 'fff':
- msec = parseInt(matchGroup, 10);
- if ((msec < 0) || (msec > 999)) return null;
- break;
- case 'dddd':
- weekDay = cultureInfo._getDayIndex(matchGroup);
- if ((weekDay < 0) || (weekDay > 6)) return null;
- break;
- case 'ddd':
- weekDay = cultureInfo._getAbbrDayIndex(matchGroup);
- if ((weekDay < 0) || (weekDay > 6)) return null;
- break;
- case 'zzz':
- var offsets = matchGroup.split(/:/);
- if (offsets.length !== 2) return null;
- var hourOffset = parseInt(offsets[0], 10);
- if ((hourOffset < -12) || (hourOffset > 13)) return null;
- var minOffset = parseInt(offsets[1], 10);
- if ((minOffset < 0) || (minOffset > 59)) return null;
- tzMinOffset = (hourOffset * 60) + (matchGroup.startsWith('-')? -minOffset : minOffset);
- break;
- case 'z': case 'zz':
- var hourOffset = parseInt(matchGroup, 10);
- if ((hourOffset < -12) || (hourOffset > 13)) return null;
- tzMinOffset = hourOffset * 60;
- break;
- }
- }
- }
- var result = new Date();
- if (year === null) {
- year = result.getFullYear();
- }
- if (month === null) {
- month = result.getMonth();
- }
- if (date === null) {
- date = result.getDate();
- }
- result.setFullYear(year, month, date);
- if (result.getDate() !== date) return null;
- if ((weekDay !== null) && (result.getDay() !== weekDay)) {
- return null;
- }
- if (pmHour && (hour < 12)) {
- hour += 12;
- }
- result.setHours(hour, min, sec, msec);
- if (tzMinOffset !== null) {
- var adjustedMin = result.getMinutes() - (tzMinOffset + result.getTimezoneOffset());
- result.setHours(result.getHours() + parseInt(adjustedMin/60, 10), adjustedMin%60);
- }
- return result;
- }
- Date.prototype.format = function Date$format(format) {
- /// <summary locid="M:J#Date.format" />
- /// <param name="format" type="String"></param>
- /// <returns type="String"></returns>
- var e = Function._validateParams(arguments, [
- {name: "format", type: String}
- ]);
- if (e) throw e;
- return this._toFormattedString(format, Sys.CultureInfo.InvariantCulture);
- }
- Date.prototype.localeFormat = function Date$localeFormat(format) {
- /// <summary locid="M:J#Date.localeFormat" />
- /// <param name="format" type="String"></param>
- /// <returns type="String"></returns>
- var e = Function._validateParams(arguments, [
- {name: "format", type: String}
- ]);
- if (e) throw e;
- return this._toFormattedString(format, Sys.CultureInfo.CurrentCulture);
- }
- Date.prototype._toFormattedString = function Date$_toFormattedString(format, cultureInfo) {
- if (!format || (format.length === 0) || (format === 'i')) {
- if (cultureInfo && (cultureInfo.name.length > 0)) {
- return this.toLocaleString();
- }
- else {
- return this.toString();
- }
- }
- var dtf = cultureInfo.dateTimeFormat;
- format = Date._expandFormat(dtf, format);
- var ret = new Sys.StringBuilder();
- var hour;
- function addLeadingZero(num) {
- if (num < 10) {
- return '0' + num;
- }
- return num.toString();
- }
- function addLeadingZeros(num) {
- if (num < 10) {
- return '00' + num;
- }
- if (num < 100) {
- return '0' + num;
- }
- return num.toString();
- }
- var quoteCount = 0;
- var tokenRegExp = Date._getTokenRegExp();
- for (;;) {
- var index = tokenRegExp.lastIndex;
- var ar = tokenRegExp.exec(format);
- var preMatch = format.slice(index, ar ? ar.index : format.length);
- quoteCount += Date._appendPreOrPostMatch(preMatch, ret);
- if (!ar) break;
- if ((quoteCount%2) === 1) {
- ret.append(ar[0]);
- continue;
- }
- switch (ar[0]) {
- case "dddd":
- ret.append(dtf.DayNames[this.getDay()]);
- break;
- case "ddd":
- ret.append(dtf.AbbreviatedDayNames[this.getDay()]);
- break;
- case "dd":
- ret.append(addLeadingZero(this.getDate()));
- break;
- case "d":
- ret.append(this.getDate());
- break;
- case "MMMM":
- ret.append(dtf.MonthNames[this.getMonth()]);
- break;
- case "MMM":
- ret.append(dtf.AbbreviatedMonthNames[this.getMonth()]);
- break;
- case "MM":
- ret.append(addLeadingZero(this.getMonth() + 1));
- break;
- case "M":
- ret.append(this.getMonth() + 1);
- break;
- case "yyyy":
- ret.append(this.getFullYear());
- break;
- case "yy":
- ret.append(addLeadingZero(this.getFullYear() % 100));
- break;
- case "y":
- ret.append(this.getFullYear() % 100);
- break;
- case "hh":
- hour = this.getHours() % 12;
- if (hour === 0) hour = 12;
- ret.append(addLeadingZero(hour));
- break;
- case "h":
- hour = this.getHours() % 12;
- if (hour === 0) hour = 12;
- ret.append(hour);
- break;
- case "HH":
- ret.append(addLeadingZero(this.getHours()));
- break;
- case "H":
- ret.append(this.getHours());
- break;
- case "mm":
- ret.append(addLeadingZero(this.getMinutes()));
- break;
- case "m":
- ret.append(this.getMinutes());
- break;
- case "ss":
- ret.append(addLeadingZero(this.getSeconds()));
- break;
- case "s":
- ret.append(this.getSeconds());
- break;
- case "tt":
- ret.append((this.getHours() < 12) ? dtf.AMDesignator : dtf.PMDesignator);
- break;
- case "t":
- ret.append(((this.getHours() < 12) ? dtf.AMDesignator : dtf.PMDesignator).charAt(0));
- break;
- case "f":
- ret.append(addLeadingZeros(this.getMilliseconds()).charAt(0));
- break;
- case "ff":
- ret.append(addLeadingZeros(this.getMilliseconds()).substr(0, 2));
- break;
- case "fff":
- ret.append(addLeadingZeros(this.getMilliseconds()));
- break;
- case "z":
- hour = this.getTimezoneOffset() / 60;
- ret.append(((hour <= 0) ? '+' : '-') + Math.floor(Math.abs(hour)));
- break;
- case "zz":
- hour = this.getTimezoneOffset() / 60;
- ret.append(((hour <= 0) ? '+' : '-') + addLeadingZero(Math.floor(Math.abs(hour))));
- break;
- case "zzz":
- hour = this.getTimezoneOffset() / 60;
- ret.append(((hour <= 0) ? '+' : '-') + addLeadingZero(Math.floor(Math.abs(hour))) +
- dtf.TimeSeparator + addLeadingZero(Math.abs(this.getTimezoneOffset() % 60)));
- break;
- }
- }
- return ret.toString();
- }
-
- Number.__typeName = 'Number';
- Number.__class = true;
- Number.parseLocale = function Number$parseLocale(value) {
- /// <summary locid="M:J#Number.parseLocale" />
- /// <param name="value" type="String"></param>
- /// <returns type="Number"></returns>
- var e = Function._validateParams(arguments, [
- {name: "value", type: String}
- ]);
- if (e) throw e;
- return Number._parse(value, Sys.CultureInfo.CurrentCulture);
- }
- Number.parseInvariant = function Number$parseInvariant(value) {
- /// <summary locid="M:J#Number.parseInvariant" />
- /// <param name="value" type="String"></param>
- /// <returns type="Number"></returns>
- var e = Function._validateParams(arguments, [
- {name: "value", type: String}
- ]);
- if (e) throw e;
- return Number._parse(value, Sys.CultureInfo.InvariantCulture);
- }
- Number._parse = function Number$_parse(value, cultureInfo) {
- value = value.trim();
-
- if (value.match(/^[+-]?infinity$/i)) {
- return parseFloat(value);
- }
- if (value.match(/^0x[a-f0-9]+$/i)) {
- return parseInt(value);
- }
- var numFormat = cultureInfo.numberFormat;
- var signInfo = Number._parseNumberNegativePattern(value, numFormat, numFormat.NumberNegativePattern);
- var sign = signInfo[0];
- var num = signInfo[1];
-
- if ((sign === '') && (numFormat.NumberNegativePattern !== 1)) {
- signInfo = Number._parseNumberNegativePattern(value, numFormat, 1);
- sign = signInfo[0];
- num = signInfo[1];
- }
- if (sign === '') sign = '+';
-
- var exponent;
- var intAndFraction;
- var exponentPos = num.indexOf('e');
- if (exponentPos < 0) exponentPos = num.indexOf('E');
- if (exponentPos < 0) {
- intAndFraction = num;
- exponent = null;
- }
- else {
- intAndFraction = num.substr(0, exponentPos);
- exponent = num.substr(exponentPos + 1);
- }
-
- var integer;
- var fraction;
- var decimalPos = intAndFraction.indexOf(numFormat.NumberDecimalSeparator);
- if (decimalPos < 0) {
- integer = intAndFraction;
- fraction = null;
- }
- else {
- integer = intAndFraction.substr(0, decimalPos);
- fraction = intAndFraction.substr(decimalPos + numFormat.NumberDecimalSeparator.length);
- }
-
- integer = integer.split(numFormat.NumberGroupSeparator).join('');
- var altNumGroupSeparator = numFormat.NumberGroupSeparator.replace(/\u00A0/g, " ");
- if (numFormat.NumberGroupSeparator !== altNumGroupSeparator) {
- integer = integer.split(altNumGroupSeparator).join('');
- }
-
- var p = sign + integer;
- if (fraction !== null) {
- p += '.' + fraction;
- }
- if (exponent !== null) {
- var expSignInfo = Number._parseNumberNegativePattern(exponent, numFormat, 1);
- if (expSignInfo[0] === '') {
- expSignInfo[0] = '+';
- }
- p += 'e' + expSignInfo[0] + expSignInfo[1];
- }
- if (p.match(/^[+-]?\d*\.?\d*(e[+-]?\d+)?$/)) {
- return parseFloat(p);
- }
- return Number.NaN;
- }
- Number._parseNumberNegativePattern = function Number$_parseNumberNegativePattern(value, numFormat, numberNegativePattern) {
- var neg = numFormat.NegativeSign;
- var pos = numFormat.PositiveSign;
- switch (numberNegativePattern) {
- case 4:
- neg = ' ' + neg;
- pos = ' ' + pos;
- case 3:
- if (value.endsWith(neg)) {
- return ['-', value.substr(0, value.length - neg.length)];
- }
- else if (value.endsWith(pos)) {
- return ['+', value.substr(0, value.length - pos.length)];
- }
- break;
- case 2:
- neg += ' ';
- pos += ' ';
- case 1:
- if (value.startsWith(neg)) {
- return ['-', value.substr(neg.length)];
- }
- else if (value.startsWith(pos)) {
- return ['+', value.substr(pos.length)];
- }
- break;
- case 0:
- if (value.startsWith('(') && value.endsWith(')')) {
- return ['-', value.substr(1, value.length - 2)];
- }
- break;
- }
- return ['', value];
- }
- Number.prototype.format = function Number$format(format) {
- /// <summary locid="M:J#Number.format" />
- /// <param name="format" type="String"></param>
- /// <returns type="String"></returns>
- var e = Function._validateParams(arguments, [
- {name: "format", type: String}
- ]);
- if (e) throw e;
- return this._toFormattedString(format, Sys.CultureInfo.InvariantCulture);
- }
- Number.prototype.localeFormat = function Number$localeFormat(format) {
- /// <summary locid="M:J#Number.localeFormat" />
- /// <param name="format" type="String"></param>
- /// <returns type="String"></returns>
- var e = Function._validateParams(arguments, [
- {name: "format", type: String}
- ]);
- if (e) throw e;
- return this._toFormattedString(format, Sys.CultureInfo.CurrentCulture);
- }
- Number.prototype._toFormattedString = function Number$_toFormattedString(format, cultureInfo) {
- if (!format || (format.length === 0) || (format === 'i')) {
- if (cultureInfo && (cultureInfo.name.length > 0)) {
- return this.toLocaleString();
- }
- else {
- return this.toString();
- }
- }
-
- var _percentPositivePattern = ["n %", "n%", "%n" ];
- var _percentNegativePattern = ["-n %", "-n%", "-%n"];
- var _numberNegativePattern = ["(n)","-n","- n","n-","n -"];
- var _currencyPositivePattern = ["$n","n$","$ n","n $"];
- var _currencyNegativePattern = ["($n)","-$n","$-n","$n-","(n$)","-n$","n-$","n$-","-n $","-$ n","n $-","$ n-","$ -n","n- $","($ n)","(n $)"];
- function zeroPad(str, count, left) {
- for (var l=str.length; l < count; l++) {
- str = (left ? ('0' + str) : (str + '0'));
- }
- return str;
- }
-
- function expandNumber(number, precision, groupSizes, sep, decimalChar) {
-
- var curSize = groupSizes[0];
- var curGroupIndex = 1;
- var factor = Math.pow(10, precision);
- var rounded = (Math.round(number * factor) / factor);
- if (!isFinite(rounded)) {
- rounded = number;
- }
- number = rounded;
-
- var numberString = number.toString();
- var right = "";
- var exponent;
-
-
- var split = numberString.split(/e/i);
- numberString = split[0];
- exponent = (split.length > 1 ? parseInt(split[1]) : 0);
- split = numberString.split('.');
- numberString = split[0];
- right = split.length > 1 ? split[1] : "";
-
- var l;
- if (exponent > 0) {
- right = zeroPad(right, exponent, false);
- numberString += right.slice(0, exponent);
- right = right.substr(exponent);
- }
- else if (exponent < 0) {
- exponent = -exponent;
- numberString = zeroPad(numberString, exponent+1, true);
- right = numberString.slice(-exponent, numberString.length) + right;
- numberString = numberString.slice(0, -exponent);
- }
- if (precision > 0) {
- if (right.length > precision) {
- right = right.slice(0, precision);
- }
- else {
- right = zeroPad(right, precision, false);
- }
- right = decimalChar + right;
- }
- else {
- right = "";
- }
- var stringIndex = numberString.length-1;
- var ret = "";
- while (stringIndex >= 0) {
- if (curSize === 0 || curSize > stringIndex) {
- if (ret.length > 0)
- return numberString.slice(0, stringIndex + 1) + sep + ret + right;
- else
- return numberString.slice(0, stringIndex + 1) + right;
- }
- if (ret.length > 0)
- ret = numberString.slice(stringIndex - curSize + 1, stringIndex+1) + sep + ret;
- else
- ret = numberString.slice(stringIndex - curSize + 1, stringIndex+1);
- stringIndex -= curSize;
- if (curGroupIndex < groupSizes.length) {
- curSize = groupSizes[curGroupIndex];
- curGroupIndex++;
- }
- }
- return numberString.slice(0, stringIndex + 1) + sep + ret + right;
- }
- var nf = cultureInfo.numberFormat;
- var number = Math.abs(this);
- if (!format)
- format = "D";
- var precision = -1;
- if (format.length > 1) precision = parseInt(format.slice(1), 10);
- var pattern;
- switch (format.charAt(0)) {
- case "d":
- case "D":
- pattern = 'n';
- if (precision !== -1) {
- number = zeroPad(""+number, precision, true);
- }
- if (this < 0) number = -number;
- break;
- case "c":
- case "C":…