| 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 |
|
| 12 |
array.forEach(styleSheet[styleSheet.cssRules?"cssRules":"rules"], function(rule){ |
| 13 |
if(!rule.type || rule.type !== 3){ |
| 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 |
|
| 22 |
}; |
| 23 |
array.forEach(context,_processSS); |
| 24 |
} |
| 25 |
}; |
| 26 |
|
| 27 |
css.findStyleSheets = function(sheets){ |
| 28 |
|
| 29 |
|
| 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 |
|
| 47 |
|
| 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){ |
| 59 |
|
| 60 |
return _processSS(importedSS); |
| 61 |
}); |
| 62 |
} |
| 63 |
|
| 64 |
return array.some(styleSheet[styleSheet.cssRules?"cssRules":"rules"], function(rule){ |
| 65 |
if(rule.type && rule.type === 3 && _processSS(rule.styleSheet)){ |
| 66 |
|
| 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 |
|
| 78 |
|
| 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){ |
| 89 |
|
| 90 |
_processSS(importedSS); |
| 91 |
}); |
| 92 |
} |
| 93 |
|
| 94 |
array.forEach(styleSheet[styleSheet.cssRules?"cssRules":"rules"], function(rule){ |
| 95 |
if(rule.type && rule.type === 3){ |
| 96 |
_processSS(rule.styleSheet); |
| 97 |
} |
| 98 |
}); |
| 99 |
}; |
| 100 |
array.forEach(initialStylesheets,_processSS); |
| 101 |
return ret; |
| 102 |
}; |
| 103 |
|
| 104 |
return css; |
| 105 |
|
| 106 |
}); |