Skip to content
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
4 changes: 2 additions & 2 deletions jquery.pjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,14 @@ function pjax(options) {
state: pjax.state,
previousState: previousState
})
context.html(container.contents)
options.context.html(container.contents)

// FF bug: Won't autofocus fields that are inserted via JS.
// This behavior is incorrect. So if theres no current focus, autofocus
// the last field.
//
// http://www.w3.org/html/wg/drafts/html/master/forms.html
var autofocusEl = context.find('input[autofocus], textarea[autofocus]').last()[0]
var autofocusEl = options.context.find('input[autofocus], textarea[autofocus]').last()[0]
if (autofocusEl && document.activeElement !== autofocusEl) {
autofocusEl.focus();
}
Expand Down
23 changes: 23 additions & 0 deletions test/unit/pjax.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,29 @@ if ($.support.pjax) {
})
})

asyncTest("change context node in pjax:beforeReplace event handler", function() {
var frame = this.frame,
targetContent = 'foo',
changedTarget = frame.$('ul > li:first')
changedTargetOriginalContent = changedTarget.text()

frame.$("#main")
.text(targetContent)
.on("pjax:beforeReplace", function(event, contents, options) {
options.context = changedTarget;
})
frame.$("#main").on("pjax:success", function(event) {
notEqual(changedTarget.text(), changedTargetOriginalContent)
equal($(event.target).text(), targetContent)
start()
})

frame.$.pjax({
url: "hello.html",
container: "#main"
})
})

asyncTest("triggers pjax:success event from container", function() {
var frame = this.frame

Expand Down