git-svn-id: svn://euphorik.ch/pompage@45 02bbb61a-6d21-0410-aba0-cb053bdfd66a
[pompage.git] / doc / webdeveloper / tools.js
1 // Loads the given application with the given URL
2 function webdeveloper_loadApplicationWithURL(application, url)
3 {
4 // If the application and URL are set
5 if(application && url)
6 {
7 application = new WebDeveloperApplication(application);
8
9 application.launchWithURL(url);
10 }
11 }
12
13 // Opens the DOM Inspector
14 function webdeveloper_openDOMInspector()
15 {
16 // If the DOM Inspector is available
17 if(webdeveloper_isDOMInspectorAvailable())
18 {
19 // If the open DOM Inspector in dashboard preference is set to true
20 if(webdeveloper_getBooleanPreference("webdeveloper.dom.inspector.dashboard", true))
21 {
22 var domInspector = document.getElementById("webdeveloper-string-bundle").getString("webdeveloper_domInspector");
23
24 // If the DOM inspector is already open in the dashboard
25 if(webdeveloper_isOpenInDashboard(domInspector))
26 {
27 webdeveloper_closeInDashboard(domInspector);
28 }
29 else
30 {
31 webdeveloper_openInDashboard(domInspector, "chrome://inspector/content/sidebar.xul");
32 window.setTimeout(BrowserReload, 1000);
33 }
34 }
35 else
36 {
37 inspectDOMDocument(webdeveloper_getContentDocument());
38 }
39 }
40 else
41 {
42 window.openDialog("chrome://webdeveloper/content/message/message.xul", "webdeveloper-message-dialog", "centerscreen,chrome,modal", document.getElementById("webdeveloper-string-bundle").getString("webdeveloper_domInspectorRequired"), "http://chrispederick.com/work/web-developer/documentation/faq/#dom-inspector");
43 }
44 }
45
46 // Opens the Java Console
47 function webdeveloper_openJavaConsole()
48 {
49 Components.classes["@mozilla.org/oji/jvm-mgr;1"].getService(Components.interfaces.nsIJVMManager).showJavaConsole();
50 }
51
52 // Updates the tools menu
53 function webdeveloper_updateToolsMenu(menu, suffix)
54 {
55 var bookmarklet = null;
56 var bookmarkletPreference = null;
57 var description = null;
58 var descriptionPreference = null;
59 var key = null;
60 var menuItem = null;
61 var path = null;
62 var separator = null;
63 var stringBundle = document.getElementById("webdeveloper-string-bundle");
64 var toolPreference = null;
65 var toolsCount = webdeveloper_getIntegerPreference("webdeveloper.tool.count", true);
66 var toolsSeparator = menu.getElementsByAttribute("id", "webdeveloper-tools-separator1-" + suffix)[0];
67 var url = null;
68
69 webdeveloper_removeGeneratedMenuItems(menu);
70
71 // Loop through the possible tools
72 for(var i = 1; i <= toolsCount; i++)
73 {
74 bookmarklet = "webdeveloper.tool." + i + ".bookmarklet";
75 description = "webdeveloper.tool." + i + ".description";
76 key = "webdeveloper.tool." + i + ".key";
77 path = "webdeveloper.tool." + i + ".path";
78 separator = "webdeveloper.tool." + i + ".separator";
79 url = "webdeveloper.tool." + i + ".url";
80
81 // If the separator preference is set
82 if(webdeveloper_getBooleanPreference(separator, true))
83 {
84 menuItem = document.createElement("menuseparator");
85 menuItem.setAttribute("class", "webdeveloper-generated-menu");
86 menu.insertBefore(menuItem, toolsSeparator);
87 }
88 else if(webdeveloper_isPreferenceSet(description) && (webdeveloper_isPreferenceSet(bookmarklet) || webdeveloper_isPreferenceSet(path) || webdeveloper_isPreferenceSet(url)))
89 {
90 descriptionPreference = webdeveloper_getStringPreference(description, true);
91
92 // If the description is not blank
93 if(descriptionPreference != "")
94 {
95 menuItem = document.createElement("menuitem");
96
97 menuItem.setAttribute("class", "webdeveloper-generated-menu");
98 menuItem.setAttribute("label", descriptionPreference);
99
100 // If the bookmarklet preference is set
101 if(webdeveloper_getStringPreference(bookmarklet, true))
102 {
103 menuItem.setAttribute("oncommand", "webdeveloper_runBookmarklet('" + encodeURIComponent(webdeveloper_getStringPreference(bookmarklet, true)).replace(new RegExp("'", "gi"), "\\'") + "')");
104 }
105 else if(webdeveloper_getStringPreference(path, true))
106 {
107 menuItem.setAttribute("oncommand", "webdeveloper_loadApplicationWithURL('" + webdeveloper_getStringPreference(path, true).replace(/\\/gi, "\\\\") + "', getBrowser().currentURI.spec)");
108 }
109 else
110 {
111 menuItem.setAttribute("oncommand", "webdeveloper_loadURL('" + webdeveloper_getStringPreference(url, true) + "' + encodeURIComponent(getBrowser().currentURI.spec))");
112 }
113
114 // If the key preference is set
115 if(webdeveloper_isPreferenceSet(key))
116 {
117 menuItem.setAttribute("key", key);
118 }
119
120 menu.insertBefore(menuItem, toolsSeparator);
121 }
122 }
123 }
124
125 menuItem = document.getElementById("webdeveloper-dom-inspector-" + suffix);
126
127 // If the menu exists
128 if(menuItem)
129 {
130 // If the DOM Inspector is not available
131 if(!webdeveloper_isDOMInspectorAvailable())
132 {
133 menuItem.setAttribute("class", "menuitem-iconic");
134 }
135 else if(menuItem.hasAttribute("class"))
136 {
137 menuItem.removeAttribute("class");
138 }
139 }
140
141 webdeveloper_configureElement(document.getElementById("webdeveloper-dom-inspector-" + suffix), "checked", webdeveloper_isOpenInDashboard(stringBundle.getString("webdeveloper_domInspector")));
142 webdeveloper_configureElement(document.getElementById("webdeveloper-display-page-validation-" + suffix), "checked", !document.getElementById("webdeveloper-page-validation-toolbar").hidden);
143 webdeveloper_configureElement(document.getElementById("webdeveloper-error-console-" + suffix), "checked", webdeveloper_isOpenInDashboard(stringBundle.getString("webdeveloper_errorConsole")));
144 }
145
146 // Validates a local HTML file for accessibility
147 function webdeveloper_validateLocalAccessibility()
148 {
149 new WebDeveloperValidateAccessibility().validateAccessibility(getBrowser().currentURI);
150 }
151
152 // Validates local CSS
153 function webdeveloper_validateLocalCSS()
154 {
155 new WebDeveloperValidateCSS().validateCSS(getBrowser().currentURI, webdeveloper_getDocuments(webdeveloper_getContentWindow()));
156 }
157
158 // Validates a local HTML file
159 function webdeveloper_validateLocalHTML()
160 {
161 new WebDeveloperValidateHTML().validateHTML(getBrowser().currentURI);
162 }