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

📄 datasource-debug.js

📁 这是YUI的源码及相关示例。里面有很多很炫的Javascript效果。
💻 JS
📖 第 1 页 / 共 5 页
字号:
/*Copyright (c) 2008, Yahoo! Inc. All rights reserved.Code licensed under the BSD License:http://developer.yahoo.net/yui/license.txtversion: 2.6.0*/(function () {var lang   = YAHOO.lang,    util   = YAHOO.util,    Ev     = util.Event;/** * The DataSource utility provides a common configurable interface for widgets to * access a variety of data, from JavaScript arrays to online database servers. * * @module datasource * @requires yahoo, event * @optional json, get, connection  * @title DataSource Utility *//****************************************************************************//****************************************************************************//****************************************************************************//** * Base class for the YUI DataSource utility. * * @namespace YAHOO.util * @class YAHOO.util.DataSourceBase * @constructor * @param oLiveData {HTMLElement}  Pointer to live data. * @param oConfigs {object} (optional) Object literal of configuration values. */util.DataSourceBase = function(oLiveData, oConfigs) {    if(oLiveData === null || oLiveData === undefined) {        YAHOO.log("Could not instantiate DataSource due to invalid live database",                "error", this.toString());        return;    }        this.liveData = oLiveData;    this._oQueue = {interval:null, conn:null, requests:[]};    this.responseSchema = {};       // Set any config params passed in to override defaults    if(oConfigs && (oConfigs.constructor == Object)) {        for(var sConfig in oConfigs) {            if(sConfig) {                this[sConfig] = oConfigs[sConfig];            }        }    }        // Validate and initialize public configs    var maxCacheEntries = this.maxCacheEntries;    if(!lang.isNumber(maxCacheEntries) || (maxCacheEntries < 0)) {        maxCacheEntries = 0;    }    // Initialize interval tracker    this._aIntervals = [];    /////////////////////////////////////////////////////////////////////////////    //    // Custom Events    //    /////////////////////////////////////////////////////////////////////////////    /**     * Fired when a request is made to the local cache.     *     * @event cacheRequestEvent     * @param oArgs.request {Object} The request object.     * @param oArgs.callback {Object} The callback object.     * @param oArgs.caller {Object} (deprecated) Use callback.scope.     */    this.createEvent("cacheRequestEvent");    /**     * Fired when data is retrieved from the local cache.     *     * @event cacheResponseEvent     * @param oArgs.request {Object} The request object.     * @param oArgs.response {Object} The response object.     * @param oArgs.callback {Object} The callback object.     * @param oArgs.caller {Object} (deprecated) Use callback.scope.     */    this.createEvent("cacheResponseEvent");    /**     * Fired when a request is sent to the live data source.     *     * @event requestEvent     * @param oArgs.request {Object} The request object.     * @param oArgs.callback {Object} The callback object.     * @param oArgs.tId {Number} Transaction ID.          * @param oArgs.caller {Object} (deprecated) Use callback.scope.     */    this.createEvent("requestEvent");    /**     * Fired when live data source sends response.     *     * @event responseEvent     * @param oArgs.request {Object} The request object.     * @param oArgs.response {Object} The raw response object.     * @param oArgs.callback {Object} The callback object.     * @param oArgs.tId {Number} Transaction ID.          * @param oArgs.caller {Object} (deprecated) Use callback.scope.     */    this.createEvent("responseEvent");    /**     * Fired when response is parsed.     *     * @event responseParseEvent     * @param oArgs.request {Object} The request object.     * @param oArgs.response {Object} The parsed response object.     * @param oArgs.callback {Object} The callback object.     * @param oArgs.caller {Object} (deprecated) Use callback.scope.     */    this.createEvent("responseParseEvent");    /**     * Fired when response is cached.     *     * @event responseCacheEvent     * @param oArgs.request {Object} The request object.     * @param oArgs.response {Object} The parsed response object.     * @param oArgs.callback {Object} The callback object.     * @param oArgs.caller {Object} (deprecated) Use callback.scope.     */    this.createEvent("responseCacheEvent");    /**     * Fired when an error is encountered with the live data source.     *     * @event dataErrorEvent     * @param oArgs.request {Object} The request object.     * @param oArgs.callback {Object} The callback object.     * @param oArgs.caller {Object} (deprecated) Use callback.scope.     * @param oArgs.message {String} The error message.     */    this.createEvent("dataErrorEvent");    /**     * Fired when the local cache is flushed.     *     * @event cacheFlushEvent     */    this.createEvent("cacheFlushEvent");    var DS = util.DataSourceBase;    this._sName = "DataSource instance" + DS._nIndex;    DS._nIndex++;    YAHOO.log("DataSource initialized", "info", this.toString());};var DS = util.DataSourceBase;lang.augmentObject(DS, {///////////////////////////////////////////////////////////////////////////////// DataSourceBase public constants////////////////////////////////////////////////////////////////////////////////** * Type is unknown. * * @property TYPE_UNKNOWN * @type Number * @final * @default -1 */TYPE_UNKNOWN : -1,/** * Type is a JavaScript Array. * * @property TYPE_JSARRAY * @type Number * @final * @default 0 */TYPE_JSARRAY : 0,/** * Type is a JavaScript Function. * * @property TYPE_JSFUNCTION * @type Number * @final * @default 1 */TYPE_JSFUNCTION : 1,/** * Type is hosted on a server via an XHR connection. * * @property TYPE_XHR * @type Number * @final * @default 2 */TYPE_XHR : 2,/** * Type is JSON. * * @property TYPE_JSON * @type Number * @final * @default 3 */TYPE_JSON : 3,/** * Type is XML. * * @property TYPE_XML * @type Number * @final * @default 4 */TYPE_XML : 4,/** * Type is plain text. * * @property TYPE_TEXT * @type Number * @final * @default 5 */TYPE_TEXT : 5,/** * Type is an HTML TABLE element. Data is parsed out of TR elements from all TBODY elements. * * @property TYPE_HTMLTABLE * @type Number * @final * @default 6 */TYPE_HTMLTABLE : 6,/** * Type is hosted on a server via a dynamic script node. * * @property TYPE_SCRIPTNODE * @type Number * @final * @default 7 */TYPE_SCRIPTNODE : 7,/** * Type is local. * * @property TYPE_LOCAL * @type Number * @final * @default 8 */TYPE_LOCAL : 8,/** * Error message for invalid dataresponses. * * @property ERROR_DATAINVALID * @type String * @final * @default "Invalid data" */ERROR_DATAINVALID : "Invalid data",/** * Error message for null data responses. * * @property ERROR_DATANULL * @type String * @final * @default "Null data" */ERROR_DATANULL : "Null data",///////////////////////////////////////////////////////////////////////////////// DataSourceBase private static properties////////////////////////////////////////////////////////////////////////////////** * Internal class variable to index multiple DataSource instances. * * @property DataSourceBase._nIndex * @type Number * @private * @static */_nIndex : 0,/** * Internal class variable to assign unique transaction IDs. * * @property DataSourceBase._nTransactionId * @type Number * @private * @static */_nTransactionId : 0,///////////////////////////////////////////////////////////////////////////////// DataSourceBase public static methods////////////////////////////////////////////////////////////////////////////////** * Executes a configured callback.  For object literal callbacks, the third * param determines whether to execute the success handler or failure handler. *   * @method issueCallback * @param callback {Function|Object} the callback to execute * @param params {Array} params to be passed to the callback method * @param error {Boolean} whether an error occurred * @param scope {Object} the scope from which to execute the callback * (deprecated - use an object literal callback) * @static      */issueCallback : function (callback,params,error,scope) {    if (lang.isFunction(callback)) {        callback.apply(scope, params);    } else if (lang.isObject(callback)) {        scope = callback.scope || scope || window;        var callbackFunc = callback.success;        if (error) {            callbackFunc = callback.failure;        }        if (callbackFunc) {            callbackFunc.apply(scope, params.concat([callback.argument]));        }    }},/** * Converts data to type String. * * @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. * @static */parseString : function(oData) {    // Special case null and undefined    if(!lang.isValue(oData)) {        return null;    }        //Convert to string    var string = oData + "";    // Validate    if(lang.isString(string)) {        return string;    }    else {        YAHOO.log("Could not convert data " + lang.dump(oData) + " to type String", "warn", this.toString());        return null;    }},/** * 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. * @static */parseNumber : function(oData) {    //Convert to number    var number = oData * 1;

⌨️ 快捷键说明

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