Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More control with callbacks for behaviors

+ You can now extend callbacks without having to basically replicate the entire '_loadcallback' function
+ Added cufon behavior
+ Modified manual-trigger behavior
+ Updated Masonry behavior
  • Loading branch information...
commit 76a5d98124ee0e70476df8534069e58569b18a02 1 parent 642a069
@lukeshumard lukeshumard authored
View
2  .gitignore
@@ -0,0 +1,2 @@
+
+infinte-scroll.tmproj
View
21 behaviors/cufon.js
@@ -0,0 +1,21 @@
+/*
+ --------------------------------
+ Infinite Scroll Behavior
+ Cufon Refresh
+ --------------------------------
+ + https://github.com/paulirish/infinitescroll/
+ + version 2.0b2.110617
+ + Copyright 2011 Paul Irish & Luke Shumard
+ + Licensed under the MIT license
+
+ + Documentation: http://infinite-scroll.com/
+
+*/
+
+$.extend($.infinitescroll.prototype,{
+
+ _callback_cufon: function infscr_callback_cufon(newElements) {
+ Cufon.refresh(newElements);
+ }
+
+});
View
9 behaviors/manual-trigger.js
@@ -25,6 +25,15 @@ $.extend($.infinitescroll.prototype,{
instance.retrieve();
}
});
+
+ // Define loadingStart to never hide pager
+ instance.options.loadingStart = function (opts) {
+ opts.loadingMsg
+ .appendTo(opts.loadMsgSelector)
+ .show(opts.loadingMsgRevealSpeed, function () {
+ beginAjax(opts);
+ });
+ }
}
});
View
68 behaviors/masonry-isotope.js
@@ -14,72 +14,8 @@
$.extend($.infinitescroll.prototype,{
- _setup_masonry: function infscr_setup_masonry () {
-
- var opts = this.options,
- instance = this;
-
- this._binding('bind');
-
- },
-
- _loadcallback_masonry: function infscr_loadcallback_masonry (box,data) {
-
- var opts = this.options,
- callback = this.options.callback,
- result = (opts.isDone) ? 'done' : 'append',
- frag;
-
- switch (result) {
-
- case 'done':
-
- this._showdonemsg();
- return false;
-
- break;
-
- case 'append':
-
- var children = box.children();
-
- // if it didn't return anything
- if (children.length == 0) {
- return this._error('end');
- }
-
-
- // use a documentFragment because it works when content is going into a table or UL
- frag = document.createDocumentFragment();
- while (box[0].firstChild) {
- frag.appendChild(box[0].firstChild);
- }
-
- this._debug('contentSelector', $(opts.contentSelector)[0])
-
- // instead of the standard append, we use masonry's appended method
- $(opts.contentSelector)[0].masonry('appended',frag);
-
- data = children.get();
-
-
- break;
-
- }
-
- // loadingEnd function
- opts.loadingEnd.call($(opts.contentSelector)[0],opts)
-
-
- // smooth scroll to ease in the new content
- if (opts.animate) {
- var scrollTo = $(window).scrollTop() + $('#infscr-loading').height() + opts.extraScrollPx + 'px';
- $('html,body').animate({ scrollTop: scrollTo }, 800, function () { opts.isDuringAjax = false; });
- }
-
- if (!opts.animate) opts.isDuringAjax = false; // once the call is done, we can allow it again.
-
- callback.call($(opts.contentSelector)[0], data);
+ _callback_masonry: function infscr_callback_masonry (newElements) {

Whoa you managed to cut it down a lot! Does is still perform the same functionality?

@lukeshumard Owner

Yep! By combining the callbacks in _create, you don't need to replicate the whole _loadcallback function when authoring behaviors.

We definitely need to get the API docs written up -- I'm having trouble keeping up! :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ $(this).masonry('appended',$(newElements));
}
});
View
11 jquery.infinitescroll.js
@@ -151,7 +151,14 @@
};
// callback loading
- opts.callback = opts.callback || callback || function () { };
+ opts.callback = function(instance,data) {
+ if (!!opts.behavior && instance['_callback_'+opts.behavior] !== undefined) {
+ instance['_callback_'+opts.behavior].call($(opts.contentSelector)[0], data);
+ }
+ if (callback) {
+ callback.call($(opts.contentSelector)[0], data);
+ }
+ };
this._setup();
@@ -317,7 +324,7 @@
if (!opts.animate) opts.isDuringAjax = false; // once the call is done, we can allow it again.
- callback.call($(opts.contentSelector)[0], data);
+ callback(this,data);
},
View
9 test/index.html
@@ -83,15 +83,6 @@
dataType : 'html',
// behavior : 'twitter',
// loadMore : '#next',
- /*
- loadingStart : function (opts) {
- opts.loadingMsg
- .appendTo(opts.loadMsgSelector)
- .show(opts.loadingMsgRevealSpeed, function () {
- beginAjax(opts);
- });
- }
- */
// appendCallback : false, // USE FOR PREPENDING
// pathParse : function( pathStr, nextPage ){ return pathStr.replace('2', nextPage ); }
}, function(newElements){
Please sign in to comment.
Something went wrong with that request. Please try again.