Permalink
Browse files

correcting infinite scroll path.

  • Loading branch information...
1 parent e22a101 commit f970565362edc4423f383fe345749fe42ff17782 @paulirish paulirish committed Jul 8, 2008
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,75 @@
+
+
+// WP-Infinite-Scroll plugin
+// copyright Paul Irish & dirkhaim
+// license: cc-wrapped GPL : http://creativecommons.org/licenses/GPL/2.0/
+
+var jQis = jQuery.noConflict(); // held separately to avoid collisions
+
+var INFSCR = { // more configuration set in init()
+ cfg : INFSCR_cfg, // defined in the php
+ currPage : 1,
+ isDuringAjax : false,
+ isInvalidPage : false,
+ isDone : false // for when it goes all the way through the archive.
+};
+
+INFSCR.isNearBottom = function(){
+ return ( jQis(document).height() - jQis(document).scrollTop() - jQis(window).height() < INFSCR.scrollDelta);
+}
+
+INFSCR.setup = function(){
+
+ if (INFSCR.isDuringAjax || INFSCR.isInvalidPage || INFSCR.isDone) return;
+
+ // the math is: docheight - distancetotopofwindow - height of window < docheight - distance of nav element to the top. [go algebra!]
+ if ( INFSCR.isNearBottom() ){
+
+ INFSCR.isDuringAjax = true; // we dont want to fire the ajax multiple times
+ INFSCR.loadingMsg.appendTo( INFSCR.cfg.contentSelector ).show();
+ jQis( INFSCR.cfg.navSelector ).hide(); // take out the previous/next links
+ INFSCR.currPage++;
+
+ jQis('<div/>')
+ .attr('id','infscr-page-'+INFSCR.currPage)
+ .attr('class','infscr-pages')
+ .appendTo( INFSCR.cfg.contentSelector )
+ .load( INFSCR.path.join( INFSCR.currPage ) + ' ' + INFSCR.cfg.postSelector,null,function(){
+ if (INFSCR.isDone){ // if we've hit the last page...
+ INFSCR.loadingMsg.find('img').hide().parent().find('span').html(INFSCR.cfg.donetext).animate({opacity: 1},2000).fadeOut('normal');
+ } else {
+ INFSCR.loadingMsg.fadeOut('normal' ); // currently makes the <em>'d text ugly in IE6
+ INFSCR.isDuringAjax = false; // once the call is done, we can allow it again.
+ INFSCR.cfg.jsCalls();
+ }
+ });
+
+ }
+};
+
+(INFSCR.init = function(){
+
+ delete INFSCR_cfg; // remove the global
+
+ INFSCR.path = jQis(INFSCR.cfg.nextSelector).attr('href').match(/(.*?\/\/).*?(\/.*)/)[2]; // gets the relative URL - everything past the domain name.
+ INFSCR.loadingMsg = jQis('<div id="infscr-loading" style="text-align: center;"><img style="float:none;" alt="Loading..." src="'+INFSCR.cfg.loadingImg+'" /><br /><span>'+INFSCR.cfg.text+'</span></div>');
+ INFSCR.scrollDelta = jQis(document).height() - jQis(INFSCR.cfg.navSelector).offset().top; //distance from nav links to bottom of page
+ (new Image()).src = INFSCR.cfg.loadingImg; // preload the image.
+
+ if (INFSCR.path.split('2').length == 2){ // there is a 2 in the next url, e.g. /page/2/
+ INFSCR.path = INFSCR.path.split('2');
+ }
+ else {
+ if (INFSCR.isAdmin){
+ alert('Sorry, we couldn\'t parse your Previous Posts URL. Verify your Previous Posts css selector points to the A tag. If you still get this error: yell, scream, and kindly ask for help.');
+ }
+ INFSCR.isInvalidPage = true; //prevent it from running on this page.
+ }
+
+ jQis(document).ajaxError(function(e,xhr,opt){
+ if (xhr.status == 404){ INFSCR.isDone = true; } // die if we're out of pages.
+ });
+
+ jQis(window).scroll( INFSCR.setup ); // hook up the function to the window scroll event.
+
+})();
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -45,7 +45,7 @@
define('infscr_state_default' , infscr_config);
define('infscr_js_calls_default' , '');
-$image_path = get_option('home').'/wp-content/plugins/wp-infinite-scroll'.'/ajax-loader.gif';
+$image_path = get_option('home').'/wp-content/plugins/infinite-scroll'.'/ajax-loader.gif';
define('infscr_image_default' , $image_path);
define('infscr_text_default' , '<em>Loading the next set of posts...</em>');
define('infscr_donetext_default' , '<em>Congratulations, you\'ve reached the end of the internet.</em>');
@@ -398,7 +398,7 @@ function wp_inf_scroll_add()
return;
}
- $plugin_dir = get_option('home').'/wp-content/plugins/wp-infinite-scroll';
+ $plugin_dir = get_option('home').'/wp-content/plugins/infinite-scroll';
$js_calls = stripslashes(get_option(key_infscr_js_calls));
$loading_image = stripslashes(get_option(key_infscr_image));
$loading_text = stripslashes(get_option(key_infscr_text));
@@ -432,7 +432,9 @@ function wp_inf_scroll_add()
}
</script>
-<script type="text/javascript" src="$plugin_dir/hotness.js"></script>
+
+<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
+<script type="text/javascript" src="$plugin_dir/infinite-scroll.js"></script>
EOT;

0 comments on commit f970565

Please sign in to comment.