File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -281,14 +281,14 @@ function pjax(options) {
281281 state : pjax . state ,
282282 previousState : previousState
283283 } )
284- context . html ( container . contents )
284+ options . context . html ( container . contents )
285285
286286 // FF bug: Won't autofocus fields that are inserted via JS.
287287 // This behavior is incorrect. So if theres no current focus, autofocus
288288 // the last field.
289289 //
290290 // http://www.w3.org/html/wg/drafts/html/master/forms.html
291- var autofocusEl = context . find ( 'input[autofocus], textarea[autofocus]' ) . last ( ) [ 0 ]
291+ var autofocusEl = options . context . find ( 'input[autofocus], textarea[autofocus]' ) . last ( ) [ 0 ]
292292 if ( autofocusEl && document . activeElement !== autofocusEl ) {
293293 autofocusEl . focus ( ) ;
294294 }
Original file line number Diff line number Diff line change @@ -563,6 +563,29 @@ if ($.support.pjax) {
563563 } )
564564 } )
565565
566+ asyncTest ( "change context node in pjax:beforeReplace event handler" , function ( ) {
567+ var frame = this . frame ,
568+ targetContent = 'foo' ,
569+ changedTarget = frame . $ ( 'ul > li:first' )
570+ changedTargetOriginalContent = changedTarget . text ( )
571+
572+ frame . $ ( "#main" )
573+ . text ( targetContent )
574+ . on ( "pjax:beforeReplace" , function ( event , contents , options ) {
575+ options . context = changedTarget ;
576+ } )
577+ frame . $ ( "#main" ) . on ( "pjax:success" , function ( event ) {
578+ notEqual ( changedTarget . text ( ) , changedTargetOriginalContent )
579+ equal ( $ ( event . target ) . text ( ) , targetContent )
580+ start ( )
581+ } )
582+
583+ frame . $ . pjax ( {
584+ url : "hello.html" ,
585+ container : "#main"
586+ } )
587+ } )
588+
566589 asyncTest ( "triggers pjax:success event from container" , function ( ) {
567590 var frame = this . frame
568591
You can’t perform that action at this time.
0 commit comments