1 // Formats a style rule property
2 function webdeveloper_formatStyleRuleProperty(styleRuleProperty
)
4 // Switch on the style rule property
5 switch(styleRuleProperty
)
7 case "margin-bottom-value":
8 return "margin-bottom";
9 case "margin-left-value":
11 case "margin-right-value":
12 return "margin-right";
13 case "margin-top-value":
15 case "padding-bottom-value":
16 return "padding-bottom";
17 case "padding-left-value":
18 return "padding-left";
19 case "padding-right-value":
20 return "padding-right";
21 case "padding-top-value":
23 case "-x-background-x-position":
24 return "background-x-position";
25 case "-x-background-y-position":
26 return "background-y-position";
28 return styleRuleProperty
;
32 // Formats a style rule value
33 function webdeveloper_formatStyleRuleValue(styleRuleValue
)
35 // If the style rule value is set
38 var rgbRegularExpression
= new RegExp("rgb\\((\\d{1,3}),\\s(\\d{1,3}),\\s(\\d{1,3})\\)", "gi");
39 var styleRuleValueColor
= rgbRegularExpression
.exec(styleRuleValue
);
41 // If the style rule value is a color
42 if(styleRuleValueColor
)
44 var blue
= parseInt(styleRuleValueColor
[3]).toString(16);
45 var green
= parseInt(styleRuleValueColor
[2]).toString(16);
46 var red
= parseInt(styleRuleValueColor
[1]).toString(16);
48 // If the blue color is only 1 character long
54 // If the green color is only 1 character long
60 // If the red color is only 1 character long
66 return "#" + red
+ green
+ blue
;
70 return styleRuleValue
;
73 // Returns the list of the style sheets for the specified document
74 function webdeveloper_getStyleSheetsForDocument(contentDocument
, includeInline
, includeAlternate
)
76 var styleSheets
= new Array();
78 // If the content document is set
81 var documentStyleSheets
= contentDocument
.styleSheets
;
82 var documentStyleSheetsLength
= documentStyleSheets
.length
;
83 var documentURL
= contentDocument
.documentURI
;
84 var styleSheet
= null;
86 // Loop through the style sheets
87 for(var i
= 0; i
< documentStyleSheetsLength
; i
++)
89 styleSheet
= documentStyleSheets
[i
];
91 // If this is a valid style sheet and including alternate style sheets or this is not alternate
92 if(webdeveloper_isValidStyleSheet(styleSheet
) && (includeAlternate
|| !webdeveloper_isAlternateStyleSheet(styleSheet
)))
94 // If including inline style sheets or this is not inline
95 if(includeInline
|| styleSheet
.href
!= documentURL
)
97 styleSheets
.push(styleSheet
);
100 styleSheets
= styleSheets
.concat(webdeveloper_getStyleSheetsImportedFromStyleSheet(styleSheet
));
108 // Returns the list of style sheets imported from the specified style sheet
109 function webdeveloper_getStyleSheetsImportedFromStyleSheet(styleSheet
)
111 var styleSheets
= new Array();
113 // If the style sheet is set
117 var cssRules
= styleSheet
.cssRules
;
118 var cssRulesLength
= cssRules
.length
;
119 var importedStyleSheet
= null;
120 var importRule
= Components
.interfaces
.nsIDOMCSSRule
.IMPORT_RULE
;
122 // Loop through the the style sheet rules
123 for(var i
= 0; i
< cssRulesLength
; i
++)
125 cssRule
= cssRules
[i
];
127 // If this is an import rule
128 if(cssRule
.type
== importRule
)
130 importedStyleSheet
= cssRule
.styleSheet
;
132 // If this style sheet is valid
133 if(webdeveloper_isValidStyleSheet(importedStyleSheet
))
135 styleSheets
.push(importedStyleSheet
);
137 styleSheets
= styleSheets
.concat(webdeveloper_getStyleSheetsImportedFromStyleSheet(importedStyleSheet
));
146 // If there is a style sheet for this media type
147 function webdeveloper_hasStyleSheetForMedia(styleSheetList
, media
)
149 // If the style sheet list and media are set
150 if(styleSheetList
&& media
)
152 var styleSheet
= null;
153 var styleSheetLength
= styleSheetList
.length
;
155 // Loop through the style sheets
156 for(var i
= 0; i
< styleSheetLength
; i
++)
158 styleSheet
= styleSheetList
[i
];
160 // If this style sheet is valid and is for this media type
161 if(webdeveloper_isValidStyleSheet(styleSheet
) && webdeveloper_isMediaStyleSheet(styleSheet
, media
))
171 // Is this style sheet an alternate style sheet
172 function webdeveloper_isAlternateStyleSheet(styleSheet
)
174 // If the style sheet is set
177 var ownerNode
= styleSheet
.ownerNode
;
179 // If the owner node is set
182 // If the owner node is a processing instruction
183 if(ownerNode
.nodeType
== Components
.interfaces
.nsIDOMNode
.PROCESSING_INSTRUCTION_NODE
)
185 // If the processing instruction data contains alternate="yes"
186 if(ownerNode
.data
.indexOf('alternate="yes"') != -1)
191 else if(ownerNode
.hasAttribute("rel") && ownerNode
.getAttribute("rel").toLowerCase() == "alternate stylesheet")
201 // Is this style sheet for this media type
202 function webdeveloper_isMediaStyleSheet(styleSheet
, matchMediaType
)
204 // If the style sheet and match media type are set
205 if(styleSheet
&& matchMediaType
)
207 var media
= styleSheet
.media
;
208 var mediaLength
= media
.length
;
209 var mediaType
= null;
211 // If there is no media and the match media type is screen
212 if(mediaLength
== 0 && matchMediaType
== "screen")
217 // Loop through the media
218 for(var i
= 0; i
< mediaLength
; i
++)
220 mediaType
= media
.item(i
).toLowerCase();
222 // If the media type is all or matches the match media type
223 if(mediaType
== "all" || mediaType
== matchMediaType
)
233 // Is this style sheet a valid style sheet
234 function webdeveloper_isValidStyleSheet(styleSheet
)
236 // If the style sheet is set
239 var styleSheetHref
= styleSheet
.href
;
241 // If the style sheet href is set and this is not an internal style sheet or the style sheet href is not set and this does not have a Web Developer id
242 if((styleSheetHref
&& styleSheetHref
.indexOf("about:PreferenceStyleSheet") != 0 && styleSheetHref
.indexOf("chrome://") != 0 && styleSheetHref
.indexOf("data:text/css") != 0 && styleSheetHref
.indexOf("jar:file://") != 0 && styleSheetHref
.indexOf("resource://") != 0) || (!styleSheetHref
&& (!styleSheet
.hasAttribute("id") || styleSheet
.getAttribute("id").indexOf("webdeveloper-") != 0)))
251 // Is this style rule is a valid style rule
252 function webdeveloper_isValidStyleRule(styleRuleList
, styleRule
)
254 // If the style rule is set
257 // If the style rule is an invalid style rule
258 if(styleRule
.indexOf("-moz-") == 0 || ((styleRule
== "margin-left-ltr-source" || styleRule
== "margin-left-rtl-source" || styleRule
== "margin-right-ltr-source" || styleRule
== "margin-right-rtl-source" || styleRule
== "padding-left-ltr-source" || styleRule
== "padding-left-rtl-source" || styleRule
== "padding-right-ltr-source" || styleRule
== "padding-right-rtl-source") && styleRuleList
.getPropertyValue(styleRule
) == "physical"))