(function($) { /** * This plugin is used to Ajax Pagenavigation functionlity */ $.fn.ajaxpaging = function(options){ //build main options before element iteration var opts = $.extend({}, $.fn.ajaxpaging.defaults, options); //iterate and reformat each matched element return this.each(function() { var $this = $(this); //get the variables of query var queryString = opts.query; var maxpages = opts.maxpage; var tempPageCount = 1; $this.bind('click', function(){ tempPageCount ++; //Ajax request for query next post item from the database $.ajax({ type: "POST", url: "http://buffalo.com/wp-content/plugins/bn-widgets/ajax-query.php", data: queryString + "&paged=" + tempPageCount, dataType: "html", beforeSend: loadingImage, success: function(msg){ //append the new content $("#ajax-post-container").append(msg); ga('send', 'event', 'button', 'click', 'river'+window.location.pathname); ga('send', 'pageview', window.location.pathname); /*_gaq.push(['_trackEvent', 'riverBlitz', 'LoadMore', window.location.pathname]); _gaq.push(['_trackPageview', window.location.pathname]);*/ /** hide next link for fetch more post if you are in the last page */ if(maxpages == tempPageCount) { //alert('hideme!'); $('#ajax_pagination').hide(); } }, complete: hideloading }); return false; }); }); }; /** loadingImage function is used to show loading image until Ajax request complete */ function loadingImage(){ //first hide the text of the read more link and show the loading icon $("._ajaxpaging_loading").show(); } /** hide the loading image */ function hideloading(){ //then just hide the loading icon and show the link text $("._ajaxpaging_loading").hide(); } // plugin defaults $.fn.ajaxpaging.defaults = { query: '', maxpage: 0 }; })(jQuery);