Skip to content

Commit 993c66e

Browse files
committed
add extsrc support
1 parent 3b141e0 commit 993c66e

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

test/extsrc-tests.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function h(html) {
2+
return html.replace(/</g,'&lt;').toLowerCase().replace(/[\s\r\n]+/g,' ');
3+
}
4+
5+
test("bar",function() {
6+
expect(2);
7+
stop();
8+
writeCapture.extsrc(function() {
9+
ok(true,"callback called");
10+
equals(h('barexternal barbar'),h($('#foo').html()));
11+
start();
12+
});
13+
});

test/extsrc.html

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
3+
dir="ltr" id="html">
4+
<head>
5+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6+
<title>Write Capture Tests</title>
7+
<link rel="Stylesheet" media="screen" href="qunit/qunit.css" />
8+
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"></script>
9+
<script type="text/javascript" src="qunit/qunit.js"></script>
10+
11+
<script src="../support/debug-support.js" type="text/javascript" charset="utf-8"></script>
12+
<script src="../writeCapture.js" type="text/javascript" charset="utf-8"></script>
13+
14+
<script type="text/javascript" src="extsrc-tests.js"></script>
15+
</head>
16+
<body>
17+
<h1 id="qunit-header">QUnit</h1>
18+
<h2 id="qunit-banner"></h2>
19+
<h2 id="qunit-userAgent"></h2>
20+
<ol id="qunit-tests"></ol>
21+
<div id="foo"><script type="text/javascript" extsrc="bar.js"></script></div>
22+
</body>
23+
</html>

writeCapture.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,37 @@
699699
});
700700
}
701701

702+
function extsrc(cb) {
703+
var scripts = document.getElementsByTagName('script'),
704+
s,o, html, q, ext, async, doneCount = 0,
705+
done = cb ? newCallbackTag(function() {
706+
if(++doneCount >= exts.length) {
707+
cb();
708+
}
709+
}) : '',
710+
exts = [];
711+
712+
for(var i = 0, len = scripts.length; i < len; i++) {
713+
s = scripts[i];
714+
ext = s.getAttribute('extsrc');
715+
async = s.getAttribute('asyncsrc');
716+
if(ext || async) {
717+
exts.push({ext:ext,async:async});
718+
}
719+
}
720+
721+
for(i = 0, len = exts.length; i < len; i++) {
722+
o = exts[i];
723+
if(o.ext) {
724+
html = '<script type="text/javascript" src="'+o.ext+'"> </script>';
725+
$.replaceWith(s,sanitize(html) + done);
726+
} else if(o.async) {
727+
html = '<script type="text/javascript" src="'+o.async+'"> </script>';
728+
$.replaceWith(s,sanitize(html,{asyncAll:true}, new Q()) + done);
729+
}
730+
}
731+
}
732+
702733
var name = 'writeCapture';
703734
var self = global[name] = {
704735
_original: global[name],
@@ -746,6 +777,7 @@
746777
}
747778
});
748779
},
780+
extsrc: extsrc,
749781
autoAsync: autoCapture,
750782
sanitize: sanitize,
751783
sanitizeSerial: sanitizeSerial

0 commit comments

Comments
 (0)