Debian Codegraph @

dojox/data/css.js

raw symbols SCIP
1 define(["dojo/_base/lang", "dojo/_base/array"],
2 function(lang, array) {
3
4 var css = lang.getObject("dojox.data.css",true)
5
6 css.rules = {};
7
8 css.rules.forEach = function(fn,ctx,context){
9 if(context){
10 var _processSS = function(styleSheet){
11 //iterate across rules in the stylesheet
12 array.forEach(styleSheet[styleSheet.cssRules?"cssRules":"rules"], function(rule){
13 if(!rule.type || rule.type !== 3){// apply fn to current rule with approp ctx. rule is arg (all browsers)
14 var href = "";
15 if(styleSheet && styleSheet.href){
16 href = styleSheet.href;
17 }
18 fn.call(ctx?ctx:this,rule, styleSheet, href);
19 }
20 });
21 //process any child stylesheets
22 };
23 array.forEach(context,_processSS);
24 }
25 };
26
27 css.findStyleSheets = function(sheets){
28 // Takes an array of stylesheet paths and finds the currently loaded StyleSheet objects matching
29 // those names
30 var sheetObjects = [];
31 var _processSS = function(styleSheet){
32 var s = css.findStyleSheet(styleSheet);
33 if(s){
34 array.forEach(s, function(sheet){
35 if(array.indexOf(sheetObjects, sheet) === -1){
36 sheetObjects.push(sheet);
37 }
38 });
39 }
40 };
41 array.forEach(sheets, _processSS);
42 return sheetObjects;
43 };
44
45 css.findStyleSheet = function(sheet){
46 // Takes a stylesheet path and finds the currently loaded StyleSheet objects matching
47 // those names (and it's parent(s), if it is imported from another)
48 var sheetObjects = [];
49 if(sheet.charAt(0) === '.'){
50 sheet = sheet.substring(1);
51 }
52 var _processSS = function(styleSheet){
53 if(styleSheet.href && styleSheet.href.match(sheet)){
54 sheetObjects.push(styleSheet);
55 return true;
56 }
57 if(styleSheet.imports){
58 return array.some(styleSheet.imports, function(importedSS){ //IE stylesheet has imports[] containing @import'ed rules
59 //console.debug("Processing IE @import rule",importedSS);
60 return _processSS(importedSS);
61 });
62 }
63 //iterate across rules in the stylesheet
64 return array.some(styleSheet[styleSheet.cssRules?"cssRules":"rules"], function(rule){
65 if(rule.type && rule.type === 3 && _processSS(rule.styleSheet)){// CSSImportRule (firefox)
66 //sheetObjects.push(styleSheet);
67 return true;
68 }
69 return false;
70 });
71 };
72 array.some(document.styleSheets, _processSS);
73 return sheetObjects;
74 };
75
76 css.determineContext = function(initialStylesheets){
77 // Takes an array of stylesheet paths and returns an array of all stylesheets that fall in the
78 // given context. If no paths are given, all stylesheets are returned.
79 var ret = [];
80 if(initialStylesheets && initialStylesheets.length > 0){
81 initialStylesheets = css.findStyleSheets(initialStylesheets);
82 }else{
83 initialStylesheets = document.styleSheets;
84 }
85 var _processSS = function(styleSheet){
86 ret.push(styleSheet);
87 if(styleSheet.imports){
88 array.forEach(styleSheet.imports, function(importedSS){ //IE stylesheet has imports[] containing @import'ed rules
89 //console.debug("Processing IE @import rule",importedSS);
90 _processSS(importedSS);
91 });
92 }
93 //iterate across rules in the stylesheet
94 array.forEach(styleSheet[styleSheet.cssRules?"cssRules":"rules"], function(rule){
95 if(rule.type && rule.type === 3){// CSSImportRule (firefox)
96 _processSS(rule.styleSheet);
97 }
98 });
99 };
100 array.forEach(initialStylesheets,_processSS);
101 return ret;
102 };
103
104 return css;
105
106 });