-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy path_helper.js
More file actions
382 lines (294 loc) · 13.5 KB
/
_helper.js
File metadata and controls
382 lines (294 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
var AiOS_HELPER = {
init: function() {
this.prefInterface = Components.interfaces.nsIPrefBranch;
this.prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
this.prefBranch = this.prefService.getBranch(null);
this.prefBranchAiOS = this.prefService.getBranch("extensions.aios.");
this.windowWatcher = Components.classes["@mozilla.org/embedcomp/window-watcher;1"].getService(Components.interfaces.nsIWindowWatcher);
this.windowMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
this.mostRecentWindow = this.windowMediator.getMostRecentWindow('navigator:browser');
this.appInfo = Components.classes['@mozilla.org/xre/app-info;1'].getService(Components.interfaces.nsIXULAppInfo);
this.os = Components.classes['@mozilla.org/xre/app-info;1'].getService(Components.interfaces.nsIXULRuntime).OS;
this.osVersion = window.navigator.oscpu;
this.defTheme = (this.prefBranch.getCharPref('general.skins.selectedSkin') == "classic/1.0") ? true : false;
},
initOnDOMLoaded: function() {
AiOS_HELPER.aiosToolbar = document.getElementById('aios-toolbar');
AiOS_HELPER.sbhToolbar = document.getElementById('aios-sbhtoolbar');
},
rememberAppInfo: function(aObj) {
aObj.setAttribute('aios-appVendor', this.appInfo.vendor);
aObj.setAttribute('aios-appVersion', this.appInfo.version);
aObj.setAttribute('aios-appOS', this.os);
aObj.setAttribute('aios-appOSVersion', this.osVersion);
aObj.setAttribute('aios-appDefTheme', this.defTheme);
},
unload: function() {
window.removeEventListener("DOMContentLoaded", AiOS_HELPER.initOnDOMLoaded);
//window.removeEventListener("load", AiOS_HELPER.initOnLoad);
window.removeEventListener("unload", AiOS_HELPER.unload);
}
};
AiOS_HELPER.init();
window.addEventListener("DOMContentLoaded", AiOS_HELPER.initOnDOMLoaded, false);
window.addEventListener("unload", AiOS_HELPER.unload, false);
// globale Variablen und Funktionen zur Ueberwachung auf Progress-Veraenderungen
// Verwendung in pageInfo.xul
var aios_ProgListStart = Components.interfaces.nsIWebProgressListener.STATE_START;
var aios_ProgListStop = Components.interfaces.nsIWebProgressListener.STATE_STOP;
var aiosProgListener = {
QueryInterface: function(aIID) {
if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
aIID.equals(Components.interfaces.nsISupports))
return this;
throw Components.results.NS_NOINTERFACE;
},
onStateChange: function(aProgress, aRequest, aFlag, aStatus) {
//if(aFlag & aios_ProgListStart) { /* This fires when the load event is initiated */ }
//if(aFlag & aios_ProgListStop) { /* This fires when the load finishes */ }
if(aFlag & aios_ProgListStop) {
if(typeof aios_onStateChange == "function") aios_onStateChange();
}
return 0;
},
onLocationChange: function(aProgress, aRequest, aURI) {
// This fires when the location bar changes i.e load event is confirmed
// or when the user switches tabs
if(typeof aios_onLocationChange == "function") aios_onLocationChange();
return 0;
},
// For definitions of the remaining functions see XulPlanet.com
onProgressChange: function() {
return 0;
},
onStatusChange: function() {
return 0;
},
onSecurityChange: function() {
return 0;
},
onLinkIconAvailable: function() {
return 0;
}
};
/*
oeffnet ein neues Tab mit der uebergebenen Adresse im Vordergrund
*/
var aiosLastSelTab; // wird fuer Page Info/MultiPanel im Tab benoetigt
function aios_addTab(aUrl) {
var browser = AiOS_HELPER.mostRecentWindow.getBrowser();
aiosLastSelTab = AiOS_HELPER.mostRecentWindow.content;
var browserDoc;
var existTab = null;
var emptyTab = null;
// alle geoeffneten Tabs durchgehen
for(var i = 0; i < browser.tabContainer.childNodes.length; i++) {
browserDoc = browser.getBrowserAtIndex(i).contentWindow.document;
//alert(browser.getBrowserAtIndex(i).currentURI.spec);
var isPermaTab = (browser.tabContainer.childNodes[i].getAttribute('isPermaTab')) ? true : false;
// wenn der Tab leer ist
if(browserDoc.location.href == "about:blank" && browser.selectedTab.getAttribute('openBy') != "aios" && !isPermaTab && emptyTab == null)
emptyTab = i;
// wenn der Tab schon existiert
if(browserDoc.location.href == aUrl && !isPermaTab && existTab == null)
existTab = i;
}
// wenn der Tab schon existiert
if(existTab != null) {
browser.selectedTab = browser.tabContainer.childNodes[existTab];
return browser.selectedTab;
}
// wenn der Tab leer ist
if(emptyTab != null) {
// URL oeffnen und Tab selektieren
browser.getBrowserAtIndex(emptyTab).contentWindow.document.location.href = aUrl;
browser.selectedTab = browser.tabContainer.childNodes[emptyTab];
browser.selectedTab.setAttribute('openBy', 'aios');
return browser.selectedTab;
}
// wenn kein leerer Tab vorhanden war, wird ein neuer geoeffnet
browser.selectedTab = browser.addTab(aUrl);
browser.selectedTab.setAttribute('openBy', 'aios');
return browser.selectedTab;
}
/*
fuegt dem Dokument dynamisch ein Stylesheet hinzu
=> Aufruf u.a. durch aios_init() und aios_sidebarLayout() bei den Add-ons, Downloads
*/
function aios_addCSS(aURI, aBefore) {
var path = "chrome://aios/skin/css/";
var elem = (typeof aBefore == "object") ? aBefore : document.getElementById(aBefore);
var css = document.createProcessingInstruction("xml-stylesheet", 'href="' + path + aURI + '" type="text/css"');
document.insertBefore(css, elem);
}
/*
errechnet die Breite des Browsers exkl. der AIOS-Toolbar
=> Aufruf durch aios_setSidebarDefWidth() in aios.js und aios_setSidebarWidth() in general.js
*/
function aios_getBrowserWidth() {
var cStyleSidebar = AiOS_HELPER.mostRecentWindow.document.defaultView.getComputedStyle(AiOS_HELPER.mostRecentWindow.document.getElementById('sidebar-box'), '');
var cStyleSplitter = AiOS_HELPER.mostRecentWindow.document.defaultView.getComputedStyle(AiOS_HELPER.mostRecentWindow.document.getElementById('sidebar-splitter'), '');
var cStyleContent = AiOS_HELPER.mostRecentWindow.document.defaultView.getComputedStyle(AiOS_HELPER.mostRecentWindow.document.getElementById('appcontent'), '');
var widthSidebar = parseInt(cStyleSidebar.width) + parseInt(cStyleSidebar.paddingLeft) + parseInt(cStyleSidebar.paddingRight) + parseInt(cStyleSidebar.marginLeft) + parseInt(cStyleSidebar.marginRight);
var widthSplitter = parseInt(cStyleSplitter.width) + parseInt(cStyleSplitter.paddingLeft) + parseInt(cStyleSplitter.paddingRight) + parseInt(cStyleSplitter.marginLeft) + parseInt(cStyleSplitter.marginRight);
var widthContent = parseInt(cStyleContent.width) + parseInt(cStyleContent.paddingLeft) + parseInt(cStyleContent.paddingRight) + parseInt(cStyleContent.marginLeft) + parseInt(cStyleContent.marginRight);
var compWidth = widthSidebar + widthSplitter + widthContent;
var ret_arr = new Array(widthSidebar, widthSplitter, widthContent, compWidth);
return(ret_arr);
}
/*
erweitert das Attribut "class" eines Elementes
*/
function aios_appendClass(elem, appClass) {
if(typeof elem == "string") elem = document.getElementById(elem);
var old_class = elem.getAttribute('class');
if(old_class.indexOf(appClass) < 0) elem.setAttribute('class', old_class + " " + appClass);
}
/*
loescht einen Klassennamen im Attribut "class" eines Elementes
*/
function aios_stripClass(elem, stripClass) {
if(typeof elem == "string") elem = document.getElementById(elem);
var old_class = elem.getAttribute('class');
if(old_class.indexOf(stripClass) >= 0) {
var pos = old_class.indexOf(stripClass);
var slice1 = old_class.substring(0, pos);
slice1 = slice1.replace(/ /, "");
var slice2 = old_class.substring(pos + stripClass.length, old_class.length);
slice2 = slice2.replace(/ /, "");
elem.setAttribute('class', slice1 + " " + slice2);
}
}
function aios_gElem(aID) {
if(AiOS_HELPER.mostRecentWindow && AiOS_HELPER.mostRecentWindow.document.getElementById(aID)) return AiOS_HELPER.mostRecentWindow.document.getElementById(aID);
return false;
}
/*
* ersetzt fuer MacOS X die Angaben zu Tastaturkuerzeln in den Tooltips
*
**/
function aios_replaceKey(aElem, aAttr, aKey) {
var strings = document.getElementById("aiosProperties");
var rep_elem = document.getElementById(aElem);
var rep = rep_elem.getAttribute(aAttr);
rep = rep.substr(rep.indexOf('+'), rep.length);
rep_elem.setAttribute(aAttr, strings.getString('key.mac.' + aKey) + rep);
}
/*
gibt den boolschen Wert eines Wertes zurueck
=> getAttribute(val) liefert nur "true" oder "false" als String
*/
function aios_getBoolean(aElem, aVal) {
var elem, bool;
if(typeof aElem == "object") {
elem = aElem;
}
else if(typeof aElem == "string" && document.getElementById(aElem)) {
elem = document.getElementById(aElem);
}
if(elem) {
if(typeof elem.getAttribute == "function") bool = elem.getAttribute(aVal);
}
if(bool == "true") return true;
else return false;
}
/*
Dialoge oeffnen
*/
function aios_openDialog(which, args) {
var theUrl, theId, theFeatures;
var theArgs = args;
switch(which) {
case "prefs":
theUrl = "chrome://aios/content/prefs/prefs.xul";
theId = "aiosPrefsDialog";
theFeatures = "chrome,titlebar,toolbar,centerscreen,";
theFeatures+= (AiOS_HELPER.os == "Darwin") ? "dialog=no" : "modal";
break;
case "about":
theUrl = "chrome://aios/content/about.xul";
theId = "aiosAboutDialog";
theFeatures = "chrome,modal";
break;
case "bookmarks":
theUrl = "chrome://browser/content/bookmarks/bookmarksPanel.xul";
theId = "aiosGlobal:Bookmarks";
theFeatures = "width=640,height=480,chrome,resizable,centerscreen";
break;
case "history":
theUrl = "chrome://browser/content/history/history-panel.xul";
theId = "aiosGlobal:History";
theFeatures = "width=640,height=480,chrome,resizable,centerscreen";
break;
case "multipanel":
theUrl = "chrome://browser/content/web-panels.xul";
theId = "aiosGlobal:MultiPanel";
theFeatures = "width=640,height=480,chrome,resizable,centerscreen";
break;
}
if(which == "prefs" || which == "about") openDialog(theUrl, theId, theFeatures, theArgs);
else toOpenWindowByType(theId, theUrl, theFeatures);
}
/*
toggelt einen Menuepunkt und das/die zugehoerige/n Element/e
=> Aufruf durch die menuitems in der aios.xul
*/
function aios_toggleElement(aMenuitem) {
var menuitem;
if(typeof aMenuitem != "object") aMenuitem = document.getElementById(aMenuitem);
if(aMenuitem.getAttribute('observes')) {
menuitem = document.getElementById(aMenuitem.getAttribute('observes'));
}
else {
menuitem = document.getElementById(aMenuitem.id);
}
var mode = aios_getBoolean(menuitem, 'checked');
var childElems = menuitem.getAttribute('aiosChilds');
menuitem.setAttribute('checked', !mode);
aios_toggleChilds(childElems, mode);
}
/*
toggelt Kindelemente eines Menuepunkts
=> Aufruf durch aios_toggleElement()
*/
function aios_toggleChilds(childElems, childMode) {
var child_str, child;
if(childElems != "") {
var childElems_arr = childElems.split(",");
for(var i = 0; i < childElems_arr.length; i++) {
child_str = childElems_arr[i].replace(/ /, "");
var idChilds_arr = document.getElementsByAttribute('id', child_str);
// wenn es nur ein Element mit der ID gibt...
if(idChilds_arr.length == 1) {
child = document.getElementById(child_str);
}
// wenn es mehrere Elemente mit der ID gibt...
else {
for(var j = 0; j < idChilds_arr.length; j++) {
//... nimm das auf der AIOS-Toolbar
if(idChilds_arr[j].parentNode.id == "aios-toolbar") child = idChilds_arr[j];
}
}
if(child) child.setAttribute('hidden', childMode);
}
}
}
/**
* Tastaturkuerzel entfernen, um nicht die des Hauptbrowsers zu blockieren
*
* => Aufruf in downloads.js, pageinfo.js
**/
function aios_removeAccesskeys() {
var keys = document.getElementsByAttribute('accesskey', '*');
for(var i = 0; i < keys.length; i++) {
keys[i].removeAttribute('accesskey')
}
}
/**
*
**/
function aios_hideMacMenubar() {
if(document.getElementById('main-menubar'))
document.getElementById('main-menubar').style.display = "none";
}