import v1.1.0_beta1 | 2009-08-21
This commit is contained in:
367
webdir/javascript/yui/datasource/datasource-debug.js
vendored
367
webdir/javascript/yui/datasource/datasource-debug.js
vendored
@ -1,8 +1,8 @@
|
||||
/*
|
||||
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
|
||||
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
|
||||
Code licensed under the BSD License:
|
||||
http://developer.yahoo.net/yui/license.txt
|
||||
version: 2.6.0
|
||||
version: 2.7.0
|
||||
*/
|
||||
(function () {
|
||||
|
||||
@ -352,7 +352,7 @@ issueCallback : function (callback,params,error,scope) {
|
||||
* @method DataSourceBase.parseString
|
||||
* @param oData {String | Number | Boolean | Date | Array | Object} Data to parse.
|
||||
* The special values null and undefined will return null.
|
||||
* @return {Number} A string, or null.
|
||||
* @return {String} A string, or null.
|
||||
* @static
|
||||
*/
|
||||
parseString : function(oData) {
|
||||
@ -378,12 +378,16 @@ parseString : function(oData) {
|
||||
* Converts data to type Number.
|
||||
*
|
||||
* @method DataSourceBase.parseNumber
|
||||
* @param oData {String | Number | Boolean | Null} Data to convert. Beware, null
|
||||
* returns as 0.
|
||||
* @return {Number} A number, or null if NaN.
|
||||
* @param oData {String | Number | Boolean} Data to convert. Note, the following
|
||||
* values return as null: null, undefined, NaN, "".
|
||||
* @return {Number} A number, or null.
|
||||
* @static
|
||||
*/
|
||||
parseNumber : function(oData) {
|
||||
if(!lang.isValue(oData) || (oData === "")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//Convert to number
|
||||
var number = oData * 1;
|
||||
|
||||
@ -581,6 +585,17 @@ responseType : DS.TYPE_UNKNOWN,
|
||||
*/
|
||||
responseSchema : null,
|
||||
|
||||
/**
|
||||
* Additional arguments passed to the JSON parse routine. The JSON string
|
||||
* is the assumed first argument (where applicable). This property is not
|
||||
* set by default, but the parse methods will use it if present.
|
||||
*
|
||||
* @property parseJSONArgs
|
||||
* @type {MIXED|Array} If an Array, contents are used as individual arguments.
|
||||
* Otherwise, value is used as an additional argument.
|
||||
*/
|
||||
// property intentionally undefined
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DataSourceBase public methods
|
||||
@ -773,7 +788,28 @@ clearAllIntervals : function() {
|
||||
},
|
||||
|
||||
/**
|
||||
* First looks for cached response, then sends request to live data.
|
||||
* First looks for cached response, then sends request to live data. The
|
||||
* following arguments are passed to the callback function:
|
||||
* <dl>
|
||||
* <dt><code>oRequest</code></dt>
|
||||
* <dd>The same value that was passed in as the first argument to sendRequest.</dd>
|
||||
* <dt><code>oParsedResponse</code></dt>
|
||||
* <dd>An object literal containing the following properties:
|
||||
* <dl>
|
||||
* <dt><code>tId</code></dt>
|
||||
* <dd>Unique transaction ID number.</dd>
|
||||
* <dt><code>results</code></dt>
|
||||
* <dd>Schema-parsed data results.</dd>
|
||||
* <dt><code>error</code></dt>
|
||||
* <dd>True in cases of data error.</dd>
|
||||
* <dt><code>cached</code></dt>
|
||||
* <dd>True when response is returned from DataSource cache.</dd>
|
||||
* <dt><code>meta</code></dt>
|
||||
* <dd>Schema-parsed meta data.</dd>
|
||||
* </dl>
|
||||
* <dt><code>oPayload</code></dt>
|
||||
* <dd>The same value as was passed in as <code>argument</code> in the oCallback object literal.</dd>
|
||||
* </dl>
|
||||
*
|
||||
* @method sendRequest
|
||||
* @param oRequest {Object} Request object.
|
||||
@ -905,6 +941,47 @@ handleResponse : function(oRequest, oRawResponse, oCallback, oCaller, tId) {
|
||||
if(xhr && oRawResponse && oRawResponse.responseText) {
|
||||
oFullResponse = oRawResponse.responseText;
|
||||
}
|
||||
try {
|
||||
// Convert to JS array if it's a string
|
||||
if(lang.isString(oFullResponse)) {
|
||||
var parseArgs = [oFullResponse].concat(this.parseJSONArgs);
|
||||
// Check for YUI JSON Util
|
||||
if(lang.JSON) {
|
||||
oFullResponse = lang.JSON.parse.apply(lang.JSON,parseArgs);
|
||||
}
|
||||
// Look for JSON parsers using an API similar to json2.js
|
||||
else if(window.JSON && JSON.parse) {
|
||||
oFullResponse = JSON.parse.apply(JSON,parseArgs);
|
||||
}
|
||||
// Look for JSON parsers using an API similar to json.js
|
||||
else if(oFullResponse.parseJSON) {
|
||||
oFullResponse = oFullResponse.parseJSON.apply(oFullResponse,parseArgs.slice(1));
|
||||
}
|
||||
// No JSON lib found so parse the string
|
||||
else {
|
||||
// Trim leading spaces
|
||||
while (oFullResponse.length > 0 &&
|
||||
(oFullResponse.charAt(0) != "{") &&
|
||||
(oFullResponse.charAt(0) != "[")) {
|
||||
oFullResponse = oFullResponse.substring(1, oFullResponse.length);
|
||||
}
|
||||
|
||||
if(oFullResponse.length > 0) {
|
||||
// Strip extraneous stuff at the end
|
||||
var arrayEnd =
|
||||
Math.max(oFullResponse.lastIndexOf("]"),oFullResponse.lastIndexOf("}"));
|
||||
oFullResponse = oFullResponse.substring(0,arrayEnd+1);
|
||||
|
||||
// Turn the string into an object literal...
|
||||
// ...eval is necessary here
|
||||
oFullResponse = eval("(" + oFullResponse + ")");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(e1) {
|
||||
}
|
||||
oFullResponse = this.doBeforeParseData(oRequest, oFullResponse, oCallback);
|
||||
oParsedResponse = this.parseArrayData(oRequest, oFullResponse);
|
||||
break;
|
||||
@ -915,17 +992,18 @@ handleResponse : function(oRequest, oRawResponse, oCallback, oCaller, tId) {
|
||||
try {
|
||||
// Convert to JSON object if it's a string
|
||||
if(lang.isString(oFullResponse)) {
|
||||
var parseArgs = [oFullResponse].concat(this.parseJSONArgs);
|
||||
// Check for YUI JSON Util
|
||||
if(lang.JSON) {
|
||||
oFullResponse = lang.JSON.parse(oFullResponse);
|
||||
oFullResponse = lang.JSON.parse.apply(lang.JSON,parseArgs);
|
||||
}
|
||||
// Look for JSON parsers using an API similar to json2.js
|
||||
else if(window.JSON && JSON.parse) {
|
||||
oFullResponse = JSON.parse(oFullResponse);
|
||||
oFullResponse = JSON.parse.apply(JSON,parseArgs);
|
||||
}
|
||||
// Look for JSON parsers using an API similar to json.js
|
||||
else if(oFullResponse.parseJSON) {
|
||||
oFullResponse = oFullResponse.parseJSON();
|
||||
oFullResponse = oFullResponse.parseJSON.apply(oFullResponse,parseArgs.slice(1));
|
||||
}
|
||||
// No JSON lib found so parse the string
|
||||
else {
|
||||
@ -957,7 +1035,9 @@ handleResponse : function(oRequest, oRawResponse, oCallback, oCaller, tId) {
|
||||
break;
|
||||
case DS.TYPE_HTMLTABLE:
|
||||
if(xhr && oRawResponse.responseText) {
|
||||
oFullResponse = oRawResponse.responseText;
|
||||
var el = document.createElement('div');
|
||||
el.innerHTML = oRawResponse.responseText;
|
||||
oFullResponse = el.getElementsByTagName('table')[0];
|
||||
}
|
||||
oFullResponse = this.doBeforeParseData(oRequest, oFullResponse, oCallback);
|
||||
oParsedResponse = this.parseHTMLTableData(oRequest, oFullResponse);
|
||||
@ -1290,11 +1370,10 @@ parseXMLResult : function(result) {
|
||||
// ...or in a node
|
||||
else {
|
||||
var xmlNode = result.getElementsByTagName(key);
|
||||
if(xmlNode && xmlNode.item(0) && xmlNode.item(0)) {
|
||||
data = xmlNode.item(0).firstChild.nodeValue;
|
||||
if(xmlNode && xmlNode.item(0)) {
|
||||
var item = xmlNode.item(0);
|
||||
// For IE, then DOM...
|
||||
data = (item.text) ? item.text : (item.textContent) ? item.textContent : null;
|
||||
data = (item) ? ((item.text) ? item.text : (item.textContent) ? item.textContent : null) : null;
|
||||
// ...then fallback, but check for multiple child nodes
|
||||
if(!data) {
|
||||
var datapieces = [];
|
||||
@ -1536,9 +1615,9 @@ parseJSONData : function(oRequest, oFullResponse) {
|
||||
}
|
||||
|
||||
// Process the results, flattening the records and/or applying parsers if needed
|
||||
//if (fieldParsers.length || fieldPaths.length) {
|
||||
for (i = resultsList.length - 1; i >= 0; --i) {
|
||||
var r = resultsList[i], rec = {};
|
||||
for (i = resultsList.length - 1; i >= 0; --i) {
|
||||
var r = resultsList[i], rec = {};
|
||||
if(r) {
|
||||
for (j = simpleFields.length - 1; j >= 0; --j) {
|
||||
// Bug 1777850: data might be held in an array
|
||||
rec[simpleFields[j].key] =
|
||||
@ -1557,9 +1636,9 @@ parseJSONData : function(oRequest, oFullResponse) {
|
||||
rec[p] = null;
|
||||
}
|
||||
}
|
||||
results[i] = rec;
|
||||
}
|
||||
//}
|
||||
results[i] = rec;
|
||||
}
|
||||
}
|
||||
else {
|
||||
results = resultsList;
|
||||
@ -1576,7 +1655,7 @@ parseJSONData : function(oRequest, oFullResponse) {
|
||||
}
|
||||
|
||||
} else {
|
||||
YAHOO.log("JSON data could not be parsed: " +
|
||||
YAHOO.log("JSON data could not be parsed due to invalid responseSchema.resultsList or invalid response: " +
|
||||
lang.dump(oFullResponse), "error", this.toString());
|
||||
|
||||
oParsedResponse.error = true;
|
||||
@ -1610,41 +1689,47 @@ parseHTMLTableData : function(oRequest, oFullResponse) {
|
||||
var fields = this.responseSchema.fields;
|
||||
var oParsedResponse = {results:[]};
|
||||
|
||||
// Iterate through each TBODY
|
||||
for(var i=0; i<elTable.tBodies.length; i++) {
|
||||
var elTbody = elTable.tBodies[i];
|
||||
|
||||
// Iterate through each TR
|
||||
for(var j=elTbody.rows.length-1; j>-1; j--) {
|
||||
var elRow = elTbody.rows[j];
|
||||
var oResult = {};
|
||||
|
||||
for(var k=fields.length-1; k>-1; k--) {
|
||||
var field = fields[k];
|
||||
var key = (lang.isValue(field.key)) ? field.key : field;
|
||||
var data = elRow.cells[k].innerHTML;
|
||||
|
||||
// Backward compatibility
|
||||
if(!field.parser && field.converter) {
|
||||
field.parser = field.converter;
|
||||
YAHOO.log("The field property converter has been deprecated" +
|
||||
" in favor of parser", "warn", this.toString());
|
||||
if(lang.isArray(fields)) {
|
||||
// Iterate through each TBODY
|
||||
for(var i=0; i<elTable.tBodies.length; i++) {
|
||||
var elTbody = elTable.tBodies[i];
|
||||
|
||||
// Iterate through each TR
|
||||
for(var j=elTbody.rows.length-1; j>-1; j--) {
|
||||
var elRow = elTbody.rows[j];
|
||||
var oResult = {};
|
||||
|
||||
for(var k=fields.length-1; k>-1; k--) {
|
||||
var field = fields[k];
|
||||
var key = (lang.isValue(field.key)) ? field.key : field;
|
||||
var data = elRow.cells[k].innerHTML;
|
||||
|
||||
// Backward compatibility
|
||||
if(!field.parser && field.converter) {
|
||||
field.parser = field.converter;
|
||||
YAHOO.log("The field property converter has been deprecated" +
|
||||
" in favor of parser", "warn", this.toString());
|
||||
}
|
||||
var parser = (typeof field.parser === 'function') ?
|
||||
field.parser :
|
||||
DS.Parser[field.parser+''];
|
||||
if(parser) {
|
||||
data = parser.call(this, data);
|
||||
}
|
||||
// Safety measure
|
||||
if(data === undefined) {
|
||||
data = null;
|
||||
}
|
||||
oResult[key] = data;
|
||||
}
|
||||
var parser = (typeof field.parser === 'function') ?
|
||||
field.parser :
|
||||
DS.Parser[field.parser+''];
|
||||
if(parser) {
|
||||
data = parser.call(this, data);
|
||||
}
|
||||
// Safety measure
|
||||
if(data === undefined) {
|
||||
data = null;
|
||||
}
|
||||
oResult[key] = data;
|
||||
oParsedResponse.results[j] = oResult;
|
||||
}
|
||||
oParsedResponse.results[j] = oResult;
|
||||
}
|
||||
}
|
||||
else {
|
||||
bError = true;
|
||||
YAHOO.log("Invalid responseSchema.fields", "error", this.toString());
|
||||
}
|
||||
|
||||
if(bError) {
|
||||
YAHOO.log("HTML TABLE data could not be parsed: " +
|
||||
@ -1707,7 +1792,7 @@ util.LocalDataSource = function(oLiveData, oConfigs) {
|
||||
this.responseType = DS.TYPE_JSARRAY;
|
||||
}
|
||||
|
||||
this.constructor.superclass.constructor.call(this, oLiveData, oConfigs);
|
||||
util.LocalDataSource.superclass.constructor.call(this, oLiveData, oConfigs);
|
||||
};
|
||||
|
||||
// LocalDataSource extends DataSourceBase
|
||||
@ -1746,12 +1831,30 @@ util.FunctionDataSource = function(oLiveData, oConfigs) {
|
||||
this.dataType = DS.TYPE_JSFUNCTION;
|
||||
oLiveData = oLiveData || function() {};
|
||||
|
||||
this.constructor.superclass.constructor.call(this, oLiveData, oConfigs);
|
||||
util.FunctionDataSource.superclass.constructor.call(this, oLiveData, oConfigs);
|
||||
};
|
||||
|
||||
// FunctionDataSource extends DataSourceBase
|
||||
lang.extend(util.FunctionDataSource, DS, {
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// FunctionDataSource public properties
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Context in which to execute the function. By default, is the DataSource
|
||||
* instance itself. If set, the function will receive the DataSource instance
|
||||
* as an additional argument.
|
||||
*
|
||||
* @property scope
|
||||
* @type Object
|
||||
* @default null
|
||||
*/
|
||||
scope : null,
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// FunctionDataSource public methods
|
||||
@ -1774,7 +1877,9 @@ makeConnection : function(oRequest, oCallback, oCaller) {
|
||||
|
||||
// Pass the request in as a parameter and
|
||||
// forward the return value to the handler
|
||||
var oRawResponse = this.liveData(oRequest);
|
||||
|
||||
|
||||
var oRawResponse = (this.scope) ? this.liveData.call(this.scope, oRequest, this) : this.liveData(oRequest);
|
||||
|
||||
// Try to sniff data type if it has not been defined
|
||||
if(this.responseType === DS.TYPE_UNKNOWN) {
|
||||
@ -1835,7 +1940,7 @@ util.ScriptNodeDataSource = function(oLiveData, oConfigs) {
|
||||
this.dataType = DS.TYPE_SCRIPTNODE;
|
||||
oLiveData = oLiveData || "";
|
||||
|
||||
this.constructor.superclass.constructor.call(this, oLiveData, oConfigs);
|
||||
util.ScriptNodeDataSource.superclass.constructor.call(this, oLiveData, oConfigs);
|
||||
};
|
||||
|
||||
// ScriptNodeDataSource extends DataSourceBase
|
||||
@ -1905,6 +2010,19 @@ generateRequestCallback : function(id) {
|
||||
return "&" + this.scriptCallbackParam + "=YAHOO.util.ScriptNodeDataSource.callbacks["+id+"]" ;
|
||||
},
|
||||
|
||||
/**
|
||||
* Overridable method gives implementers access to modify the URI before the dynamic
|
||||
* script node gets inserted. Implementers should take care not to return an
|
||||
* invalid URI.
|
||||
*
|
||||
* @method doBeforeGetScriptNode
|
||||
* @param {String} URI to the script
|
||||
* @return {String} URI to the script
|
||||
*/
|
||||
doBeforeGetScriptNode : function(sUri) {
|
||||
return sUri;
|
||||
},
|
||||
|
||||
/**
|
||||
* Overriding method passes query to Get Utility. The returned
|
||||
* response is then forwarded to the handleResponse function.
|
||||
@ -1967,6 +2085,7 @@ makeConnection : function(oRequest, oCallback, oCaller) {
|
||||
// We are now creating a request
|
||||
util.ScriptNodeDataSource._nPending++;
|
||||
var sUri = this.liveData + oRequest + this.generateRequestCallback(id);
|
||||
sUri = this.doBeforeGetScriptNode(sUri);
|
||||
YAHOO.log("DataSource is querying URL " + sUri, "info", this.toString());
|
||||
this.getUtility.script(sUri,
|
||||
{autopurge: true,
|
||||
@ -2055,7 +2174,7 @@ util.XHRDataSource = function(oLiveData, oConfigs) {
|
||||
this.connMgr = this.connMgr || util.Connect;
|
||||
oLiveData = oLiveData || "";
|
||||
|
||||
this.constructor.superclass.constructor.call(this, oLiveData, oConfigs);
|
||||
util.XHRDataSource.superclass.constructor.call(this, oLiveData, oConfigs);
|
||||
};
|
||||
|
||||
// XHRDataSource extends DataSourceBase
|
||||
@ -2161,7 +2280,7 @@ makeConnection : function(oRequest, oCallback, oCaller) {
|
||||
var _xhrSuccess = function(oResponse) {
|
||||
// If response ID does not match last made request ID,
|
||||
// silently fail and wait for the next response
|
||||
if(oResponse && (this.asyncMode == "ignoreStaleResponses") &&
|
||||
if(oResponse && (this.connXhrMode == "ignoreStaleResponses") &&
|
||||
(oResponse.tId != oQueue.conn.tId)) {
|
||||
YAHOO.log("Ignored stale response", "warn", this.toString());
|
||||
return null;
|
||||
@ -2434,23 +2553,29 @@ lang.augmentObject(util.DataSource, DS);
|
||||
* <dt>suffix {String}</dd>
|
||||
* <dd>String appended after each number, like " items" (note the space)</dd>
|
||||
* </dl>
|
||||
* @return {String} Formatted number for display.
|
||||
* @return {String} Formatted number for display. Note, the following values
|
||||
* return as "": null, undefined, NaN, "".
|
||||
*/
|
||||
format : function(nData, oConfig) {
|
||||
var lang = YAHOO.lang;
|
||||
if(!lang.isValue(nData) || (nData === "")) {
|
||||
return "";
|
||||
}
|
||||
|
||||
oConfig = oConfig || {};
|
||||
|
||||
if(!YAHOO.lang.isNumber(nData)) {
|
||||
if(!lang.isNumber(nData)) {
|
||||
nData *= 1;
|
||||
}
|
||||
|
||||
if(YAHOO.lang.isNumber(nData)) {
|
||||
if(lang.isNumber(nData)) {
|
||||
var bNegative = (nData < 0);
|
||||
var sOutput = nData + "";
|
||||
var sDecimalSeparator = (oConfig.decimalSeparator) ? oConfig.decimalSeparator : ".";
|
||||
var nDotIndex;
|
||||
|
||||
// Manage decimals
|
||||
if(YAHOO.lang.isNumber(oConfig.decimalPlaces)) {
|
||||
if(lang.isNumber(oConfig.decimalPlaces)) {
|
||||
// Round to the correct decimal place
|
||||
var nDecimalPlaces = oConfig.decimalPlaces;
|
||||
var nDecimal = Math.pow(10, nDecimalPlaces);
|
||||
@ -2647,63 +2772,69 @@ var xPad=function (x, pad, r)
|
||||
*
|
||||
* @method format
|
||||
* @param oDate {Date} Date.
|
||||
* @param oConfig {Object} (Optional) Optional configuration values:
|
||||
* @param oConfig {Object} (Optional) Object literal of configuration values:
|
||||
* <dl>
|
||||
* <dt>format {String}</dt>
|
||||
* <dd>Any format defined by strftime is supported</dd>
|
||||
* </dl>
|
||||
* strftime has several format specifiers defined by the Open group at
|
||||
* http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html
|
||||
*
|
||||
* PHP added a few of its own, defined at http://www.php.net/strftime
|
||||
*
|
||||
* This javascript implementation supports all the PHP specifiers and a few more.
|
||||
*
|
||||
* @arg \%a - abbreviated weekday name according to the current locale
|
||||
* @arg \%A - full weekday name according to the current locale
|
||||
* @arg \%b - abbreviated month name according to the current locale
|
||||
* @arg \%B - full month name according to the current locale
|
||||
* @arg \%c - preferred date and time representation for the current locale
|
||||
* @arg \%C - century number (the year divided by 100 and truncated to an integer, range 00 to 99)
|
||||
* @arg \%d - day of the month as a decimal number (range 01 to 31)
|
||||
* @arg \%D - same as %m/%d/%y
|
||||
* @arg \%e - day of the month as a decimal number, a single digit is preceded by a space (range ' 1' to '31')
|
||||
* @arg \%F - same as %Y-%m-%d (ISO 8601 date format)
|
||||
* @arg \%g - like %G, but without the century
|
||||
* @arg \%G - The 4-digit year corresponding to the ISO week number
|
||||
* @arg \%h - same as %b
|
||||
* @arg \%H - hour as a decimal number using a 24-hour clock (range 00 to 23)
|
||||
* @arg \%I - hour as a decimal number using a 12-hour clock (range 01 to 12)
|
||||
* @arg \%j - day of the year as a decimal number (range 001 to 366)
|
||||
* @arg \%k - hour as a decimal number using a 24-hour clock (range 0 to 23); single digits are preceded by a blank. (See also %H.)
|
||||
* @arg \%l - hour as a decimal number using a 12-hour clock (range 1 to 12); single digits are preceded by a blank. (See also %I.)
|
||||
* @arg \%m - month as a decimal number (range 01 to 12)
|
||||
* @arg \%M - minute as a decimal number
|
||||
* @arg \%n - newline character
|
||||
* @arg \%p - either `AM' or `PM' according to the given time value, or the corresponding strings for the current locale
|
||||
* @arg \%P - like %p, but lower case
|
||||
* @arg \%r - time in a.m. and p.m. notation equal to %I:%M:%S %p
|
||||
* @arg \%R - time in 24 hour notation equal to %H:%M
|
||||
* @arg \%s - number of seconds since the Epoch, ie, since 1970-01-01 00:00:00 UTC
|
||||
* @arg \%S - second as a decimal number
|
||||
* @arg \%t - tab character
|
||||
* @arg \%T - current time, equal to %H:%M:%S
|
||||
* @arg \%u - weekday as a decimal number [1,7], with 1 representing Monday
|
||||
* @arg \%U - week number of the current year as a decimal number, starting with
|
||||
* the first Sunday as the first day of the first week
|
||||
* @arg \%V - The ISO 8601:1988 week number of the current year as a decimal number,
|
||||
* range 01 to 53, where week 1 is the first week that has at least 4 days
|
||||
* in the current year, and with Monday as the first day of the week.
|
||||
* @arg \%w - day of the week as a decimal, Sunday being 0
|
||||
* @arg \%W - week number of the current year as a decimal number, starting with the
|
||||
* first Monday as the first day of the first week
|
||||
* @arg \%x - preferred date representation for the current locale without the time
|
||||
* @arg \%X - preferred time representation for the current locale without the date
|
||||
* @arg \%y - year as a decimal number without a century (range 00 to 99)
|
||||
* @arg \%Y - year as a decimal number including the century
|
||||
* @arg \%z - numerical time zone representation
|
||||
* @arg \%Z - time zone name or abbreviation
|
||||
* @arg \%% - a literal `\%' character
|
||||
* <dt>format <String></dt>
|
||||
* <dd>
|
||||
* <p>
|
||||
* Any strftime string is supported, such as "%I:%M:%S %p". strftime has several format specifiers defined by the Open group at
|
||||
* <a href="http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html">http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html</a>
|
||||
* </p>
|
||||
* <p>
|
||||
* PHP added a few of its own, defined at <a href="http://www.php.net/strftime">http://www.php.net/strftime</a>
|
||||
* </p>
|
||||
* <p>
|
||||
* This javascript implementation supports all the PHP specifiers and a few more. The full list is below:
|
||||
* </p>
|
||||
* <dl>
|
||||
* <dt>%a</dt> <dd>abbreviated weekday name according to the current locale</dd>
|
||||
* <dt>%A</dt> <dd>full weekday name according to the current locale</dd>
|
||||
* <dt>%b</dt> <dd>abbreviated month name according to the current locale</dd>
|
||||
* <dt>%B</dt> <dd>full month name according to the current locale</dd>
|
||||
* <dt>%c</dt> <dd>preferred date and time representation for the current locale</dd>
|
||||
* <dt>%C</dt> <dd>century number (the year divided by 100 and truncated to an integer, range 00 to 99)</dd>
|
||||
* <dt>%d</dt> <dd>day of the month as a decimal number (range 01 to 31)</dd>
|
||||
* <dt>%D</dt> <dd>same as %m/%d/%y</dd>
|
||||
* <dt>%e</dt> <dd>day of the month as a decimal number, a single digit is preceded by a space (range ' 1' to '31')</dd>
|
||||
* <dt>%F</dt> <dd>same as %Y-%m-%d (ISO 8601 date format)</dd>
|
||||
* <dt>%g</dt> <dd>like %G, but without the century</dd>
|
||||
* <dt>%G</dt> <dd>The 4-digit year corresponding to the ISO week number</dd>
|
||||
* <dt>%h</dt> <dd>same as %b</dd>
|
||||
* <dt>%H</dt> <dd>hour as a decimal number using a 24-hour clock (range 00 to 23)</dd>
|
||||
* <dt>%I</dt> <dd>hour as a decimal number using a 12-hour clock (range 01 to 12)</dd>
|
||||
* <dt>%j</dt> <dd>day of the year as a decimal number (range 001 to 366)</dd>
|
||||
* <dt>%k</dt> <dd>hour as a decimal number using a 24-hour clock (range 0 to 23); single digits are preceded by a blank. (See also %H.)</dd>
|
||||
* <dt>%l</dt> <dd>hour as a decimal number using a 12-hour clock (range 1 to 12); single digits are preceded by a blank. (See also %I.) </dd>
|
||||
* <dt>%m</dt> <dd>month as a decimal number (range 01 to 12)</dd>
|
||||
* <dt>%M</dt> <dd>minute as a decimal number</dd>
|
||||
* <dt>%n</dt> <dd>newline character</dd>
|
||||
* <dt>%p</dt> <dd>either `AM' or `PM' according to the given time value, or the corresponding strings for the current locale</dd>
|
||||
* <dt>%P</dt> <dd>like %p, but lower case</dd>
|
||||
* <dt>%r</dt> <dd>time in a.m. and p.m. notation equal to %I:%M:%S %p</dd>
|
||||
* <dt>%R</dt> <dd>time in 24 hour notation equal to %H:%M</dd>
|
||||
* <dt>%s</dt> <dd>number of seconds since the Epoch, ie, since 1970-01-01 00:00:00 UTC</dd>
|
||||
* <dt>%S</dt> <dd>second as a decimal number</dd>
|
||||
* <dt>%t</dt> <dd>tab character</dd>
|
||||
* <dt>%T</dt> <dd>current time, equal to %H:%M:%S</dd>
|
||||
* <dt>%u</dt> <dd>weekday as a decimal number [1,7], with 1 representing Monday</dd>
|
||||
* <dt>%U</dt> <dd>week number of the current year as a decimal number, starting with the
|
||||
* first Sunday as the first day of the first week</dd>
|
||||
* <dt>%V</dt> <dd>The ISO 8601:1988 week number of the current year as a decimal number,
|
||||
* range 01 to 53, where week 1 is the first week that has at least 4 days
|
||||
* in the current year, and with Monday as the first day of the week.</dd>
|
||||
* <dt>%w</dt> <dd>day of the week as a decimal, Sunday being 0</dd>
|
||||
* <dt>%W</dt> <dd>week number of the current year as a decimal number, starting with the
|
||||
* first Monday as the first day of the first week</dd>
|
||||
* <dt>%x</dt> <dd>preferred date representation for the current locale without the time</dd>
|
||||
* <dt>%X</dt> <dd>preferred time representation for the current locale without the date</dd>
|
||||
* <dt>%y</dt> <dd>year as a decimal number without a century (range 00 to 99)</dd>
|
||||
* <dt>%Y</dt> <dd>year as a decimal number including the century</dd>
|
||||
* <dt>%z</dt> <dd>numerical time zone representation</dd>
|
||||
* <dt>%Z</dt> <dd>time zone name or abbreviation</dd>
|
||||
* <dt>%%</dt> <dd>a literal `%' character</dd>
|
||||
* </dl>
|
||||
* </dd>
|
||||
* </dl>
|
||||
* @param sLocale {String} (Optional) The locale to use when displaying days of week,
|
||||
* months of the year, and other locale specific strings. The following locales are
|
||||
* built in:
|
||||
@ -2883,4 +3014,4 @@ var xPad=function (x, pad, r)
|
||||
|
||||
})();
|
||||
|
||||
YAHOO.register("datasource", YAHOO.util.DataSource, {version: "2.6.0", build: "1321"});
|
||||
YAHOO.register("datasource", YAHOO.util.DataSource, {version: "2.7.0", build: "1799"});
|
||||
|
File diff suppressed because one or more lines are too long
360
webdir/javascript/yui/datasource/datasource.js
vendored
360
webdir/javascript/yui/datasource/datasource.js
vendored
@ -1,8 +1,8 @@
|
||||
/*
|
||||
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
|
||||
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
|
||||
Code licensed under the BSD License:
|
||||
http://developer.yahoo.net/yui/license.txt
|
||||
version: 2.6.0
|
||||
version: 2.7.0
|
||||
*/
|
||||
(function () {
|
||||
|
||||
@ -349,7 +349,7 @@ issueCallback : function (callback,params,error,scope) {
|
||||
* @method DataSourceBase.parseString
|
||||
* @param oData {String | Number | Boolean | Date | Array | Object} Data to parse.
|
||||
* The special values null and undefined will return null.
|
||||
* @return {Number} A string, or null.
|
||||
* @return {String} A string, or null.
|
||||
* @static
|
||||
*/
|
||||
parseString : function(oData) {
|
||||
@ -374,12 +374,16 @@ parseString : function(oData) {
|
||||
* Converts data to type Number.
|
||||
*
|
||||
* @method DataSourceBase.parseNumber
|
||||
* @param oData {String | Number | Boolean | Null} Data to convert. Beware, null
|
||||
* returns as 0.
|
||||
* @return {Number} A number, or null if NaN.
|
||||
* @param oData {String | Number | Boolean} Data to convert. Note, the following
|
||||
* values return as null: null, undefined, NaN, "".
|
||||
* @return {Number} A number, or null.
|
||||
* @static
|
||||
*/
|
||||
parseNumber : function(oData) {
|
||||
if(!lang.isValue(oData) || (oData === "")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//Convert to number
|
||||
var number = oData * 1;
|
||||
|
||||
@ -569,6 +573,17 @@ responseType : DS.TYPE_UNKNOWN,
|
||||
*/
|
||||
responseSchema : null,
|
||||
|
||||
/**
|
||||
* Additional arguments passed to the JSON parse routine. The JSON string
|
||||
* is the assumed first argument (where applicable). This property is not
|
||||
* set by default, but the parse methods will use it if present.
|
||||
*
|
||||
* @property parseJSONArgs
|
||||
* @type {MIXED|Array} If an Array, contents are used as individual arguments.
|
||||
* Otherwise, value is used as an additional argument.
|
||||
*/
|
||||
// property intentionally undefined
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// DataSourceBase public methods
|
||||
@ -752,7 +767,28 @@ clearAllIntervals : function() {
|
||||
},
|
||||
|
||||
/**
|
||||
* First looks for cached response, then sends request to live data.
|
||||
* First looks for cached response, then sends request to live data. The
|
||||
* following arguments are passed to the callback function:
|
||||
* <dl>
|
||||
* <dt><code>oRequest</code></dt>
|
||||
* <dd>The same value that was passed in as the first argument to sendRequest.</dd>
|
||||
* <dt><code>oParsedResponse</code></dt>
|
||||
* <dd>An object literal containing the following properties:
|
||||
* <dl>
|
||||
* <dt><code>tId</code></dt>
|
||||
* <dd>Unique transaction ID number.</dd>
|
||||
* <dt><code>results</code></dt>
|
||||
* <dd>Schema-parsed data results.</dd>
|
||||
* <dt><code>error</code></dt>
|
||||
* <dd>True in cases of data error.</dd>
|
||||
* <dt><code>cached</code></dt>
|
||||
* <dd>True when response is returned from DataSource cache.</dd>
|
||||
* <dt><code>meta</code></dt>
|
||||
* <dd>Schema-parsed meta data.</dd>
|
||||
* </dl>
|
||||
* <dt><code>oPayload</code></dt>
|
||||
* <dd>The same value as was passed in as <code>argument</code> in the oCallback object literal.</dd>
|
||||
* </dl>
|
||||
*
|
||||
* @method sendRequest
|
||||
* @param oRequest {Object} Request object.
|
||||
@ -882,6 +918,47 @@ handleResponse : function(oRequest, oRawResponse, oCallback, oCaller, tId) {
|
||||
if(xhr && oRawResponse && oRawResponse.responseText) {
|
||||
oFullResponse = oRawResponse.responseText;
|
||||
}
|
||||
try {
|
||||
// Convert to JS array if it's a string
|
||||
if(lang.isString(oFullResponse)) {
|
||||
var parseArgs = [oFullResponse].concat(this.parseJSONArgs);
|
||||
// Check for YUI JSON Util
|
||||
if(lang.JSON) {
|
||||
oFullResponse = lang.JSON.parse.apply(lang.JSON,parseArgs);
|
||||
}
|
||||
// Look for JSON parsers using an API similar to json2.js
|
||||
else if(window.JSON && JSON.parse) {
|
||||
oFullResponse = JSON.parse.apply(JSON,parseArgs);
|
||||
}
|
||||
// Look for JSON parsers using an API similar to json.js
|
||||
else if(oFullResponse.parseJSON) {
|
||||
oFullResponse = oFullResponse.parseJSON.apply(oFullResponse,parseArgs.slice(1));
|
||||
}
|
||||
// No JSON lib found so parse the string
|
||||
else {
|
||||
// Trim leading spaces
|
||||
while (oFullResponse.length > 0 &&
|
||||
(oFullResponse.charAt(0) != "{") &&
|
||||
(oFullResponse.charAt(0) != "[")) {
|
||||
oFullResponse = oFullResponse.substring(1, oFullResponse.length);
|
||||
}
|
||||
|
||||
if(oFullResponse.length > 0) {
|
||||
// Strip extraneous stuff at the end
|
||||
var arrayEnd =
|
||||
Math.max(oFullResponse.lastIndexOf("]"),oFullResponse.lastIndexOf("}"));
|
||||
oFullResponse = oFullResponse.substring(0,arrayEnd+1);
|
||||
|
||||
// Turn the string into an object literal...
|
||||
// ...eval is necessary here
|
||||
oFullResponse = eval("(" + oFullResponse + ")");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(e1) {
|
||||
}
|
||||
oFullResponse = this.doBeforeParseData(oRequest, oFullResponse, oCallback);
|
||||
oParsedResponse = this.parseArrayData(oRequest, oFullResponse);
|
||||
break;
|
||||
@ -892,17 +969,18 @@ handleResponse : function(oRequest, oRawResponse, oCallback, oCaller, tId) {
|
||||
try {
|
||||
// Convert to JSON object if it's a string
|
||||
if(lang.isString(oFullResponse)) {
|
||||
var parseArgs = [oFullResponse].concat(this.parseJSONArgs);
|
||||
// Check for YUI JSON Util
|
||||
if(lang.JSON) {
|
||||
oFullResponse = lang.JSON.parse(oFullResponse);
|
||||
oFullResponse = lang.JSON.parse.apply(lang.JSON,parseArgs);
|
||||
}
|
||||
// Look for JSON parsers using an API similar to json2.js
|
||||
else if(window.JSON && JSON.parse) {
|
||||
oFullResponse = JSON.parse(oFullResponse);
|
||||
oFullResponse = JSON.parse.apply(JSON,parseArgs);
|
||||
}
|
||||
// Look for JSON parsers using an API similar to json.js
|
||||
else if(oFullResponse.parseJSON) {
|
||||
oFullResponse = oFullResponse.parseJSON();
|
||||
oFullResponse = oFullResponse.parseJSON.apply(oFullResponse,parseArgs.slice(1));
|
||||
}
|
||||
// No JSON lib found so parse the string
|
||||
else {
|
||||
@ -934,7 +1012,9 @@ handleResponse : function(oRequest, oRawResponse, oCallback, oCaller, tId) {
|
||||
break;
|
||||
case DS.TYPE_HTMLTABLE:
|
||||
if(xhr && oRawResponse.responseText) {
|
||||
oFullResponse = oRawResponse.responseText;
|
||||
var el = document.createElement('div');
|
||||
el.innerHTML = oRawResponse.responseText;
|
||||
oFullResponse = el.getElementsByTagName('table')[0];
|
||||
}
|
||||
oFullResponse = this.doBeforeParseData(oRequest, oFullResponse, oCallback);
|
||||
oParsedResponse = this.parseHTMLTableData(oRequest, oFullResponse);
|
||||
@ -1252,11 +1332,10 @@ parseXMLResult : function(result) {
|
||||
// ...or in a node
|
||||
else {
|
||||
var xmlNode = result.getElementsByTagName(key);
|
||||
if(xmlNode && xmlNode.item(0) && xmlNode.item(0)) {
|
||||
data = xmlNode.item(0).firstChild.nodeValue;
|
||||
if(xmlNode && xmlNode.item(0)) {
|
||||
var item = xmlNode.item(0);
|
||||
// For IE, then DOM...
|
||||
data = (item.text) ? item.text : (item.textContent) ? item.textContent : null;
|
||||
data = (item) ? ((item.text) ? item.text : (item.textContent) ? item.textContent : null) : null;
|
||||
// ...then fallback, but check for multiple child nodes
|
||||
if(!data) {
|
||||
var datapieces = [];
|
||||
@ -1488,9 +1567,9 @@ parseJSONData : function(oRequest, oFullResponse) {
|
||||
}
|
||||
|
||||
// Process the results, flattening the records and/or applying parsers if needed
|
||||
//if (fieldParsers.length || fieldPaths.length) {
|
||||
for (i = resultsList.length - 1; i >= 0; --i) {
|
||||
var r = resultsList[i], rec = {};
|
||||
for (i = resultsList.length - 1; i >= 0; --i) {
|
||||
var r = resultsList[i], rec = {};
|
||||
if(r) {
|
||||
for (j = simpleFields.length - 1; j >= 0; --j) {
|
||||
// Bug 1777850: data might be held in an array
|
||||
rec[simpleFields[j].key] =
|
||||
@ -1509,9 +1588,9 @@ parseJSONData : function(oRequest, oFullResponse) {
|
||||
rec[p] = null;
|
||||
}
|
||||
}
|
||||
results[i] = rec;
|
||||
}
|
||||
//}
|
||||
results[i] = rec;
|
||||
}
|
||||
}
|
||||
else {
|
||||
results = resultsList;
|
||||
@ -1558,39 +1637,44 @@ parseHTMLTableData : function(oRequest, oFullResponse) {
|
||||
var fields = this.responseSchema.fields;
|
||||
var oParsedResponse = {results:[]};
|
||||
|
||||
// Iterate through each TBODY
|
||||
for(var i=0; i<elTable.tBodies.length; i++) {
|
||||
var elTbody = elTable.tBodies[i];
|
||||
|
||||
// Iterate through each TR
|
||||
for(var j=elTbody.rows.length-1; j>-1; j--) {
|
||||
var elRow = elTbody.rows[j];
|
||||
var oResult = {};
|
||||
|
||||
for(var k=fields.length-1; k>-1; k--) {
|
||||
var field = fields[k];
|
||||
var key = (lang.isValue(field.key)) ? field.key : field;
|
||||
var data = elRow.cells[k].innerHTML;
|
||||
|
||||
// Backward compatibility
|
||||
if(!field.parser && field.converter) {
|
||||
field.parser = field.converter;
|
||||
if(lang.isArray(fields)) {
|
||||
// Iterate through each TBODY
|
||||
for(var i=0; i<elTable.tBodies.length; i++) {
|
||||
var elTbody = elTable.tBodies[i];
|
||||
|
||||
// Iterate through each TR
|
||||
for(var j=elTbody.rows.length-1; j>-1; j--) {
|
||||
var elRow = elTbody.rows[j];
|
||||
var oResult = {};
|
||||
|
||||
for(var k=fields.length-1; k>-1; k--) {
|
||||
var field = fields[k];
|
||||
var key = (lang.isValue(field.key)) ? field.key : field;
|
||||
var data = elRow.cells[k].innerHTML;
|
||||
|
||||
// Backward compatibility
|
||||
if(!field.parser && field.converter) {
|
||||
field.parser = field.converter;
|
||||
}
|
||||
var parser = (typeof field.parser === 'function') ?
|
||||
field.parser :
|
||||
DS.Parser[field.parser+''];
|
||||
if(parser) {
|
||||
data = parser.call(this, data);
|
||||
}
|
||||
// Safety measure
|
||||
if(data === undefined) {
|
||||
data = null;
|
||||
}
|
||||
oResult[key] = data;
|
||||
}
|
||||
var parser = (typeof field.parser === 'function') ?
|
||||
field.parser :
|
||||
DS.Parser[field.parser+''];
|
||||
if(parser) {
|
||||
data = parser.call(this, data);
|
||||
}
|
||||
// Safety measure
|
||||
if(data === undefined) {
|
||||
data = null;
|
||||
}
|
||||
oResult[key] = data;
|
||||
oParsedResponse.results[j] = oResult;
|
||||
}
|
||||
oParsedResponse.results[j] = oResult;
|
||||
}
|
||||
}
|
||||
else {
|
||||
bError = true;
|
||||
}
|
||||
|
||||
if(bError) {
|
||||
oParsedResponse.error = true;
|
||||
@ -1649,7 +1733,7 @@ util.LocalDataSource = function(oLiveData, oConfigs) {
|
||||
this.responseType = DS.TYPE_JSARRAY;
|
||||
}
|
||||
|
||||
this.constructor.superclass.constructor.call(this, oLiveData, oConfigs);
|
||||
util.LocalDataSource.superclass.constructor.call(this, oLiveData, oConfigs);
|
||||
};
|
||||
|
||||
// LocalDataSource extends DataSourceBase
|
||||
@ -1688,12 +1772,30 @@ util.FunctionDataSource = function(oLiveData, oConfigs) {
|
||||
this.dataType = DS.TYPE_JSFUNCTION;
|
||||
oLiveData = oLiveData || function() {};
|
||||
|
||||
this.constructor.superclass.constructor.call(this, oLiveData, oConfigs);
|
||||
util.FunctionDataSource.superclass.constructor.call(this, oLiveData, oConfigs);
|
||||
};
|
||||
|
||||
// FunctionDataSource extends DataSourceBase
|
||||
lang.extend(util.FunctionDataSource, DS, {
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// FunctionDataSource public properties
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Context in which to execute the function. By default, is the DataSource
|
||||
* instance itself. If set, the function will receive the DataSource instance
|
||||
* as an additional argument.
|
||||
*
|
||||
* @property scope
|
||||
* @type Object
|
||||
* @default null
|
||||
*/
|
||||
scope : null,
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// FunctionDataSource public methods
|
||||
@ -1716,7 +1818,9 @@ makeConnection : function(oRequest, oCallback, oCaller) {
|
||||
|
||||
// Pass the request in as a parameter and
|
||||
// forward the return value to the handler
|
||||
var oRawResponse = this.liveData(oRequest);
|
||||
|
||||
|
||||
var oRawResponse = (this.scope) ? this.liveData.call(this.scope, oRequest, this) : this.liveData(oRequest);
|
||||
|
||||
// Try to sniff data type if it has not been defined
|
||||
if(this.responseType === DS.TYPE_UNKNOWN) {
|
||||
@ -1777,7 +1881,7 @@ util.ScriptNodeDataSource = function(oLiveData, oConfigs) {
|
||||
this.dataType = DS.TYPE_SCRIPTNODE;
|
||||
oLiveData = oLiveData || "";
|
||||
|
||||
this.constructor.superclass.constructor.call(this, oLiveData, oConfigs);
|
||||
util.ScriptNodeDataSource.superclass.constructor.call(this, oLiveData, oConfigs);
|
||||
};
|
||||
|
||||
// ScriptNodeDataSource extends DataSourceBase
|
||||
@ -1847,6 +1951,19 @@ generateRequestCallback : function(id) {
|
||||
return "&" + this.scriptCallbackParam + "=YAHOO.util.ScriptNodeDataSource.callbacks["+id+"]" ;
|
||||
},
|
||||
|
||||
/**
|
||||
* Overridable method gives implementers access to modify the URI before the dynamic
|
||||
* script node gets inserted. Implementers should take care not to return an
|
||||
* invalid URI.
|
||||
*
|
||||
* @method doBeforeGetScriptNode
|
||||
* @param {String} URI to the script
|
||||
* @return {String} URI to the script
|
||||
*/
|
||||
doBeforeGetScriptNode : function(sUri) {
|
||||
return sUri;
|
||||
},
|
||||
|
||||
/**
|
||||
* Overriding method passes query to Get Utility. The returned
|
||||
* response is then forwarded to the handleResponse function.
|
||||
@ -1908,6 +2025,7 @@ makeConnection : function(oRequest, oCallback, oCaller) {
|
||||
// We are now creating a request
|
||||
util.ScriptNodeDataSource._nPending++;
|
||||
var sUri = this.liveData + oRequest + this.generateRequestCallback(id);
|
||||
sUri = this.doBeforeGetScriptNode(sUri);
|
||||
this.getUtility.script(sUri,
|
||||
{autopurge: true,
|
||||
onsuccess: util.ScriptNodeDataSource._bumpPendingDown,
|
||||
@ -1995,7 +2113,7 @@ util.XHRDataSource = function(oLiveData, oConfigs) {
|
||||
this.connMgr = this.connMgr || util.Connect;
|
||||
oLiveData = oLiveData || "";
|
||||
|
||||
this.constructor.superclass.constructor.call(this, oLiveData, oConfigs);
|
||||
util.XHRDataSource.superclass.constructor.call(this, oLiveData, oConfigs);
|
||||
};
|
||||
|
||||
// XHRDataSource extends DataSourceBase
|
||||
@ -2101,7 +2219,7 @@ makeConnection : function(oRequest, oCallback, oCaller) {
|
||||
var _xhrSuccess = function(oResponse) {
|
||||
// If response ID does not match last made request ID,
|
||||
// silently fail and wait for the next response
|
||||
if(oResponse && (this.asyncMode == "ignoreStaleResponses") &&
|
||||
if(oResponse && (this.connXhrMode == "ignoreStaleResponses") &&
|
||||
(oResponse.tId != oQueue.conn.tId)) {
|
||||
return null;
|
||||
}
|
||||
@ -2364,23 +2482,29 @@ lang.augmentObject(util.DataSource, DS);
|
||||
* <dt>suffix {String}</dd>
|
||||
* <dd>String appended after each number, like " items" (note the space)</dd>
|
||||
* </dl>
|
||||
* @return {String} Formatted number for display.
|
||||
* @return {String} Formatted number for display. Note, the following values
|
||||
* return as "": null, undefined, NaN, "".
|
||||
*/
|
||||
format : function(nData, oConfig) {
|
||||
var lang = YAHOO.lang;
|
||||
if(!lang.isValue(nData) || (nData === "")) {
|
||||
return "";
|
||||
}
|
||||
|
||||
oConfig = oConfig || {};
|
||||
|
||||
if(!YAHOO.lang.isNumber(nData)) {
|
||||
if(!lang.isNumber(nData)) {
|
||||
nData *= 1;
|
||||
}
|
||||
|
||||
if(YAHOO.lang.isNumber(nData)) {
|
||||
if(lang.isNumber(nData)) {
|
||||
var bNegative = (nData < 0);
|
||||
var sOutput = nData + "";
|
||||
var sDecimalSeparator = (oConfig.decimalSeparator) ? oConfig.decimalSeparator : ".";
|
||||
var nDotIndex;
|
||||
|
||||
// Manage decimals
|
||||
if(YAHOO.lang.isNumber(oConfig.decimalPlaces)) {
|
||||
if(lang.isNumber(oConfig.decimalPlaces)) {
|
||||
// Round to the correct decimal place
|
||||
var nDecimalPlaces = oConfig.decimalPlaces;
|
||||
var nDecimal = Math.pow(10, nDecimalPlaces);
|
||||
@ -2577,63 +2701,69 @@ var xPad=function (x, pad, r)
|
||||
*
|
||||
* @method format
|
||||
* @param oDate {Date} Date.
|
||||
* @param oConfig {Object} (Optional) Optional configuration values:
|
||||
* @param oConfig {Object} (Optional) Object literal of configuration values:
|
||||
* <dl>
|
||||
* <dt>format {String}</dt>
|
||||
* <dd>Any format defined by strftime is supported</dd>
|
||||
* </dl>
|
||||
* strftime has several format specifiers defined by the Open group at
|
||||
* http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html
|
||||
*
|
||||
* PHP added a few of its own, defined at http://www.php.net/strftime
|
||||
*
|
||||
* This javascript implementation supports all the PHP specifiers and a few more.
|
||||
*
|
||||
* @arg \%a - abbreviated weekday name according to the current locale
|
||||
* @arg \%A - full weekday name according to the current locale
|
||||
* @arg \%b - abbreviated month name according to the current locale
|
||||
* @arg \%B - full month name according to the current locale
|
||||
* @arg \%c - preferred date and time representation for the current locale
|
||||
* @arg \%C - century number (the year divided by 100 and truncated to an integer, range 00 to 99)
|
||||
* @arg \%d - day of the month as a decimal number (range 01 to 31)
|
||||
* @arg \%D - same as %m/%d/%y
|
||||
* @arg \%e - day of the month as a decimal number, a single digit is preceded by a space (range ' 1' to '31')
|
||||
* @arg \%F - same as %Y-%m-%d (ISO 8601 date format)
|
||||
* @arg \%g - like %G, but without the century
|
||||
* @arg \%G - The 4-digit year corresponding to the ISO week number
|
||||
* @arg \%h - same as %b
|
||||
* @arg \%H - hour as a decimal number using a 24-hour clock (range 00 to 23)
|
||||
* @arg \%I - hour as a decimal number using a 12-hour clock (range 01 to 12)
|
||||
* @arg \%j - day of the year as a decimal number (range 001 to 366)
|
||||
* @arg \%k - hour as a decimal number using a 24-hour clock (range 0 to 23); single digits are preceded by a blank. (See also %H.)
|
||||
* @arg \%l - hour as a decimal number using a 12-hour clock (range 1 to 12); single digits are preceded by a blank. (See also %I.)
|
||||
* @arg \%m - month as a decimal number (range 01 to 12)
|
||||
* @arg \%M - minute as a decimal number
|
||||
* @arg \%n - newline character
|
||||
* @arg \%p - either `AM' or `PM' according to the given time value, or the corresponding strings for the current locale
|
||||
* @arg \%P - like %p, but lower case
|
||||
* @arg \%r - time in a.m. and p.m. notation equal to %I:%M:%S %p
|
||||
* @arg \%R - time in 24 hour notation equal to %H:%M
|
||||
* @arg \%s - number of seconds since the Epoch, ie, since 1970-01-01 00:00:00 UTC
|
||||
* @arg \%S - second as a decimal number
|
||||
* @arg \%t - tab character
|
||||
* @arg \%T - current time, equal to %H:%M:%S
|
||||
* @arg \%u - weekday as a decimal number [1,7], with 1 representing Monday
|
||||
* @arg \%U - week number of the current year as a decimal number, starting with
|
||||
* the first Sunday as the first day of the first week
|
||||
* @arg \%V - The ISO 8601:1988 week number of the current year as a decimal number,
|
||||
* range 01 to 53, where week 1 is the first week that has at least 4 days
|
||||
* in the current year, and with Monday as the first day of the week.
|
||||
* @arg \%w - day of the week as a decimal, Sunday being 0
|
||||
* @arg \%W - week number of the current year as a decimal number, starting with the
|
||||
* first Monday as the first day of the first week
|
||||
* @arg \%x - preferred date representation for the current locale without the time
|
||||
* @arg \%X - preferred time representation for the current locale without the date
|
||||
* @arg \%y - year as a decimal number without a century (range 00 to 99)
|
||||
* @arg \%Y - year as a decimal number including the century
|
||||
* @arg \%z - numerical time zone representation
|
||||
* @arg \%Z - time zone name or abbreviation
|
||||
* @arg \%% - a literal `\%' character
|
||||
* <dt>format <String></dt>
|
||||
* <dd>
|
||||
* <p>
|
||||
* Any strftime string is supported, such as "%I:%M:%S %p". strftime has several format specifiers defined by the Open group at
|
||||
* <a href="http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html">http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html</a>
|
||||
* </p>
|
||||
* <p>
|
||||
* PHP added a few of its own, defined at <a href="http://www.php.net/strftime">http://www.php.net/strftime</a>
|
||||
* </p>
|
||||
* <p>
|
||||
* This javascript implementation supports all the PHP specifiers and a few more. The full list is below:
|
||||
* </p>
|
||||
* <dl>
|
||||
* <dt>%a</dt> <dd>abbreviated weekday name according to the current locale</dd>
|
||||
* <dt>%A</dt> <dd>full weekday name according to the current locale</dd>
|
||||
* <dt>%b</dt> <dd>abbreviated month name according to the current locale</dd>
|
||||
* <dt>%B</dt> <dd>full month name according to the current locale</dd>
|
||||
* <dt>%c</dt> <dd>preferred date and time representation for the current locale</dd>
|
||||
* <dt>%C</dt> <dd>century number (the year divided by 100 and truncated to an integer, range 00 to 99)</dd>
|
||||
* <dt>%d</dt> <dd>day of the month as a decimal number (range 01 to 31)</dd>
|
||||
* <dt>%D</dt> <dd>same as %m/%d/%y</dd>
|
||||
* <dt>%e</dt> <dd>day of the month as a decimal number, a single digit is preceded by a space (range ' 1' to '31')</dd>
|
||||
* <dt>%F</dt> <dd>same as %Y-%m-%d (ISO 8601 date format)</dd>
|
||||
* <dt>%g</dt> <dd>like %G, but without the century</dd>
|
||||
* <dt>%G</dt> <dd>The 4-digit year corresponding to the ISO week number</dd>
|
||||
* <dt>%h</dt> <dd>same as %b</dd>
|
||||
* <dt>%H</dt> <dd>hour as a decimal number using a 24-hour clock (range 00 to 23)</dd>
|
||||
* <dt>%I</dt> <dd>hour as a decimal number using a 12-hour clock (range 01 to 12)</dd>
|
||||
* <dt>%j</dt> <dd>day of the year as a decimal number (range 001 to 366)</dd>
|
||||
* <dt>%k</dt> <dd>hour as a decimal number using a 24-hour clock (range 0 to 23); single digits are preceded by a blank. (See also %H.)</dd>
|
||||
* <dt>%l</dt> <dd>hour as a decimal number using a 12-hour clock (range 1 to 12); single digits are preceded by a blank. (See also %I.) </dd>
|
||||
* <dt>%m</dt> <dd>month as a decimal number (range 01 to 12)</dd>
|
||||
* <dt>%M</dt> <dd>minute as a decimal number</dd>
|
||||
* <dt>%n</dt> <dd>newline character</dd>
|
||||
* <dt>%p</dt> <dd>either `AM' or `PM' according to the given time value, or the corresponding strings for the current locale</dd>
|
||||
* <dt>%P</dt> <dd>like %p, but lower case</dd>
|
||||
* <dt>%r</dt> <dd>time in a.m. and p.m. notation equal to %I:%M:%S %p</dd>
|
||||
* <dt>%R</dt> <dd>time in 24 hour notation equal to %H:%M</dd>
|
||||
* <dt>%s</dt> <dd>number of seconds since the Epoch, ie, since 1970-01-01 00:00:00 UTC</dd>
|
||||
* <dt>%S</dt> <dd>second as a decimal number</dd>
|
||||
* <dt>%t</dt> <dd>tab character</dd>
|
||||
* <dt>%T</dt> <dd>current time, equal to %H:%M:%S</dd>
|
||||
* <dt>%u</dt> <dd>weekday as a decimal number [1,7], with 1 representing Monday</dd>
|
||||
* <dt>%U</dt> <dd>week number of the current year as a decimal number, starting with the
|
||||
* first Sunday as the first day of the first week</dd>
|
||||
* <dt>%V</dt> <dd>The ISO 8601:1988 week number of the current year as a decimal number,
|
||||
* range 01 to 53, where week 1 is the first week that has at least 4 days
|
||||
* in the current year, and with Monday as the first day of the week.</dd>
|
||||
* <dt>%w</dt> <dd>day of the week as a decimal, Sunday being 0</dd>
|
||||
* <dt>%W</dt> <dd>week number of the current year as a decimal number, starting with the
|
||||
* first Monday as the first day of the first week</dd>
|
||||
* <dt>%x</dt> <dd>preferred date representation for the current locale without the time</dd>
|
||||
* <dt>%X</dt> <dd>preferred time representation for the current locale without the date</dd>
|
||||
* <dt>%y</dt> <dd>year as a decimal number without a century (range 00 to 99)</dd>
|
||||
* <dt>%Y</dt> <dd>year as a decimal number including the century</dd>
|
||||
* <dt>%z</dt> <dd>numerical time zone representation</dd>
|
||||
* <dt>%Z</dt> <dd>time zone name or abbreviation</dd>
|
||||
* <dt>%%</dt> <dd>a literal `%' character</dd>
|
||||
* </dl>
|
||||
* </dd>
|
||||
* </dl>
|
||||
* @param sLocale {String} (Optional) The locale to use when displaying days of week,
|
||||
* months of the year, and other locale specific strings. The following locales are
|
||||
* built in:
|
||||
@ -2813,4 +2943,4 @@ var xPad=function (x, pad, r)
|
||||
|
||||
})();
|
||||
|
||||
YAHOO.register("datasource", YAHOO.util.DataSource, {version: "2.6.0", build: "1321"});
|
||||
YAHOO.register("datasource", YAHOO.util.DataSource, {version: "2.7.0", build: "1799"});
|
||||
|
Reference in New Issue
Block a user