-
Notifications
You must be signed in to change notification settings - Fork 0
/
csi.js
40 lines (33 loc) · 1.24 KB
/
csi.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
$(function() {
var commentNodes = [];
var getCommentsFromChildNodes = function(node) {
var childNodes = node.childNodes;
for (var i = 0, length = childNodes.length, childNode; i < length; i++) {
childNode = childNodes[i];
if (childNode.nodeType === 8) commentNodes.push(childNode);
if (childNode.hasChildNodes()) getCommentsFromChildNodes(childNode);
}
};
var getIncludesFromCommentNodes = function(commentNodes) {
var includeNodes = [];
var pattern = /^#include virtual\=".+"/;
for (var i = 0, length = commentNodes.length; i < length; i++) {
if (pattern.test(commentNodes[i].nodeValue)) includeNodes.push(commentNodes[i]);
}
return includeNodes;
};
getCommentsFromChildNodes(document);
var includeNodes = getIncludesFromCommentNodes(commentNodes);
var includePath;
for (var i = 0, length = includeNodes.length, includeNode; i < length; i++) {
includeNode = includeNodes[i];
includePath = $.trim(includeNode.nodeValue);
includePath = includePath.substring(18, includePath.length - 1);
$.ajax({
url: includePath,
async: false,
dataType: 'html',
success: function(data) { $(includeNode).after($(data)).remove(); }
});
}
});