git-svn-id: svn://euphorik.ch/pompage@45 02bbb61a-6d21-0410-aba0-cb053bdfd66a
[pompage.git] / doc / webdeveloper / miscellaneous.js
1 // Clears all private data
2 function webdeveloper_clearAllPrivateData()
3 {
4 // If the browser glue is found
5 if(Components.classes["@mozilla.org/browser/browserglue;1"])
6 {
7 Components.classes["@mozilla.org/browser/browserglue;1"].getService(nsCI.nsIBrowserGlue).sanitize(window || null);
8 }
9 else
10 {
11 window.openDialog("chrome://webdeveloper/content/message/message.xul", "webdeveloper-message-dialog", "centerscreen,chrome,modal", document.getElementById("webdeveloper-string-bundle").getString("webdeveloper_firefox15Required"));
12 }
13 }
14
15 // Clears the cache
16 function webdeveloper_clearCache()
17 {
18 var stringBundle = document.getElementById("webdeveloper-string-bundle");
19
20 // If the clearing is confirmed
21 if(webdeveloper_clearConfirmation(stringBundle.getString("webdeveloper_clearCacheConfirmation")))
22 {
23 var cacheInterface = Components.interfaces.nsICache;
24 var cacheService = Components.classes["@mozilla.org/network/cache-service;1"].getService(Components.interfaces.nsICacheService);
25
26 try
27 {
28 cacheService.evictEntries(cacheInterface.STORE_ON_DISK);
29 cacheService.evictEntries(cacheInterface.STORE_IN_MEMORY);
30
31 // If the hide informational dialogs preference is not set
32 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
33 {
34 webdeveloper_informationalDialog(stringBundle.getString("webdeveloper_clearCache"), stringBundle.getString("webdeveloper_clearCacheResult"));
35 }
36 }
37 catch(exception)
38 {
39 // Do nothing
40 }
41 }
42 }
43
44 // Clears the history
45 function webdeveloper_clearHistory()
46 {
47 var stringBundle = document.getElementById("webdeveloper-string-bundle");
48
49 // If the clearing is confirmed
50 if(webdeveloper_clearConfirmation(stringBundle.getString("webdeveloper_clearHistoryConfirmation")))
51 {
52 webdeveloper_removeAllFromHistory();
53
54 // If the hide informational dialogs preference is not set
55 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
56 {
57 webdeveloper_informationalDialog(stringBundle.getString("webdeveloper_clearHistory"), stringBundle.getString("webdeveloper_clearHistoryResult"));
58 }
59 }
60 }
61
62 // Clears the HTTP authentication
63 function webdeveloper_clearHTTPAuthentication()
64 {
65 var authenticationManager = Components.classes["@mozilla.org/network/http-auth-manager;1"].getService(Components.interfaces.nsIHttpAuthManager);
66
67 authenticationManager.clearAll();
68
69 // If the hide informational dialogs preference is not set
70 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
71 {
72 var stringBundle = document.getElementById("webdeveloper-string-bundle");
73
74 webdeveloper_informationalDialog(stringBundle.getString("webdeveloper_clearHTTPAuthentication"), stringBundle.getString("webdeveloper_clearHTTPAuthenticationResult"));
75 }
76 }
77
78 // Allows the user to edit the HTML of the current page
79 function webdeveloper_editHTML()
80 {
81 var stringBundle = document.getElementById("webdeveloper-string-bundle");
82 var editHTML = stringBundle.getString("webdeveloper_editHTML");
83
84 // If edit HTML is open in the dashboard
85 if(webdeveloper_isOpenInDashboard(editHTML))
86 {
87 webdeveloper_closeInDashboard(editHTML);
88 }
89 else if(webdeveloper_pageHasFrames())
90 {
91 window.openDialog("chrome://webdeveloper/content/message/message.xul", "webdeveloper-message-dialog", "centerscreen,chrome,modal", stringBundle.getString("webdeveloper_framesNotSupported"));
92 }
93 else
94 {
95 webdeveloper_openInDashboard(editHTML, "chrome://webdeveloper/content/dashboard/edit_html.xul");
96 }
97 }
98
99 // Linearizes all elements
100 function webdeveloper_linearizePage(element)
101 {
102 webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/linearize_page.css", "webdeveloper-linearize-page");
103 }
104
105 // Makes all the frames resizable
106 function webdeveloper_makeFramesResizable()
107 {
108 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
109 var documentLength = documentList.length;
110 var frame = null;
111 var framesList = null;
112 var framesLength = null;
113 var pageDocument = null;
114 var resizableFrames = 0;
115
116 // Loop through the documents
117 for(var i = 0; i < documentLength; i++)
118 {
119 pageDocument = documentList[i];
120 framesList = pageDocument.getElementsByTagName("frame");
121 framesLength = framesList.length;
122
123 // Loop through all the frames
124 for(var j = 0; j < framesLength; j++)
125 {
126 frame = framesList[j];
127
128 // If the frame has a no resize attribute
129 if(frame.hasAttribute("noresize"))
130 {
131 frame.removeAttribute("noresize");
132 resizableFrames++;
133 }
134 }
135 }
136
137 // If the hide informational dialogs preference is not set
138 if(!webdeveloper_getBooleanPreference("webdeveloper.informational.dialogs.hide", true))
139 {
140 var stringBundle = document.getElementById("webdeveloper-string-bundle");
141 var title = stringBundle.getString("webdeveloper_makeFramesResizable");
142
143 // If one frame was made resizable
144 if(resizableFrames == 1)
145 {
146 webdeveloper_informationalDialog(title, stringBundle.getString("webdeveloper_makeFramesResizableSingleResult"));
147 }
148 else
149 {
150 webdeveloper_informationalDialog(title, stringBundle.getFormattedString("webdeveloper_makeFramesResizableMultipleResult", [resizableFrames]));
151 }
152 }
153 }
154
155 // Shows all hidden elements
156 function webdeveloper_showHiddenElements()
157 {
158 var computedStyle = null;
159 var display = null;
160 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
161 var documentLength = documentList.length;
162 var element = null;
163 var hiddenElements = new Array("area", "base", "basefont", "head", "meta", "param", "script", "style", "title");
164 var pageDocument = null;
165 var tagName = null;
166 var treeWalker = null;
167
168 // Loop through the documents
169 for(var i = 0; i < documentLength; i++)
170 {
171 pageDocument = documentList[i];
172 treeWalker = pageDocument.createTreeWalker(webdeveloper_getDocumentBodyElement(pageDocument), NodeFilter.SHOW_ELEMENT, null, false);
173
174 // While the tree walker has more nodes
175 while((element = treeWalker.nextNode()) != null)
176 {
177 computedStyle = element.ownerDocument.defaultView.getComputedStyle(element, null);
178
179 // If the computed style is set
180 if(computedStyle)
181 {
182 display = computedStyle.getPropertyCSSValue("display");
183 tagName = element.tagName;
184
185 // If this element has a display and tag name, the display is set to none and the tag name is not script
186 if(display && tagName && display.cssText == "none" && !webdeveloper_contains(hiddenElements, tagName.toLowerCase()))
187 {
188 element.style.display = "";
189 }
190 }
191 }
192 }
193 }
194
195 // Shows the window chrome
196 function webdeveloper_showWindowChrome()
197 {
198 var browserWindow = null;
199 var windowEnumeration = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator).getEnumerator("navigator:browser");
200
201 // Loop through the open windows
202 while(windowEnumeration.hasMoreElements())
203 {
204 browserWindow = windowEnumeration.getNext();
205
206 browserWindow.locationbar.visible = true;
207 browserWindow.menubar.visible = true;
208 browserWindow.personalbar.visible = true;
209 browserWindow.statusbar.visible = true;
210 browserWindow.toolbar.visible = true;
211 }
212 }
213
214 // Renders the page for a small screen
215 function webdeveloper_smallScreenRendering(element)
216 {
217 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
218 var documentLength = documentList.length;
219 var styleSheetList = new Array();
220
221 // Loop through the documents
222 for(var i = 0; i < documentLength; i++)
223 {
224 styleSheetList = styleSheetList.concat(webdeveloper_getStyleSheetsForDocument(documentList[i], false, false));
225 }
226
227 // If there is a handheld style sheet
228 if(webdeveloper_hasStyleSheetForMedia(styleSheetList, "handheld"))
229 {
230 webdeveloper_displayCSSMediaType("handheld", !element.getAttribute("checked"));
231 webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/empty.css", "webdeveloper-small-screen-rendering");
232 }
233 else
234 {
235 webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/small_screen_rendering.css", "webdeveloper-small-screen-rendering");
236 }
237 }
238
239 // Toggles all links on the page between visited and unvisited
240 function webdeveloper_toggleVisitedLinks(visited)
241 {
242 var documentList = webdeveloper_getDocuments(webdeveloper_getContentWindow());
243 var documentLength = documentList.length;
244 var href = null;
245 var link = null;
246 var linkLength = null;
247 var linkList = null;
248 var pageDocument = null;
249
250 // Loop through the documents
251 for(var i = 0; i < documentLength; i++)
252 {
253 pageDocument = documentList[i];
254 linkList = pageDocument.links;
255 linkLength = linkList.length;
256
257 // Loop through all the links
258 for(var j = 0; j < linkLength; j++)
259 {
260 link = linkList[j];
261 href = link.href;
262
263 // If this link has an href
264 if(href)
265 {
266 // If marking links as visited
267 if(visited)
268 {
269 webdeveloper_addToHistory(href);
270 }
271 else
272 {
273 webdeveloper_removeFromHistory(href);
274 }
275
276 // Force the browser to recheck the history by changing the href
277 link.href = "";
278 link.href = href;
279 }
280 }
281 }
282 }
283 // Updates the clear private data menu
284 function webdeveloper_updateClearPrivateDataMenu(suffix)
285 {
286 var menu = document.getElementById("webdeveloper-clear-all-private-data-" + suffix);
287
288 // If the menu exists
289 if(menu)
290 {
291 // If the browser glue is not found
292 if(!Components.classes["@mozilla.org/browser/browserglue;1"])
293 {
294 menu.setAttribute("class", "menuitem-iconic");
295 }
296 else if(menu.hasAttribute("class"))
297 {
298 menu.removeAttribute("class");
299 }
300 }
301 }
302
303 // Updates the miscellaneous menu
304 function webdeveloper_updateMiscellaneousMenu(suffix)
305 {
306 var menu = document.getElementById("webdeveloper-edit-html-" + suffix);
307 var pageHasFrames = webdeveloper_pageHasFrames();
308
309 // If the menu exists
310 if(menu)
311 {
312 var editHTMLOpen = webdeveloper_isOpenInDashboard(document.getElementById("webdeveloper-string-bundle").getString("webdeveloper_editHTML"));
313
314 webdeveloper_configureElement(menu, "checked", editHTMLOpen);
315
316 // If edit HTML is not open and the page has frames
317 if(!editHTMLOpen && pageHasFrames)
318 {
319 menu.setAttribute("class", "menuitem-iconic");
320 }
321 else if(menu.hasAttribute("class"))
322 {
323 menu.removeAttribute("class");
324 }
325 }
326
327 menu = document.getElementById("webdeveloper-display-line-guides-" + suffix);
328
329 // If the menu exists
330 if(menu)
331 {
332 // If the page has frames
333 if(pageHasFrames)
334 {
335 menu.setAttribute("class", "menuitem-iconic");
336 }
337 else if(menu.hasAttribute("class"))
338 {
339 menu.removeAttribute("class");
340 }
341 }
342
343 menu = document.getElementById("webdeveloper-display-page-magnifier-" + suffix);
344
345 // If the menu exists
346 if(menu)
347 {
348 var canvas = document.getElementById("webdeveloper-page-magnifier");
349
350 // If the canvas is not set or has no context
351 if(!canvas || !canvas.getContext)
352 {
353 menu.setAttribute("class", "menuitem-iconic");
354 }
355 else if(menu.hasAttribute("class"))
356 {
357 menu.removeAttribute("class");
358 }
359 }
360
361 menu = document.getElementById("webdeveloper-display-ruler-" + suffix);
362
363 // If the menu exists
364 if(menu)
365 {
366 // If the page has frames
367 if(pageHasFrames)
368 {
369 menu.setAttribute("class", "menuitem-iconic");
370 }
371 else if(menu.hasAttribute("class"))
372 {
373 menu.removeAttribute("class");
374 }
375 }
376
377 webdeveloper_configureElement(document.getElementById("webdeveloper-display-page-magnifier-" + suffix), "checked", !document.getElementById("webdeveloper-page-magnifier-toolbar").hidden);
378 webdeveloper_configureElementByAppliedStyle(document.getElementById("webdeveloper-display-line-guides-" + suffix), "checked", "webdeveloper-display-line-guides");
379 webdeveloper_configureElementByAppliedStyle(document.getElementById("webdeveloper-display-ruler-" + suffix), "checked", "webdeveloper-display-ruler");
380 webdeveloper_configureElementByAppliedStyle(document.getElementById("webdeveloper-linearize-page-" + suffix), "checked", "webdeveloper-linearize-page");
381 webdeveloper_configureElementByAppliedStyle(document.getElementById("webdeveloper-show-comments-" + suffix), "checked", "webdeveloper-show-comments");
382 webdeveloper_configureElementByAppliedStyle(document.getElementById("webdeveloper-small-screen-rendering-" + suffix), "checked", "webdeveloper-small-screen-rendering");
383 }