~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-css2/selector-css2-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-css2', function(Y) {
8
 
 
9
 
/**
10
 
 * The selector module provides helper methods allowing CSS2 Selectors to be used with DOM elements.
11
 
 * @module dom
12
 
 * @submodule selector-css2
13
 
 * @for Selector
14
 
 */
15
 
 
16
 
/*
17
 
 * Provides helper methods for collecting and filtering DOM elements.
18
 
 */
19
 
 
20
 
var PARENT_NODE = 'parentNode',
21
 
    TAG_NAME = 'tagName',
22
 
    ATTRIBUTES = 'attributes',
23
 
    COMBINATOR = 'combinator',
24
 
    PSEUDOS = 'pseudos',
25
 
 
26
 
    Selector = Y.Selector,
27
 
 
28
 
    SelectorCSS2 = {
29
 
        _reRegExpTokens: /([\^\$\?\[\]\*\+\-\.\(\)\|\\])/, // TODO: move?
30
 
        SORT_RESULTS: true,
31
 
        _children: function(node, tag) {
32
 
            var ret = node.children,
33
 
                i,
34
 
                children = [],
35
 
                childNodes,
36
 
                child;
37
 
 
38
 
            if (node.children && tag && node.children.tags) {
39
 
                children = node.children.tags(tag);
40
 
            } else if ((!ret && node[TAG_NAME]) || (ret && tag)) { // only HTMLElements have children
41
 
                childNodes = ret || node.childNodes;
42
 
                ret = [];
43
 
                for (i = 0; (child = childNodes[i++]);) {
44
 
                    if (child.tagName) {
45
 
                        if (!tag || tag === child.tagName) {
46
 
                            ret.push(child);
47
 
                        }
48
 
                    }
49
 
                }
50
 
            }
51
 
 
52
 
            return ret || [];
53
 
        },
54
 
 
55
 
        _re: {
56
 
            attr: /(\[[^\]]*\])/g,
57
 
            esc: /\\[:\[\]\(\)#\.\'\>+~"]/gi,
58
 
            pseudos: /(\([^\)]*\))/g
59
 
        },
60
 
 
61
 
        /**
62
 
         * Mapping of shorthand tokens to corresponding attribute selector 
63
 
         * @property shorthand
64
 
         * @type object
65
 
         */
66
 
        shorthand: {
67
 
            '\\#(-?[_a-z0-9]+[-\\w\\uE000]*)': '[id=$1]',
68
 
            '\\.(-?[_a-z]+[-\\w\\uE000]*)': '[className~=$1]'
69
 
        },
70
 
 
71
 
        /**
72
 
         * List of operators and corresponding boolean functions. 
73
 
         * These functions are passed the attribute and the current node's value of the attribute.
74
 
         * @property operators
75
 
         * @type object
76
 
         */
77
 
        operators: {
78
 
            '': function(node, attr) { return Y.DOM.getAttribute(node, attr) !== ''; }, // Just test for existence of attribute
79
 
            //'': '.+',
80
 
            //'=': '^{val}$', // equality
81
 
            '~=': '(?:^|\\s+){val}(?:\\s+|$)', // space-delimited
82
 
            '|=': '^{val}-?' // optional hyphen-delimited
83
 
        },
84
 
 
85
 
        pseudos: {
86
 
           'first-child': function(node) { 
87
 
                return Y.Selector._children(node[PARENT_NODE])[0] === node; 
88
 
            } 
89
 
        },
90
 
 
91
 
        _bruteQuery: function(selector, root, firstOnly) {
92
 
            var ret = [],
93
 
                nodes = [],
94
 
                tokens = Selector._tokenize(selector),
95
 
                token = tokens[tokens.length - 1],
96
 
                rootDoc = Y.DOM._getDoc(root),
97
 
                child,
98
 
                id,
99
 
                className,
100
 
                tagName;
101
 
 
102
 
 
103
 
            // if we have an initial ID, set to root when in document
104
 
            /*
105
 
            if (tokens[0] && rootDoc === root &&  
106
 
                    (id = tokens[0].id) &&
107
 
                    rootDoc.getElementById(id)) {
108
 
                root = rootDoc.getElementById(id);
109
 
            }
110
 
            */
111
 
 
112
 
            if (token) {
113
 
                // prefilter nodes
114
 
                id = token.id;
115
 
                className = token.className;
116
 
                tagName = token.tagName || '*';
117
 
 
118
 
                if (root.getElementsByTagName) { // non-IE lacks DOM api on doc frags
119
 
                    // try ID first, unless no root.all && root not in document
120
 
                    // (root.all works off document, but not getElementById)
121
 
                    // TODO: move to allById?
122
 
                    if (id && (root.all || (root.nodeType === 9 || Y.DOM.inDoc(root)))) {
123
 
                        nodes = Y.DOM.allById(id, root);
124
 
                    // try className
125
 
                    } else if (className) {
126
 
                        nodes = root.getElementsByClassName(className);
127
 
                    } else { // default to tagName
128
 
                        nodes = root.getElementsByTagName(tagName);
129
 
                    }
130
 
 
131
 
                } else { // brute getElementsByTagName('*')
132
 
                    child = root.firstChild;
133
 
                    while (child) {
134
 
                        if (child.tagName) { // only collect HTMLElements
135
 
                            nodes.push(child);
136
 
                        }
137
 
                        child = child.nextSilbing || child.firstChild;
138
 
                    }
139
 
                }
140
 
                if (nodes.length) {
141
 
                    ret = Selector._filterNodes(nodes, tokens, firstOnly);
142
 
                }
143
 
            }
144
 
 
145
 
            return ret;
146
 
        },
