/** * This jQuery plugin displays pagination links inside the selected elements. * * This plugin needs at least jQuery 1.4.2 * * @author Gabriel Birke (birke *at* d-scribe *dot* de) * @version 2.2 * @param {int} maxentries Number of entries to paginate * @param {Object} opts Several options (see README for documentation) * @return {Object} jQuery Object */ (function($){ /** * @class Class for calculating pagination values */ $.PaginationCalculator = function(maxentries, opts) { this.maxentries = maxentries; this.opts = opts; }; $.extend($.PaginationCalculator.prototype, { /** * Calculate the maximum number of pages * @method * @returns {Number} */ numPages:function() { return Math.ceil(this.maxentries/this.opts.items_per_page); }, /** * Calculate start and end point of pagination links depending on * current_page and num_display_entries. * @returns {Array} */ getInterval:function(current_page) { var ne_half = Math.floor(this.opts.num_display_entries/2); var np = this.numPages(); var upper_limit = np - this.opts.num_display_entries; var start = current_page > ne_half ? Math.max( Math.min(current_page - ne_half, upper_limit), 0 ) : 0; var end = current_page > ne_half?Math.min(current_page+ne_half + (this.opts.num_display_entries % 2), np):Math.min(this.opts.num_display_entries, np); return {start:start, end:end}; } }); // Initialize jQuery object container for pagination renderers $.PaginationRenderers = {}; /** * @class Default renderer for rendering pagination links */ $.PaginationRenderers.defaultRenderer = function(maxentries, opts) { this.maxentries = maxentries; this.opts = opts; this.pc = new $.PaginationCalculator(maxentries, opts); }; $.extend($.PaginationRenderers.defaultRenderer.prototype, { /** * Helper function for generating a single link (or a span tag if it's the current page) * @param {Number} page_id The page id for the new item * @param {Number} current_page * @param {Object} appendopts Options for the new item: text and classes * @returns {jQuery} jQuery object containing the link */ createLink:function(page_id, current_page, appendopts){ var lnk, np = this.pc.numPages(); page_id = page_id<0?0:(page_id" + appendopts.text + ""); } else { lnk = $("" + appendopts.text + "") .attr('href', this.opts.link_to.replace(/__id__/, page_id)); } if(appendopts.classes){ lnk.addClass(appendopts.classes); } if(appendopts.rel){ lnk.attr('rel', appendopts.rel); } lnk.attr('page_id', page_id); if (page_id != current_page) { lnk.bind('mouseover', function() { $(this).addClass("hover"); }).bind('mouseout', function() { $(this).removeClass("hover"); }); } return lnk; }, // Generate a range of numeric links appendRange:function(container, current_page, start, end, opts) { var i; for(i=start; i
"); if (this.opts.showrecord) { var pagerstate = DN.Language.PagerBeforeState; pagerstate = pagerstate.replace("{total}", this.opts.maxentries); pagerstate = pagerstate.replace("{pagesize}", this.opts.items_per_page); fragment.append(pagerstate); } // Generate "Previous"-Link if(this.opts.prev_text && (current_page > 0 || this.opts.prev_show_always)){ fragment.append(this.createLink(current_page-1, current_page, {text:this.opts.prev_text, classes:"prev",rel:"prev"})); } // Generate starting points if (interval.start > 0 && this.opts.num_edge_entries > 0) { end = Math.min(this.opts.num_edge_entries, interval.start); this.appendRange(fragment, current_page, 0, end, {classes:'sp'}); if(this.opts.num_edge_entries < interval.start && this.opts.ellipse_text) { $(""+this.opts.ellipse_text+"").appendTo(fragment); } } // Generate interval links this.appendRange(fragment, current_page, interval.start, interval.end); // Generate ending points if (interval.end < np && this.opts.num_edge_entries > 0) { if(np-this.opts.num_edge_entries > interval.end && this.opts.ellipse_text) { $(""+this.opts.ellipse_text+"").appendTo(fragment); } begin = Math.max(np-this.opts.num_edge_entries, interval.end); this.appendRange(fragment, current_page, begin, np, {classes:'ep'}); } // Generate "Next"-Link if(this.opts.next_text && (current_page < np-1 || this.opts.next_show_always)){ fragment.append(this.createLink(current_page+1, current_page, {text:this.opts.next_text, classes:"next",rel:"next"})); } if (this.opts.showpage) { var pagerState = DN.Language.PagerAfterState; pagerState = pagerState.replace('{pageindex}', (parseInt(current_page) + 1)); pagerState = pagerState.replace('{total}', np); fragment.append(pagerState); } $('a', fragment).click(eventHandler); return fragment; } }); // Extend jQuery $.fn.pagination = function(maxentries, opts){ // Initialize options with default values this.options = opts = $.extend({ items_per_page:15, //分页大小pagesize num_display_entries:10,//中间显示几页 current_page:0, num_edge_entries:2, //头尾两边显示页的个数 link_to:"#", prev_text:DN.Language.PrePage, next_text:DN.Language.NextPage, ellipse_text:"...", prev_show_always:true, next_show_always:true, renderer:"defaultRenderer", show_if_single_page:true, load_first_page:true, callback:function(){return false;} }, opts || {}); this.options.maxentries = maxentries; this.getPageSize = function() { return this.options.items_per_page; }; this.setPageSize = function (pageSize) { if (parseInt(pageSize) != this.options.items_per_page) { this.options.items_per_page = pageSize; this.resetPager(); } }; this.getRecordCount=function() { return this.options.maxentries; } this.setRecordCount = function (recordCount, ctlPageIndex) { var npage = ctlPageIndex ? ctlPageIndex - 1 : 0; if (current_page != npage || parseInt(recordCount) != this.options.maxentries) { current_page = npage; this.options.maxentries = recordCount; maxentries = recordCount; this.resetPager(); } } this.setCurrentPage=function(pageIndex) { current_page = pageIndex; } this.resetPager=function() { renderer = new $.PaginationRenderers[this.options.renderer](this.options.maxentries, this.options); var pc = new $.PaginationCalculator(this.options.maxentries, this.options); var np = pc.numPages(); links = renderer.getLinks(current_page, paginationClickHandler); containers.empty(); if (this.options.maxentries <= 0) { if (this.options.emptyText) { containers.html(this.options.emptyText); } } else if (np > 1 || this.options.show_if_single_page) { links.appendTo(containers); } } this.clearPager=function() { containers.empty(); if (this.options.emptyText) { containers.html(this.options.emptyText); } } var containers = this, renderer, links, current_page; /** * This is the event handling function for the pagination links. * @param {int} page_id The new page number */ function paginationClickHandler(evt) { var links, new_current_page = parseInt($(evt.target).attr('page_id')), continuePropagation = selectPage(new_current_page); //if (!continuePropagation) { //evt.stopPropagation(); var ie = navigator.appName == "Microsoft Internet Explorer" ? true : false; var e = evt ? evt : window.event; if (ie) { window.event.cancelBubble = true; window.event.returnValue = false; } else { e.preventDefault(); e.stopPropagation(); } //} return continuePropagation; } /** * This is a utility function for the internal event handlers. * It sets the new current page on the pagination container objects, * generates a new HTMl fragment for the pagination links and calls * the callback function. */ function selectPage(new_current_page) { // update the link display of a all containers containers.data('current_page', new_current_page); links = renderer.getLinks(new_current_page, paginationClickHandler); current_page = new_current_page; containers.empty(); links.appendTo(containers); // call the callback and propagate the event if it does not return false var continuePropagation = opts.callback(new_current_page, containers); return continuePropagation; } // ----------------------------------- // Initialize containers // ----------------------------------- current_page = parseInt(opts.current_page, 10); containers.data('current_page', current_page); // Create a sane value for maxentries and items_per_page maxentries = (!maxentries || maxentries < 0)?1:maxentries; opts.items_per_page = (!opts.items_per_page || opts.items_per_page < 0)?1:opts.items_per_page; if(!$.PaginationRenderers[opts.renderer]) { throw new ReferenceError("Pagination renderer '" + opts.renderer + "' was not found in jQuery.PaginationRenderers object."); } renderer = new $.PaginationRenderers[opts.renderer](maxentries, opts); // Attach control events to the DOM elements var pc = new $.PaginationCalculator(maxentries, opts); var np = pc.numPages(); /*containers.off('setPage').on('setPage', {numPages:np}, function(evt, page_id) { if(page_id >= 0 && page_id < evt.data.numPages) { selectPage(page_id); return false; } }); containers.off('prevPage').on('prevPage', function(evt){ var current_page = $(this).data('current_page'); if (current_page > 0) { selectPage(current_page - 1); } return false; }); containers.off('nextPage').on('nextPage', {numPages:np}, function(evt){ var current_page = $(this).data('current_page'); if(current_page < evt.data.numPages - 1) { selectPage(current_page + 1); } return false; }); containers.off('currentPage').on('currentPage', function(){ var current_page = $(this).data('current_page'); selectPage(current_page); return false; });*/ // When all initialisation is done, draw the links links = renderer.getLinks(current_page, paginationClickHandler); containers.empty(); if (this.options.maxentries <=0) { if (this.options.emptyText) { containers.html(this.options.emptyText); } } else if(np > 1 || opts.show_if_single_page) { links.appendTo(containers); } // call callback function if(opts.load_first_page) { opts.callback(current_page, containers); } return this; }; // End of $.fn.pagination block })(jQuery); 亚洲中文字幕草必客永不丢失地址亚洲精品.45p亚洲永久免费精品网站大神yq-k视频45p链接链接