Skip to content

Commit

Permalink
fix issue mnot#23 Nested hincludes
Browse files Browse the repository at this point in the history
  • Loading branch information
s7ntech committed Apr 5, 2013
1 parent ee5760b commit b1d0d40
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
25 changes: 25 additions & 0 deletions hinclude.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ var hinclude;
var js_onload = this.hinclude_check_onload_body(parsed_document);
var js_code = this.hinclude_check_js_code(include);
this.run_hinclude_js(js_onload, js_code);
this.hinclude_check_child_include(include);
},

// verificarion exist head script
Expand Down Expand Up @@ -230,6 +231,30 @@ var hinclude;
}
},

// verification exists child hinclude
child_includes: [],
hinclude_check_child_include: function(include) {
if(!hinclude.isEmpty(include)) {
var i = 0;
var mode = this.get_meta("include_mode", "buffered");
var callback = function (element, req) {};
this.child_includes = include[0].getElementsByTagName("hx:include");
if (this.child_includes.length === 0) { // remove ns for IE
this.child_includes = include[0].getElementsByTagName("include");
}
if (mode === "async") {
callback = this.set_content_async;
} else if (mode === "buffered") {
callback = this.set_content_buffered;
var timeout = this.get_meta("include_timeout", 2.5) * 1000;
setTimeout(hinclude.show_buffered_content, timeout);
}
for (i; i < this.child_includes.length; i += 1) {
this.include(this.child_includes[i], this.child_includes[i].getAttribute("src"), callback);
}
}
},

// verification exists scripts into content
hinclude_check_js_code: function(include) {
var js_code = '';
Expand Down
3 changes: 2 additions & 1 deletion test/advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ var runTests = require('./framework.js').runTests;

var tests = [
['#onload', "this onload is executed"],
['#library', "this library is visible"]
['#library', "this library is visible"],
['#child', "child included"]
];

runTests("advanced.html", tests);
2 changes: 1 addition & 1 deletion test/assets/advanced.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ <h2 id="h">Advanced Include</h2>

<p id="a" name="a"><hx:include src="onload.html"></hx:include></p>
<p id="b" name="b"><hx:include src="library.html"></hx:include></p>

<p id="c" name="c"><hx:include src="child_hinclude.html"></hx:include></p>
</body>
</html>
1 change: 1 addition & 0 deletions test/assets/child
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<span id="child" style="text-decoration: underline">child included</span>
8 changes: 8 additions & 0 deletions test/assets/child_hinclude.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html xmlns:hx="http://purl.org/NET/hinclude">
<head>
<title>Child Test</title>
</head>
<body>
<hx:include src="child"></hx:include>
</body>
</html>

0 comments on commit b1d0d40

Please sign in to comment.