~ubuntu-branches/ubuntu/raring/maas/raring-updates

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/docs/assets/widget/listbox.js

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-03 17:42:37 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20120703174237-p8l0keuuznfg721k
Tags: 0.1+bzr709+dfsg-0ubuntu1
* New Upstream release
* debian/control:
  - Depends on python-celery, python-tempita, libjs-yui3-{full,min},
    libjs-raphael
* debian/maas.install:
  - Install apiclient, celeryconfig.py, maas-import-pxe-files, preseeds_v2.
  - Update to install various files from chroot, rather tha manually copy
    them from the source.
* debian/maas.links: symlink celeryconfig.py
* debian/maas.maas-celery.upstart: Add job.
* debian/rules:
  - Install celery upstart job.
  - Do not install jslibs as packages are now used.
  - Drop copying of maas_local_settings_sample.py as source now ships
    a maas_local_settings.py
* debian/patches:
  - 04-maas-http-fix.patch: Drop. Merged upstream.
  - 01-fix-database-settings.patch: Refreshed.
  - 99_enums_js.patch: Added until creation of enum.js / build process
    is fixed.
* debian/maas.postinst: Update bzr version to correctly handle upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
YUI.add('listbox', function(Y) {
2
 
 
3
 
Y.ListBox = Y.Base.create("listbox", Y.Widget, [Y.WidgetParent, Y.WidgetChild], {
4
 
 
5
 
    CONTENT_TEMPLATE : "<ul></ul>",
6
 
 
7
 
    bindUI: function() {
8
 
 
9
 
        if (this.isRoot()) {
10
 
            this.get("boundingBox").plug(Y.Plugin.NodeFocusManager, {
11
 
                descendants: ".yui3-option",
12
 
                keys: {
13
 
                    next: "down:40",    // Down arrow
14
 
                    previous: "down:38" // Up arrow 
15
 
                },
16
 
                circular: true
17
 
            });
18
 
        }
19
 
 
20
 
        this.get("boundingBox").on("contextmenu", function (event) {
21
 
            event.preventDefault();
22
 
        });
23
 
 
24
 
        // Setup listener to control keyboard based single/multiple item selection
25
 
        this.on("option:keydown", function (event) {
26
 
 
27
 
            var item = event.target,
28
 
                domEvent = event.domEvent,
29
 
                keyCode = domEvent.keyCode,
30
 
                direction = (keyCode == 40);
31
 
 
32
 
            if (this.get("multiple")) {
33
 
                if (keyCode == 40 || keyCode == 38) {
34
 
                    if (domEvent.shiftKey) {
35
 
                        this._selectNextSibling(item, direction);
36
 
                    } else {
37
 
                        this.deselectAll();
38
 
                        this._selectNextSibling(item, direction);
39
 
                    }
40
 
                }
41
 
            } else {
42
 
                if (keyCode == 13 || keyCode == 32) {
43
 
                    domEvent.preventDefault();
44
 
                    item.set("selected", 1);
45
 
                }
46
 
            }
47
 
        });
48
 
 
49
 
        // Setup listener to control mouse based single/multiple item selection
50
 
        this.on("option:mousedown", function (event) {
51
 
 
52
 
            var item = event.target,
53
 
                domEvent = event.domEvent,
54
 
                selection;
55
 
 
56
 
            if (this.get("multiple")) {
57
 
                if (domEvent.metaKey) {
58
 
                    item.set("selected", 1);
59
 
                } else {
60
 
                    this.deselectAll();
61
 
                    item.set("selected", 1);
62
 
                }
63
 
            } else {
64
 
                item.set("selected", 1);
65
 
            }
66
 
 
67
 
        });
68
 
    },
69
 
 
70
 
    // Helper Method, to find the correct next sibling, taking into account nested ListBoxes    
71
 
    _selectNextSibling : function(item, direction) {
72
 
 
73
 
        var parent = item.get("parent"),
74
 
            method =  (direction) ? "next" : "previous",
75
 
 
76
 
            // Only go circular for the root listbox
77
 
            circular = (parent === this),
78
 
            sibling = item[method](circular);
79
 
 
80
 
        if (sibling) {
81
 
            // If we found a sibling, it's either an Option or a ListBox
82
 
            if (sibling instanceof Y.ListBox) {
83
 
                // If it's a ListBox, select it's first child (in the direction we're headed)
84
 
                sibling.selectChild((direction) ? 0 : sibling.size() - 1);
85
 
            } else {
86
 
                // If it's an Option, select it
87
 
                sibling.set("selected", 1);
88
 
            }
89
 
        } else {
90
 
            // If we didn't find a sibling, we're at the last leaf in a nested ListBox
91
 
            parent[method](true).set("selected", 1);
92
 
        }
93
 
    },
94
 
 
95
 
    NESTED_TEMPLATE : '<li class="{nestedOptionClassName}"><em class="{labelClassName}">{label}</em></li>',
96
 
 
97
 
    renderUI: function () {
98
 
 
99
 
        if (this.get("depth") > -1) {
100
 
 
101
 
            var tokens = {
102
 
                    labelClassName : this.getClassName("label"),
103
 
                    nestedOptionClassName : this.getClassName("option"),
104
 
                    label : this.get("label")
105
 
                },
106
 
                liHtml = Y.substitute(this.NESTED_TEMPLATE, tokens),
107
 
                li = Y.Node.create(liHtml),
108
 
 
109
 
                boundingBox = this.get("boundingBox"),
110
 
                parent = boundingBox.get("parentNode");
111
 
 
112
 
            li.appendChild(boundingBox);
113
 
            parent.appendChild(li);
114
 
        }
115
 
    }
116
 
 
117
 
}, { 
118
 
    ATTRS : {
119
 
        defaultChildType: {  
120
 
            value: "Option"
121
 
        },
122
 
        label : {
123
 
            validator: Y.Lang.isString
124
 
        }
125
 
    }
126
 
});
127
 
 
128
 
Y.Option = Y.Base.create("option", Y.Widget, [Y.WidgetChild], {
129
 
 
130
 
    CONTENT_TEMPLATE : "<em></em>",
131
 
    BOUNDING_TEMPLATE : "<li></li>",
132
 
 
133
 
    renderUI: function () {
134
 
        this.get("contentBox").setContent(this.get("label"));
135
 
    }
136
 
 
137
 
}, {
138
 
 
139
 
    ATTRS : {
140
 
        label : {
141
 
            validator: Y.Lang.isString
142
 
        },
143
 
        tabIndex: {
144
 
                value: -1
145
 
        }        
146
 
    }
147
 
});
148
 
 
149
 
}, '3.1.0' ,{requires:['substitute', 'widget', 'widget-parent', 'widget-child', 'node-focusmanager']});