Created
April 30, 2012 20:19
-
-
Save bradenmacdonald/2562364 to your computer and use it in GitHub Desktop.
Get infinite-scroll to send X-PJAX header.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.infinitescroll.prototype.retrieve = function (pageNum) { | |
var instance = this, | |
opts = instance.options, | |
path = opts.path, | |
box, frag, desturl, method, condition, | |
pageNum = pageNum || null, | |
getPage = (!!pageNum) ? pageNum : opts.state.currPage; | |
beginAjax = function infscr_ajax(opts) { | |
// increment the URL bit. e.g. /page/3/ | |
opts.state.currPage++; | |
instance._debug('heading into ajax', path); | |
// if we're dealing with a table we can't use DIVs | |
box = $(opts.contentSelector).is('table') ? $('<tbody/>') : $('<div/>'); | |
desturl = path.join(opts.state.currPage); | |
// Use PJAX to load the new part: | |
$.ajax({ | |
// params | |
url: desturl, | |
dataType: opts.dataType, | |
////////////////////////////////////////////////////////////////////////////////// | |
data: {_pjax: '.pjax-target'}, | |
beforeSend: function(xhr){ xhr.setRequestHeader('X-PJAX', 'true') }, | |
////////////////////////////////////////////////////////////////////////////////// | |
complete: function infscr_ajax_callback(jqXHR, textStatus) { | |
condition = (typeof (jqXHR.isResolved) !== 'undefined') ? (jqXHR.isResolved()) : (textStatus === "success" || textStatus === "notmodified"); | |
if (condition) { | |
box.append($(jqXHR.responseText).find(opts.itemSelector)); | |
instance._loadcallback(box, jqXHR.responseText); | |
} else { instance._error('end'); } | |
} | |
}); | |
}; | |
// for manual triggers, if destroyed, get out of here | |
if (opts.state.isDestroyed) { | |
this._debug('Instance is destroyed'); | |
return false; | |
}; | |
// we dont want to fire the ajax multiple times | |
opts.state.isDuringAjax = true; | |
opts.loading.start.call($(opts.contentSelector)[0],opts); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment