~ubuntu-branches/debian/sid/refcontrol/sid

« back to all changes in this revision

Viewing changes to chrome/content/refcontrolPrefs.js

  • Committer: Package Import Robot
  • Author(s): Fabrizio Regalli
  • Date: 2012-01-07 00:33:43 UTC
  • Revision ID: package-import@ubuntu.com-20120107003343-uf2v9vzg6fft1ul9
Tags: upstream-0.8.16
ImportĀ upstreamĀ versionĀ 0.8.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
var refcontrolPrefs =
 
3
{
 
4
        getPrefBranch: function getPrefBranch()
 
5
        {
 
6
                var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
 
7
                return prefService.getBranch("refcontrol.");
 
8
        },
 
9
 
 
10
        onPopupShowing: function onPopupShowing(aEvent)
 
11
        {
 
12
                // onpopupshowing is inherited by child elements.
 
13
                // avoid processing on these
 
14
                if (aEvent.target.id != "refcontrol-popupOptions")
 
15
                        return true;
 
16
                        
 
17
                var prefBranch = this.getPrefBranch();
 
18
                var bChecked;
 
19
        
 
20
                var arrMenuItems = aEvent.target.getElementsByTagName("menuitem");
 
21
                for (var i = 0; i < arrMenuItems.length; i++)
 
22
                {
 
23
                        var type = arrMenuItems[i].getAttribute('type');
 
24
                        switch (type)
 
25
                        {
 
26
                                case 'checkbox':
 
27
                                case 'radio':
 
28
                                        try {
 
29
                                                if (type == 'checkbox')
 
30
                                                        bChecked = prefBranch.getBoolPref(arrMenuItems[i].value);
 
31
                                                else if (type == 'radio')
 
32
                                                        bChecked = (prefBranch.getIntPref(arrMenuItems[i].getAttribute('name')) == arrMenuItems[i].value);
 
33
                                        } catch (e) {
 
34
                                                bChecked = false;
 
35
                                        }
 
36
                                        if (bChecked)
 
37
                                                arrMenuItems[i].setAttribute("checked", true);
 
38
                                        else
 
39
                                                arrMenuItems[i].removeAttribute("checked");
 
40
                                        break;
 
41
                        }
 
42
                }
 
43
                
 
44
                return true;
 
45
        },
 
46
        
 
47
        onChangeCheckboxPref: function onChangeCheckboxPref(aEvent)
 
48
        {
 
49
                this.getPrefBranch().setBoolPref(aEvent.target.value, !!aEvent.target.getAttribute('checked'));
 
50
        },
 
51
        
 
52
        onChangeRadioPref: function onChangeRadioPref(aEvent)
 
53
        {
 
54
                this.getPrefBranch().setIntPref(aEvent.target.getAttribute('name'), aEvent.target.value);
 
55
        },
 
56
 
 
57
        toggleBooleanPref: function toggleBooleanPref(aEvent)
 
58
        {
 
59
                var pref;
 
60
                if (aEvent.target.id == "refcontrol-toolbarbutton")
 
61
                        pref = "enabled";
 
62
                else
 
63
                        return;
 
64
                var prefBranch = this.getPrefBranch();
 
65
                prefBranch.setBoolPref(pref, !prefBranch.getBoolPref(pref));
 
66
        },
 
67
};