!function ($) { "use strict"; // jshint ;_; var AjaxPagination = function (element, options) { this.init('ajaxpagination', element, options); }; AjaxPagination.prototype = { constructor: AjaxPagination, init : function(type, element, options) { this.options = $.extend({}, $.fn.ajaxpagination.defaults, options); this.element = $(element); this.sid = this.element.data('sid'); this.mid = this.element.data('module'); this.task = null; this.token = this.element.data('token'); this.resultContainer = $(this.element.data('result')); this.direction = 'desc'; this.order = null; this.safeUrl = $(location).attr('href'); //'index.php?option=com_anief&task='+this.task+'&tmpl=component&s_id='+this.sid+'&'+this.token+'=1'; this.attachEvents(); }, attachEvents : function(){ this.paginations = $('ul.pagination a',this.element.parent()); if(this.paginations.length){ this.paginations.each(function(i,el){ el = $(el); el.on('click',function(event){ event.preventDefault(); var limitstart = (el.attr('href').match(/limitstart=([0-9]+)/)[1]); this.ajaxCall(limitstart); }.bind(this)); }.bind(this)); } }, ajaxCall : function(limitstart){ this.element.closest('.ajloader').append('
Loading...
'); var formUrl = this.safeUrl; //this.createUrl(); $.ajax({ url : formUrl, dataType : "json", type: 'get', data :{ 'position' : this.sid, 'moduleid' : this.mid, 'callfunction' : 'getMoreNews', 'limitstart' : limitstart }, success: function(data, textStatus, jqXHR) { this.element.empty().html(data.contents); this.element.parent().find('.ajq-pagination').remove(); $(data.pagination).appendTo(this.element.parent()); this.attachEvents(); $('.hasTooltip',this.element.parent()).tooltip({"container": false}); $('#ajaxloadinginner').remove(); }.bind(this), error: function(jqXHR, textStatus, errorThrown) { $('#ajaxloadinginner').remove(); //alert('Errore durante la richiesta'); } }); } }; $.fn.ajaxpagination = function ( option ) { return this.each(function () { var $this = $(this) , data = $this.data('ajaxpagination') , options = $.extend({}, $.fn.ajaxpagination.defaults, typeof option == 'object' && option); if (!data) $this.data('ajaxpagination', (data = new AjaxPagination(this, options))); }); }; $.fn.ajaxpagination.Constructor = AjaxPagination; $.fn.ajaxpagination.defaults = { processemptyvalue : false, processonload : false, addempty : false, usepagination : false }; $(document).on('ready', function () { $('[data-mode="ajaxpagination"]').each(function () { var $this = $(this) $this.ajaxpagination($this.data()) }); }); }(window.jQuery);