git-svn-id: svn://euphorik.ch/pompage@46 02bbb61a-6d21-0410-aba0-cb053bdfd66a
[pompage.git] / doc / webdeveloper / dashboard / dashboard.js
1 // Closes the selected dashboard tab
2 function webdeveloper_closeDashboardTab()
3 {
4 var tabBox = document.getElementById("webdeveloper-dashboard-tab-box");
5 var selectedTabPanel = tabBox.selectedPanel;
6 var tabPanels = document.getElementById("webdeveloper-dashboard-tab-panels");
7 var tabs = document.getElementById("webdeveloper-dashboard-tabs");
8
9 // If the selected tab panel is set
10 if(selectedTabPanel)
11 {
12 tabPanels.removeChild(selectedTabPanel);
13 }
14 else
15 {
16 tabPanels.removeChild(tabPanels.childNodes[tabBox.selectedIndex]);
17 }
18
19 tabs.removeChild(tabBox.selectedTab);
20
21 // If there are no tab panels remaining
22 if(tabPanels.childNodes.length == 0)
23 {
24 document.getElementById("webdeveloper-dashboard").hidden = true;
25 document.getElementById("webdeveloper-dashboard-splitter").hidden = true;
26 }
27 else
28 {
29 tabs.selectedIndex = 0;
30 }
31 }
32
33 // Closes the given tab in the dashboard
34 function webdeveloper_closeInDashboard(title)
35 {
36 var position = 0;
37 var tab = null;
38 var tabPanels = document.getElementById("webdeveloper-dashboard-tab-panels");
39 var tabs = document.getElementById("webdeveloper-dashboard-tabs");
40 var tabElements = tabs.childNodes;
41 var tabsLength = tabElements.length;
42
43 // Loop through the tabs
44 for(var i = 0; i < tabsLength; i++)
45 {
46 tab = tabElements.item(i);
47
48 // If this is a tab
49 if(tab.nodeName == "tab")
50 {
51 // If the tab has a matching label attribute
52 if(tab.hasAttribute("label") && tab.getAttribute("label") == title)
53 {
54 break;
55 }
56
57 position++;
58 }
59 }
60
61 // If a tab was matched
62 if(position < tabsLength)
63 {
64 tabPanels.removeChild(tabPanels.childNodes[position]);
65 tabs.removeItemAt(position);
66
67 // If there are no tab panels remaining
68 if(tabPanels.childNodes.length == 0)
69 {
70 document.getElementById("webdeveloper-dashboard").hidden = true;
71 document.getElementById("webdeveloper-dashboard-splitter").hidden = true;
72 }
73 else
74 {
75 tabs.selectedIndex = 0;
76 }
77 }
78 }
79
80 // Returns the document for given tab in the dashboard
81 function webdeveloper_getDocumentInDashboard(title)
82 {
83 var position = 0;
84 var tab = null;
85 var tabPanels = document.getElementById("webdeveloper-dashboard-tab-panels");
86 var tabs = document.getElementById("webdeveloper-dashboard-tabs");
87 var tabElements = tabs.childNodes;
88 var tabsLength = tabElements.length;
89
90 // Loop through the tabs
91 for(var i = 0; i < tabsLength; i++)
92 {
93 tab = tabElements.item(i);
94
95 // If this is a tab
96 if(tab.nodeName == "tab")
97 {
98 // If the tab has a matching label attribute
99 if(tab.hasAttribute("label") && tab.getAttribute("label") == title)
100 {
101 break;
102 }
103
104 position++;
105 }
106 }
107
108 // If a tab was matched
109 if(position < tabsLength)
110 {
111 return tabPanels.childNodes[position].childNodes[0].contentDocument;
112 }
113
114 return null;
115 }
116
117 // Is the given tab open in the dashboard
118 function webdeveloper_isOpenInDashboard(title)
119 {
120 var tab = null;
121 var tabs = document.getElementById("webdeveloper-dashboard-tabs").childNodes;
122 var tabsLength = tabs.length;
123
124 // Loop through the tabs
125 for(var i = 0; i < tabsLength; i++)
126 {
127 tab = tabs.item(i);
128
129 // If this is a tab and it has a matching label attribute
130 if(tab.nodeName == "tab" && tab.hasAttribute("label") && tab.getAttribute("label") == title)
131 {
132 return true;
133 }
134 }
135
136 return false;
137 }
138
139 // Opens the given URL in the dashboard
140 function webdeveloper_openInDashboard(title, url)
141 {
142 var browser = document.createElement("browser");
143 var tab = document.createElement("tab");
144 var tabCount = 0;
145 var tabPanel = document.createElement("tabpanel");
146 var tabPanels = document.getElementById("webdeveloper-dashboard-tab-panels");
147 var tabs = document.getElementById("webdeveloper-dashboard-tabs");
148
149 browser.setAttribute("flex", "1");
150 browser.setAttribute("src", url);
151 tabPanel.appendChild(browser);
152 tab.setAttribute("label", title);
153
154 tabPanels.appendChild(tabPanel);
155 tabs.insertBefore(tab, document.getElementById("webdeveloper-dashboard-spacer"));
156
157 tabCount = tabPanels.childNodes.length - 1;
158 tabs.selectedIndex = tabCount;
159
160 // If this is the only tab
161 if(tabCount == 0)
162 {
163 var dashboard = document.getElementById("webdeveloper-dashboard");
164
165 // If the dashboard height is less than 100
166 if(dashboard.height < 100)
167 {
168 dashboard.height = 100;
169 }
170
171 // If the dashboard width is less than 100
172 if(dashboard.width < 100)
173 {
174 dashboard.width = 100;
175 }
176
177 dashboard.hidden = false;
178 document.getElementById("webdeveloper-dashboard-splitter").hidden = false;
179 }
180 }
181
182 // Positions the dashboard
183 function webdeveloper_positionDashboard()
184 {
185 var currentPosition = webdeveloper_getStringPreference("webdeveloper.dashboard.position", true);
186 var dashboard = document.getElementById("webdeveloper-dashboard");
187 var dashboardSplitter = document.getElementById("webdeveloper-dashboard-splitter");
188
189 dashboard.hidden = true;
190 dashboardSplitter.hidden = true;
191
192 // If the current position is bottom
193 if(currentPosition == "bottom")
194 {
195 webdeveloper_setStringPreference("webdeveloper.dashboard.position", "left");
196 webdeveloper_setupDashboardPosition("left");
197 }
198 else if(currentPosition == "left")
199 {
200 webdeveloper_setStringPreference("webdeveloper.dashboard.position", "top");
201 webdeveloper_setupDashboardPosition("top");
202 }
203 else if(currentPosition == "right")
204 {
205 webdeveloper_setStringPreference("webdeveloper.dashboard.position", "bottom");
206 webdeveloper_setupDashboardPosition("bottom");
207 }
208 else if(currentPosition == "top")
209 {
210 webdeveloper_setStringPreference("webdeveloper.dashboard.position", "right");
211 webdeveloper_setupDashboardPosition("right");
212 }
213
214 dashboard.hidden = false;
215 dashboardSplitter.hidden = false;
216 }
217
218 // Selects the given tab in the dashboard
219 function webdeveloper_selectInDashboard(title)
220 {
221 var tab = null;
222 var tabs = document.getElementById("webdeveloper-dashboard-tabs").childNodes;
223 var tabsLength = tabs.length;
224
225 // Loop through the tabs
226 for(var i = 0; i < tabsLength; i++)
227 {
228 tab = tabs.item(i);
229
230 // If this is a tab and it has a matching label attribute
231 if(tab.nodeName == "tab" && tab.hasAttribute("label") && tab.getAttribute("label") == title)
232 {
233 tabs.selectedIndex = i;
234
235 break;
236 }
237 }
238 }
239
240 // Sets up the dashboard position
241 function webdeveloper_setupDashboardPosition(position)
242 {
243 var appContent = document.getElementById("appcontent");
244 var dashboard = document.getElementById("webdeveloper-dashboard");
245 var dashboardSplitter = document.getElementById("webdeveloper-dashboard-splitter");
246
247 // If the current position is bottom
248 if(position == "bottom")
249 {
250 appContent.appendChild(dashboardSplitter);
251 appContent.appendChild(dashboard);
252 }
253 else if(position == "left")
254 {
255 var browser = appContent.parentNode;
256
257 browser.insertBefore(dashboard, appContent);
258 browser.insertBefore(dashboardSplitter, appContent);
259 }
260 else if(position == "right")
261 {
262 webdeveloper_insertAfter(dashboard, appContent);
263 webdeveloper_insertAfter(dashboardSplitter, appContent);
264 }
265 else if(position == "top")
266 {
267 webdeveloper_insertAsFirstChild(appContent, dashboardSplitter);
268 webdeveloper_insertAsFirstChild(appContent, dashboard);
269 }
270
271 // If the position is bottom or top
272 if(position == "bottom" || position == "top")
273 {
274 dashboardSplitter.setAttribute("orient", "vertical");
275 }
276 else if((position == "left" || position == "right") && dashboardSplitter.hasAttribute("orient"))
277 {
278 dashboardSplitter.removeAttribute("orient");
279 }
280 }