📄 opmlstore.js
字号:
something.tagName == 'outline' && something.ownerDocument === this._xmlData); //Boolean }, isItemLoaded: function(/* anything */ something){ // summary: // See dojo.data.api.Read.isItemLoaded() // OpmlStore loads every item, so if it's an item, then it's loaded. return this.isItem(something); //Boolean }, loadItem: function(/* item */ item){ // summary: // See dojo.data.api.Read.loadItem() // description: // The OpmlStore always loads all items, so if it's an item, then it's loaded. // From the dojo.data.api.Read.loadItem docs: // If a call to isItemLoaded() returns true before loadItem() is even called, // then loadItem() need not do any work at all and will not even invoke the callback handlers. }, getLabel: function(/* item */ item){ // summary: // See dojo.data.api.Read.getLabel() if(this.isItem(item)){ return this.getValue(item,this.label); //String } return undefined; //undefined }, getLabelAttributes: function(/* item */ item){ // summary: // See dojo.data.api.Read.getLabelAttributes() return [this.label]; //array }, // The dojo.data.api.Read.fetch() function is implemented as // a mixin from dojo.data.util.simpleFetch. // That mixin requires us to define _fetchItems(). _fetchItems: function( /* Object */ keywordArgs, /* Function */ findCallback, /* Function */ errorCallback){ // summary: // See dojo.data.util.simpleFetch.fetch() var self = this; var filter = function(requestArgs, arrayOfItems){ var items = null; if(requestArgs.query){ items = []; var ignoreCase = requestArgs.queryOptions ? requestArgs.queryOptions.ignoreCase : false; //See if there are any string values that can be regexp parsed first to avoid multiple regexp gens on the //same value for each item examined. Much more efficient. var regexpList = {}; for(var key in requestArgs.query){ var value = requestArgs.query[key]; if(typeof value === "string"){ regexpList[key] = dojo.data.util.filter.patternToRegExp(value, ignoreCase); } } for(var i = 0; i < arrayOfItems.length; ++i){ var match = true; var candidateItem = arrayOfItems[i]; for(var key in requestArgs.query){ var value = requestArgs.query[key]; if(!self._containsValue(candidateItem, key, value, regexpList[key])){ match = false; } } if(match){ items.push(candidateItem); } } }else{ // We want a copy to pass back in case the parent wishes to sort the array. We shouldn't allow resort // of the internal list so that multiple callers can get lists and sort without affecting each other. if(arrayOfItems.length> 0){ items = arrayOfItems.slice(0,arrayOfItems.length); } } findCallback(items, requestArgs); }; if(this._loadFinished){ filter(keywordArgs, this._getItemsArray(keywordArgs.queryOptions)); }else{ //If fetches come in before the loading has finished, but while //a load is in progress, we have to defer the fetching to be //invoked in the callback. if(this._loadInProgress){ this._queuedFetches.push({args: keywordArgs, filter: filter}); }else{ if(this.url !== ""){ this._loadInProgress = true; var getArgs = { url: self.url, handleAs: "xml" }; var getHandler = dojo.xhrGet(getArgs); getHandler.addCallback(function(data){ self._processRawXmlTree(data); filter(keywordArgs, self._getItemsArray(keywordArgs.queryOptions)); self._handleQueuedFetches(); }); getHandler.addErrback(function(error){ throw error; }); }else if(this._opmlData){ this._processRawXmlTree(this._opmlData); this._opmlData = null; filter(keywordArgs, this._getItemsArray(keywordArgs.queryOptions)); }else{ throw new Error("dojox.data.OpmlStore: No OPML source data was provided as either URL or XML data input."); } } } }, getFeatures: function(){ // summary: See dojo.data.api.Read.getFeatures() var features = { 'dojo.data.api.Read': true, 'dojo.data.api.Identity': true }; return features; //Object },/*************************************** dojo.data.api.Identity API***************************************/ getIdentity: function(/* item */ item){ // summary: // See dojo.data.api.Identity.getIdentity() if(this.isItem(item)){ //No ther way to do this other than O(n) without //complete rework of how the tree stores nodes. for(var i in this._identityMap){ if(this._identityMap[i] === item){ return i; } } } return null; //null }, fetchItemByIdentity: function(/* Object */ keywordArgs){ // summary: // See dojo.data.api.Identity.fetchItemByIdentity() //Hasn't loaded yet, we have to trigger the load. if(!this._loadFinished){ var self = this; if(this.url !== ""){ //If fetches come in before the loading has finished, but while //a load is in progress, we have to defer the fetching to be //invoked in the callback. if(this._loadInProgress){ this._queuedFetches.push({args: keywordArgs}); }else{ this._loadInProgress = true; var getArgs = { url: self.url, handleAs: "xml" }; var getHandler = dojo.xhrGet(getArgs); getHandler.addCallback(function(data){ var scope = keywordArgs.scope?keywordArgs.scope:dojo.global; try{ self._processRawXmlTree(data); var item = self._identityMap[keywordArgs.identity]; if(!self.isItem(item)){ item = null; } if(keywordArgs.onItem){ keywordArgs.onItem.call(scope, item); } self._handleQueuedFetches(); }catch(error){ if(keywordArgs.onError){ keywordArgs.onError.call(scope, error); } } }); getHandler.addErrback(function(error){ this._loadInProgress = false; if(keywordArgs.onError){ var scope = keywordArgs.scope?keywordArgs.scope:dojo.global; keywordArgs.onError.call(scope, error); } }); } }else if(this._opmlData){ this._processRawXmlTree(this._opmlData); this._opmlData = null; var item = this._identityMap[keywordArgs.identity]; if(!self.isItem(item)){ item = null; } if(keywordArgs.onItem){ var scope = keywordArgs.scope?keywordArgs.scope:dojo.global; keywordArgs.onItem.call(scope, item); } } }else{ //Already loaded. We can just look it up and call back. var item = this._identityMap[keywordArgs.identity]; if(!this.isItem(item)){ item = null; } if(keywordArgs.onItem){ var scope = keywordArgs.scope?keywordArgs.scope:dojo.global; keywordArgs.onItem.call(scope, item); } } }, getIdentityAttributes: function(/* item */ item){ // summary: // See dojo.data.api.Identity.getIdentifierAttributes() //Identity isn't a public attribute in the item, it's the node count. //So, return null. return null; }, _handleQueuedFetches: function(){ // summary: // Internal function to execute delayed request in the store. //Execute any deferred fetches now. if (this._queuedFetches.length > 0) { for(var i = 0; i < this._queuedFetches.length; i++){ var fData = this._queuedFetches[i]; var delayedQuery = fData.args; var delayedFilter = fData.filter; if(delayedFilter){ delayedFilter(delayedQuery, this._getItemsArray(delayedQuery.queryOptions)); }else{ this.fetchItemByIdentity(delayedQuery); } } this._queuedFetches = []; } }, close: function(/*dojo.data.api.Request || keywordArgs || null */ request){ // summary: // See dojo.data.api.Read.close() }});//Mix in the simple fetch implementation to this class.dojo.extend(dojox.data.OpmlStore,dojo.data.util.simpleFetch); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -