jquery.infinitescroll.min.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810
  1. /*jshint undef: true */
  2. /*global jQuery: true */
  3. /*
  4. --------------------------------
  5. Infinite Scroll
  6. --------------------------------
  7. + https://github.com/paulirish/infinite-scroll
  8. + version 2.0b2.120519
  9. + Copyright 2011/12 Paul Irish & Luke Shumard
  10. + Licensed under the MIT license
  11. + Documentation: http://infinite-scroll.com/
  12. */
  13. (function(window, $, undefined) {
  14. "use strict";
  15. $.infinitescroll = function infscr(options, callback, element) {
  16. this.element = $(element);
  17. // Flag the object in the event of a failed creation
  18. if (!this._create(options, callback)) {
  19. this.failed = true;
  20. }
  21. };
  22. $.infinitescroll.defaults = {
  23. loading: {
  24. finished: undefined,
  25. finishedMsg: "<em>Congratulations, you've reached the end of the internet.</em>",
  26. img: "data:image/gif;base64,R0lGODlh3AATAPQeAPDy+MnQ6LW/4N3h8MzT6rjC4sTM5r/I5NHX7N7j8c7U6tvg8OLl8uXo9Ojr9b3G5MfP6Ovu9tPZ7PT1+vX2+tbb7vf4+8/W69jd7rC73vn5/O/x+K243ai02////wAAACH/C05FVFNDQVBFMi4wAwEAAAAh+QQECgD/ACwAAAAA3AATAAAF/6AnjmRpnmiqrmzrvnAsz3Rt33iu73zv/8CgcEj0BAScpHLJbDqf0Kh0Sq1ar9isdioItAKGw+MAKYMFhbF63CW438f0mg1R2O8EuXj/aOPtaHx7fn96goR4hmuId4qDdX95c4+RBIGCB4yAjpmQhZN0YGYGXitdZBIVGAsLoq4BBKQDswm1CQRkcG6ytrYKubq8vbfAcMK9v7q7EMO1ycrHvsW6zcTKsczNz8HZw9vG3cjTsMIYqQkCLBwHCgsMDQ4RDAYIqfYSFxDxEfz88/X38Onr16+Bp4ADCco7eC8hQYMAEe57yNCew4IVBU7EGNDiRn8Z831cGLHhSIgdFf9chIeBg7oA7gjaWUWTVQAGE3LqBDCTlc9WOHfm7PkTqNCh54rePDqB6M+lR536hCpUqs2gVZM+xbrTqtGoWqdy1emValeXKzggYBBB5y1acFNZmEvXAoN2cGfJrTv3bl69Ffj2xZt3L1+/fw3XRVw4sGDGcR0fJhxZsF3KtBTThZxZ8mLMgC3fRatCbYMNFCzwLEqLgE4NsDWs/tvqdezZf13Hvk2A9Szdu2X3pg18N+68xXn7rh1c+PLksI/Dhe6cuO3ow3NfV92bdArTqC2Ebd3A8vjf5QWfH6Bg7Nz17c2fj69+fnq+8N2Lty+fuP78/eV2X13neIcCeBRwxorbZrA1ANoCDGrgoG8RTshahQ9iSKEEzUmYIYfNW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W6oNBgSfiMMDQkGCBLCwxIQDhHIyQwQCGMKxsnKVyPCF9DREQ3MxMPX0cu4wt7J2uHWx9jlKd3o39MiuefYEcvNkuLt5O8c1ePI2tyELXGQwoGDAQf+iEC2xByDCRAjTlAgIUWCBRgCPJQ4AQBFXAs0coT40WLIjRxL/47AcHLkxIomRXL0CHPERZkpa4q4iVKiyp0tR/7kwHMkTUBBJR5dOCEBAVcKKtCAyOHpowXCpk7goABqBZdcvWploACpBKkpIJI1q5OD2rIWE0R1uTZu1LFwbWL9OlKuWb4c6+o9i3dEgw0RCGDUG9KlRw56gDY2qmCByZBaASi+TACA0TucAaTteCcy0ZuOK3N2vJlx58+LRQyY3Xm0ZsgjZg+oPQLi7dUcNXi0LOJw1pgNtB7XG6CBy+U75SYfPTSQAgZTNUDnQHt67wnbZyvwLgKiMN3oCZB3C76tdewpLFgIP2C88rbi4Y+QT3+8S5USMICZXWj1pkEDeUU3lOYGB3alSoEiMIjgX4WlgNF2EibIwQIXauWXSRg2SAOHIU5IIIMoZkhhWiJaiFVbKo6AQEgQXrTAazO1JhkBrBG3Y2Y6EsUhaGn95hprSN0oWpFE7rhkeaQBchGOEWnwEmc0uKWZj0LeuNV3W4Y2lZHFlQCSRjTIl8uZ+kG5HU/3sRlnTG2ytyadytnD3HrmuRcSn+0h1dycexIK1KCjYaCnjCCVqOFFJTZ5GkUUjESWaUIKU2lgCmAKKQIUjHapXRKE+t2og1VgankNYnohqKJ2CmKplso6GKz7WYCgqxeuyoF8u9IQAgA7",
  27. msg: null,
  28. msgText: "<em>Loading the next set of posts...</em>",
  29. selector: null,
  30. speed: 'fast',
  31. start: undefined
  32. },
  33. state: {
  34. isDuringAjax: false,
  35. isInvalidPage: false,
  36. isDestroyed: false,
  37. isDone: false, // For when it goes all the way through the archive.
  38. isPaused: false,
  39. currPage: 1
  40. },
  41. debug: false,
  42. behavior: undefined,
  43. binder: $(window), // used to cache the selector
  44. nextSelector: "div.navigation a:first",
  45. navSelector: "div.navigation",
  46. contentSelector: null, // rename to pageFragment
  47. extraScrollPx: 150,
  48. itemSelector: "div.post",
  49. animate: false,
  50. pathParse: undefined,
  51. dataType: 'html',
  52. appendCallback: true,
  53. bufferPx: 40,
  54. errorCallback: function() { },
  55. infid: 0, //Instance ID
  56. pixelsFromNavToBottom: undefined,
  57. path: undefined, // Either parts of a URL as an array (e.g. ["/page/", "/"] or a function that takes in the page number and returns a URL
  58. prefill: false, // When the document is smaller than the window, load data until the document is larger or links are exhausted
  59. maxPage: undefined // to manually control maximum page (when maxPage is undefined, maximum page limitation is not work)
  60. };
  61. $.infinitescroll.prototype = {
  62. /*
  63. ----------------------------
  64. Private methods
  65. ----------------------------
  66. */
  67. // Bind or unbind from scroll
  68. _binding: function infscr_binding(binding) {
  69. var instance = this,
  70. opts = instance.options;
  71. opts.v = '2.0b2.120520';
  72. // if behavior is defined and this function is extended, call that instead of default
  73. if (!!opts.behavior && this['_binding_' + opts.behavior] !== undefined) {
  74. this['_binding_' + opts.behavior].call(this);
  75. return;
  76. }
  77. if (binding !== 'bind' && binding !== 'unbind') {
  78. this._debug('Binding value ' + binding + ' not valid');
  79. return false;
  80. }
  81. if (binding === 'unbind') {
  82. (this.options.binder).unbind('smartscroll.infscr.' + instance.options.infid);
  83. } else {
  84. (this.options.binder)[binding]('smartscroll.infscr.' + instance.options.infid, function() {
  85. instance.scroll();
  86. });
  87. }
  88. this._debug('Binding', binding);
  89. },
  90. // Fundamental aspects of the plugin are initialized
  91. _create: function infscr_create(options, callback) {
  92. // Add custom options to defaults
  93. var opts = $.extend(true, {}, $.infinitescroll.defaults, options);
  94. this.options = opts;
  95. var $window = $(window);
  96. var instance = this;
  97. // Validate selectors
  98. if (!instance._validate(options)) {
  99. return false;
  100. }
  101. // Validate page fragment path
  102. var path = $(opts.nextSelector).attr('href');
  103. if (!path) {
  104. this._debug('Navigation selector not found');
  105. return false;
  106. }
  107. // Set the path to be a relative URL from root.
  108. opts.path = opts.path || this._determinepath(path);
  109. // contentSelector is 'page fragment' option for .load() / .ajax() calls
  110. opts.contentSelector = opts.contentSelector || this.element;
  111. // loading.selector - if we want to place the load message in a specific selector, defaulted to the contentSelector
  112. opts.loading.selector = opts.loading.selector || opts.contentSelector;
  113. // Define loading.msg
  114. opts.loading.msg = opts.loading.msg || $('<div id="infscr-loading"><img alt="Loading..." src="' + opts.loading.img + '" /><div>' + opts.loading.msgText + '</div></div>');
  115. // Preload loading.img
  116. (new Image()).src = opts.loading.img;
  117. // distance from nav links to bottom
  118. // computed as: height of the document + top offset of container - top offset of nav link
  119. if (opts.pixelsFromNavToBottom === undefined) {
  120. opts.pixelsFromNavToBottom = $(document).height() - $(opts.navSelector).offset().top;
  121. }
  122. var self = this;
  123. // determine loading.start actions
  124. opts.loading.start = opts.loading.start || function() {
  125. $(opts.navSelector).hide();
  126. opts.loading.msg
  127. .appendTo(opts.loading.selector)
  128. .show(opts.loading.speed, $.proxy(function() {
  129. this.beginAjax(opts);
  130. }, self));
  131. };
  132. // determine loading.finished actions
  133. opts.loading.finished = opts.loading.finished || function() {
  134. opts.loading.msg.fadeOut(opts.loading.speed);
  135. };
  136. // callback loading
  137. opts.callback = function(instance, data, url) {
  138. if (!!opts.behavior && instance['_callback_' + opts.behavior] !== undefined) {
  139. instance['_callback_' + opts.behavior].call($(opts.contentSelector)[0], data, url);
  140. }
  141. if (callback) {
  142. callback.call($(opts.contentSelector)[0], data, opts, url);
  143. }
  144. if (opts.prefill) {
  145. $window.bind("resize.infinite-scroll", instance._prefill);
  146. }
  147. };
  148. if (options.debug) {
  149. // Tell IE9 to use its built-in console
  150. if (Function.prototype.bind && (typeof console === 'object' || typeof console === 'function') && typeof console.log === "object") {
  151. ["log", "info", "warn", "error", "assert", "dir", "clear", "profile", "profileEnd"]
  152. .forEach(function(method) {
  153. console[method] = this.call(console[method], console);
  154. }, Function.prototype.bind);
  155. }
  156. }
  157. this._setup();
  158. // Setups the prefill method for use
  159. if (opts.prefill) {
  160. this._prefill();
  161. }
  162. // Return true to indicate successful creation
  163. return true;
  164. },
  165. _prefill: function infscr_prefill() {
  166. var instance = this;
  167. var $document = $(document);
  168. var $window = $(window);
  169. function needsPrefill() {
  170. return ($document.height() <= $window.height());
  171. }
  172. this._prefill = function() {
  173. if (needsPrefill()) {
  174. instance.scroll();
  175. }
  176. $window.bind("resize.infinite-scroll", function() {
  177. if (needsPrefill()) {
  178. $window.unbind("resize.infinite-scroll");
  179. instance.scroll();
  180. }
  181. });
  182. };
  183. // Call self after setting up the new function
  184. this._prefill();
  185. },
  186. // Console log wrapper
  187. _debug: function infscr_debug() {
  188. if (true !== this.options.debug) {
  189. return;
  190. }
  191. if (typeof console !== 'undefined' && typeof console.log === 'function') {
  192. // Modern browsers
  193. // Single argument, which is a string
  194. if ((Array.prototype.slice.call(arguments)).length === 1 && typeof Array.prototype.slice.call(arguments)[0] === 'string') {
  195. console.log((Array.prototype.slice.call(arguments)).toString());
  196. } else {
  197. console.log(Array.prototype.slice.call(arguments));
  198. }
  199. } else if (!Function.prototype.bind && typeof console !== 'undefined' && typeof console.log === 'object') {
  200. // IE8
  201. Function.prototype.call.call(console.log, console, Array.prototype.slice.call(arguments));
  202. }
  203. },
  204. // find the number to increment in the path.
  205. _determinepath: function infscr_determinepath(path) {
  206. var opts = this.options;
  207. // if behavior is defined and this function is extended, call that instead of default
  208. if (!!opts.behavior && this['_determinepath_' + opts.behavior] !== undefined) {
  209. return this['_determinepath_' + opts.behavior].call(this, path);
  210. }
  211. if (!!opts.pathParse) {
  212. this._debug('pathParse manual');
  213. return opts.pathParse(path, this.options.state.currPage + 1);
  214. } else if (path.match(/^(.*?)\b2\b(.*?$)/)) {
  215. path = path.match(/^(.*?)\b2\b(.*?$)/).slice(1);
  216. // if there is any 2 in the url at all.
  217. } else if (path.match(/^(.*?)2(.*?$)/)) {
  218. // page= is used in django:
  219. // http://www.infinite-scroll.com/changelog/comment-page-1/#comment-127
  220. if (path.match(/^(.*?page=)2(\/.*|$)/)) {
  221. path = path.match(/^(.*?page=)2(\/.*|$)/).slice(1);
  222. return path;
  223. }
  224. path = path.match(/^(.*?)2(.*?$)/).slice(1);
  225. } else {
  226. // page= is used in drupal too but second page is page=1 not page=2:
  227. // thx Jerod Fritz, vladikoff
  228. if (path.match(/^(.*?page=)1(\/.*|$)/)) {
  229. path = path.match(/^(.*?page=)1(\/.*|$)/).slice(1);
  230. return path;
  231. } else {
  232. this._debug('Sorry, we couldn\'t parse your Next (Previous Posts) URL. Verify your the css selector points to the correct A tag. If you still get this error: yell, scream, and kindly ask for help at infinite-scroll.com.');
  233. // Get rid of isInvalidPage to allow permalink to state
  234. opts.state.isInvalidPage = true; //prevent it from running on this page.
  235. }
  236. }
  237. this._debug('determinePath', path);
  238. return path;
  239. },
  240. // Custom error
  241. _error: function infscr_error(xhr) {
  242. var opts = this.options;
  243. // if behavior is defined and this function is extended, call that instead of default
  244. if (!!opts.behavior && this['_error_' + opts.behavior] !== undefined) {
  245. this['_error_' + opts.behavior].call(this, xhr);
  246. return;
  247. }
  248. if (xhr !== 'destroy' && xhr !== 'end') {
  249. xhr = 'unknown';
  250. }
  251. this._debug('Error', xhr);
  252. if (xhr === 'end') {
  253. this._showdonemsg();
  254. }
  255. opts.state.isDone = true;
  256. opts.state.currPage = 1; // if you need to go back to this instance
  257. opts.state.isPaused = false;
  258. this._binding('unbind');
  259. },
  260. // Load Callback
  261. _loadcallback: function infscr_loadcallback(box, data, url) {
  262. var opts = this.options,
  263. callback = this.options.callback, // GLOBAL OBJECT FOR CALLBACK
  264. result = (opts.state.isDone) ? 'done' : (!opts.appendCallback) ? 'no-append' : 'append',
  265. frag;
  266. // if behavior is defined and this function is extended, call that instead of default
  267. if (!!opts.behavior && this['_loadcallback_' + opts.behavior] !== undefined) {
  268. this['_loadcallback_' + opts.behavior].call(this, box, data);
  269. return;
  270. }
  271. switch (result) {
  272. case 'done':
  273. this._showdonemsg();
  274. return false;
  275. case 'no-append':
  276. if (opts.dataType === 'html') {
  277. data = '<div>' + data + '</div>';
  278. data = $(data).find(opts.itemSelector);
  279. }
  280. break;
  281. case 'append':
  282. var children = box.children();
  283. // if it didn't return anything
  284. if (children.length === 0) {
  285. return this._error('end');
  286. }
  287. // use a documentFragment because it works when content is going into a table or UL
  288. frag = document.createDocumentFragment();
  289. while (box[0].firstChild) {
  290. frag.appendChild(box[0].firstChild);
  291. }
  292. this._debug('contentSelector', $(opts.contentSelector)[0]);
  293. $(opts.contentSelector)[0].appendChild(frag);
  294. // previously, we would pass in the new DOM element as context for the callback
  295. // however we're now using a documentfragment, which doesn't have parents or children,
  296. // so the context is the contentContainer guy, and we pass in an array
  297. // of the elements collected as the first argument.
  298. data = children.get();
  299. break;
  300. }
  301. // loadingEnd function
  302. opts.loading.finished.call($(opts.contentSelector)[0], opts);
  303. // smooth scroll to ease in the new content
  304. if (opts.animate) {
  305. var scrollTo = $(window).scrollTop() + $('#infscr-loading').height() + opts.extraScrollPx + 'px';
  306. $('html,body').animate({ scrollTop: scrollTo }, 800, function() { opts.state.isDuringAjax = false; });
  307. }
  308. if (!opts.animate) {
  309. // once the call is done, we can allow it again.
  310. opts.state.isDuringAjax = false;
  311. }
  312. callback(this, data, url);
  313. if (opts.prefill) {
  314. this._prefill();
  315. }
  316. },
  317. _nearbottom: function infscr_nearbottom() {
  318. var opts = this.options,
  319. pixelsFromWindowBottomToBottom = 0 + $(document).height() - (opts.binder.scrollTop()) - $(window).height();
  320. // if behavior is defined and this function is extended, call that instead of default
  321. if (!!opts.behavior && this['_nearbottom_' + opts.behavior] !== undefined) {
  322. return this['_nearbottom_' + opts.behavior].call(this);
  323. }
  324. this._debug('math:', pixelsFromWindowBottomToBottom, opts.pixelsFromNavToBottom);
  325. // if distance remaining in the scroll (including buffer) is less than the orignal nav to bottom....
  326. return (pixelsFromWindowBottomToBottom - opts.bufferPx < opts.pixelsFromNavToBottom);
  327. },
  328. // Pause / temporarily disable plugin from firing
  329. _pausing: function infscr_pausing(pause) {
  330. var opts = this.options;
  331. // if behavior is defined and this function is extended, call that instead of default
  332. if (!!opts.behavior && this['_pausing_' + opts.behavior] !== undefined) {
  333. this['_pausing_' + opts.behavior].call(this, pause);
  334. return;
  335. }
  336. // If pause is not 'pause' or 'resume', toggle it's value
  337. if (pause !== 'pause' && pause !== 'resume' && pause !== null) {
  338. this._debug('Invalid argument. Toggling pause value instead');
  339. }
  340. pause = (pause && (pause === 'pause' || pause === 'resume')) ? pause : 'toggle';
  341. switch (pause) {
  342. case 'pause':
  343. opts.state.isPaused = true;
  344. break;
  345. case 'resume':
  346. opts.state.isPaused = false;
  347. break;
  348. case 'toggle':
  349. opts.state.isPaused = !opts.state.isPaused;
  350. break;
  351. }
  352. this._debug('Paused', opts.state.isPaused);
  353. return false;
  354. },
  355. // Behavior is determined
  356. // If the behavior option is undefined, it will set to default and bind to scroll
  357. _setup: function infscr_setup() {
  358. var opts = this.options;
  359. // if behavior is defined and this function is extended, call that instead of default
  360. if (!!opts.behavior && this['_setup_' + opts.behavior] !== undefined) {
  361. this['_setup_' + opts.behavior].call(this);
  362. return;
  363. }
  364. this._binding('bind');
  365. return false;
  366. },
  367. // Show done message
  368. _showdonemsg: function infscr_showdonemsg() {
  369. var opts = this.options;
  370. // if behavior is defined and this function is extended, call that instead of default
  371. if (!!opts.behavior && this['_showdonemsg_' + opts.behavior] !== undefined) {
  372. this['_showdonemsg_' + opts.behavior].call(this);
  373. return;
  374. }
  375. opts.loading.msg
  376. .find('img')
  377. .hide()
  378. .parent()
  379. .find('div').html(opts.loading.finishedMsg).animate({ opacity: 1 }, 2000, function() {
  380. $(this).parent().fadeOut(opts.loading.speed);
  381. });
  382. // user provided callback when done
  383. opts.errorCallback.call($(opts.contentSelector)[0], 'done');
  384. },
  385. // grab each selector option and see if any fail
  386. _validate: function infscr_validate(opts) {
  387. for (var key in opts) {
  388. if (key.indexOf && key.indexOf('Selector') > -1 && $(opts[key]).length === 0) {
  389. this._debug('Your ' + key + ' found no elements.');
  390. return false;
  391. }
  392. }
  393. return true;
  394. },
  395. /*
  396. ----------------------------
  397. Public methods
  398. ----------------------------
  399. */
  400. // Bind to scroll
  401. bind: function infscr_bind() {
  402. this._binding('bind');
  403. },
  404. // Destroy current instance of plugin
  405. destroy: function infscr_destroy() {
  406. this.options.state.isDestroyed = true;
  407. this.options.loading.finished();
  408. return this._error('destroy');
  409. },
  410. // Set pause value to false
  411. pause: function infscr_pause() {
  412. this._pausing('pause');
  413. },
  414. // Set pause value to false
  415. resume: function infscr_resume() {
  416. this._pausing('resume');
  417. },
  418. beginAjax: function infscr_ajax(opts) {
  419. var instance = this,
  420. path = opts.path,
  421. box, desturl, method, condition;
  422. // increment the URL bit. e.g. /page/3/
  423. opts.state.currPage++;
  424. // Manually control maximum page
  425. if (opts.maxPage != undefined && opts.state.currPage > opts.maxPage) {
  426. this.destroy();
  427. return;
  428. }
  429. // if we're dealing with a table we can't use DIVs
  430. box = $(opts.contentSelector).is('table') ? $('<tbody/>') : $('<div/>');
  431. desturl = (typeof path === 'function') ? path(opts.state.currPage) : path.join(opts.state.currPage);
  432. instance._debug('heading into ajax', desturl);
  433. method = (opts.dataType === 'html' || opts.dataType === 'json') ? opts.dataType : 'html+callback';
  434. if (opts.appendCallback && opts.dataType === 'html') {
  435. method += '+callback';
  436. }
  437. switch (method) {
  438. case 'html+callback':
  439. instance._debug('Using HTML via .load() method');
  440. box.load(desturl + ' ' + opts.itemSelector, undefined, function infscr_ajax_callback(responseText) {
  441. instance._loadcallback(box, responseText, desturl);
  442. });
  443. break;
  444. case 'html':
  445. instance._debug('Using ' + (method.toUpperCase()) + ' via $.ajax() method');
  446. $.ajax({
  447. // params
  448. url: desturl,
  449. dataType: opts.dataType,
  450. complete: function infscr_ajax_callback(jqXHR, textStatus) {
  451. condition = (typeof (jqXHR.isResolved) !== 'undefined') ? (jqXHR.isResolved()) : (textStatus === "success" || textStatus === "notmodified");
  452. if (condition) {
  453. instance._loadcallback(box, jqXHR.responseText, desturl);
  454. } else {
  455. instance._error('end');
  456. }
  457. }
  458. });
  459. break;
  460. case 'json':
  461. instance._debug('Using ' + (method.toUpperCase()) + ' via $.ajax() method');
  462. $.ajax({
  463. dataType: 'json',
  464. type: 'GET',
  465. url: desturl,
  466. success: function(data, textStatus, jqXHR) {
  467. condition = (typeof (jqXHR.isResolved) !== 'undefined') ? (jqXHR.isResolved()) : (textStatus === "success" || textStatus === "notmodified");
  468. if (opts.appendCallback) {
  469. // if appendCallback is true, you must defined template in options.
  470. // note that data passed into _loadcallback is already an html (after processed in opts.template(data)).
  471. if (opts.template !== undefined) {
  472. var theData = opts.template(data);
  473. box.append(theData);
  474. if (condition) {
  475. instance._loadcallback(box, theData);
  476. } else {
  477. instance._error('end');
  478. }
  479. } else {
  480. instance._debug("template must be defined.");
  481. instance._error('end');
  482. }
  483. } else {
  484. // if appendCallback is false, we will pass in the JSON object. you should handle it yourself in your callback.
  485. if (condition) {
  486. instance._loadcallback(box, data, desturl);
  487. } else {
  488. instance._error('end');
  489. }
  490. }
  491. },
  492. error: function() {
  493. instance._debug("JSON ajax request failed.");
  494. instance._error('end');
  495. }
  496. });
  497. break;
  498. }
  499. },
  500. // Retrieve next set of content items
  501. retrieve: function infscr_retrieve(pageNum) {
  502. pageNum = pageNum || null;
  503. var instance = this,
  504. opts = instance.options;
  505. // if behavior is defined and this function is extended, call that instead of default
  506. if (!!opts.behavior && this['retrieve_' + opts.behavior] !== undefined) {
  507. this['retrieve_' + opts.behavior].call(this, pageNum);
  508. return;
  509. }
  510. // for manual triggers, if destroyed, get out of here
  511. if (opts.state.isDestroyed) {
  512. this._debug('Instance is destroyed');
  513. return false;
  514. }
  515. // we dont want to fire the ajax multiple times
  516. opts.state.isDuringAjax = true;
  517. opts.loading.start.call($(opts.contentSelector)[0], opts);
  518. },
  519. // Check to see next page is needed
  520. scroll: function infscr_scroll() {
  521. var opts = this.options,
  522. state = opts.state;
  523. // if behavior is defined and this function is extended, call that instead of default
  524. if (!!opts.behavior && this['scroll_' + opts.behavior] !== undefined) {
  525. this['scroll_' + opts.behavior].call(this);
  526. return;
  527. }
  528. if (state.isDuringAjax || state.isInvalidPage || state.isDone || state.isDestroyed || state.isPaused) {
  529. return;
  530. }
  531. if (!this._nearbottom()) {
  532. return;
  533. }
  534. this.retrieve();
  535. },
  536. // Toggle pause value
  537. toggle: function infscr_toggle() {
  538. this._pausing();
  539. },
  540. // Unbind from scroll
  541. unbind: function infscr_unbind() {
  542. this._binding('unbind');
  543. },
  544. // update options
  545. update: function infscr_options(key) {
  546. if ($.isPlainObject(key)) {
  547. this.options = $.extend(true, this.options, key);
  548. }
  549. }
  550. };
  551. /*
  552. ----------------------------
  553. Infinite Scroll function
  554. ----------------------------
  555. Borrowed logic from the following...
  556. jQuery UI
  557. - https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.widget.js
  558. jCarousel
  559. - https://github.com/jsor/jcarousel/blob/master/lib/jquery.jcarousel.js
  560. Masonry
  561. - https://github.com/desandro/masonry/blob/master/jquery.masonry.js
  562. */
  563. $.fn.infinitescroll = function infscr_init(options, callback) {
  564. var thisCall = typeof options;
  565. switch (thisCall) {
  566. // method
  567. case 'string':
  568. var args = Array.prototype.slice.call(arguments, 1);
  569. this.each(function() {
  570. var instance = $.data(this, 'infinitescroll');
  571. if (!instance) {
  572. // not setup yet
  573. // return $.error('Method ' + options + ' cannot be called until Infinite Scroll is setup');
  574. return false;
  575. }
  576. if (!$.isFunction(instance[options]) || options.charAt(0) === "_") {
  577. // return $.error('No such method ' + options + ' for Infinite Scroll');
  578. return false;
  579. }
  580. // no errors!
  581. instance[options].apply(instance, args);
  582. });
  583. break;
  584. // creation
  585. case 'object':
  586. this.each(function() {
  587. var instance = $.data(this, 'infinitescroll');
  588. if (instance) {
  589. // update options of current instance
  590. instance.update(options);
  591. } else {
  592. // initialize new instance
  593. instance = new $.infinitescroll(options, callback, this);
  594. // don't attach if instantiation failed
  595. if (!instance.failed) {
  596. $.data(this, 'infinitescroll', instance);
  597. }
  598. }
  599. });
  600. break;
  601. }
  602. return this;
  603. };
  604. /*
  605. * smartscroll: debounced scroll event for jQuery *
  606. * https://github.com/lukeshumard/smartscroll
  607. * Based on smartresize by @louis_remi: https://github.com/lrbabe/jquery.smartresize.js *
  608. * Copyright 2011 Louis-Remi & Luke Shumard * Licensed under the MIT license. *
  609. */
  610. var event = $.event,
  611. scrollTimeout;
  612. event.special.smartscroll = {
  613. setup: function() {
  614. $(this).bind("scroll", event.special.smartscroll.handler);
  615. },
  616. teardown: function() {
  617. $(this).unbind("scroll", event.special.smartscroll.handler);
  618. },
  619. handler: function(event, execAsap) {
  620. // Save the context
  621. var context = this,
  622. args = arguments;
  623. // set correct event type
  624. event.type = "smartscroll";
  625. if (scrollTimeout) { clearTimeout(scrollTimeout); }
  626. scrollTimeout = setTimeout(function() {
  627. $(context).trigger('smartscroll', args);
  628. }, execAsap === "execAsap" ? 0 : 100);
  629. }
  630. };
  631. $.fn.smartscroll = function(fn) {
  632. return fn ? this.bind("smartscroll", fn) : this.trigger("smartscroll", ["execAsap"]);
  633. };
  634. })(window, jQuery);