diff --git a/public/javascripts/jquery.infinitescroll-custom.js b/public/javascripts/jquery.infinitescroll-custom.js index 5689232e23873f4176d4b6a5490b499a91d206f4..7e5c70fc0870f0d100ee7da28657e38bd1244c9c 100644 --- a/public/javascripts/jquery.infinitescroll-custom.js +++ b/public/javascripts/jquery.infinitescroll-custom.js @@ -4,15 +4,17 @@ // version 2.0b1.110420 // home and docs: http://www.infinite-scroll.com +// Modified by Diaspora: +// A few callbacks were made options and generateInstanceID was make jquery 162 compatible */ ; (function ($) { /* Define 'infinitescroll' function ---------------------------------------------------*/ - + $.fn.infinitescroll = function infscr(options, callback) { - + // grab each selector option and see if any fail. function areSelectorsValid(opts) { var debug = $.fn.infinitescroll._debug; @@ -28,29 +30,29 @@ // find the number to increment in the path. function determinePath(path) { - + if ($.isFunction(opts.pathParse)) { - + debug('pathParse'); return [path]; - + } else if (path.match(/^(.*?)\b2\b(.*?$)/)) { path = path.match(/^(.*?)\b2\b(.*?$)/).slice(1); - - // if there is any 2 in the url at all. + + // if there is any 2 in the url at all. } else if (path.match(/^(.*?)2(.*?$)/)) { - + // page= is used in django: // http://www.infinite-scroll.com/changelog/comment-page-1/#comment-127 if (path.match(/^(.*?page=)2(\/.*|$)/)) { path = path.match(/^(.*?page=)2(\/.*|$)/).slice(1); return path; } - + path = path.match(/^(.*?)2(.*?$)/).slice(1); - + } else { - + // page= is used in drupal too but second page is page=1 not page=2: // thx Jerod Fritz, vladikoff if (path.match(/^(.*?page=)1(\/.*|$)/)) { @@ -64,8 +66,8 @@ debug('determinePath',path); return path; } - - + + // Calculate internal height (used for local scroll) function hiddenHeight(element) { var height = 0; @@ -74,30 +76,37 @@ }); return height; } - - + + //Generate InstanceID based on random data (to give consistent but different ID's) function generateInstanceID(element) { - var number = $(element).length + $(element).html().length + $(element).attr("class").length + $(element).attr("id").length; + var $element = $(element) + var number = $element.length + $element.html().length + if($element.attr("class") !== undefined){ + number += $element.attr("class").length + } + if($element.attr("id") !== undefined){ + number += $element.attr("id").length + } opts.infid = number; } - - + + // if options is a string, use as a command if (typeof options=='string') { - + var command = options, argument = callback, validCommand = (command == 'pause' || command == 'destroy' || command == 'retrieve' || command == 'binding'), debug = $.fn.infinitescroll._debug; - + argument = argument || null; command = (validCommand) ? $.fn.infinitescroll[command](argument) : debug('Invalid command'); - + return false; } - - + + // lets get started. var opts = $.infinitescroll.opts = $.extend({}, $.infinitescroll.defaults, options), props = $.infinitescroll, // shorthand @@ -108,68 +117,68 @@ pause = $.fn.infinitescroll.pause, destroy = $.fn.infinitescroll.destroy, binding = $.fn.infinitescroll.binding; - - + + // if selectors from opts aren't valid, return false if (!areSelectorsValid(opts)) { return false; } - + opts.container = opts.container || document.documentElement; - + // contentSelector we'll use for our ajax call opts.contentSelector = opts.contentSelector || this; - + // Generate unique instance ID opts.infid = (opts.infid == 0) ? generateInstanceID(opts.contentSelector) : opts.infid; - + // loadMsgSelector - if we want to place the load message in a specific selector, defaulted to the contentSelector opts.loadMsgSelector = opts.loadMsgSelector || opts.contentSelector; - + // get the relative URL - everything past the domain name. var relurl = /(.*?\/\/).*?(\/.*)/, path = $(opts.nextSelector).attr('href'); - + if (!path) { debug('Navigation selector not found'); return; } // set the path to be a relative URL from root. opts.path = determinePath(path); - - + + // define loading msg props.loadingMsg = $('<div id="infscr-loading" style="text-align: center;"><img alt="Loading..." src="' + - + opts.loadingImg + '" /><div>' + opts.loadingText + '</div></div>'); // preload the image (new Image()).src = opts.loadingImg; - - + + //Check if its HTML (window scroll) and set innerContainerHeight opts.binder = (opts.container.nodeName == "HTML") ? $(window) : $(opts.container); innerContainerHeight = (opts.container.nodeName == "HTML") ? $(document).height() : innerContainerHeight = hiddenHeight(opts.container); debug('Scrolling in: ',(opts.container.nodeName == "HTML") ? 'window' : opts.container); - + // distance from nav links to bottom // computed as: height of the document + top offset of container - top offset of nav link opts.pixelsFromNavToBottom = innerContainerHeight + (opts.container == document.documentElement ? 0 : $(opts.container).offset().top) - $(opts.navSelector).offset().top; - + // set up our bindings - // bind scroll handler to element (if its a local scroll) or window + // bind scroll handler to element (if its a local scroll) or window binding('bind'); opts.binder.trigger('smartscroll.infscr.' + opts.infid); // trigger the event, in case it's a short page - + return this; } // end of $.fn.infinitescroll() - - + + /* Defaults and read-only properties object ---------------------------------------------------*/ - + $.infinitescroll = { defaults: { debug: false, @@ -207,35 +216,35 @@ loadingMsg: undefined, currDOMChunk: null // defined in setup()'s load() }; - - + + /* Methods + Commands ---------------------------------------------------*/ - + // Console log wrapper. $.fn.infinitescroll._debug = function infscr_debug() { - if ($.infinitescroll.opts.debug) { + if ($.infinitescroll.opts.debug) { return window.console && console.log.call(console, arguments); } } - - + + // shortcut function for...getting shortcuts $.fn.infinitescroll._shorthand = function infscr_shorthand() { - + // someone should write this, and it would rule - + }; - - + + // Near Bottom (isNearBottom) $.fn.infinitescroll._nearbottom = function infscr_nearbottom() { - + // replace with shorthand function var opts = $.infinitescroll.opts, debug = $.fn.infinitescroll._debug, hiddenHeight = $.fn.infinitescroll._hiddenheight; - + // distance remaining in the scroll // computed as: document height - distance already scroll - viewport height - buffer @@ -256,31 +265,31 @@ // if distance remaining in the scroll (including buffer) is less than the orignal nav to bottom.... return (pixelsFromWindowBottomToBottom - opts.bufferPx < opts.pixelsFromNavToBottom); - + } - - + + // Setup function (infscrSetup) $.fn.infinitescroll._setup = function infscr_setup() { - + // replace with shorthand function var props = $.infinitescroll, opts = $.infinitescroll.opts, isNearBottom = $.fn.infinitescroll._nearbottom, kickOffAjax = $.fn.infinitescroll.retrieve; - + if (opts.isDuringAjax || opts.isInvalidPage || opts.isDone || opts.isDestroyed || opts.isPaused) return; - + if (!isNearBottom(opts, props)) return; - - kickOffAjax(); - + + kickOffAjax(); + }; - - + + // Ajax function (kickOffAjax) $.fn.infinitescroll.retrieve = function infscr_retrieve() { - + // replace with shorthand function var props = $.infinitescroll, opts = props.opts, @@ -289,17 +298,17 @@ error = $.fn.infinitescroll._error, path = opts.path, // get this box, frag, desturl, method, condition; - - + + // we dont want to fire the ajax multiple times opts.isDuringAjax = true; - - + + // show the loading message quickly // then hide the previous/next links after we're // sure the loading message was visible props.loadingMsg.appendTo(opts.loadMsgSelector).show(); - + $(opts.navSelector).hide(); // increment the URL bit. e.g. /page/3/ @@ -309,31 +318,31 @@ // if we're dealing with a table we can't use DIVs box = $(opts.contentSelector).is('table') ? $('<tbody/>') : $('<div/>'); - - + + // INSERT DEBUG ERROR FOR invalid desturl desturl = ($.isFunction(opts.pathParse)) ? opts.pathParse(path.join('2'), opts.currPage) : desturl = path.join(opts.currPage); // desturl = path.join(opts.currPage); - + // create switch parameter for append / callback // MAKE SURE CALLBACK EXISTS??? method = (opts.dataType == 'html' || opts.dataType == 'json') ? opts.dataType : 'html+callback'; if (opts.appendCallback && opts.dataType == 'html') method += '+callback'; - + switch (method) { - + case 'html+callback': - + debug('Using HTML via .load() method'); box.load(desturl + ' ' + opts.itemSelector, null, function(jqXHR,textStatus) { loadCallback(box,jqXHR.responseText); }); - + break; - + case 'html': case 'json': - + debug('Using '+(method.toUpperCase())+' via $.ajax() method'); $.ajax({ // params @@ -344,16 +353,16 @@ (condition) ? loadCallback(box,jqXHR.responseText) : error([404]); } }); - + break; - + } }; - - + + // Load callback $.fn.infinitescroll._loadcallback = function infscr_loadcallback(box,data) { - + // replace with shorthand function var props = $.infinitescroll, opts = $.infinitescroll.opts, @@ -361,81 +370,81 @@ showDoneMsg = $.fn.infinitescroll._donemsg, callback = $.fn.infinitescroll._callback, // GLOBAL OBJECT FOR CALLBACK result, frag; - + result = (opts.isDone) ? 'done' : (!opts.appendCallback) ? 'no-append' : 'append'; - + switch (result) { - + case 'done': - + showDoneMsg(); return false; - + break; - + case 'no-append': if (opts.dataType == 'html') { data = '<div>'+data+'</div>'; data = $(data).find(opts.itemSelector); }; - + break; - + case 'append': - + var children = box.children(); - + // if it didn't return anything if (children.length == 0 || children.hasClass('error404')) { // trigger a 404 error so we can quit. return error([404]); } - + // 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); } - + $(opts.contentSelector)[0].appendChild(frag); // previously, we would pass in the new DOM element as context for the callback // however we're now using a documentfragment, which doesnt havent parents or children, // so the context is the contentContainer guy, and we pass in an array // of the elements collected as the first argument. - + data = children.get(); - - + + break; - + } - + // fadeout currently makes the <em>'d text ugly in IE6 props.loadingMsg.hide(); - - + + // 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); - + }; - - + + // Show done message. $.fn.infinitescroll._donemsg = function infscr_donemsg() { - + // replace with shorthand function var props = $.infinitescroll, opts = $.infinitescroll.opts; - + props.loadingMsg .find('img') .hide() @@ -444,24 +453,24 @@ $(this).parent().fadeOut('normal'); }); - // user provided callback when done + // user provided callback when done opts.errorCallback(); } - - + + // Pause function $.fn.infinitescroll.pause = function infscr_pause(pause) { - + // if pauseValue is not 'pause' or 'resume', toggle it's value var debug = $.fn.infinitescroll._debug, opts = $.infinitescroll.opts; - + if (pause !== 'pause' && pause !== 'resume' && pause !== 'toggle' && pause !== null) { debug('Invalid argument. Toggling pause value instead'); }; - + pause = (pause && (pause == 'pause' || pause == 'resume')) ? pause : 'toggle'; - + switch (pause) { case 'pause': opts.isPaused = true; @@ -475,26 +484,26 @@ opts.isPaused = !opts.isPaused; break; } - + debug('Paused',opts.isPaused); return false; } - - + + // Error function $.fn.infinitescroll._error = function infscr_error(xhr) { - + // replace with shorthand function var opts = $.infinitescroll.opts, binder = (opts.container.nodeName == "HTML") ? $(window) : $(opts.container), debug = $.fn.infinitescroll._debug, showDoneMsg = $.fn.infinitescroll._donemsg, error = (!opts.isDone && xhr == 404) ? 'end' : (opts.isDestroyed && xhr == 302) ? 'destroy' : 'unknown'; - + switch (error) { - + case 'end': - + // die if we're out of pages. debug('Page not found. Self-destructing...'); showDoneMsg(); @@ -502,86 +511,86 @@ opts.currPage = 1; // if you need to go back to this instance opts.isPaused = false; binder.unbind('smartscroll.infscr.' + opts.infid); - + break; - + case 'destroy': - + // die if destroyed. debug('Destroyed. Going to next instance...'); opts.isDone = true; opts.currPage = 1; // if you need to go back to this instance opts.isPaused = false; binder.unbind('smartscroll.infscr.' + opts.infid); - + break; - + case 'unknown': - + // unknown error. debug('Unknown Error. WHAT DID YOU DO?!...'); showDoneMsg(); opts.isDone = true; opts.currPage = 1; // if you need to go back to this instance binder.unbind('smartscroll.infscr.' + opts.infid); - + break; - + } - + } - - + + // Destroy current instance of the plugin $.fn.infinitescroll.destroy = function infscr_destroy() { - + // replace with shorthand function var opts = $.infinitescroll.opts, error = $.fn.infinitescroll._error; - + opts.isDestroyed = true; return error([302]); - + } - - + + // Scroll binding + unbinding $.fn.infinitescroll.binding = function infscr_binding(binding) { - + // replace with shorthand function var opts = $.infinitescroll.opts, setup = $.fn.infinitescroll._setup, error = $.fn.infinitescroll._error, debug = $.fn.infinitescroll._debug; - + switch(binding) { - + case 'bind': opts.binder.bind('smartscroll.infscr.'+opts.infid, setup); break; - + case 'unbind': opts.binder.unbind('smartscroll.infscr.'+opts.infid); break; - + } - + debug('Binding',binding); return false; - + } - - - /* + + + /* * smartscroll: debounced scroll event for jQuery * * https://github.com/lukeshumard/smartscroll * Based on smartresize by @louis_remi: https://github.com/lrbabe/jquery.smartresize.js * * Copyright 2011 Louis-Remi & Luke Shumard * Licensed under the MIT license. * */ - + var event = $.event, scrollTimeout; - + event.special.smartscroll = { setup: function() { $(this).bind( "scroll", event.special.smartscroll.handler ); @@ -593,17 +602,17 @@ // Save the context var context = this, args = arguments; - + // set correct event type event.type = "smartscroll"; - + if (scrollTimeout) { clearTimeout(scrollTimeout); } scrollTimeout = setTimeout(function() { jQuery.event.handle.apply( context, args ); }, execAsap === "execAsap"? 0 : 100); } }; - + $.fn.smartscroll = function( fn ) { return fn ? this.bind( "smartscroll", fn ) : this.trigger( "smartscroll", ["execAsap"] ); };