~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/build/selector-native/selector-native-debug.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
 
/*
2
 
YUI 3.4.1 (build 4118)
3
 
Copyright 2011 Yahoo! Inc. All rights reserved.
4
 
Licensed under the BSD License.
5
 
http://yuilibrary.com/license/
6
 
*/
7
 
YUI.add('selector-native', function(Y) {
8
 
 
9
 
(function(Y) {
10
 
/**
11
 
 * The selector-native module provides support for native querySelector
12
 
 * @module dom
13
 
 * @submodule selector-native
14
 
 * @for Selector
15
 
 */
16
 
 
17
 
/**
18
 
 * Provides support for using CSS selectors to query the DOM 
19
 
 * @class Selector 
20
 
 * @static
21
 
 * @for Selector
22
 
 */
23
 
 
24
 
Y.namespace('Selector'); // allow native module to standalone
25
 
 
26
 
var COMPARE_DOCUMENT_POSITION = 'compareDocumentPosition',
27
 
    OWNER_DOCUMENT = 'ownerDocument';
28
 
 
29
 
var Selector = {
30
 
    _foundCache: [],
31
 
 
32
 
    useNative: true,
33
 
 
34
 
    _compare: ('sourceIndex' in Y.config.doc.documentElement) ?
35
 
        function(nodeA, nodeB) {
36
 
            var a = nodeA.sourceIndex,
37
 
                b = nodeB.sourceIndex;
38
 
 
39
 
            if (a === b) {
40
 
                return 0;
41
 
            } else if (a > b) {
42
 
                return 1;
43
 
            }
44
 
 
45
 
            return -1;
46
 
 
47
 
        } : (Y.config.doc.documentElement[COMPARE_DOCUMENT_POSITION] ?
48
 
        function(nodeA, nodeB) {
49
 
            if (nodeA[COMPARE_DOCUMENT_POSITION](nodeB) & 4) {
50
 
                return -1;
51
 
            } else {
52
 
                return 1;
53
 
            }
54
 
        } :
55
 
        function(nodeA, nodeB) {
56
 
            var rangeA, rangeB, compare;
57
 
            if (nodeA && nodeB) {
58
 
                rangeA = nodeA[OWNER_DOCUMENT].createRange();
59
 
                rangeA.setStart(nodeA, 0);
60
 
                rangeB = nodeB[OWNER_DOCUMENT].createRange();
61
 
                rangeB.setStart(nodeB, 0);
62
 
                compare = rangeA.compareBoundaryPoints(1, rangeB); // 1 === Range.START_TO_END
63
 
            }
64
 
 
65
 
            return compare;
66
 
        
67
 
    }),
68
 
 
69
 
    _sort: function(nodes) {
70
 
        if (nodes) {
71
 
            nodes = Y.Array(nodes, 0, true);
72
 
            if (nodes.sort) {
73
 
                nodes.sort(Selector._compare);
74
 
            }
75
 
        }
76
 
 
77
 
        return nodes;
78
 
    },
79
 
 
80
 
    _deDupe: function(nodes) {
81
 
        var ret = [],
82
 
            i, node;
83
 
 
84
 
        for (i = 0; (node = nodes[i++]);) {
85
 
            if (!node._found) {
86
 
                ret[ret.length] = node;
87
 
                node._found = true;
88
 
            }
89
 
        }
90
 
 
91
 
        for (i = 0; (node = ret[i++]);) {
92
 
            node._found = null;
93
 
            node.removeAttribute('_found');
94
 
        }
95
 
 
96
 
        return ret;
97
 
    },
98
 
 
99
 
    /**
100
 
     * Retrieves a set of nodes based on a given CSS selector. 
101
 
     * @method query
102
 
     *
103
 
     * @param {string} selector The CSS Selector to test the node against.
104
 
     * @param {HTMLElement} root optional An HTMLElement to start the query from. Defaults to Y.config.doc
105
 
     * @param {Boolean} firstOnly optional Whether or not to return only the first match.
106
 
     * @return {Array} An array of nodes that match the given selector.
107
 
     * @static
108
 
     */
109
 
    query: function(selector, root, firstOnly, skipNative) {
110
 
        root = root || Y.config.doc;
111
 
        var ret = [],
112
 
            useNative = (Y.Selector.useNative && Y.config.doc.querySelector && !skipNative),
113
 
            queries = [[selector, root]],
114
 
            query,
115
 
            result,
116
 
            i,
117
 
            fn = (useNative) ? Y.Selector._nativeQuery : Y.Selector._bruteQuery;
118
 
 
119
 
        if (selector && fn) {
120
 
            // split group into seperate queries
121
 
            if (!skipNative && // already done if skipping
122
 
                    (!useNative || root.tagName)) { // split native when element scoping is needed
123
 
                queries = Selector._splitQueries(selector, root);
124
 
            }
125
 
 
126
 
            for (i = 0; (query = queries[i++]);) {
127
 
                result = fn(query[0], query[1], firstOnly);
128
 
                if (!firstOnly) { // coerce DOM Collection to Array
129
 
                    result = Y.Array(result, 0, true);
130
 
                }
131
 
                if (result) {
132
 
                    ret = ret.concat(result);
133
 
                }
134
 
            }
135
 
 
136
 
            if (queries.length > 1) { // remove dupes and sort by doc order 
137
 
                ret = Selector._sort(Selector._deDupe(ret));
138
 
            }
139
 
        }
140
 
 
141
 
        Y.log('query: ' + selector + ' returning: ' + ret.length, 'info', 'Selector');
142
 
        return (firstOnly) ? (ret[0] || null) : ret;
143
 
 
144
 
    },
145
 
 
146
 
    // allows element scoped queries to begin with combinator
147
 
    // e.g. query('> p', document.body) === query('body > p')
148
 
    _splitQueries: function(selector, node) {
149
 
        var groups = selector.split(','),
150
 
            queries = [],
151
 
            prefix = '',
152
 
            i, len;
153
 
 
154
 
        if (node) {
155
 
            // enforce for element scoping
156
 
            if (node.tagName) {
157
 
                node.id = node.id || Y.guid();
158
 
                prefix = '[id="' + node.id + '"] ';
159
 
            }
160
 
 
161
 
            for (i = 0, len = groups.length; i < len; ++i) {
162
 
                selector =  prefix + groups[i];
163
 
                queries.push([selector, node]);
164
 
            }
165
 
        }
166
 
 
167
 
        return queries;
168
 
    },
169
 
 
170
 
    _nativeQuery: function(selector, root, one) {
171
 
        if (Y.UA.webkit && selector.indexOf(':checked') > -1 &&
172
 
                (Y.Selector.pseudos && Y.Selector.pseudos.checked)) { // webkit (chrome, safari) fails to pick up "selected"  with "checked"
173
 
            return Y.Selector.query(selector, root, one, true); // redo with skipNative true to try brute query
174
 
        }
175
 
        try {
176
 
            //Y.log('trying native query with: ' + selector, 'info', 'selector-native');
177
 
            return root['querySelector' + (one ? '' : 'All')](selector);
178
 
        } catch(e) { // fallback to brute if available
179
 
            //Y.log('native query error; reverting to brute query with: ' + selector, 'info', 'selector-native');
180
 
            return Y.Selector.query(selector, root, one, true); // redo with skipNative true
181
 
        }
182
 
    },
183
 
 
184
 
    filter: function(nodes, selector) {
185
 
        var ret = [],
186
 
            i, node;
187
 
 
188
 
        if (nodes && selector) {
189
 
            for (i = 0; (node = nodes[i++]);) {
190
 
                if (Y.Selector.test(node, selector)) {
191
 
                    ret[ret.length] = node;
192
 
                }
193
 
            }
194
 
        } else {
195
 
            Y.log('invalid filter input (nodes: ' + nodes +
196
 
                    ', selector: ' + selector + ')', 'warn', 'Selector');
197
 
        }
198
 
 
199
 
        return ret;
200
 
    },
201
 
 
202
 
    test: function(node, selector, root) {
203
 
        var ret = false,
204
 
            useFrag = false,
205
 
            groups,
206
 
            parent,
207
 
            item,
208
 
            items,
209
 
            frag,
210
 
            i, j, group;
211
 
 
212
 
        if (node && node.tagName) { // only test HTMLElements
213
 
 
214
 
            if (typeof selector == 'function') { // test with function
215
 
                ret = selector.call(node, node);
216
 
            } else { // test with query
217
 
                // we need a root if off-doc
218
 
                groups = selector.split(',');
219
 
                if (!root && !Y.DOM.inDoc(node)) {
220
 
                    parent = node.parentNode;
221
 
                    if (parent) { 
222
 
                        root = parent;
223
 
                    } else { // only use frag when no parent to query
224
 
                        frag = node[OWNER_DOCUMENT].createDocumentFragment();
225
 
                        frag.appendChild(node);
226
 
                        root = frag;
227
 
                        useFrag = true;
228
 
                    }
229
 
                }
230
 
                root = root || node[OWNER_DOCUMENT];
231
 
 
232
 
                if (!node.id) {
233
 
                    node.id = Y.guid();
234
 
                }
235
 
                for (i = 0; (group = groups[i++]);) { // TODO: off-dom test
236
 
                    group += '[id="' + node.id + '"]';
237
 
                    items = Y.Selector.query(group, root);
238
 
 
239
 
                    for (j = 0; item = items[j++];) {
240
 
                        if (item === node) {
241
 
                            ret = true;
242
 
                            break;
243
 
                        }
244
 
                    }
245
 
                    if (ret) {
246
 
                        break;
247
 
                    }
248
 
                }
249
 
 
250
 
                if (useFrag) { // cleanup
251
 
                    frag.removeChild(node);
252
 
                }
253
 
            };
254
 
        }
255
 
 
256
 
        return ret;
257
 
    },
258
 
 
259
 
    /**
260
 
     * A convenience function to emulate Y.Node's aNode.ancestor(selector).
261
 
     * @param {HTMLElement} element An HTMLElement to start the query from.
262
 
     * @param {String} selector The CSS selector to test the node against.
263
 
     * @return {HTMLElement} The ancestor node matching the selector, or null.
264
 
     * @param {Boolean} testSelf optional Whether or not to include the element in the scan 
265
 
     * @static
266
 
     * @method ancestor
267
 
     */
268
 
    ancestor: function (element, selector, testSelf) {
269
 
        return Y.DOM.ancestor(element, function(n) {
270
 
            return Y.Selector.test(n, selector);
271
 
        }, testSelf);
272
 
    }
273
 
};
274
 
 
275
 
Y.mix(Y.Selector, Selector, true);
276
 
 
277
 
})(Y);
278
 
 
279
 
 
280
 
}, '3.4.1' ,{requires:['dom-base']});