git-svn-id: svn://euphorik.ch/pompage@45 02bbb61a-6d21-0410-aba0-cb053bdfd66a
[pompage.git] / doc / webdeveloper / view_source.js
1 // Clears the view generated source selection
2 function webdeveloper_clearViewGeneratedSourceSelection(selection, generatedSourceWindow)
3 {
4 selection.removeAllRanges();
5 generatedSourceWindow.document.getElementById("content").contentWindow.getSelection().removeAllRanges();
6 }
7
8 // Displays the view frame source menu
9 function webdeveloper_displayViewFrameSourceMenu(menu)
10 {
11 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
12 var documentLength = documentList.length;
13 var menuItem = null;
14 var pageDocument = null;
15
16 webdeveloper_removeGeneratedMenuItems(menu);
17
18 // Loop through the documents
19 for(var i = 0; i < documentLength; i++)
20 {
21 menuItem = document.createElement("menuitem");
22 pageDocument = documentList[i];
23 menuItem.pageDocument = pageDocument;
24
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);
29 }
30 }
31
32 // Displays the view source with menu
33 function webdeveloper_displayViewSourceWithMenu(menu, suffix)
34 {
35 var description = null;
36 var descriptionPreference = null;
37 var key = null;
38 var menuItem = document.createElement("menuitem");
39 var path = null;
40 var viewSourceWithCount = webdeveloper_getIntegerPreference("webdeveloper.view.source.with.count", true);
41 var viewSourceWithSeparator = menu.getElementsByAttribute("id", "webdeveloper-view-source-separator3-" + suffix)[0];
42
43 webdeveloper_removeGeneratedMenuItems(menu);
44
45 // If there are no view source with applications
46 if(viewSourceWithCount == 0)
47 {
48 viewSourceWithSeparator.setAttribute("hidden", true);
49 }
50 else
51 {
52 viewSourceWithSeparator.setAttribute("hidden", false);
53
54 // Loop through the view source with options
55 for(var i = 1; i <= viewSourceWithCount; i++)
56 {
57 description = "webdeveloper.view.source.with." + i + ".description";
58 key = "webdeveloper.view.source.with." + i + ".key";
59 path = "webdeveloper.view.source.with." + i + ".path";
60
61 // If the description and path are set
62 if(webdeveloper_isPreferenceSet(description) && webdeveloper_isPreferenceSet(path))
63 {
64 descriptionPreference = webdeveloper_getStringPreference(description, true);
65
66 // If the description is not blank
67 if(descriptionPreference != "")
68 {
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, "\\\\") + "')");
73
74 // If the key preference is set
75 if(webdeveloper_isPreferenceSet(key))
76 {
77 menuItem.setAttribute("key", key);
78 }
79
80 menu.insertBefore(menuItem, viewSourceWithSeparator);
81 }
82 }
83 }
84 }
85 }
86
87 // Loads the given application with the source of the current page
88 function webdeveloper_loadApplicationWithSource(application)
89 {
90 // If the application is set
91 if(application)
92 {
93 application = new WebDeveloperApplication(application);
94
95 application.launchWithSource(getBrowser().currentURI);
96 }
97 }
98
99 // Toggles the view frame source menu
100 function webdeveloper_toggleViewFrameSourceMenu(suffix)
101 {
102 var disabled = true;
103 var frameCount = webdeveloper_getContentWindow().frames.length;
104 var menu = document.getElementById("webdeveloper-view-frame-source-" + suffix);
105
106 // If there are frames
107 if(frameCount > 0)
108 {
109 disabled = false;
110 }
111
112 webdeveloper_configureElement(menu, "disabled", disabled);
113 }
114
115 // Adjusts the view source menu
116 function webdeveloper_updateViewSourceMenu(menu, suffix)
117 {
118 webdeveloper_toggleViewFrameSourceMenu(suffix);
119 webdeveloper_displayViewSourceWithMenu(menu, suffix);
120 }
121
122 // View the generated source
123 function webdeveloper_viewGeneratedSource()
124 {
125 var currentDocument = webdeveloper_getContentDocument();
126 var currentWindow = webdeveloper_getContentWindow();
127 var generatedSourceWindow = null;
128 var selection = currentWindow.getSelection();
129
130 selection.selectAllChildren(currentDocument.documentElement);
131
132 generatedSourceWindow = window.openDialog("chrome://global/content/viewPartialSource.xul", "_blank", "chrome,dialog=no,resizable,scrollbars", getBrowser().currentURI.spec, "charset=" + currentDocument.characterSet, currentWindow.getSelection(), "selection");
133
134 window.setTimeout(webdeveloper_clearViewGeneratedSourceSelection, 1500, selection, generatedSourceWindow);
135 }
136
137 // View source
138 function webdeveloper_viewSource(frameDocument)
139 {
140 // If the view source in tab preference is set to true
141 if(webdeveloper_getBooleanPreference("webdeveloper.view.source.tab", true))
142 {
143 var newTab = getBrowser().addTab("view-source:" + frameDocument.documentURI);
144
145 // If the open tabs in background preference is not set to true
146 if(!webdeveloper_getBooleanPreference("webdeveloper.open.tabs.background", true))
147 {
148 getBrowser().selectedTab = newTab;
149 }
150 }
151 else
152 {
153 BrowserViewSourceOfDocument(frameDocument);
154 }
155 }