~ubuntu-branches/ubuntu/karmic/all-in-one-sidebar/karmic

« back to all changes in this revision

Viewing changes to content/_common.js

  • Committer: Bazaar Package Importer
  • Author(s): Sveinung Kvilhaugsvik
  • Date: 2009-08-04 19:25:10 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090804192510-u4bm1ehm9ve4zdne
Tags: 0.7.10-0ubuntu1
* new upstream release (LP: #398535)
* list firefox-3.5 as alternate dependency
* depend on ${misc:Depends} to fix lintian warning
* changed maintainer field do to change in rules
* merged all-in-one-sidebar 0.7.4-0ubuntu2
   + replace current watchfile with the one from it
   + add the change log entry from it
   + discard it's other changes
* bump standards-version to 3.8.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
// globale Variablen f�r Preferences-Zugriff
 
3
var aios_pBranch = Components.interfaces.nsIPrefBranch;
 
4
var aios_gPref = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
 
5
var aios_gPrefBranchN = aios_gPref.getBranch(null);
 
6
var aios_gPrefBranch = aios_gPref.getBranch("extensions.aios.");
 
7
 
 
8
 
 
9
// globale Variablen f�r Browser-Zugriff
 
10
var aios_WW = Components.classes["@mozilla.org/embedcomp/window-watcher;1"].getService(Components.interfaces.nsIWindowWatcher);
 
11
var aios_WM = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
 
12
var aios_WIN = aios_WM.getMostRecentWindow('navigator:browser');
 
13
var aios_APPCONTENT = aios_WIN.document.getElementById('appcontent');
 
14
 
 
15
 
 
16
var aios_XULAppInfo = Components.classes['@mozilla.org/xre/app-info;1'].getService(Components.interfaces.nsIXULAppInfo);
 
17
// {ec8030f7-c20a-464f-9b0e-13a3a9e97384} => Firefox; {a463f10c-3994-11da-9945-000d60ca027b} => Flock
 
18
var aios_appID = aios_XULAppInfo.ID;
 
19
// Mozilla, Flock
 
20
var aios_appVendor = aios_XULAppInfo.vendor;
 
21
var aios_appVersion = aios_XULAppInfo.version;
 
22
// WINNT, Darwin
 
23
var aios_appOS = Components.classes['@mozilla.org/xre/app-info;1'].getService(Components.interfaces.nsIXULRuntime).OS;
 
24
// true, false
 
25
var aios_appDefTheme = (aios_gPrefBranchN.getCharPref('general.skins.selectedSkin') == "classic/1.0") ? true : false;
 
26
 
 
27
 
 
28
// globale Variablen und Funktionen zur �berwachung auf Progress-Ver�nderungen
 
29
// Verwendung in pageInfo.xul und viewSource.xul
 
30
var aios_ProgListStart = Components.interfaces.nsIWebProgressListener.STATE_START;
 
31
var aios_ProgListStop = Components.interfaces.nsIWebProgressListener.STATE_STOP;
 
32
 
 
33
var aiosProgListener = {
 
34
        QueryInterface: function(aIID) {
 
35
                if (aIID.equals(Components.interfaces.nsIWebProgressListener) ||
 
36
                                aIID.equals(Components.interfaces.nsISupportsWeakReference) ||
 
37
                                aIID.equals(Components.interfaces.nsISupports))
 
38
                        return this;
 
39
                        throw Components.results.NS_NOINTERFACE;
 
40
                },
 
41
 
 
42
        onStateChange: function(aProgress, aRequest, aFlag, aStatus) {
 
43
                //if(aFlag & aios_ProgListStart) { /* This fires when the load event is initiated */ }
 
44
                //if(aFlag & aios_ProgListStop) { /* This fires when the load finishes */ }
 
45
                if(aFlag & aios_ProgListStop) {
 
46
                  if(typeof aios_onStateChange == "function") aios_onStateChange();
 
47
                }
 
48
                return 0;
 
49
        },
 
50
 
 
51
        onLocationChange: function(aProgress, aRequest, aURI) {
 
52
                // This fires when the location bar changes i.e load event is confirmed
 
53
                // or when the user switches tabs
 
54
                if(typeof aios_onLocationChange == "function") aios_onLocationChange();
 
55
                return 0;
 
56
        },
 
57
 
 
58
        // For definitions of the remaining functions see XulPlanet.com
 
59
        onProgressChange: function() { return 0; },
 
60
        onStatusChange: function() { return 0; },
 
61
        onSecurityChange: function() { return 0; },
 
62
        onLinkIconAvailable: function() { return 0; }
 
63
}
 
64
 
 
65
 
 
66
/*
 
67
        Variablen zur Verwendung der Erweiterung "DebugLogger" - http://mozmonkey.com/debuglogger/
 
68
*/
 
69
if(Components.classes["@mozmonkey.com/debuglogger/manager;1"]) {
 
70
        var aios_debugLogMngr = Components.classes["@mozmonkey.com/debuglogger/manager;1"].
 
71
                                                                                                        getService(Components.interfaces.nsIDebugLoggerManager);
 
72
        var aios_debugLogger = aios_debugLogMngr.registerLogger("aios");
 
73
}
 
74
//aios_debugLogger.log(3, "Hello World");
 
75
 
 
76
 
 
77
/*
 
78
        Debug-Funktion unter Verwendung der JavaScript-Konsole
 
79
*/
 
80
function aios_debug(aMsg) {
 
81
        var aConsoleService = Components.classes["@mozilla.org/consoleservice;1"].
 
82
                                                                                                getService(Components.interfaces.nsIConsoleService),
 
83
 
 
84
        msg = 'AIOS: ' + aMsg;
 
85
        aConsoleService.logStringMessage(msg);
 
86
}
 
87
//aios_debug('Hallo');
 
88
 
 
89
 
 
90
/*
 
91
        �ffnet ein neues Tab mit der �bergebenen Adresse im Vordergrund
 
92
*/
 
93
var aiosLastSelTab;             // wird f�r Page Info/Page Source/MultiPanel im Tab ben�tigt
 
94
function aios_addTab(aUrl) {
 
95
 
 
96
        var browser = aios_WIN.getBrowser();
 
97
        aiosLastSelTab = aios_WIN.content;
 
98
 
 
99
        var browserDoc;
 
100
        var existTab = null;
 
101
        var emptyTab = null;
 
102
 
 
103
        // alle ge�ffneten Tabs durchgehen
 
104
        for(var i = 0; i < browser.tabContainer.childNodes.length; i++) {
 
105
                browserDoc = browser.getBrowserAtIndex(i).contentWindow.document;
 
106
                //alert(browser.getBrowserAtIndex(i).currentURI.spec);
 
107
 
 
108
                var isPermaTab = (browser.tabContainer.childNodes[i].getAttribute('isPermaTab')) ? true : false;
 
109
                //alert(isPermaTab);
 
110
 
 
111
                /*var attribs = browser.tabContainer.childNodes[i].attributes;
 
112
                //var attribs = browser.mCurrentTab.attributes;
 
113
                for(var a = 0; a < attribs.length; a++) {
 
114
                        alert(attribs[a].name + ": " + attribs[a].value);
 
115
                }*/
 
116
 
 
117
                // wenn der Tab leer ist
 
118
                if(browserDoc.location.href == "about:blank" && browser.selectedTab.getAttribute('openBy') != "aios" && !isPermaTab && emptyTab == null)
 
119
                        emptyTab = i;
 
120
                // wenn der Tab schon existiert
 
121
                if(browserDoc.location.href == aUrl && !isPermaTab && existTab == null)
 
122
                        existTab = i;
 
123
        }
 
124
 
 
125
        // wenn der Tab schon existiert
 
126
        if(existTab != null) {
 
127
                browser.selectedTab = browser.tabContainer.childNodes[existTab];
 
128
                return browser.selectedTab;
 
129
        }
 
130
 
 
131
        // wenn der Tab leer ist
 
132
        if(emptyTab != null) {
 
133
                // URL �ffnen und Tab selektieren
 
134
                browser.getBrowserAtIndex(emptyTab).contentWindow.document.location.href = aUrl;
 
135
                browser.selectedTab = browser.tabContainer.childNodes[emptyTab];
 
136
                browser.selectedTab.setAttribute('openBy', 'aios');
 
137
                return browser.selectedTab;
 
138
        }
 
139
 
 
140
        // wenn kein leerer Tab vorhanden war, wird ein neuer ge�ffnet
 
141
        browser.selectedTab = browser.addTab(aUrl);
 
142
        browser.selectedTab.setAttribute('openBy', 'aios');
 
143
        return browser.selectedTab;
 
144
}
 
145
 
 
146
 
 
147
/*
 
148
  f�gt dem Dokument dynamisch ein Stylesheet hinzu
 
149
    => Aufruf u.a. durch aios_init() und aios_sidebarLayout() bei den Add-ons, Downloads
 
150
*/
 
151
function aios_addCSS(aURI) {
 
152
        var css = document.createElementNS('http://www.w3.org/1999/xhtml', 'link');
 
153
        css.setAttribute('rel', 'stylesheet');
 
154
        css.setAttribute('href', aURI);
 
155
        css.setAttribute('type', 'text/css');
 
156
        document.documentElement.appendChild(css);
 
157
}
 
158
 
 
159
 
 
160
/*
 
161
        errechnet die Breite des Browsers exkl. der AIOS-Toolbar
 
162
                => Aufruf durch aios_setSidebarDefWidth() in aios.js und aios_setSidebarWidth() in general.js
 
163
*/
 
164
function aios_getBrowserWidth() {
 
165
        var cStyleSidebar = aios_WIN.document.defaultView.getComputedStyle(aios_WIN.document.getElementById('sidebar-box'), '');
 
166
        var cStyleSplitter = aios_WIN.document.defaultView.getComputedStyle(aios_WIN.document.getElementById('sidebar-splitter'), '');
 
167
        var cStyleContent = aios_WIN.document.defaultView.getComputedStyle(aios_WIN.document.getElementById('appcontent'), '');
 
168
 
 
169
        var widthSidebar = parseInt(cStyleSidebar.width) + parseInt(cStyleSidebar.paddingLeft) + parseInt(cStyleSidebar.paddingRight) + parseInt(cStyleSidebar.marginLeft) + parseInt(cStyleSidebar.marginRight);
 
170
 
 
171
        var widthSplitter = parseInt(cStyleSplitter.width) + parseInt(cStyleSplitter.paddingLeft) + parseInt(cStyleSplitter.paddingRight) + parseInt(cStyleSplitter.marginLeft) + parseInt(cStyleSplitter.marginRight);
 
172
 
 
173
        var widthContent = parseInt(cStyleContent.width) + parseInt(cStyleContent.paddingLeft) + parseInt(cStyleContent.paddingRight) + parseInt(cStyleContent.marginLeft) + parseInt(cStyleContent.marginRight);
 
174
 
 
175
        var compWidth = widthSidebar + widthSplitter + widthContent;
 
176
 
 
177
        var ret_arr = new Array(widthSidebar, widthSplitter, widthContent, compWidth);
 
178
        return(ret_arr);
 
179
}
 
180
 
 
181
 
 
182
/*
 
183
        erweitert das Attribut "class" eines Elementes
 
184
*/
 
185
function aios_appendClass(elem, appClass) {
 
186
        if(typeof elem == "string") elem = document.getElementById(elem);
 
187
 
 
188
        var old_class = elem.getAttribute('class');
 
189
        if(old_class.indexOf(appClass) < 0) elem.setAttribute('class', old_class + " " + appClass);
 
190
}
 
191
 
 
192
 
 
193
/*
 
194
        l�scht einen Klassennamen im Attribut "class" eines Elementes
 
195
*/
 
196
function aios_stripClass(elem, stripClass) {
 
197
        if(typeof elem == "string") elem = document.getElementById(elem);
 
198
 
 
199
        var old_class = elem.getAttribute('class');
 
200
 
 
201
        if(old_class.indexOf(stripClass) >= 0) {
 
202
                var pos = old_class.indexOf(stripClass);
 
203
 
 
204
                var slice1 = old_class.substring(0, pos);
 
205
                slice1 = slice1.replace(/ /, "");
 
206
                var slice2 = old_class.substring(pos + stripClass.length, old_class.length);
 
207
                slice2 = slice2.replace(/ /, "");
 
208
 
 
209
                elem.setAttribute('class', slice1 + " " + slice2);
 
210
        }
 
211
 
 
212
}
 
213
 
 
214
 
 
215
function aios_gElem(aID) {
 
216
        if(aios_WIN && aios_WIN.document.getElementById(aID)) return aios_WIN.document.getElementById(aID);
 
217
        return false;
 
218
}
 
219
 
 
220
 
 
221
/*
 
222
        gibt den boolschen Wert eines Wertes zur�ck
 
223
                => getAttribute(val) liefert nur "true" oder "false" als String
 
224
*/
 
225
function aios_getBoolean(aElem, aVal) {
 
226
        var elem, bool;
 
227
 
 
228
        if(typeof aElem == "object") {
 
229
                elem = aElem;
 
230
        }
 
231
        else if(typeof aElem == "string" && document.getElementById(aElem)) {
 
232
                elem = document.getElementById(aElem);
 
233
        }
 
234
 
 
235
        if(elem) {
 
236
                if(typeof elem.getAttribute == "function") bool = elem.getAttribute(aVal);
 
237
        }
 
238
 
 
239
        if(bool == "true") return true;
 
240
        else return false;
 
241
}
 
242
 
 
243
 
 
244
/*
 
245
        Dialoge �ffnen
 
246
*/
 
247
function aios_openDialog(which, args) {
 
248
        var theUrl, theId, theFeatures, theArgs;
 
249
        var theArgs = args;
 
250
 
 
251
        switch(which) {
 
252
                case "prefs":
 
253
                        theUrl = "chrome://aios/content/prefs/prefs.xul";
 
254
                        theId = "aiosPrefsDialog";
 
255
                        theFeatures = "chrome,titlebar,toolbar,centerscreen,";
 
256
                        theFeatures+= (aios_appOS == "Darwin") ? "dialog=no" : "modal";
 
257
                        break;
 
258
 
 
259
                case "about":
 
260
                        theUrl = "chrome://aios/content/about.xul";
 
261
                        theId = "aiosAboutDialog";
 
262
                        theFeatures = "chrome,modal";
 
263
                        break;
 
264
 
 
265
                case "bookmarks":
 
266
                        theUrl = "chrome://browser/content/bookmarks/bookmarksPanel.xul";
 
267
                        theId = "aiosGlobal:Bookmarks";
 
268
                        theFeatures = "width=640,height=480,chrome,resizable,centerscreen";
 
269
                        break;
 
270
 
 
271
                case "history":
 
272
                        theUrl = "chrome://browser/content/history/history-panel.xul";
 
273
                        theId = "aiosGlobal:History";
 
274
                        theFeatures = "width=640,height=480,chrome,resizable,centerscreen";
 
275
                        break;
 
276
 
 
277
                case "multipanel":
 
278
                        theUrl = "chrome://browser/content/web-panels.xul";
 
279
                        theId = "aiosGlobal:MultiPanel";
 
280
                        theFeatures = "width=640,height=480,chrome,resizable,centerscreen";
 
281
                        break;
 
282
        }
 
283
 
 
284
        if(which == "prefs" || which == "about") openDialog(theUrl, theId, theFeatures, theArgs);
 
285
        else toOpenWindowByType(theId, theUrl, theFeatures);
 
286
}
 
287
 
 
288
 
 
289
/*
 
290
        pr�ft welche Elemente angezeigt werden sollen
 
291
                => Aufruf jeweils durch Initialisierung
 
292
*/
 
293
function aios_synchElements(aElems) {
 
294
        var elem, child;
 
295
 
 
296
        for(var i = 0; i < aElems.length; i++) {
 
297
                elem = document.getElementById(aElems[i]);
 
298
 
 
299
                if(elem) {
 
300
 
 
301
                        childElems = elem.getAttribute('aiosChilds');
 
302
 
 
303
                        if(childElems) {
 
304
                                childMode = !aios_getBoolean(elem, 'checked');
 
305
                                aios_toggleChilds(childElems, childMode);
 
306
                        }
 
307
                }
 
308
        }
 
309
}
 
310
 
 
311
 
 
312
/*
 
313
        toggelt einen Men�punkt und das/die zugeh�rige/n Element/e
 
314
                => Aufruf durch die menuitems in der aios.xul
 
315
*/
 
316
function aios_toggleElement(aMenuitem) {
 
317
  var menuitem;
 
318
 
 
319
  if(typeof aMenuitem != "object") aMenuitem = document.getElementById(aMenuitem);
 
320
 
 
321
        if(aMenuitem.getAttribute('observes')) {
 
322
                menuitem = document.getElementById(aMenuitem.getAttribute('observes'));
 
323
        }
 
324
        else {
 
325
                menuitem = document.getElementById(aMenuitem.id);
 
326
        }
 
327
 
 
328
        var mode = aios_getBoolean(menuitem, 'checked');
 
329
        var childElems = menuitem.getAttribute('aiosChilds');
 
330
 
 
331
        menuitem.setAttribute('checked', !mode);
 
332
        aios_toggleChilds(childElems, mode);
 
333
}
 
334
 
 
335
 
 
336
/*
 
337
        toggelt Kindelemente eines Men�punkts
 
338
                => Aufruf durch aios_toggleElement()
 
339
*/
 
340
function aios_toggleChilds(childElems, childMode) {
 
341
        var child_str, child;
 
342
 
 
343
        if(childElems != "") {
 
344
                var childElems_arr = childElems.split(",");
 
345
 
 
346
                for(var i = 0; i < childElems_arr.length; i++) {
 
347
                        child_str = childElems_arr[i].replace(/ /, "");
 
348
 
 
349
                        var idChilds_arr = document.getElementsByAttribute('id', child_str);
 
350
 
 
351
                        // wenn es nur ein Element mit der ID gibt...
 
352
                        if(idChilds_arr.length == 1) {
 
353
                                child = document.getElementById(child_str);
 
354
                        }
 
355
                        // wenn es mehrere Elemente mit der ID gibt...
 
356
                        else {
 
357
                                for(var j = 0; j < idChilds_arr.length; j++) {
 
358
                                        //... nimm das auf der AIOS-Toolbar
 
359
                                        if(idChilds_arr[j].parentNode.id == "aios-toolbar") child = idChilds_arr[j];
 
360
                                }
 
361
                        }
 
362
 
 
363
                        if(child) child.setAttribute('hidden', childMode);
 
364
                }
 
365
        }
 
366
}
 
 
b'\\ No newline at end of file'