147
 
        
148
 
        _filterNodes: function(nodes, tokens, firstOnly) {
149
 
            var i = 0,
150
 
                j,
151
 
                len = tokens.length,
152
 
                n = len - 1,
153
 
                result = [],
154
 
                node = nodes[0],
155
 
                tmpNode = node,
156
 
                getters = Y.Selector.getters,
157
 
                operator,
158
 
                combinator,
159
 
                token,
160
 
                path,
161
 
                pass,
162
 
                //FUNCTION = 'function',
163
 
                value,
164
 
                tests,
165
 
                test;
166
 
 
167
 
            //do {
168
 
            for (i = 0; (tmpNode = node = nodes[i++]);) {
169
 
                n = len - 1;
170
 
                path = null;
171
 
                
172
 
                testLoop:
173
 
                while (tmpNode && tmpNode.tagName) {
174
 
                    token = tokens[n];
175
 
                    tests = token.tests;
176
 
                    j = tests.length;
177
 
                    if (j && !pass) {
178
 
                        while ((test = tests[--j])) {
179
 
                            operator = test[1];
180
 
                            if (getters[test[0]]) {
181
 
                                value = getters[test[0]](tmpNode, test[0]);
182
 
                            } else {
183
 
                                value = tmpNode[test[0]];
184
 
                                // use getAttribute for non-standard attributes
185
 
                                if (value === undefined && tmpNode.getAttribute) {
186
 
                                    value = tmpNode.getAttribute(test[0]);
187
 
                                }
188
 
                            }
189
 
 
190
 
                            if ((operator === '=' && value !== test[2]) ||  // fast path for equality
191
 
                                (typeof operator !== 'string' && // protect against String.test monkey-patch (Moo)
192
 
                                operator.test && !operator.test(value)) ||  // regex test
193
 
                                (!operator.test && // protect against RegExp as function (webkit)
194
 
                                        typeof operator === 'function' && !operator(tmpNode, test[0], test[2]))) { // function test
195
 
 
196
 
                                // skip non element nodes or non-matching tags
197
 
                                if ((tmpNode = tmpNode[path])) {
198
 
                                    while (tmpNode &&
199
 
                                        (!tmpNode.tagName ||
200
 
                                            (token.tagName && token.tagName !== tmpNode.tagName))
201
 
                                    ) {
202
 
                                        tmpNode = tmpNode[path]; 
203
 
                                    }
204
 
                                }
205
 
                                continue testLoop;
206
 
                            }
207
 
                        }
208
 
                    }
209
 
 
210
 
                    n--; // move to next token
211
 
                    // now that we've passed the test, move up the tree by combinator
212
 
                    if (!pass && (combinator = token.combinator)) {
213
 
                        path = combinator.axis;
214
 
                        tmpNode = tmpNode[path];
215
 
 
216
 
                        // skip non element nodes
217
 
                        while (tmpNode && !tmpNode.tagName) {
218
 
                            tmpNode = tmpNode[path]; 
219
 
                        }
220
 
 
221
 
                        if (combinator.direct) { // one pass only
222
 
                            path = null; 
223
 
                        }
224
 
 
225
 
                    } else { // success if we made it this far
226
 
                        result.push(node);
227
 
                        if (firstOnly) {
228
 
                            return result;
229
 
                        }
230
 
                        break;
231
 
                    }
232
 
                }
233
 
            }// while (tmpNode = node = nodes[++i]);
234
 
            node = tmpNode = null;
235
 
            return result;
236
 
        },
237
 
 
238
 
        combinators: {
239
 
            ' ': {
240
 
                axis: 'parentNode'
241
 
            },
242
 
 
243
 
            '>': {
244
 
                axis: 'parentNode',
245
 
                direct: true
246
 
            },
247
 
 
248
 
 
249
 
            '+': {
250
 
                axis: 'previousSibling',
251
 
                direct: true
252
 
            }
253
 
        },
