Skip to content

Commit 3f7859d

Browse files
olemoignmislav
authored andcommitted
jQuery 3 compatibility
1 parent d76e840 commit 3f7859d

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

jquery.pjax.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -642,20 +642,25 @@ function optionsFor(container, options) {
642642
// Because we can't persist elements using the history API, we must be
643643
// able to find a String selector that will consistently find the Element.
644644
//
645-
// container - A selector String, jQuery object, or DOM Element.
645+
// container - A selector String or jQuery object.
646646
//
647647
// Returns a jQuery object whose context is `document` and has a selector.
648648
function findContainerFor(container) {
649-
container = $(container)
650-
651-
if ( !container.length ) {
652-
throw "no pjax container for " + container.selector
653-
} else if ( container.selector !== '' && container.context === document ) {
654-
return container
655-
} else if ( container.attr('id') ) {
656-
return $('#' + container.attr('id'))
649+
var formatedContainer
650+
651+
if (jQuery.type(container) === 'string') {
652+
formatedContainer = $(container)
653+
formatedContainer.selector = container
657654
} else {
658-
throw "cant get selector for pjax container!"
655+
formatedContainer = container
656+
}
657+
658+
if (!formatedContainer.length) {
659+
throw "no pjax container for " + container
660+
} else if (!formatedContainer.selector) {
661+
throw "cant get selector for pjax container"
662+
} else {
663+
return formatedContainer
659664
}
660665
}
661666

@@ -911,8 +916,11 @@ function disable() {
911916

912917
// Add the state property to jQuery's event object so we can use it in
913918
// $(window).bind('popstate')
914-
if ( $.inArray('state', $.event.props) < 0 )
919+
if ($.event.props && $.inArray('state', $.event.props) < 0) {
915920
$.event.props.push('state')
921+
} else if (!('state' in $.Event.prototype)) {
922+
$.event.addProp('state')
923+
}
916924

917925
// Is pjax supported by this browser?
918926
$.support.pjax =

0 commit comments

Comments
 (0)