~ubuntu-branches/ubuntu/maverick/all-in-one-sidebar/maverick-security

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
var aios_xulUrl = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
//var aios_remMinWidth, aios_remDefWidth, aios_remMaxWidth;


/*
	Liste der zur Verfügung stehenden Sidebars erstellen
		=> Aufruf durch aios_initPane()
*/
function aios_genSidebarList() {

	if(!document.getElementById('sidebarInitPopup') || !document.getElementById('panelInitPopup')) return false;

	var strings = document.getElementById("aiosStrings");
	//if(!confirm(strings.getString('prefs.confirm'))) return false;

	var sidebarInit = document.getElementById('sidebarInitPopup');
	var panelInit = document.getElementById('panelInitPopup');
	var allSidebars = aios_WIN.document.getElementsByAttribute('group', 'sidebar');

	var cnt = 0;
	var initID = null;
	var sidebarPrefInit = "";
	var panelPrefInit = "";
	try {
		sidebarPrefInit = aios_gPrefBranch.getCharPref("gen.init");
		panelPrefInit = aios_gPrefBranch.getCharPref("gen.open.init");
	} catch(e) { }

	for(var i = 0; i < allSidebars.length; i++) {
		var xulElem = null;

		// muß eine ID haben, darf keinen observer haben (Menüeinträge usw.) und muss eine Sidebar-URL haben
		if(allSidebars[i].id && !allSidebars[i].getAttribute('observes') && allSidebars[i].getAttribute('sidebarurl')) {

			var separator = document.createElementNS(aios_xulUrl, "menuseparator");
			if(cnt == 0) {
				sidebarInit.appendChild(separator);
				panelInit.appendChild(separator.cloneNode(true));
			}

			if(allSidebars[i].id != "extensionsEMbSidebar" && allSidebars[i].id != "themesEMbSidebar") {
				xulElem = document.createElementNS(aios_xulUrl, "menuitem");
				xulElem.setAttribute('label', strings.getString('prefs.openpanel') + " " + allSidebars[i].getAttribute('label'));
				xulElem.setAttribute('value', allSidebars[i].id);

				if(allSidebars[i].getAttribute('tooltiptext'))
					xulElem.setAttribute('tooltiptext', allSidebars[i].getAttribute('tooltiptext'));

				sidebarInit.appendChild(xulElem);
				panelInit.appendChild(xulElem.cloneNode(true));
			}

			cnt++;
		}
	}

	sidebarInit.parentNode.value = sidebarPrefInit;
	panelInit.parentNode.value = panelPrefInit;
	return true;
}


/*
	Werte der aktuellen Sidebarbreite einsetzen
		=> Aufruf durch oncommand() der drei <toolbarbutton>
*/
function aios_setWidthVal(mode) {
	var browserWidth = aios_getBrowserWidth();
	var widthSidebar = browserWidth[0];
	var widthContent = browserWidth[1] + browserWidth[2];
	var compWidth = browserWidth[3];

	var percent = parseInt(Math.round((widthSidebar * 100) / compWidth));
	var theUnit = document.getElementById('obj-' + mode + 'WidthUnit').value;

	if(theUnit == "px") {
	  document.getElementById('obj-' + mode + 'WidthVal').value = widthSidebar;
	  document.getElementById(mode + 'WidthVal').value = widthSidebar;
	}
	else if(theUnit == "%") {
	  document.getElementById('obj-' + mode + 'WidthVal').value = percent;
	  document.getElementById(mode + 'WidthVal').value = percent;
	}
}


/*
	Breitenangaben bei Änderung der Maßeinheit umrechnen und ausgeben
		=> Aufruf durch ValueChange-Listener, initiert in aios_initPrefs()
*/
function aios_changeWidthUnit(mode) {
	var elem = document.getElementById('obj-' + mode + 'WidthVal');
	var theUnit = document.getElementById('obj-' + mode + 'WidthUnit').value;

	var browserWidth = aios_getBrowserWidth();
	var compWidth = browserWidth[3];

	if(theUnit == "px") elem.value = parseInt((parseInt(elem.value) * compWidth) / 100);
	else elem.value = parseInt((parseInt(elem.value) * 100) / compWidth);

	// Kontrolle
	aios_checkWidthVal(mode);
}


/*
	Angaben zur Sidebarbreite prüfen
		=> Aufruf durch onBlur() der drei Textfelder, aios_changeWidthUnit(), aios_setConfSidebarWidth()
*/
function aios_checkWidthVal(mode) {
	var elem = document.getElementById('obj-' + mode + 'WidthVal');
	var theUnit = document.getElementById('obj-' + mode + 'WidthUnit').value;

	elem.value = parseInt(elem.value);

	// Kontrolle
	if(mode == "max") {
		if(theUnit == "px" && elem.value < 100) elem.value = 100;
		else if(theUnit == "%" && elem.value < 10) elem.value = 10;
	}
}


/*
	stellt die Größe der Sidebar ein
		=> Aufruf durch aios_savePrefs() in prefs.js
*/
function aios_setConfSidebarWidth() {
	var elem, theUnit, theValue;
	var widthStyle = "";
	var modes = new Array('min', 'def', 'max');

	var browserWidth = aios_getBrowserWidth();
	var compWidth = browserWidth[3];

	for(var i = 0; i < modes.length; i++) {
		elem = document.getElementById('obj-' + modes[i] + 'WidthVal');
		theUnit = document.getElementById('obj-' + modes[i] + 'WidthUnit').value;

		// Kontrolle
		aios_checkWidthVal(modes[i]);

		theValue = elem.value;

		// Prozente in Px umrechnen (Angaben in % funktionieren hier nicht??)
		if(theUnit == "%") theValue = parseInt((compWidth * theValue) / 100);

		switch(modes[i]) {
			case "min":	widthStyle+= 'min-width: ' + theValue + 'px !important; '; break;
			case "def":	widthStyle+= 'width: ' + theValue + 'px !important; '; break;
			case "max": widthStyle+= 'max-width: ' + theValue + 'px !important; '; break;
		}
	}

	aios_WIN.document.getElementById('sidebar').setAttribute('style', widthStyle);
	aios_WIN.document.persist('sidebar', 'style');
}