~ubuntu-branches/ubuntu/precise/maas/precise-security

« back to all changes in this revision

Viewing changes to debian/extras/jslibs/yui/dom-create/dom-create-debug.js

Tags: 1.2+bzr1373+dfsg-0ubuntu1~12.04.4
* SECURITY UPDATE: failure to authenticate downloaded content (LP: #1039513)
  - debian/patches/CVE-2013-1058.patch: Authenticate downloaded files with
    GnuPG and MD5SUM files. Thanks to Julian Edwards.
  - CVE-2013-1058
* SECURITY UPDATE: configuration options may be loaded from current working
  directory (LP: #1158425)
  - debian/patches/CVE-2013-1057-1-2.patch: Do not load configuration
    options from the current working directory. Thanks to Julian Edwards.
  - CVE-2013-1057

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
YUI 3.5.1 (build 22)
 
3
Copyright 2012 Yahoo! Inc. All rights reserved.
 
4
Licensed under the BSD License.
 
5
http://yuilibrary.com/license/
 
6
*/
 
7
YUI.add('dom-create', function(Y) {
 
8
 
 
9
var re_tag = /<([a-z]+)/i,
 
10
 
 
11
    Y_DOM = Y.DOM,
 
12
 
 
13
    addFeature = Y.Features.add,
 
14
    testFeature = Y.Features.test,
 
15
 
 
16
    creators = {},
 
17
 
 
18
    createFromDIV = function(html, tag) {
 
19
        var div = Y.config.doc.createElement('div'),
 
20
            ret = true;
 
21
 
 
22
        div.innerHTML = html;
 
23
        if (!div.firstChild || div.firstChild.tagName !== tag.toUpperCase()) {
 
24
            ret = false;
 
25
        }
 
26
 
 
27
        return ret;
 
28
    },
 
29
 
 
30
    re_tbody = /(?:\/(?:thead|tfoot|tbody|caption|col|colgroup)>)+\s*<tbody/,
 
31
 
 
32
    TABLE_OPEN = '<table>',
 
33
    TABLE_CLOSE = '</table>';
 
34
 
 
35
Y.mix(Y.DOM, {
 
36
    _fragClones: {},
 
37
 
 
38
    _create: function(html, doc, tag) {
 
39
        tag = tag || 'div';
 
40
 
 
41
        var frag = Y_DOM._fragClones[tag];
 
42
        if (frag) {
 
43
            frag = frag.cloneNode(false);
 
44
        } else {
 
45
            frag = Y_DOM._fragClones[tag] = doc.createElement(tag);
 
46
        }
 
47
        frag.innerHTML = html;
 
48
        return frag;
 
49
    },
 
50
 
 
51
    /**
 
52
     * Creates a new dom node using the provided markup string. 
 
53
     * @method create
 
54
     * @param {String} html The markup used to create the element
 
55
     * @param {HTMLDocument} doc An optional document context 
 
56
     * @return {HTMLElement|DocumentFragment} returns a single HTMLElement 
 
57
     * when creating one node, and a documentFragment when creating
 
58
     * multiple nodes.
 
59
     */
 
60
    create: function(html, doc) {
 
61
        if (typeof html === 'string') {
 
62
            html = Y.Lang.trim(html); // match IE which trims whitespace from innerHTML
 
63
 
 
64
        }
 
65
 
 
66
        doc = doc || Y.config.doc;
 
67
        var m = re_tag.exec(html),
 
68
            create = Y_DOM._create,
 
69
            custom = creators,
 
70
            ret = null,
 
71
            creator,
 
72
            tag, nodes;
 
73
 
 
74
        if (html != undefined) { // not undefined or null
 
75
            if (m && m[1]) {
 
76
                creator = custom[m[1].toLowerCase()];
 
77
                if (typeof creator === 'function') {
 
78
                    create = creator; 
 
79
                } else {
 
80
                    tag = creator;
 
81
                }
 
82
            }
 
83
 
 
84
            nodes = create(html, doc, tag).childNodes;
 
85
 
 
86
            if (nodes.length === 1) { // return single node, breaking parentNode ref from "fragment"
 
87
                ret = nodes[0].parentNode.removeChild(nodes[0]);
 
88
            } else if (nodes[0] && nodes[0].className === 'yui3-big-dummy') { // using dummy node to preserve some attributes (e.g. OPTION not selected)
 
89
                if (nodes.length === 2) {
 
90
                    ret = nodes[0].nextSibling;
 
91
                } else {
 
92
                    nodes[0].parentNode.removeChild(nodes[0]); 
 
93
                     ret = Y_DOM._nl2frag(nodes, doc);
 
94
                }
 
95
            } else { // return multiple nodes as a fragment
 
96
                 ret = Y_DOM._nl2frag(nodes, doc);
 
97
            }
 
98
        }
 
99
 
 
100
        return ret;
 
101
    },
 
102
 
 
103
    _nl2frag: function(nodes, doc) {
 
104
        var ret = null,
 
105
            i, len;
 
106
 
 
107
        if (nodes && (nodes.push || nodes.item) && nodes[0]) {
 
108
            doc = doc || nodes[0].ownerDocument; 
 
109
            ret = doc.createDocumentFragment();
 
110
 
 
111
            if (nodes.item) { // convert live list to static array
 
112
                nodes = Y.Array(nodes, 0, true);
 
113
            }
 
114
 
 
115
            for (i = 0, len = nodes.length; i < len; i++) {
 
116
                ret.appendChild(nodes[i]); 
 
117
            }
 
118
        } // else inline with log for minification
 
119
        else { Y.log('unable to convert ' + nodes + ' to fragment', 'warn', 'dom'); }
 
120
        return ret;
 
121
    },
 
122
 
 
123
    /**
 
124
     * Inserts content in a node at the given location 
 
125
     * @method addHTML
 
126
     * @param {HTMLElement} node The node to insert into
 
127
     * @param {HTMLElement | Array | HTMLCollection} content The content to be inserted 
 
128
     * @param {HTMLElement} where Where to insert the content
 
129
     * If no "where" is given, content is appended to the node
 
130
     * Possible values for "where"
 
131
     * <dl>
 
132
     * <dt>HTMLElement</dt>
 
133
     * <dd>The element to insert before</dd>
 
134
     * <dt>"replace"</dt>
 
135
     * <dd>Replaces the existing HTML</dd>
 
136
     * <dt>"before"</dt>
 
137
     * <dd>Inserts before the existing HTML</dd>
 
138
     * <dt>"before"</dt>
 
139
     * <dd>Inserts content before the node</dd>
 
140
     * <dt>"after"</dt>
 
141
     * <dd>Inserts content after the node</dd>
 
142
     * </dl>
 
143
     */
 
144
    addHTML: function(node, content, where) {
 
145
        var nodeParent = node.parentNode,
 
146
            i = 0,
 
147
            item,
 
148
            ret = content,
 
149
            newNode;
 
150
            
 
151
 
 
152
        if (content != undefined) { // not null or undefined (maybe 0)
 
153
            if (content.nodeType) { // DOM node, just add it
 
154
                newNode = content;
 
155
            } else if (typeof content == 'string' || typeof content == 'number') {
 
156
                ret = newNode = Y_DOM.create(content);
 
157
            } else if (content[0] && content[0].nodeType) { // array or collection 
 
158
                newNode = Y.config.doc.createDocumentFragment();
 
159
                while ((item = content[i++])) {
 
160
                    newNode.appendChild(item); // append to fragment for insertion
 
161
                }
 
162
            }
 
163
        }
 
164
 
 
165
        if (where) {
 
166
            if (where.nodeType) { // insert regardless of relationship to node
 
167
                where.parentNode.insertBefore(newNode, where);
 
168
            } else {
 
169
                switch (where) {
 
170
                    case 'replace':
 
171
                        while (node.firstChild) {
 
172
                            node.removeChild(node.firstChild);
 
173
                        }
 
174
                        if (newNode) { // allow empty content to clear node
 
175
                            node.appendChild(newNode);
 
176
                        }
 
177
                        break;
 
178
                    case 'before':
 
179
                        nodeParent.insertBefore(newNode, node);
 
180
                        break;
 
181
                    case 'after':
 
182
                        if (node.nextSibling) { // IE errors if refNode is null
 
183
                            nodeParent.insertBefore(newNode, node.nextSibling);
 
184
                        } else {
 
185
                            nodeParent.appendChild(newNode);
 
186
                        }
 
187
                        break;
 
188
                    default:
 
189
                        node.appendChild(newNode);
 
190
                }
 
191
            }
 
192
        } else if (newNode) {
 
193
            node.appendChild(newNode);
 
194
        }
 
195
 
 
196
        return ret;
 
197
    }
 
198
});
 
199
 
 
200
addFeature('innerhtml', 'table', {
 
201
    test: function() {
 
202
        var node = Y.config.doc.createElement('table');
 
203
        try {
 
204
            node.innerHTML = '<tbody></tbody>';
 
205
        } catch(e) {
 
206
            return false;
 
207
        }
 
208
        return (node.firstChild && node.firstChild.nodeName === 'TBODY');
 
209
    }
 
210
});
 
211
 
 
212
addFeature('innerhtml-div', 'tr', {
 
213
    test: function() {
 
214
        return createFromDIV('<tr></tr>', 'tr');
 
215
    }
 
216
});
 
217
 
 
218
addFeature('innerhtml-div', 'script', {
 
219
    test: function() {
 
220
        return createFromDIV('<script></script>', 'script');
 
221
    }
 
222
});
 
223
 
 
224
if (!testFeature('innerhtml', 'table')) {
 
225
    // TODO: thead/tfoot with nested tbody
 
226
        // IE adds TBODY when creating TABLE elements (which may share this impl)
 
227
    creators.tbody = function(html, doc) {
 
228
        var frag = Y_DOM.create(TABLE_OPEN + html + TABLE_CLOSE, doc),
 
229
            tb = frag.children.tags('tbody')[0];
 
230
 
 
231
        if (frag.children.length > 1 && tb && !re_tbody.test(html)) {
 
232
            tb.parentNode.removeChild(tb); // strip extraneous tbody
 
233
        }
 
234
        return frag;
 
235
    };
 
236
}
 
237
 
 
238
if (!testFeature('innerhtml-div', 'script')) {
 
239
    creators.script = function(html, doc) {
 
240
        var frag = doc.createElement('div');
 
241
 
 
242
        frag.innerHTML = '-' + html;
 
243
        frag.removeChild(frag.firstChild);
 
244
        return frag;
 
245
    }
 
246
 
 
247
    creators.link = creators.style = creators.script;
 
248
}
 
249
 
 
250
if (!testFeature('innerhtml-div', 'tr')) {
 
251
    Y.mix(creators, {
 
252
        option: function(html, doc) {
 
253
            return Y_DOM.create('<select><option class="yui3-big-dummy" selected></option>' + html + '</select>', doc);
 
254
        },
 
255
 
 
256
        tr: function(html, doc) {
 
257
            return Y_DOM.create('<tbody>' + html + '</tbody>', doc);
 
258
        },
 
259
 
 
260
        td: function(html, doc) {
 
261
            return Y_DOM.create('<tr>' + html + '</tr>', doc);
 
262
        }, 
 
263
 
 
264
        col: function(html, doc) {
 
265
            return Y_DOM.create('<colgroup>' + html + '</colgroup>', doc);
 
266
        }, 
 
267
 
 
268
        tbody: 'table'
 
269
    });
 
270
 
 
271
    Y.mix(creators, {
 
272
        legend: 'fieldset',
 
273
        th: creators.td,
 
274
        thead: creators.tbody,
 
275
        tfoot: creators.tbody,
 
276
        caption: creators.tbody,
 
277
        colgroup: creators.tbody,
 
278
        optgroup: creators.option
 
279
    });
 
280
}
 
281
 
 
282
Y_DOM.creators = creators;
 
283
 
 
284
 
 
285
}, '3.5.1' ,{requires:['dom-core']});