📄 datasource.js
字号:
if(YAHOO.lang.isArray(oLiveData)) { // array this.responseType = DS.TYPE_JSARRAY; } // xml else if(oLiveData.nodeType && oLiveData.nodeType == 9) { this.responseType = DS.TYPE_XML; } else if(oLiveData.nodeName && (oLiveData.nodeName.toLowerCase() == "table")) { // table this.responseType = DS.TYPE_HTMLTABLE; oLiveData = oLiveData.cloneNode(true); } else if(YAHOO.lang.isString(oLiveData)) { // text this.responseType = DS.TYPE_TEXT; } else if(YAHOO.lang.isObject(oLiveData)) { // json this.responseType = DS.TYPE_JSON; } } else { oLiveData = []; this.responseType = DS.TYPE_JSARRAY; } this.constructor.superclass.constructor.call(this, oLiveData, oConfigs); };// LocalDataSource extends DataSourceBaselang.extend(util.LocalDataSource, DS);// Copy static members to LocalDataSource classlang.augmentObject(util.LocalDataSource, DS);/****************************************************************************//****************************************************************************//****************************************************************************//** * FunctionDataSource class for JavaScript functions. * * @namespace YAHOO.util * @class YAHOO.util.FunctionDataSource * @extends YAHOO.util.DataSourceBase * @constructor * @param oLiveData {HTMLElement} Pointer to live data. * @param oConfigs {object} (optional) Object literal of configuration values. */util.FunctionDataSource = function(oLiveData, oConfigs) { this.dataType = DS.TYPE_JSFUNCTION; oLiveData = oLiveData || function() {}; this.constructor.superclass.constructor.call(this, oLiveData, oConfigs); };// FunctionDataSource extends DataSourceBaselang.extend(util.FunctionDataSource, DS, {///////////////////////////////////////////////////////////////////////////////// FunctionDataSource public methods////////////////////////////////////////////////////////////////////////////////** * Overriding method passes query to a function. The returned response is then * forwarded to the handleResponse function. * * @method makeConnection * @param oRequest {Object} Request object. * @param oCallback {Object} Callback object literal. * @param oCaller {Object} (deprecated) Use oCallback.scope. * @return {Number} Transaction ID. */makeConnection : function(oRequest, oCallback, oCaller) { var tId = DS._nTransactionId++; this.fireEvent("requestEvent", {tId:tId,request:oRequest,callback:oCallback,caller:oCaller}); // Pass the request in as a parameter and // forward the return value to the handler var oRawResponse = this.liveData(oRequest); // Try to sniff data type if it has not been defined if(this.responseType === DS.TYPE_UNKNOWN) { if(YAHOO.lang.isArray(oRawResponse)) { // array this.responseType = DS.TYPE_JSARRAY; } // xml else if(oRawResponse && oRawResponse.nodeType && oRawResponse.nodeType == 9) { this.responseType = DS.TYPE_XML; } else if(oRawResponse && oRawResponse.nodeName && (oRawResponse.nodeName.toLowerCase() == "table")) { // table this.responseType = DS.TYPE_HTMLTABLE; } else if(YAHOO.lang.isObject(oRawResponse)) { // json this.responseType = DS.TYPE_JSON; } else if(YAHOO.lang.isString(oRawResponse)) { // text this.responseType = DS.TYPE_TEXT; } } this.handleResponse(oRequest, oRawResponse, oCallback, oCaller, tId); return tId;}});// Copy static members to FunctionDataSource classlang.augmentObject(util.FunctionDataSource, DS);/****************************************************************************//****************************************************************************//****************************************************************************//** * ScriptNodeDataSource class for accessing remote data via the YUI Get Utility. * * @namespace YAHOO.util * @class YAHOO.util.ScriptNodeDataSource * @extends YAHOO.util.DataSourceBase * @constructor * @param oLiveData {HTMLElement} Pointer to live data. * @param oConfigs {object} (optional) Object literal of configuration values. */util.ScriptNodeDataSource = function(oLiveData, oConfigs) { this.dataType = DS.TYPE_SCRIPTNODE; oLiveData = oLiveData || ""; this.constructor.superclass.constructor.call(this, oLiveData, oConfigs); };// ScriptNodeDataSource extends DataSourceBaselang.extend(util.ScriptNodeDataSource, DS, {///////////////////////////////////////////////////////////////////////////////// ScriptNodeDataSource public properties////////////////////////////////////////////////////////////////////////////////** * Alias to YUI Get Utility, to allow implementers to use a custom class. * * @property getUtility * @type Object * @default YAHOO.util.Get */getUtility : util.Get,/** * Defines request/response management in the following manner: * <dl> * <!--<dt>queueRequests</dt> * <dd>If a request is already in progress, wait until response is returned before sending the next request.</dd> * <dt>cancelStaleRequests</dt> * <dd>If a request is already in progress, cancel it before sending the next request.</dd>--> * <dt>ignoreStaleResponses</dt> * <dd>Send all requests, but handle only the response for the most recently sent request.</dd> * <dt>allowAll</dt> * <dd>Send all requests and handle all responses.</dd> * </dl> * * @property asyncMode * @type String * @default "allowAll" */asyncMode : "allowAll",/** * Callback string parameter name sent to the remote script. By default, * requests are sent to * <URI>?<scriptCallbackParam>=callbackFunction * * @property scriptCallbackParam * @type String * @default "callback" */scriptCallbackParam : "callback",///////////////////////////////////////////////////////////////////////////////// ScriptNodeDataSource public methods////////////////////////////////////////////////////////////////////////////////** * Creates a request callback that gets appended to the script URI. Implementers * can customize this string to match their server's query syntax. * * @method generateRequestCallback * @return {String} String fragment that gets appended to script URI that * specifies the callback function */generateRequestCallback : function(id) { return "&" + this.scriptCallbackParam + "=YAHOO.util.ScriptNodeDataSource.callbacks["+id+"]" ;},/** * Overriding method passes query to Get Utility. The returned * response is then forwarded to the handleResponse function. * * @method makeConnection * @param oRequest {Object} Request object. * @param oCallback {Object} Callback object literal. * @param oCaller {Object} (deprecated) Use oCallback.scope. * @return {Number} Transaction ID. */makeConnection : function(oRequest, oCallback, oCaller) { var tId = DS._nTransactionId++; this.fireEvent("requestEvent", {tId:tId,request:oRequest,callback:oCallback,caller:oCaller}); // If there are no global pending requests, it is safe to purge global callback stack and global counter if(util.ScriptNodeDataSource._nPending === 0) { util.ScriptNodeDataSource.callbacks = []; util.ScriptNodeDataSource._nId = 0; } // ID for this request var id = util.ScriptNodeDataSource._nId; util.ScriptNodeDataSource._nId++; // Dynamically add handler function with a closure to the callback stack var oSelf = this; util.ScriptNodeDataSource.callbacks[id] = function(oRawResponse) { if((oSelf.asyncMode !== "ignoreStaleResponses")|| (id === util.ScriptNodeDataSource.callbacks.length-1)) { // Must ignore stale responses // Try to sniff data type if it has not been defined if(oSelf.responseType === DS.TYPE_UNKNOWN) { if(YAHOO.lang.isArray(oRawResponse)) { // array oSelf.responseType = DS.TYPE_JSARRAY; } // xml else if(oRawResponse.nodeType && oRawResponse.nodeType == 9) { oSelf.responseType = DS.TYPE_XML; } else if(oRawResponse.nodeName && (oRawResponse.nodeName.toLowerCase() == "table")) { // table oSelf.responseType = DS.TYPE_HTMLTABLE; } else if(YAHOO.lang.isObject(oRawResponse)) { // json oSelf.responseType = DS.TYPE_JSON; } else if(YAHOO.lang.isString(oRawResponse)) { // text oSelf.responseType = DS.TYPE_TEXT; } } oSelf.handleResponse(oRequest, oRawResponse, oCallback, oCaller, tId); } else { } delete util.ScriptNodeDataSource.callbacks[id]; }; // We are now creating a request util.ScriptNodeDataSource._nPending++; var sUri = this.liveData + oRequest + this.generateRequestCallback(id); this.getUtility.script(sUri, {autopurge: true, onsuccess: util.ScriptNodeDataSource._bumpPendingDown, onfail: util.ScriptNodeDataSource._bumpPendingDown}); return tId;}});// Copy static members to ScriptNodeDataSource classlang.augmentObject(util.ScriptNodeDataSource, DS);// Copy static members to ScriptNodeDataSource classlang.augmentObject(util.ScriptNodeDataSource, {///////////////////////////////////////////////////////////////////////////////// ScriptNodeDataSource private static properties////////////////////////////////////////////////////////////////////////////////** * Unique ID to track requests. * * @property _nId * @type Number * @private * @static */_nId : 0,/** * Counter for pending requests. When this is 0, it is safe to purge callbacks * array. * * @property _nPending * @type Number * @private * @static */_nPending : 0,/** * Global array of callback functions, one for each request sent. * * @property callbacks * @type Function[] * @static */callbacks : []});/****************************************************************************//****************************************************************************//****************************************************************************//** * XHRDataSource class for accessing remote data via the YUI Connection Manager * Utility * * @namespace YAHOO.util * @class YAHOO.util.XHRDataSource * @extends YAHOO.util.DataSourceBase * @constructor * @param oLiveData {HTMLElement} Pointer to live data. * @param oConfigs {object} (optional) Object literal of configuration values. */util.XHRDataSource = function(oLiveData, oConfigs) { this.dataType = DS.TYPE_XHR; this.connMgr = this.connMgr || util.Connect; oLiveData = oLiveData || ""; this.constructor.superclass.constructor.call(this, oLiveData, oConfigs); };// XHRDataSource extends DataSourceBaselang.extend(util.XHRDataSource, DS, {///////////////////////////////////////////////////////////////////////////////// XHRDataSource public properties/////////////////////////////////////////////////////////////////////////////// /** * Alias to YUI Connection Manager, to allow implementers to use a custom class. * * @property connMgr * @type Object * @default YAHOO.util.Connect */connMgr: null, /** * Defines request/response management in the following manner: * <dl> * <dt>queueRequests</dt> * <dd>If a request is already in progress, wait until response is returned * before sending the next request.</dd> * * <dt>cancelStaleRequests</dt> * <dd>If a request is already in progress, cancel it before sending the next * request.</dd> * * <dt>ignoreStaleResponses</dt> * <dd>Send all requests, but handle only the response for the most recently * sent request.</dd> * * <dt>allowAll</
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -