File: windowOpenExceptions.js

package info (click to toggle)
tabextensions 2.1.2006031301-6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,440 kB
  • ctags: 424
  • sloc: xml: 6,135; makefile: 38; sh: 35
file content (164 lines) | stat: -rwxr-xr-x 4,632 bytes parent folder | download | duplicates (2)
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
var gExceptions;

var gExceptionsList;
var gListShouldAcceptWindowOpen;
var gURIBox;
var gAddButton;
var gRemoveButton;
var gRemoveAllButton;

var gAllowPopupWithOption;
var gAllowPopupWithOptionValue;

function init()
{
	gListShouldAcceptWindowOpen = ('arguments' in window && window.arguments.length > 1) ? window.arguments[1] : (TabbrowserService.opentabforJS || TabbrowserService.winHookMode > 0) ;

	gExceptionsList  = document.getElementById('exceptions');
	gURIBox          = document.getElementById('URIBox');
	gAddButton       = document.getElementById('addButton');
	gRemoveButton    = document.getElementById('removeButton');
	gRemoveAllButton = document.getElementById('removeAllButton');

	document.documentElement.addEventListener('keypress', onReturnHit, true);

	gAllowPopupWithOption = document.getElementById('allowPopupWithOption');
	gAllowPopupWithOptionValue = document.getElementById('allowPopupWithOptionValue');
	gAllowPopupWithOptionValue.value = TabbrowserService.getPref(gAllowPopupWithOptionValue.getAttribute('prefstring'));
	if (Number(gAllowPopupWithOptionValue.value) == 0)
		gAllowPopupWithOption.removeAttribute('checked');
	else
		gAllowPopupWithOption.setAttribute('checked', true);


	window.sizeToContent();
	window.setTimeout(initWithDelay, 0);
}
function initWithDelay()
{
	if ('arguments' in window &&
		window.arguments[0])
		gURIBox.value = window.arguments[0];

	initList();
}


function initList(aListShouldAcceptWindowOpen)
{
	var shouldAcceptWindowOpen = (aListShouldAcceptWindowOpen !== void(0)) ? aListShouldAcceptWindowOpen : gListShouldAcceptWindowOpen ;
	gExceptions = shouldAcceptWindowOpen ? TabbrowserPopupController.JSWindowOpenExceptionsWhite : TabbrowserPopupController.JSWindowOpenExceptionsBlack ;

	initMessages(shouldAcceptWindowOpen);

	var range = document.createRange();
	range.selectNodeContents(gExceptionsList);
	range.deleteContents();
	range.detach();

	var item;
	var node;
	for (var i = 0; i < gExceptions.length; i++)
	{
		node = gExceptions.item(i);

		item = document.createElement('listitem');
		item.setAttribute('label', gExceptions.getData(node, 'Rule'));
		gExceptionsList.appendChild(item);
	}

	gRemoveButton.setAttribute('disabled', true);
	if (gExceptionsList.hasChildNodes())
		gRemoveAllButton.removeAttribute('disabled');
	else
		gRemoveAllButton.setAttribute('disabled', true);
}

function initMessages(aShouldAcceptWindowOpen)
{
	var type = aShouldAcceptWindowOpen ? 'white' : 'black' ;
	window.title = document.getElementById('labelTitle-'+type).getAttribute('label');

	var range = document.createRange();

	var desc = document.getElementById('description');
	range.selectNodeContents(desc);
	range.deleteContents();
	desc.appendChild(document.createTextNode(document.getElementById('labelDesc-'+type).getAttribute('label')));

	var note = document.getElementById('note');
	range.selectNodeContents(note);
	range.deleteContents();
	note.appendChild(document.createTextNode(document.getElementById('labelNote-'+type).getAttribute('label')));

	var onlyForWhiteListGroup = document.getElementById('exceptionsForAnyWebPage');
	if (type == 'white')
		onlyForWhiteListGroup.removeAttribute('collapsed');
	else
		onlyForWhiteListGroup.setAttribute('collapsed', true);

	range.detach();

	window.sizeToContent();
}


function addURI()
{
	var uri = gURIBox.value;
	if (!uri) return;

	gExceptions.setData(uri, 'Rule', uri);
	gURIBox.value = '';
	initList();
}

function removeURI()
{
	if (!gExceptionsList.selectedItem) return;

	var uri = gExceptionsList.selectedItem.getAttribute('label');

	gExceptions.removeData(uri);
	initList();
}

function removeAllURIs()
{
	gExceptions.clearData();
	initList();
}




function onSelect()
{
	if (gExceptionsList.selectedItem)
		gRemoveButton.removeAttribute('disabled');
	else
		gRemoveButton.setAttribute('disabled', true);
}

function onReturnHit(aEvent)
{
	var focusedElement = document.commandDispatcher.focusedElement;

	if (!focusedElement ||
		(aEvent.keyCode != aEvent.DOM_VK_ENTER &&
		aEvent.keyCode != aEvent.DOM_VK_RETURN)) return;

	aEvent.preventBubble();
	if (focusedElement == gURIBox.inputField)
		gAddButton.doCommand();
}



function onAccept()
{
	if (Number(gAllowPopupWithOptionValue.value) != TabbrowserService.getPref(gAllowPopupWithOptionValue.getAttribute('prefstring')))
		TabbrowserService.setPref(gAllowPopupWithOptionValue.getAttribute('prefstring'), Number(gAllowPopupWithOptionValue.value));

	window.close();
}