function setPagination(element, opts) { $(element).paging(opts.total, { format: '< ncnn (- p) >', perpage: opts.perpage, onSelect: function (page) { if(document.readyState !== 'complete') return; $.ajax({ url: opts.url, type: 'POST', data: { op: opts.op, load: opts.load, page: page.toString(), fld_id: opts.fld_id, usr_login: opts.usr_login }, success: function(result) { $(opts.target).html(result); } }); }, onFormat: function (type) { var show_right = this.pages > 4; var show_block = !show_right || this.value != this.pages; if(this.pages <= 1) return ' '; /* TODO: looks ugly, needs refactoring */ switch (type) { case 'right': if(!show_right) return ''; return show_right ? '' + this.value + '' : ''; case 'block': if(!show_block) return ''; return this.value == this.page ? '' + this.value + '' : '' + this.value + ''; case 'next': // > return ''; case 'prev': // < return '' case 'fill': return show_right ? ".." : ''; } } }); $(element).css('cursor', 'pointer'); }