amitabhaghosh197
4/23/2014 - 2:30 PM

gistfile1.js

    function kickOffAjax(){
        
        // 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.loadingMsgRevealSpeed, function(){
	        $( opts.navSelector ).hide(); 
	        
	        // increment the URL bit. e.g. /page/3/
	        opts.currPage++;
	        
	        debug('heading into ajax',path);
	        
	        if ($.isFunction(opts.pathParse)){
		        // if we got a custom path parsing function, pass in our path guess and page iteration
		        desturl = opts.pathParse(path.join('2'), opts.currPage);
		    } else {
		      	desturl = path.join( opts.currPage );
		    }

			$.ajax({
				url: desturl,
				type: 'GET',
			  	dataType: 'html',
			  	success: function (data) {
					if (data.trim().length == 0) {
                                            showDoneMsg();
			                    return false;
					} else {
					    // append the ajax data to the end
					    $(opts.contentSelector).append(data);

			                    // fadeout currently makes the <em>'d text ugly in IE6
			                    props.loadingMsg.fadeOut('normal' ); 

			                    // 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; }); 
			                    }

			                    callback.call( $(opts.contentSelector) );

			                    if (!opts.animate) opts.isDuringAjax = false; // once the call is done, we can allow it again.
					}
				}
			});
		    
	    });
        
    }