1 // Clears the view generated source selection
2 function webdeveloper_clearViewGeneratedSourceSelection(selection
, generatedSourceWindow
)
4 selection
.removeAllRanges();
5 generatedSourceWindow
.document
.getElementById("content").contentWindow
.getSelection().removeAllRanges();
8 // Displays the view frame source menu
9 function webdeveloper_displayViewFrameSourceMenu(menu
)
11 var documentList
= webdeveloper_getDocuments(webdeveloper_getContentWindow());
12 var documentLength
= documentList
.length
;
14 var pageDocument
= null;
16 webdeveloper_removeGeneratedMenuItems(menu
);
18 // Loop through the documents
19 for(var i
= 0; i
< documentLength
; i
++)
21 menuItem
= document
.createElement("menuitem");
22 pageDocument
= documentList
[i
];
23 menuItem
.pageDocument
= pageDocument
;
25 menuItem
.setAttribute("class", "webdeveloper-generated-menu");
26 menuItem
.setAttribute("label", pageDocument
.documentURI
);
27 menuItem
.setAttribute("oncommand", "webdeveloper_viewSource(this.pageDocument)");
28 menu
.appendChild(menuItem
);
32 // Displays the view source with menu
33 function webdeveloper_displayViewSourceWithMenu(menu
, suffix
)
35 var description
= null;
36 var descriptionPreference
= null;
38 var menuItem
= document
.createElement("menuitem");
40 var viewSourceWithCount
= webdeveloper_getIntegerPreference("webdeveloper.view.source.with.count", true);
41 var viewSourceWithSeparator
= menu
.getElementsByAttribute("id", "webdeveloper-view-source-separator3-" + suffix
)[0];
43 webdeveloper_removeGeneratedMenuItems(menu
);
45 // If there are no view source with applications
46 if(viewSourceWithCount
== 0)
48 viewSourceWithSeparator
.setAttribute("hidden", true);
52 viewSourceWithSeparator
.setAttribute("hidden", false);
54 // Loop through the view source with options
55 for(var i
= 1; i
<= viewSourceWithCount
; i
++)
57 description
= "webdeveloper.view.source.with." + i
+ ".description";
58 key
= "webdeveloper.view.source.with." + i
+ ".key";
59 path
= "webdeveloper.view.source.with." + i
+ ".path";
61 // If the description and path are set
62 if(webdeveloper_isPreferenceSet(description
) && webdeveloper_isPreferenceSet(path
))
64 descriptionPreference
= webdeveloper_getStringPreference(description
, true);
66 // If the description is not blank
67 if(descriptionPreference
!= "")
69 menuItem
= document
.createElement("menuitem");
70 menuItem
.setAttribute("class", "webdeveloper-generated-menu");
71 menuItem
.setAttribute("label", descriptionPreference
);
72 menuItem
.setAttribute("oncommand", "webdeveloper_loadApplicationWithSource('" + webdeveloper_getStringPreference(path
, true).replace(/\\/gi
, "\\\\") + "')");
74 // If the key preference is set
75 if(webdeveloper_isPreferenceSet(key
))
77 menuItem
.setAttribute("key", key
);
80 menu
.insertBefore(menuItem
, viewSourceWithSeparator
);
87 // Loads the given application with the source of the current page
88 function webdeveloper_loadApplicationWithSource(application
)
90 // If the application is set
93 application
= new WebDeveloperApplication(application
);
95 application
.launchWithSource(getBrowser().currentURI
);
99 // Toggles the view frame source menu
100 function webdeveloper_toggleViewFrameSourceMenu(suffix
)
103 var frameCount
= webdeveloper_getContentWindow().frames
.length
;
104 var menu
= document
.getElementById("webdeveloper-view-frame-source-" + suffix
);
106 // If there are frames
112 webdeveloper_configureElement(menu
, "disabled", disabled
);
115 // Adjusts the view source menu
116 function webdeveloper_updateViewSourceMenu(menu
, suffix
)
118 webdeveloper_toggleViewFrameSourceMenu(suffix
);
119 webdeveloper_displayViewSourceWithMenu(menu
, suffix
);
122 // View the generated source
123 function webdeveloper_viewGeneratedSource()
125 var currentDocument
= webdeveloper_getContentDocument();
126 var currentWindow
= webdeveloper_getContentWindow();
127 var generatedSourceWindow
= null;
128 var selection
= currentWindow
.getSelection();
130 selection
.selectAllChildren(currentDocument
.documentElement
);
132 generatedSourceWindow
= window
.openDialog("chrome://global/content/viewPartialSource.xul", "_blank", "chrome,dialog=no,resizable,scrollbars", getBrowser().currentURI
.spec
, "charset=" + currentDocument
.characterSet
, currentWindow
.getSelection(), "selection");
134 window
.setTimeout(webdeveloper_clearViewGeneratedSourceSelection
, 1500, selection
, generatedSourceWindow
);
138 function webdeveloper_viewSource(frameDocument
)
140 // If the view source in tab preference is set to true
141 if(webdeveloper_getBooleanPreference("webdeveloper.view.source.tab", true))
143 var newTab
= getBrowser().addTab("view-source:" + frameDocument
.documentURI
);
145 // If the open tabs in background preference is not set to true
146 if(!webdeveloper_getBooleanPreference("webdeveloper.open.tabs.background", true))
148 getBrowser().selectedTab
= newTab
;
153 BrowserViewSourceOfDocument(frameDocument
);