254
 
 
255
 
        _parsers: [
256
 
            {
257
 
                name: ATTRIBUTES,
258
 
                re: /^\uE003(-?[a-z]+[\w\-]*)+([~\|\^\$\*!=]=?)?['"]?([^\uE004'"]*)['"]?\uE004/i,
259
 
                fn: function(match, token) {
260
 
                    var operator = match[2] || '',
261
 
                        operators = Selector.operators,
262
 
                        escVal = (match[3]) ? match[3].replace(/\\/g, '') : '',
263
 
                        test;
264
 
 
265
 
                    // add prefiltering for ID and CLASS
266
 
                    if ((match[1] === 'id' && operator === '=') ||
267
 
                            (match[1] === 'className' &&
268
 
                            Y.config.doc.documentElement.getElementsByClassName &&
269
 
                            (operator === '~=' || operator === '='))) {
270
 
                        token.prefilter = match[1];
271
 
 
272
 
 
273
 
                        match[3] = escVal; 
274
 
 
275
 
                        // escape all but ID for prefilter, which may run through QSA (via Dom.allById)
276
 
                        token[match[1]] = (match[1] === 'id') ? match[3] : escVal;
277
 
 
278
 
                    }
279
 
 
280
 
                    // add tests
281
 
                    if (operator in operators) {
282
 
                        test = operators[operator];
283
 
                        if (typeof test === 'string') {
284
 
                            match[3] = escVal.replace(Selector._reRegExpTokens, '\\$1');
285
 
                            test = new RegExp(test.replace('{val}', match[3]));
286
 
                        }
287
 
                        match[2] = test;
288
 
                    }
289
 
                    if (!token.last || token.prefilter !== match[1]) {
290
 
                        return match.slice(1);
291
 
                    }
292
 
                }
293
 
            },
294
 
            {
295
 
                name: TAG_NAME,
296
 
                re: /^((?:-?[_a-z]+[\w-]*)|\*)/i,
297
 
                fn: function(match, token) {
298
 
                    var tag = match[1].toUpperCase();
299
 
                    token.tagName = tag;
300
 
 
301
 
                    if (tag !== '*' && (!token.last || token.prefilter)) {
302
 
                        return [TAG_NAME, '=', tag];
303
 
                    }
304
 
                    if (!token.prefilter) {
305
 
                        token.prefilter = 'tagName';
306
 
                    }
307
 
                }
308
 
            },
309
 
            {
310
 
                name: COMBINATOR,
311
 
                re: /^\s*([>+~]|\s)\s*/,
312
 
                fn: function(match, token) {
313
 
                }
314
 
            },
315
 
            {
316
 
                name: PSEUDOS,
317
 
                re: /^:([\-\w]+)(?:\uE005['"]?([^\uE005]*)['"]?\uE006)*/i,
318
 
                fn: function(match, token) {
319
 
                    var test = Selector[PSEUDOS][match[1]];
320
 
                    if (test) { // reorder match array and unescape special chars for tests
321
 
                        if (match[2]) {
322
 
                            match[2] = match[2].replace(/\\/g, '');
323
 
                        }
324
 
                        return [match[2], test]; 
325
 
                    } else { // selector token not supported (possibly missing CSS3 module)
326
 
                        return false;
327
 
                    }
328
 
                }
329
 
            }
330
 
            ],
331
 
 
332
 
        _getToken: function(token) {
333
 
            return {
334
 
                tagName: null,
335
 
                id: null,
336
 
                className: null,
337
 
                attributes: {},
338
 
                combinator: null,
339
 
                tests: []
340
 
            };
341
 
        },
342
 
 
343
 
        /*
344
 
            Break selector into token units per simple selector.
345
 
            Combinator is attached to the previous token.
346
 
         */
347
 
        _tokenize: function(selector) {
348
 
            selector = selector || '';
349
 
            selector = Selector._replaceShorthand(Y.Lang.trim(selector)); 
350
 
            var token = Selector._getToken(),     // one token per simple selector (left selector holds combinator)
351
 
                query = selector, // original query for debug report
352
 
                tokens = [],    // array of tokens
353
 
                found = false,  // whether or not any matches were found this pass
354
 
                match,         // the regex match
355
 
                test,
356
 
                i, parser;
357
 
 
358
 
            /*
359
 
                Search for selector patterns, store, and strip them from the selector string
360
 
                until no patterns match (invalid selector) or we run out of chars.
361
 
 
362
 
                Multiple attributes and pseudos are allowed, in any order.
363
 
                for example:
364
 
                    'form:first-child[type=button]:not(button)[lang|=en]'
365
 
            */
366
 
            outer:
367
 
            do {
368
 
                found = false; // reset after full pass
369
 
                for (i = 0; (parser = Selector._parsers[i++]);) {
370
 
                    if ( (match = parser.re.exec(selector)) ) { // note assignment
371
 
                        if (parser.name !== COMBINATOR ) {
372
 
                            token.selector = selector;
373
 
                        }
374
 
                        selector = selector.replace(match[0], ''); // strip current match from selector
375
 
                        if (!selector.length) {
376
 
                            token.last = true;
377
 
                        }
378
 
 
379
 
                        if (Selector._attrFilters[match[1]]) { // convert class to className, etc.
380
 
                            match[1] = Selector._attrFilters[match[1]];
381
 
                        }
382
 
 
383
 
                        test = parser.fn(match, token);
384
 
                        if (test === false) { // selector not supported
385
 
                            found = false;
386
 
                            break outer;
387
 
                        } else if (test) {
388
 
                            token.tests.push(test);
389
 
                        }
390
 
 
391
 
                        if (!selector.length || parser.name === COMBINATOR) {
392
 
                            tokens.push(token);
393
 
                            token = Selector._getToken(token);
394
 
                            if (parser.name === COMBINATOR) {
395
 
                                token.combinator = Y.Selector.combinators[match[1]];
396
 
                            }
397
 
                        }
398
 
                        found = true;
399
 
                    }
400
 
                }
401
 
            } while (found && selector.length);
402
 
 
403
 
            if (!found || selector.length) { // not fully parsed
404
 
                Y.log('query: ' + query + ' contains unsupported token in: ' + selector, 'warn', 'Selector');
405
 
                tokens = [];
406
 
            }
407
 
            return tokens;
408
 
        },
409
 
 
410
 
        _replaceShorthand: function(selector) {
411
 
            var shorthand = Selector.shorthand,
412
 
                esc = selector.match(Selector._re.esc), // pull escaped colon, brackets, etc. 
413
 
                attrs,
414
 
                pseudos,
415
 
                re, i, len;
416
 
 
417
 
            if (esc) {
418
 
                selector = selector.replace(Selector._re.esc, '\uE000');
419
 
            }
420
 
 
421
 
            attrs = selector.match(Selector._re.attr);
422
 
            pseudos = selector.match(Selector._re.pseudos);
423
 
 
424
 
            if (attrs) {
425
 
                selector = selector.replace(Selector._re.attr, '\uE001');
426
 
            }
427
 
 
428
 
            if (pseudos) {
429
 
                selector = selector.replace(Selector._re.pseudos, '\uE002');
430
 
            }
431
 
 
432
 
 
433
 
            for (re in shorthand) {
434
 
                if (shorthand.hasOwnProperty(re)) {
435
 
                    selector = selector.replace(new RegExp(re, 'gi'), shorthand[re]);
436
 
                }
437
 
            }
438
 
 
439
 
            if (attrs) {
440
 
                for (i = 0, len = attrs.length; i < len; ++i) {
441
 
                    selector = selector.replace(/\uE001/, attrs[i]);
442
 
                }
443
 
            }
444
 
 
445
 
            if (pseudos) {
446
 
                for (i = 0, len = pseudos.length; i < len; ++i) {
447
 
                    selector = selector.replace(/\uE002/, pseudos[i]);
448
 
                }
449
 
            }
450
 
 
451
 
            selector = selector.replace(/\[/g, '\uE003');
452
 
            selector = selector.replace(/\]/g, '\uE004');
453
 
 
454
 
            selector = selector.replace(/\(/g, '\uE005');
455
 
            selector = selector.replace(/\)/g, '\uE006');
456
 
 
457
 
            if (esc) {
458
 
                for (i = 0, len = esc.length; i < len; ++i) {
459
 
                    selector = selector.replace('\uE000', esc[i]);
460
 
                }
461
 
            }
462
 
 
463
 
            return selector;
464
 
        },
465
 
 
466
 
        _attrFilters: {
467
 
            'class': 'className',
468
 
            'for': 'htmlFor'
469
 
        },
470
 
 
471
 
        getters: {
472
 
            href: function(node, attr) {
473
 
                return Y.DOM.getAttribute(node, attr);
474
 
            }
475
 
        }
476
 
    };
477
 
 
478
 
Y.mix(Y.Selector, SelectorCSS2, true);
479
 
Y.Selector.getters.src = Y.Selector.getters.rel = Y.Selector.getters.href;
480
 
 
481
 
// IE wants class with native queries
482
 
if (Y.Selector.useNative && Y.config.doc.querySelector) {
483
 
    Y.Selector.shorthand['\\.(-?[_a-z]+[-\\w]*)'] = '[class~=$1]';
484
 
}
485
 
 
486
 
 
487
 
 
488
 
}, '3.4.1' ,{requires:['selector-native']});