1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | function require(p, parent, orig){
|
10 | var path = require.resolve(p)
|
11 | , mod = require.modules[path];
|
12 |
|
13 |
|
14 | if (null == path) {
|
15 | orig = orig || p;
|
16 | parent = parent || 'root';
|
17 | throw new Error('failed to require "' + orig + '" from "' + parent + '"');
|
18 | }
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | if (!mod.exports) {
|
24 | mod.exports = {};
|
25 | mod.client = mod.component = true;
|
26 | mod.call(this, mod, mod.exports, require.relative(path));
|
27 | }
|
28 |
|
29 | return mod.exports;
|
30 | }
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | require.modules = {};
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | require.aliases = {};
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | require.resolve = function(path){
|
59 | var orig = path
|
60 | , reg = path + '.js'
|
61 | , regJSON = path + '.json'
|
62 | , index = path + '/index.js'
|
63 | , indexJSON = path + '/index.json';
|
64 |
|
65 | return require.modules[reg] && reg
|
66 | || require.modules[regJSON] && regJSON
|
67 | || require.modules[index] && index
|
68 | || require.modules[indexJSON] && indexJSON
|
69 | || require.modules[orig] && orig
|
70 | || require.aliases[index];
|
71 | };
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | require.normalize = function(curr, path) {
|
83 | var segs = [];
|
84 |
|
85 | if ('.' != path.charAt(0)) return path;
|
86 |
|
87 | curr = curr.split('/');
|
88 | path = path.split('/');
|
89 |
|
90 | for (var i = 0; i < path.length; ++i) {
|
91 | if ('..' == path[i]) {
|
92 | curr.pop();
|
93 | } else if ('.' != path[i] && '' != path[i]) {
|
94 | segs.push(path[i]);
|
95 | }
|
96 | }
|
97 |
|
98 | return curr.concat(segs).join('/');
|
99 | };
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 | require.register = function(path, fn){
|
110 | require.modules[path] = fn;
|
111 | };
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 | require.alias = function(from, to){
|
122 | var fn = require.modules[from];
|
123 | if (!fn) throw new Error('failed to alias "' + from + '", it does not exist');
|
124 | require.aliases[to] = from;
|
125 | };
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 | require.relative = function(parent) {
|
136 | var p = require.normalize(parent, '..');
|
137 |
|
138 | |
139 |
|
140 |
|
141 |
|
142 | function lastIndexOf(arr, obj){
|
143 | var i = arr.length;
|
144 | while (i--) {
|
145 | if (arr[i] === obj) return i;
|
146 | }
|
147 | return -1;
|
148 | }
|
149 |
|
150 | |
151 |
|
152 |
|
153 |
|
154 | function fn(path){
|
155 | var orig = path;
|
156 | path = fn.resolve(path);
|
157 | return require(path, parent, orig);
|
158 | }
|
159 |
|
160 | |
161 |
|
162 |
|
163 |
|
164 | fn.resolve = function(path){
|
165 |
|
166 |
|
167 |
|
168 | if ('.' != path.charAt(0)) {
|
169 | var segs = parent.split('/');
|
170 | var i = lastIndexOf(segs, 'deps') + 1;
|
171 | if (!i) i = 0;
|
172 | path = segs.slice(0, i + 1).join('/') + '/deps/' + path;
|
173 | return path;
|
174 | }
|
175 | return require.normalize(p, path);
|
176 | };
|
177 |
|
178 | |
179 |
|
180 |
|
181 |
|
182 | fn.exists = function(path){
|
183 | return !! require.modules[fn.resolve(path)];
|
184 | };
|
185 |
|
186 | return fn;
|
187 | };require.register("domify/index.js", function(module, exports, require){
|
188 |
|
189 |
|
190 |
|
191 |
|
192 |
|
193 | var map = {
|
194 | option: [1, '<select multiple="multiple">', '</select>'],
|
195 | optgroup: [1, '<select multiple="multiple">', '</select>'],
|
196 | legend: [1, '<fieldset>', '</fieldset>'],
|
197 | thead: [1, '<table>', '</table>'],
|
198 | tbody: [1, '<table>', '</table>'],
|
199 | tfoot: [1, '<table>', '</table>'],
|
200 | colgroup: [1, '<table>', '</table>'],
|
201 | caption: [1, '<table>', '</table>'],
|
202 | tr: [2, '<table><tbody>', '</tbody></table>'],
|
203 | td: [3, '<table><tbody><tr>', '</tr></tbody></table>'],
|
204 | th: [3, '<table><tbody><tr>', '</tr></tbody></table>'],
|
205 | col: [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'],
|
206 | _default: [0, '', '']
|
207 | };
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 | module.exports = function(html){
|
216 | if ('string' != typeof html) throw new TypeError('String expected');
|
217 |
|
218 |
|
219 | var m = /<([\w:]+)/.exec(html);
|
220 | if (!m) throw new Error('No elements were generated.');
|
221 | var tag = m[1];
|
222 |
|
223 |
|
224 | if (tag == 'body') {
|
225 | var el = document.createElement('html');
|
226 | el.innerHTML = html;
|
227 | return el.removeChild(el.lastChild);
|
228 | }
|
229 |
|
230 |
|
231 | var wrap = map[tag] || map._default;
|
232 | var depth = wrap[0];
|
233 | var prefix = wrap[1];
|
234 | var suffix = wrap[2];
|
235 | var el = document.createElement('div');
|
236 | el.innerHTML = prefix + html + suffix;
|
237 | while (depth--) el = el.lastChild;
|
238 |
|
239 | if (el.lastChild.nextElementSibling || el.lastChild.previousElementSibling) {
|
240 | throw new Error('More than one element was generated.');
|
241 | }
|
242 |
|
243 | return el.removeChild(el.lastChild);
|
244 | };
|
245 |
|
246 | });
|