source: [view]
define("dojox/data/CssRuleStore", ["dojo", "dojox", "dojo.data.util.sorter", "dojo/data/util/filter", "dojox/data/css"], function(dojo, dojox) {
dojo.declare("dojox.data.CssRuleStore", null, {
// summary:
// Basic store to display CSS information.
// description:
// The CssRuleStore allows users to get information about active CSS rules in the page running the CssRuleStore.
// It can also filter out rules from specific stylesheets. The attributes it exposes on rules are as follows:
// selector: The selector text.
// classes: An array of classes present in this selector.
// rule: The actual DOM Rule object.
// style: The actual DOM CSSStyleDeclaration object.
// cssText: The cssText string provided on the rule object.
// styleSheet: The originating DOM Stylesheet object.
// parentStyleSheet: The parent stylesheet to the sheet this rule originates from.
// parentStyleSheetHref: The href of the parent stylesheet.
// AND every style attribute denoted as style.*, such as style.textAlign or style.backgroundColor
_storeRef: '_S',
_labelAttribute: 'selector', // text representation of the Item [label and identifier may need to stay due to method names]
_cache: null,
_browserMap: null,
_cName: "dojox.data.CssRuleStore",
constructor: function(/* Object */ keywordParameters){
// Initializes this store
if(keywordParameters){
dojo.mixin(this, keywordParameters);
}
this._cache = {};
this._allItems = null;
this._waiting = [];
this.gatherHandle = null;
var self = this;
// CSS files may not be finished loading by the time the store is constructed. We need to
// give them a little time, so setting the stylesheet loading to retry every 250ms.
function gatherRules(){
try{
// Funkiness here is due to css that may still be loading. This throws an DOM Access
// error if css isnt completely loaded.
self.context = dojox.data.css.determineContext(self.context);
if(self.gatherHandle){
clearInterval(self.gatherHandle);
self.gatherHandle = null;
}
// Handle any fetches that have been queued while we've been waiting on the CSS files
// to finish
while(self._waiting.length){
var item = self._waiting.pop();
dojox.data.css.rules.forEach(item.forFunc, null, self.context);
item.finishFunc();
}
}catch(e){}
}
this.gatherHandle = setInterval(gatherRules,250);
},
setContext: function(/* Array */ context){
// Sets the context in which queries are executed
// context: Array - Array of CSS string paths to execute queries within
if(context){
this.close();
this.context = dojox.data.css.determineContext(context);
}