(function ($) { //修改地址id function pageurl(id) { var urlSearch = location.href; var unformatStr = changeURLArg(urlSearch, "page", id); if (!!(window.history && history.pushState)) { history.replaceState(null, "", unformatStr); } } function changeURLArg(url, arg, arg_val) { var pattern = arg + '=([^&]*)'; var replaceText = arg + '=' + arg_val; if (url.match(pattern)) { var tmp = '/(' + arg + '=)([^&]*)/gi'; tmp = url.replace(eval(tmp), replaceText); return tmp; } else { if (url.match('[\?]')) { return url + '&' + replaceText; } else { return url + '?' + replaceText; } } } function getUrlParms(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return "1"; } //获取地址id var getid = getUrlParms("page"); var methods = { init: function (options) { var o = $.extend({ items: 1, itemsOnPage: 1, pages: 0, displayedPages: 5, edges: '', currentPage: getid, prevText: '上一页', nextText: '下一页', ellipseText: '…', cssStyle: '', labelMap: [], selectOnClick: true, onPageClick: function (pageNumber, event) { //点击加载 }, onInit: function (getid) { //初始页面 } }, options || {}); var self = this; o.pages = o.pages ? o.pages : Math.ceil(o.items / o.itemsOnPage) ? Math.ceil(o.items / o.itemsOnPage) : 1; o.currentPage = o.currentPage - 1; o.halfDisplayed = o.displayedPages / 2; this.each(function () { self.addClass(o.cssStyle + ' simple-pagination').data('pagination', o); methods._draw.call(self); }); o.onInit(getid); return this; }, selectPage: function (page) { methods._selectPage.call(this, page - 1); return this; }, prevPage: function () { var o = this.data('pagination'); if (o.currentPage > 0) { methods._selectPage.call(this, o.currentPage - 1); } return this; }, nextPage: function () { var o = this.data('pagination'); if (o.currentPage < o.pages - 1) { methods._selectPage.call(this, o.currentPage + 1); } return this; }, getPagesCount: function () { return this.data('pagination').pages; }, getCurrentPage: function () { return this.data('pagination').currentPage + 1; }, destroy: function () { this.empty(); return this; }, drawPage: function (page) { var o = this.data('pagination'); o.currentPage = page - 1; this.data('pagination', o); methods._draw.call(this); return this; }, redraw: function () { methods._draw.call(this); return this; }, disable: function () { var o = this.data('pagination'); o.disabled = true; this.data('pagination', o); methods._draw.call(this); return this; }, enable: function () { var o = this.data('pagination'); o.disabled = false; this.data('pagination', o); methods._draw.call(this); return this; }, updateItems: function (newItems) { var o = this.data('pagination'); o.items = newItems; o.pages = methods._getPages(o); this.data('pagination', o); methods._draw.call(this); }, updateItemsOnPage: function (itemsOnPage) { var o = this.data('pagination'); o.itemsOnPage = itemsOnPage; o.pages = methods._getPages(o); this.data('pagination', o); methods._selectPage.call(this, 0); return this; }, _draw: function () { var o = this.data('pagination'), interval = methods._getInterval(o), i, tagName; methods.destroy.call(this); tagName = (typeof this.prop === 'function') ? this.prop('tagName') : this.attr('tagName'); var $panel = tagName === 'UL' ? this : $('