~lutostag/ubuntu/utopic/maas/1.5.2

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/build/dom-base/dom-base-debug.js

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-03-15 18:14:08 UTC
  • mfrom: (1.1.3)
  • Revision ID: package-import@ubuntu.com-20120315181408-zgl94hzo0x4n99an
Tags: 0.1+bzr295+dfsg-0ubuntu2
* debian/patches:
  - 01-fix-database-settings.patch: Update to set PSERV_URL.
  - 02-pserv-config.patch: Set port to 8001.
* debian/maas.postinst: Run maas-import-isos on install.
* debian/control: Depends on rabbitmq-server.

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('dom-base', function(Y) {
 
8
 
 
9
var documentElement = Y.config.doc.documentElement,
 
10
    Y_DOM = Y.DOM,
 
11
    TAG_NAME = 'tagName',
 
12
    OWNER_DOCUMENT = 'ownerDocument',
 
13
    EMPTY_STRING = '',
 
14
    addFeature = Y.Features.add,
 
15
    testFeature = Y.Features.test;
 
16
 
 
17
Y.mix(Y_DOM, {
 
18
    /**
 
19
     * Returns the text content of the HTMLElement. 
 
20
     * @method getText         
 
21
     * @param {HTMLElement} element The html element. 
 
22
     * @return {String} The text content of the element (includes text of any descending elements).
 
23
     */
 
24
    getText: (documentElement.textContent !== undefined) ?
 
25
        function(element) {
 
26
            var ret = '';
 
27
            if (element) {
 
28
                ret = element.textContent;
 
29
            }
 
30
            return ret || '';
 
31
        } : function(element) {
 
32
            var ret = '';
 
33
            if (element) {
 
34
                ret = element.innerText || element.nodeValue; // might be a textNode
 
35
            }
 
36
            return ret || '';
 
37
        },
 
38
 
 
39
    /**
 
40
     * Sets the text content of the HTMLElement. 
 
41
     * @method setText         
 
42
     * @param {HTMLElement} element The html element. 
 
43
     * @param {String} content The content to add. 
 
44
     */
 
45
    setText: (documentElement.textContent !== undefined) ?
 
46
        function(element, content) {
 
47
            if (element) {
 
48
                element.textContent = content;
 
49
            }
 
50
        } : function(element, content) {
 
51
            if ('innerText' in element) {
 
52
                element.innerText = content;
 
53
            } else if ('nodeValue' in element) {
 
54
                element.nodeValue = content;
 
55
            }
 
56
    },
 
57
 
 
58
    CUSTOM_ATTRIBUTES: (!documentElement.hasAttribute) ? { // IE < 8
 
59
        'for': 'htmlFor',
 
60
        'class': 'className'
 
61
    } : { // w3c
 
62
        'htmlFor': 'for',
 
63
        'className': 'class'
 
64
    },
 
65
 
 
66
    /**
 
67
     * Provides a normalized attribute interface. 
 
68
     * @method setAttribute
 
69
     * @param {HTMLElement} el The target element for the attribute.
 
70
     * @param {String} attr The attribute to set.
 
71
     * @param {String} val The value of the attribute.
 
72
     */
 
73
    setAttribute: function(el, attr, val, ieAttr) {
 
74
        if (el && attr && el.setAttribute) {
 
75
            attr = Y_DOM.CUSTOM_ATTRIBUTES[attr] || attr;
 
76
            el.setAttribute(attr, val, ieAttr);
 
77
        }
 
78
        else { Y.log('bad input to setAttribute', 'warn', 'dom'); }
 
79
    },
 
80
 
 
81
 
 
82
    /**
 
83
     * Provides a normalized attribute interface. 
 
84
     * @method getAttibute
 
85
     * @param {HTMLElement} el The target element for the attribute.
 
86
     * @param {String} attr The attribute to get.
 
87
     * @return {String} The current value of the attribute. 
 
88
     */
 
89
    getAttribute: function(el, attr, ieAttr) {
 
90
        ieAttr = (ieAttr !== undefined) ? ieAttr : 2;
 
91
        var ret = '';
 
92
        if (el && attr && el.getAttribute) {
 
93
            attr = Y_DOM.CUSTOM_ATTRIBUTES[attr] || attr;
 
94
            ret = el.getAttribute(attr, ieAttr);
 
95
 
 
96
            if (ret === null) {
 
97
                ret = ''; // per DOM spec
 
98
            }
 
99
        }
 
100
        else { Y.log('bad input to getAttribute', 'warn', 'dom'); }
 
101
        return ret;
 
102
    },
 
103
 
 
104
    VALUE_SETTERS: {},
 
105
 
 
106
    VALUE_GETTERS: {},
 
107
 
 
108
    getValue: function(node) {
 
109
        var ret = '', // TODO: return null?
 
110
            getter;
 
111
 
 
112
        if (node && node[TAG_NAME]) {
 
113
            getter = Y_DOM.VALUE_GETTERS[node[TAG_NAME].toLowerCase()];
 
114
 
 
115
            if (getter) {
 
116
                ret = getter(node);
 
117
            } else {
 
118
                ret = node.value;
 
119
            }
 
120
        }
 
121
 
 
122
        // workaround for IE8 JSON stringify bug
 
123
        // which converts empty string values to null
 
124
        if (ret === EMPTY_STRING) {
 
125
            ret = EMPTY_STRING; // for real
 
126
        }
 
127
 
 
128
        return (typeof ret === 'string') ? ret : '';
 
129
    },
 
130
 
 
131
    setValue: function(node, val) {
 
132
        var setter;
 
133
 
 
134
        if (node && node[TAG_NAME]) {
 
135
            setter = Y_DOM.VALUE_SETTERS[node[TAG_NAME].toLowerCase()];
 
136
 
 
137
            if (setter) {
 
138
                setter(node, val);
 
139
            } else {
 
140
                node.value = val;
 
141
            }
 
142
        }
 
143
    },
 
144
 
 
145
    creators: {}
 
146
});
 
147
 
 
148
addFeature('value-set', 'select', {
 
149
    test: function() {
 
150
        var node = Y.config.doc.createElement('select');
 
151
        node.innerHTML = '<option>1</option><option>2</option>';
 
152
        node.value = '2';
 
153
        return (node.value && node.value === '2');
 
154
    }
 
155
});
 
156
 
 
157
if (!testFeature('value-set', 'select')) {
 
158
    Y_DOM.VALUE_SETTERS.select = function(node, val) {
 
159
        for (var i = 0, options = node.getElementsByTagName('option'), option;
 
160
                option = options[i++];) {
 
161
            if (Y_DOM.getValue(option) === val) {
 
162
                option.selected = true;
 
163
                //Y_DOM.setAttribute(option, 'selected', 'selected');
 
164
                break;
 
165
            }
 
166
        }
 
167
    }
 
168
}
 
169
 
 
170
Y.mix(Y_DOM.VALUE_GETTERS, {
 
171
    button: function(node) {
 
172
        return (node.attributes && node.attributes.value) ? node.attributes.value.value : '';
 
173
    }
 
174
});
 
175
 
 
176
Y.mix(Y_DOM.VALUE_SETTERS, {
 
177
    // IE: node.value changes the button text, which should be handled via innerHTML
 
178
    button: function(node, val) {
 
179
        var attr = node.attributes.value;
 
180
        if (!attr) {
 
181
            attr = node[OWNER_DOCUMENT].createAttribute('value');
 
182
            node.setAttributeNode(attr);
 
183
        }
 
184
 
 
185
        attr.value = val;
 
186
    }
 
187
});
 
188
 
 
189
 
 
190
Y.mix(Y_DOM.VALUE_GETTERS, {
 
191
    option: function(node) {
 
192
        var attrs = node.attributes;
 
193
        return (attrs.value && attrs.value.specified) ? node.value : node.text;
 
194
    },
 
195
 
 
196
    select: function(node) {
 
197
        var val = node.value,
 
198
            options = node.options;
 
199
 
 
200
        if (options && options.length) {
 
201
            // TODO: implement multipe select
 
202
            if (node.multiple) {
 
203
                Y.log('multiple select normalization not implemented', 'warn', 'DOM');
 
204
            } else {
 
205
                val = Y_DOM.getValue(options[node.selectedIndex]);
 
206
            }
 
207
        }
 
208
 
 
209
        return val;
 
210
    }
 
211
});
 
212
var addClass, hasClass, removeClass;
 
213
 
 
214
Y.mix(Y.DOM, {
 
215
    /**
 
216
     * Determines whether a DOM element has the given className.
 
217
     * @method hasClass
 
218
     * @for DOM
 
219
     * @param {HTMLElement} element The DOM element. 
 
220
     * @param {String} className the class name to search for
 
221
     * @return {Boolean} Whether or not the element has the given class. 
 
222
     */
 
223
    hasClass: function(node, className) {
 
224
        var re = Y.DOM._getRegExp('(?:^|\\s+)' + className + '(?:\\s+|$)');
 
225
        return re.test(node.className);
 
226
    },
 
227
 
 
228
    /**
 
229
     * Adds a class name to a given DOM element.
 
230
     * @method addClass         
 
231
     * @for DOM
 
232
     * @param {HTMLElement} element The DOM element. 
 
233
     * @param {String} className the class name to add to the class attribute
 
234
     */
 
235
    addClass: function(node, className) {
 
236
        if (!Y.DOM.hasClass(node, className)) { // skip if already present 
 
237
            node.className = Y.Lang.trim([node.className, className].join(' '));
 
238
        }
 
239
    },
 
240
 
 
241
    /**
 
242
     * Removes a class name from a given element.
 
243
     * @method removeClass         
 
244
     * @for DOM
 
245
     * @param {HTMLElement} element The DOM element. 
 
246
     * @param {String} className the class name to remove from the class attribute
 
247
     */
 
248
    removeClass: function(node, className) {
 
249
        if (className && hasClass(node, className)) {
 
250
            node.className = Y.Lang.trim(node.className.replace(Y.DOM._getRegExp('(?:^|\\s+)' +
 
251
                            className + '(?:\\s+|$)'), ' '));
 
252
 
 
253
            if ( hasClass(node, className) ) { // in case of multiple adjacent
 
254
                removeClass(node, className);
 
255
            }
 
256
        }                 
 
257
    },
 
258
 
 
259
    /**
 
260
     * Replace a class with another class for a given element.
 
261
     * If no oldClassName is present, the newClassName is simply added.
 
262
     * @method replaceClass  
 
263
     * @for DOM
 
264
     * @param {HTMLElement} element The DOM element 
 
265
     * @param {String} oldClassName the class name to be replaced
 
266
     * @param {String} newClassName the class name that will be replacing the old class name
 
267
     */
 
268
    replaceClass: function(node, oldC, newC) {
 
269
        //Y.log('replaceClass replacing ' + oldC + ' with ' + newC, 'info', 'Node');
 
270
        removeClass(node, oldC); // remove first in case oldC === newC
 
271
        addClass(node, newC);
 
272
    },
 
273
 
 
274
    /**
 
275
     * If the className exists on the node it is removed, if it doesn't exist it is added.
 
276
     * @method toggleClass  
 
277
     * @for DOM
 
278
     * @param {HTMLElement} element The DOM element
 
279
     * @param {String} className the class name to be toggled
 
280
     * @param {Boolean} addClass optional boolean to indicate whether class
 
281
     * should be added or removed regardless of current state
 
282
     */
 
283
    toggleClass: function(node, className, force) {
 
284
        var add = (force !== undefined) ? force :
 
285
                !(hasClass(node, className));
 
286
 
 
287
        if (add) {
 
288
            addClass(node, className);
 
289
        } else {
 
290
            removeClass(node, className);
 
291
        }
 
292
    }
 
293
});
 
294
 
 
295
hasClass = Y.DOM.hasClass;
 
296
removeClass = Y.DOM.removeClass;
 
297
addClass = Y.DOM.addClass;
 
298
 
 
299
var re_tag = /<([a-z]+)/i,
 
300
 
 
301
    Y_DOM = Y.DOM,
 
302
 
 
303
    addFeature = Y.Features.add,
 
304
    testFeature = Y.Features.test,
 
305
 
 
306
    creators = {},
 
307
 
 
308
    createFromDIV = function(html, tag) {
 
309
        var div = Y.config.doc.createElement('div'),
 
310
            ret = true;
 
311
 
 
312
        div.innerHTML = html;
 
313
        if (!div.firstChild || div.firstChild.tagName !== tag.toUpperCase()) {
 
314
            ret = false;
 
315
        }
 
316
 
 
317
        return ret;
 
318
    },
 
319
 
 
320
    re_tbody = /(?:\/(?:thead|tfoot|tbody|caption|col|colgroup)>)+\s*<tbody/,
 
321
 
 
322
    TABLE_OPEN = '<table>',
 
323
    TABLE_CLOSE = '</table>';
 
324
 
 
325
Y.mix(Y.DOM, {
 
326
    _fragClones: {},
 
327
 
 
328
    _create: function(html, doc, tag) {
 
329
        tag = tag || 'div';
 
330
 
 
331
        var frag = Y_DOM._fragClones[tag];
 
332
        if (frag) {
 
333
            frag = frag.cloneNode(false);
 
334
        } else {
 
335
            frag = Y_DOM._fragClones[tag] = doc.createElement(tag);
 
336
        }
 
337
        frag.innerHTML = html;
 
338
        return frag;
 
339
    },
 
340
 
 
341
    /**
 
342
     * Creates a new dom node using the provided markup string. 
 
343
     * @method create
 
344
     * @param {String} html The markup used to create the element
 
345
     * @param {HTMLDocument} doc An optional document context 
 
346
     * @return {HTMLElement|DocumentFragment} returns a single HTMLElement 
 
347
     * when creating one node, and a documentFragment when creating
 
348
     * multiple nodes.
 
349
     */
 
350
    create: function(html, doc) {
 
351
        if (typeof html === 'string') {
 
352
            html = Y.Lang.trim(html); // match IE which trims whitespace from innerHTML
 
353
 
 
354
        }
 
355
 
 
356
        doc = doc || Y.config.doc;
 
357
        var m = re_tag.exec(html),
 
358
            create = Y_DOM._create,
 
359
            custom = creators,
 
360
            ret = null,
 
361
            creator,
 
362
            tag, nodes;
 
363
 
 
364
        if (html != undefined) { // not undefined or null
 
365
            if (m && m[1]) {
 
366
                creator = custom[m[1].toLowerCase()];
 
367
                if (typeof creator === 'function') {
 
368
                    create = creator; 
 
369
                } else {
 
370
                    tag = creator;
 
371
                }
 
372
            }
 
373
 
 
374
            nodes = create(html, doc, tag).childNodes;
 
375
 
 
376
            if (nodes.length === 1) { // return single node, breaking parentNode ref from "fragment"
 
377
                ret = nodes[0].parentNode.removeChild(nodes[0]);
 
378
            } else if (nodes[0] && nodes[0].className === 'yui3-big-dummy') { // using dummy node to preserve some attributes (e.g. OPTION not selected)
 
379
                if (nodes.length === 2) {
 
380
                    ret = nodes[0].nextSibling;
 
381
                } else {
 
382
                    nodes[0].parentNode.removeChild(nodes[0]); 
 
383
                     ret = Y_DOM._nl2frag(nodes, doc);
 
384
                }
 
385
            } else { // return multiple nodes as a fragment
 
386
                 ret = Y_DOM._nl2frag(nodes, doc);
 
387
            }
 
388
        }
 
389
 
 
390
        return ret;
 
391
    },
 
392
 
 
393
    _nl2frag: function(nodes, doc) {
 
394
        var ret = null,
 
395
            i, len;
 
396
 
 
397
        if (nodes && (nodes.push || nodes.item) && nodes[0]) {
 
398
            doc = doc || nodes[0].ownerDocument; 
 
399
            ret = doc.createDocumentFragment();
 
400
 
 
401
            if (nodes.item) { // convert live list to static array
 
402
                nodes = Y.Array(nodes, 0, true);
 
403
            }
 
404
 
 
405
            for (i = 0, len = nodes.length; i < len; i++) {
 
406
                ret.appendChild(nodes[i]); 
 
407
            }
 
408
        } // else inline with log for minification
 
409
        else { Y.log('unable to convert ' + nodes + ' to fragment', 'warn', 'dom'); }
 
410
        return ret;
 
411
    },
 
412
 
 
413
    /**
 
414
     * Inserts content in a node at the given location 
 
415
     * @method addHTML
 
416
     * @param {HTMLElement} node The node to insert into
 
417
     * @param {HTMLElement | Array | HTMLCollection} content The content to be inserted 
 
418
     * @param {HTMLElement} where Where to insert the content
 
419
     * If no "where" is given, content is appended to the node
 
420
     * Possible values for "where"
 
421
     * <dl>
 
422
     * <dt>HTMLElement</dt>
 
423
     * <dd>The element to insert before</dd>
 
424
     * <dt>"replace"</dt>
 
425
     * <dd>Replaces the existing HTML</dd>
 
426
     * <dt>"before"</dt>
 
427
     * <dd>Inserts before the existing HTML</dd>
 
428
     * <dt>"before"</dt>
 
429
     * <dd>Inserts content before the node</dd>
 
430
     * <dt>"after"</dt>
 
431
     * <dd>Inserts content after the node</dd>
 
432
     * </dl>
 
433
     */
 
434
    addHTML: function(node, content, where) {
 
435
        var nodeParent = node.parentNode,
 
436
            i = 0,
 
437
            item,
 
438
            ret = content,
 
439
            newNode;
 
440
            
 
441
 
 
442
        if (content != undefined) { // not null or undefined (maybe 0)
 
443
            if (content.nodeType) { // DOM node, just add it
 
444
                newNode = content;
 
445
            } else if (typeof content == 'string' || typeof content == 'number') {
 
446
                ret = newNode = Y_DOM.create(content);
 
447
            } else if (content[0] && content[0].nodeType) { // array or collection 
 
448
                newNode = Y.config.doc.createDocumentFragment();
 
449
                while ((item = content[i++])) {
 
450
                    newNode.appendChild(item); // append to fragment for insertion
 
451
                }
 
452
            }
 
453
        }
 
454
 
 
455
        if (where) {
 
456
            if (newNode && where.parentNode) { // insert regardless of relationship to node
 
457
                where.parentNode.insertBefore(newNode, where);
 
458
            } else {
 
459
                switch (where) {
 
460
                    case 'replace':
 
461
                        while (node.firstChild) {
 
462
                            node.removeChild(node.firstChild);
 
463
                        }
 
464
                        if (newNode) { // allow empty content to clear node
 
465
                            node.appendChild(newNode);
 
466
                        }
 
467
                        break;
 
468
                    case 'before':
 
469
                        if (newNode) {
 
470
                            nodeParent.insertBefore(newNode, node);
 
471
                        }
 
472
                        break;
 
473
                    case 'after':
 
474
                        if (newNode) {
 
475
                            if (node.nextSibling) { // IE errors if refNode is null
 
476
                                nodeParent.insertBefore(newNode, node.nextSibling);
 
477
                            } else {
 
478
                                nodeParent.appendChild(newNode);
 
479
                            }
 
480
                        }
 
481
                        break;
 
482
                    default:
 
483
                        if (newNode) {
 
484
                            node.appendChild(newNode);
 
485
                        }
 
486
                }
 
487
            }
 
488
        } else if (newNode) {
 
489
            node.appendChild(newNode);
 
490
        }
 
491
 
 
492
        return ret;
 
493
    }
 
494
});
 
495
 
 
496
addFeature('innerhtml', 'table', {
 
497
    test: function() {
 
498
        var node = Y.config.doc.createElement('table');
 
499
        try {
 
500
            node.innerHTML = '<tbody></tbody>';
 
501
        } catch(e) {
 
502
            return false;
 
503
        }
 
504
        return (node.firstChild && node.firstChild.nodeName === 'TBODY');
 
505
    }
 
506
});
 
507
 
 
508
addFeature('innerhtml-div', 'tr', {
 
509
    test: function() {
 
510
        return createFromDIV('<tr></tr>', 'tr');
 
511
    }
 
512
});
 
513
 
 
514
addFeature('innerhtml-div', 'script', {
 
515
    test: function() {
 
516
        return createFromDIV('<script></script>', 'script');
 
517
    }
 
518
});
 
519
 
 
520
if (!testFeature('innerhtml', 'table')) {
 
521
    // TODO: thead/tfoot with nested tbody
 
522
        // IE adds TBODY when creating TABLE elements (which may share this impl)
 
523
    creators.tbody = function(html, doc) {
 
524
        var frag = Y_DOM.create(TABLE_OPEN + html + TABLE_CLOSE, doc),
 
525
            tb = frag.children.tags('tbody')[0];
 
526
 
 
527
        if (frag.children.length > 1 && tb && !re_tbody.test(html)) {
 
528
            tb.parentNode.removeChild(tb); // strip extraneous tbody
 
529
        }
 
530
        return frag;
 
531
    };
 
532
}
 
533
 
 
534
if (!testFeature('innerhtml-div', 'script')) {
 
535
    creators.script = function(html, doc) {
 
536
        var frag = doc.createElement('div');
 
537
 
 
538
        frag.innerHTML = '-' + html;
 
539
        frag.removeChild(frag.firstChild);
 
540
        return frag;
 
541
    }
 
542
 
 
543
    creators.link = creators.style = creators.script;
 
544
}
 
545
 
 
546
if (!testFeature('innerhtml-div', 'tr')) {
 
547
    Y.mix(creators, {
 
548
        option: function(html, doc) {
 
549
            return Y_DOM.create('<select><option class="yui3-big-dummy" selected></option>' + html + '</select>', doc);
 
550
        },
 
551
 
 
552
        tr: function(html, doc) {
 
553
            return Y_DOM.create('<tbody>' + html + '</tbody>', doc);
 
554
        },
 
555
 
 
556
        td: function(html, doc) {
 
557
            return Y_DOM.create('<tr>' + html + '</tr>', doc);
 
558
        }, 
 
559
 
 
560
        col: function(html, doc) {
 
561
            return Y_DOM.create('<colgroup>' + html + '</colgroup>', doc);
 
562
        }, 
 
563
 
 
564
        tbody: 'table'
 
565
    });
 
566
 
 
567
    Y.mix(creators, {
 
568
        legend: 'fieldset',
 
569
        th: creators.td,
 
570
        thead: creators.tbody,
 
571
        tfoot: creators.tbody,
 
572
        caption: creators.tbody,
 
573
        colgroup: creators.tbody,
 
574
        optgroup: creators.option
 
575
    });
 
576
}
 
577
 
 
578
Y_DOM.creators = creators;
 
579
Y.mix(Y.DOM, {
 
580
    /**
 
581
     * Sets the width of the element to the given size, regardless
 
582
     * of box model, border, padding, etc.
 
583
     * @method setWidth
 
584
     * @param {HTMLElement} element The DOM element. 
 
585
     * @param {String|Int} size The pixel height to size to
 
586
     */
 
587
 
 
588
    setWidth: function(node, size) {
 
589
        Y.DOM._setSize(node, 'width', size);
 
590
    },
 
591
 
 
592
    /**
 
593
     * Sets the height of the element to the given size, regardless
 
594
     * of box model, border, padding, etc.
 
595
     * @method setHeight
 
596
     * @param {HTMLElement} element The DOM element. 
 
597
     * @param {String|Int} size The pixel height to size to
 
598
     */
 
599
 
 
600
    setHeight: function(node, size) {
 
601
        Y.DOM._setSize(node, 'height', size);
 
602
    },
 
603
 
 
604
    _setSize: function(node, prop, val) {
 
605
        val = (val > 0) ? val : 0;
 
606
        var size = 0;
 
607
 
 
608
        node.style[prop] = val + 'px';
 
609
        size = (prop === 'height') ? node.offsetHeight : node.offsetWidth;
 
610
 
 
611
        if (size > val) {
 
612
            val = val - (size - val);
 
613
 
 
614
            if (val < 0) {
 
615
                val = 0;
 
616
            }
 
617
 
 
618
            node.style[prop] = val + 'px';
 
619
        }
 
620
    }
 
621
});
 
622
 
 
623
 
 
624
}, '3.4.1' ,{requires:['dom-core']});