Mercurial > MadButterfly
comparison inkscape/firefox/content/css.js @ 352:4350aa369149
Use jQuery UI components.
author | wycc |
---|---|
date | Mon, 09 Mar 2009 01:27:33 +0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
351:4ae9888bbde6 | 352:4350aa369149 |
---|---|
1 function get_css(rule_name, stylesheet, delete_flag) { | |
2 if (!document.styleSheets) return false; | |
3 rule_name = rule_name.toLowerCase(); stylesheet = stylesheet || 0; | |
4 for (var i = stylesheet; i < document.styleSheets.length; i++) { | |
5 var styleSheet = document.styleSheets[i]; css_rules = document.styleSheets[i].cssRules || document.styleSheets[i].rules; | |
6 if(!css_rules) continue; | |
7 var j = 0; | |
8 do { | |
9 if(css_rules[j].selectorText.toLowerCase() == rule_name) { | |
10 if(delete_flag == true) { | |
11 if(document.styleSheets[i].removeRule) document.styleSheets[i].removeRule(j); | |
12 if(document.styleSheets[i].deleteRule) document.styleSheets[i].deleteRule(j); | |
13 return true; | |
14 } | |
15 else return css_rules[j]; | |
16 } | |
17 } | |
18 while (css_rules[++j]); | |
19 } | |
20 return false; | |
21 } | |
22 function add_css(rule_name, stylesheet) { | |
23 rule_name = rule_name.toLowerCase(); stylesheet = stylesheet || 0; | |
24 if (!document.styleSheets || get_css(rule_name, stylesheet)) return false; | |
25 (document.styleSheets[stylesheet].addRule) ? document.styleSheets[stylesheet].addRule(rule_name, null, 0) : document.styleSheets[stylesheet].insertRule(rule_name+' { }', 0); | |
26 return get_css(rule_name); | |
27 } | |
28 function get_sheet_num (href_name) { | |
29 if (!document.styleSheets) return false; | |
30 for (var i = 0; i < document.styleSheets.length; i++) { if(document.styleSheets[i].href && document.styleSheets[i].href.toString().match(href_name)) return i; } | |
31 return false; | |
32 } | |
33 function remove_css(rule_name, stylesheet) { return get_css(rule_name, stylesheet, true); } | |
34 | |
35 function add_sheet(url, media) { | |
36 if(document.createStyleSheet) { | |
37 document.createStyleSheet(url); | |
38 } | |
39 else { | |
40 var newSS = document.createElement('link'); | |
41 newSS.rel = 'stylesheet'; | |
42 newSS.type = 'text/css'; | |
43 newSS.media = media || "all"; | |
44 | |
45 newSS.href = url; | |
46 // var styles = "@import url(' " + url + " ');"; | |
47 // newSS.href ='data:text/css,'+escape(styles); | |
48 document.getElementsByTagName("head")[0].appendChild(newSS); | |
49 } | |
50 } |