Add example code to use beagle as a service provider.
[beagle.git] / mozilla-extension / content / beaglePrefs.js
bloba7f941ca49f26636b761cdfeee42f5fbc98d8809
1 /*
2 * Beagle Extension: Index webpages you visit using the Beagle Indexing Engine.
3 * An Extension for the Firefox (and Mozilla?) Browser.
4 */
6 // Initiate a new preference instance.
7 var gPref = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
9 // Declare form variables.
10 var _elementIDs = [
11 'beagle.context.active',
12 'beagle.security.active',
13 'beagle.security.filters'
16 function beaglePrefsInit()
18 for( var i = 0; i < _elementIDs.length; i++ )
20 var elementID = _elementIDs[i];
21 var element = document.getElementById(elementID);
23 if (!element)
25 continue;
27 else if (element.localName == 'checkbox')
29 try { element.checked = gPref.getBoolPref(elementID); }
30 catch(e) { element.checked = false; }
32 else if (element.localName == 'radiogroup')
34 try { element.selectedItem = element.childNodes[gPref.getIntPref(elementID)]; }
35 catch(e) { element.selectedItem = element.childNodes[0]; }
37 else if (element.localName == 'textbox')
39 if (element.getAttribute('preftype') == 'int')
41 try { element.value = gPref.getIntPref(elementID); }
42 catch(e) { element.value = 180; }
44 else
46 try { element.value = gPref.getCharPref(elementID); }
47 catch(e) { element.value = ''; }
50 else if (element.id == 'beagle.security.filters')
52 try {
53 var val = gPref.getCharPref("beagle.security.filters");
54 var items = val.split(';');
55 var listbox = document.getElementById('beagle.security.filters');
57 for (var j = 0; j < items.length; j++){
58 if(items[j] != ''){
59 var item = listbox.appendItem(items[j], items[j]);
62 } catch(e) {
63 // We don't seem to care about this.
70 function beaglePrefsSave()
72 for( var i = 0; i < _elementIDs.length; i++ )
74 var elementID = _elementIDs[i];
75 var element = document.getElementById(elementID);
77 if (!element)
79 continue;
81 else if (element.localName == 'checkbox')
83 gPref.setBoolPref(elementID, element.checked);
85 else if (element.localName == 'radiogroup')
87 gPref.setIntPref(elementID, parseInt(element.value));
89 else if (element.localName == 'textbox')
91 if (element.getAttribute('preftype') == 'int')
93 var bOkay = true;
94 var cPref = '';
95 var sPref = element.value.replace(/^[0]*/);
96 var sWork = "0123456789";
98 for (var j = 0; j < sPref.length; j++)
100 if (sWork.indexOf(sPref.charAt(j)) == -1) bOkay = false;
101 else cPref = cPref + sPref.charAt(j);
104 if (cPref.length == 0 ) cPref = '0';
105 var iPref = parseInt(cPref);
106 if (iPref < 180) iPref = 180;
107 gPref.setIntPref(elementID, iPref);
109 else
111 gPref.setCharPref(elementID, element.value);
114 else if (element.id == 'beagle.security.filters')
116 var val = "";
117 for (var j = 0; j < element.getRowCount(); j++){
118 var listitem = element.getItemAtIndex(j);
119 val += listitem.value + ";";
121 gPref.setCharPref(element.id, val);
126 function beaglePrefsAddFilter() {
127 window.openDialog('chrome://beagle/content/beagleAddDomainDialog.xul', 'Add Domain', 'chrome, modal');
130 function beaglePrefsRemoveFilter() {
131 var listbox = document.getElementById('beagle.security.filters');
132 listbox.removeItemAt(listbox.selectedIndex);
135 function updateFilterAddButton() {
136 var button = document.getElementById('beagle.filter.add');
137 var filter = document.getElementById('beagle.filter');
139 if (filter.value != ''){
140 button.disabled = false;
141 } else {
142 button.disabled = true;
146 function updateFilterRemoveButton() {
147 var button = document.getElementById('beagle.filter.remove');
148 var listbox = document.getElementById('beagle.security.filters');
150 if (listbox.selectedCount > 0){
151 button.disabled = false;
152 } else {
153 button.disabled = true;