From a40fd6fed1a0f7dff499d09872d1449cc4832dbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E8=BE=BE?= Date: Thu, 5 Feb 2015 09:12:47 +0800 Subject: [PATCH 1/3] leave special script tags inline leave special script tags with attribute context inline --- jquery.pjax.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery.pjax.js b/jquery.pjax.js index 444891e3..c5496ece 100644 --- a/jquery.pjax.js +++ b/jquery.pjax.js @@ -714,7 +714,7 @@ function extractContainer(data, xhr, options) { obj.contents.find('title').remove() // Gather all script[src] elements - obj.scripts = findAll(obj.contents, 'script[src]').remove() + obj.scripts = findAll(obj.contents, 'script[src][context!=inline]').remove() obj.contents = obj.contents.not(obj.scripts) } From 21d0430bd4ecbdbf827fba9f7210496462237b37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E8=BE=BE?= Date: Thu, 5 Feb 2015 09:19:52 +0800 Subject: [PATCH 2/3] add script tags tip --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index 58094e14..65d3bfb7 100644 --- a/README.md +++ b/README.md @@ -418,6 +418,14 @@ $(document).on('click', 'a[data-pjax]', function(event) { **NOTE** The new api gives you control over the delegated element container. `$.fn.live` always bound to `document`. This is what you still want to do most of the time. +### Script tags + +All script tags with attribute `src` will be move to head, for the reason once CSP enabled, internal `eval` will be disabled. If you don't want the script tags moved, add an attribute context with value `inline`: + +``` html + +``` + ## Contributing ``` From 62460a81899974ecfae2346d28b7b0ea9f48f9d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E8=BE=BE?= Date: Thu, 5 Feb 2015 09:21:47 +0800 Subject: [PATCH 3/3] execute script tags before html content loaded --- jquery.pjax.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/jquery.pjax.js b/jquery.pjax.js index c5496ece..49ff2e9a 100644 --- a/jquery.pjax.js +++ b/jquery.pjax.js @@ -290,6 +290,8 @@ function pjax(options) { } catch (e) { } if (container.title) document.title = container.title + + executeScriptTags(container.scripts) fire('pjax:beforeReplace', [container.contents, options], { state: pjax.state, @@ -307,8 +309,6 @@ function pjax(options) { autofocusEl.focus(); } - executeScriptTags(container.scripts) - // Scroll to top by default if (typeof options.scrollTo === 'number') $(window).scrollTop(options.scrollTo)