Skip to content

Commit

Permalink
Added 'resetCounter' option.
Browse files Browse the repository at this point in the history
  • Loading branch information
fredwu committed Dec 2, 2009
1 parent 775849c commit f662f32
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions jquery.endless-scroll.js
Original file line number Original file line Diff line number Diff line change
@@ -1,5 +1,5 @@
/** /**
* Endless Scroll plugin for jQuery v1.1 * Endless Scroll plugin for jQuery v1.2
* *
* Copyright (c) 2008 Fred Wu * Copyright (c) 2008 Fred Wu
* *
Expand All @@ -9,15 +9,33 @@
*/ */


/** /**
* Usage:
*
* // using default options
* $(document).endlessScroll();
*
* // using some custom options
* $(document).endlessScroll({
* fireOnce: false,
* fireDelay: false,
* loader: "<div class=\"loading\"><div>",
* callback: function(){
* alert("test");
* }
* });
*
* Configuration options: * Configuration options:
* *
* bottomPixels integer the number of pixels from the bottom of the page that triggers the event * bottomPixels integer the number of pixels from the bottom of the page that triggers the event
* fireOnce boolean only fire once until the execution of the current event is completed * fireOnce boolean only fire once until the execution of the current event is completed
* fireDelay integer delay the subsequent firing, in milliseconds. 0 or false to disable delay. * fireDelay integer delay the subsequent firing, in milliseconds. 0 or false to disable delay.
* loader string HTML loader * loader string the HTML to be displayed during loading
* data string plain HTML data * data string|function plain HTML data, can be either a string or a function that returns a string
* insertAfter string jQuery selector syntax: where to put the loader as well as the plain HTML data * insertAfter string jQuery selector syntax: where to put the loader as well as the plain HTML data
* callback function callback function, accepets one argument: fire sequence (the number of times the event triggered during the current page session) * callback function callback function, accepets one argument: fire sequence (the number of times
* the event triggered during the current page session)
* resetCounter function resets the fire sequence counter if the function returns true, this function
* could also perform hook actions since it is applied at the start of the event
* *
* Usage tips: * Usage tips:
* *
Expand All @@ -36,6 +54,7 @@
loader: "<br />Loading...<br />", loader: "<br />Loading...<br />",
data: "", data: "",
insertAfter: "div:last", insertAfter: "div:last",
resetCounter: function(){ return false; },
callback: function(fs){ return true; } callback: function(fs){ return true; }
}; };


Expand All @@ -49,14 +68,19 @@
{ {
if ((options.fireOnce == false || options.fireOnce == true && fired != true)) if ((options.fireOnce == false || options.fireOnce == true && fired != true))
{ {
if(options.resetCounter.apply(this) === true)
{
fireSequence = 0;
}

fired = true; fired = true;
fireSequence++; fireSequence++;


$(options.insertAfter).after("<div id=\"endless_scroll_loader\">" + options.loader + "</div>"); $(options.insertAfter).after("<div id=\"endless_scroll_loader\">" + options.loader + "</div>");


if (typeof options.data == 'function') if (typeof options.data == 'function')
{ {
data = options.data.apply(); data = options.data.apply(this);
} }
else else
{ {
Expand Down

0 comments on commit f662f32

Please sign in to comment.