Skip to content

Commit eeb27eb

Browse files
committed
Merge branch 'pjax-with-scripts' of git://github.com/sshirokov/jquery-pjax into sshirokov-pjax-with-scripts
2 parents 12c98fb + c7b2fcd commit eeb27eb

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

jquery.pjax.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,19 @@ function pjax(options) {
261261
if (container.title) document.title = container.title
262262
context.html(container.contents)
263263

264+
container.scripts.each(function(_, script) {
265+
var $script = $(script)
266+
var src = $script.attr('src')
267+
if($('script[src="' + src + '"]').length) return
268+
269+
var target = document.head || context.get(0)
270+
var tag = document.createElement('script')
271+
tag.type = $script.attr('type') || "text/javascript"
272+
tag.async = false
273+
tag.src = src
274+
target.appendChild(tag)
275+
})
276+
264277
// Scroll to top by default
265278
if (typeof options.scrollTo === 'number')
266279
$(window).scrollTop(options.scrollTo)
@@ -592,6 +605,8 @@ function extractContainer(data, xhr, options) {
592605
} else {
593606
var $head = $body = $(parseHTML(data))
594607
}
608+
obj.scripts = findAll($body, 'script[src]')
609+
findAll($body, 'script[src]').remove()
595610

596611
// If response data is empty, return fast
597612
if ($body.length === 0)

0 commit comments

Comments
 (0)