/* Copyright 2010 Nuwan Sameera (email : nuwan28@gmail.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ /** this query simple plugin used to Ajax functionality for query next posts in Wordpress database */ (function() { /** * This plugin is used to Ajax Pagenavigation functionlity */ jQuery.fn.ajaxpaging = function(options){ //build main options before element iteration var opts = jQuery.extend({}, jQuery.fn.ajaxpaging.defaults, options); //iterate and reformat each matched element return this.each(function() { var $this = jQuery(this); //get the variables of query var maxpages = opts.maxpages; var loopfile = opts.loop; var query = opts.query; var paged = 1; $this.bind('click', function(){ paged ++; //Ajax request for query next post item from the database jQuery.ajax({ type: "POST", url: "http://www.tempoagora.com.br/wp-admin/admin-ajax.php", data: "paged="+paged+"&action=ajax_navigation&loop="+loopfile+"&"+query, dataType: "html", beforeSend: loadingImage, success: function(msg){ //append the new content $data = jQuery(msg); jQuery(".product-listing").append($data); /** hide next link for fetch more post if you are in the last page */ if(maxpages == paged) jQuery('#ajax_pagination_btn').hide(); /* trigger CompletPagination callback */ jQuery("#ajax_pagination_btn").trigger("complete-paginate",[$data]); }, 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 jQuery("._ajaxpaging_loading").show(); } /** hide the loading image */ function hideloading(){ //then just hide the loading icon and show the link text jQuery("._ajaxpaging_loading").hide(); } // plugin defaults jQuery.fn.ajaxpaging.defaults = { maxpage: 1 }; })(jQuery);