-
Notifications
You must be signed in to change notification settings - Fork 3
/
html.js
56 lines (45 loc) · 1.69 KB
/
html.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* @license RequireJS html 0.0.2 Copyright (c) 2012-2012, Gabriel Reitz Giannattasio All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/gartz/html for details
*/
/*jslint regexp: true */
/*global define: false */
define(['text'], function (text) {
'use strict';
var html = {
load: function (name, req, load, config) {
// Do not bother with the work if a build
if (config.isBuild) {
load();
return;
}
req(['text!' + name], function (value) {
var doc = document.createDocumentFragment();
var re = /<html( |>)((.|[\r\n])*)<\/html(.*)>|<head( |>)((.|[\r\n])*)<\/head(.*)>/i;
var isDocument = re.test(value);
var el = document.createElement(isDocument ? 'html' : 'body');
el.innerHTML = value;
if (el.children) {
for (var i = 0, max = el.children.length; i < max; i++) {
doc.appendChild(el.children[0]);
}
}
var stash = doc.cloneNode(true);
doc.stash = function () {
if (this.childNodes) {
var nodes = this.childNodes;
for (var i = 0, max = nodes.length; i < max; i++) {
this.removeChild(nodes[0]);
}
}
this.appendChild(stash.cloneNode(true));
};
doc.path = name;
doc.source = value;
load(doc);
});
}
};
return html;
});