Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a option to stop moving script #480

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
<script type="text/javascript" src="test.js" context="inline"></script>
```

## Contributing

```
Expand Down
6 changes: 3 additions & 3 deletions jquery.pjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down