⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datasource-debug.js

📁 这是YUI的源码及相关示例。里面有很多很炫的Javascript效果。
💻 JS
📖 第 1 页 / 共 5 页
字号:
                        for (j = fieldParsers.length - 1; j >= 0; --j) {                            var p = fieldParsers[j].key;                            rec[p] = fieldParsers[j].parser(rec[p]);                            if (rec[p] === undefined) {                                rec[p] = null;                            }                        }                        results[i] = rec;                    }                //}            }            else {                results = resultsList;            }            for (key in metaFields) {                if (lang.hasOwnProperty(metaFields,key)) {                    path = buildPath(metaFields[key]);                    if (path) {                        v = walkPath(path, oFullResponse);                        oParsedResponse.meta[key] = v;                    }                }            }        } else {            YAHOO.log("JSON data could not be parsed: " +                    lang.dump(oFullResponse), "error", this.toString());            oParsedResponse.error = true;        }        oParsedResponse.results = results;    }    else {        YAHOO.log("JSON data could not be parsed: " +                lang.dump(oFullResponse), "error", this.toString());        oParsedResponse.error = true;    }    return oParsedResponse;},/** * Overridable method parses an HTML TABLE element reference into a response object. * Data is parsed out of TR elements from all TBODY elements.  * * @method parseHTMLTableData * @param oRequest {Object} Request object. * @param oFullResponse {Object} The full HTML element reference from the live database. * @return {Object} Parsed response object with the following properties<br> *     - results (Array) Array of parsed data results<br> *     - error (Boolean) True if there was an error */parseHTMLTableData : function(oRequest, oFullResponse) {    var bError = false;    var elTable = 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());                }                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;        }    }    if(bError) {        YAHOO.log("HTML TABLE data could not be parsed: " +                lang.dump(oFullResponse), "error", this.toString());        oParsedResponse.error = true;    }    else {        YAHOO.log("Parsed HTML TABLE data is " +                lang.dump(oParsedResponse), "info", this.toString());    }    return oParsedResponse;}};// DataSourceBase uses EventProviderlang.augmentProto(DS, util.EventProvider);/****************************************************************************//****************************************************************************//****************************************************************************//** * LocalDataSource class for in-memory data structs including JavaScript arrays, * JavaScript object literals (JSON), XML documents, and HTML tables. * * @namespace YAHOO.util * @class YAHOO.util.LocalDataSource * @extends YAHOO.util.DataSourceBase  * @constructor * @param oLiveData {HTMLElement}  Pointer to live data. * @param oConfigs {object} (optional) Object literal of configuration values. */util.LocalDataSource = function(oLiveData, oConfigs) {    this.dataType = DS.TYPE_LOCAL;        if(oLiveData) {        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 * &#60;URI&#62;?&#60;scriptCallbackParam&#62;=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 sta

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -