From 6eae5feaa1f227cd0c9f9b01fbb1c9f3569063a2 Mon Sep 17 00:00:00 2001 From: superRaytin Date: Fri, 16 Jan 2015 18:56:07 +0800 Subject: [PATCH] Add pagination+styles.js --- Gruntfile.js | 7 +- dist/pagination-with-styles.js | 1102 ++++++++++++++++++++++++++++ dist/pagination-with-styles.min.js | 11 + 3 files changed, 1119 insertions(+), 1 deletion(-) create mode 100644 dist/pagination-with-styles.js create mode 100644 dist/pagination-with-styles.min.js diff --git a/Gruntfile.js b/Gruntfile.js index 1063d40..2a902a6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -7,7 +7,8 @@ module.exports = function(grunt){ banner: '/*\n' + ' * pagination.js <%= pkg.version %>\n' + ' * <%= pkg.description %>\n' + - ' * https://github.com/superRaytin/paginationjs\n' + + ' * https://github.com/superRaytin/paginationjs\n\n' + + ' * Homepage: https://paginationjs.com\n' + ' *\n' + ' * Copyright 2014, superRaytin\n' + ' * Released under the MIT license.\n' + @@ -18,6 +19,10 @@ module.exports = function(grunt){ { src: ['dist/pagination.js'], dest: 'dist/pagination.min.js' + }, + { + src: ['dist/pagination-with-styles.js'], + dest: 'dist/pagination-with-styles.min.js' } ] } diff --git a/dist/pagination-with-styles.js b/dist/pagination-with-styles.js new file mode 100644 index 0000000..15bdf68 --- /dev/null +++ b/dist/pagination-with-styles.js @@ -0,0 +1,1102 @@ +/* + * pagination.js 2.0.0 + * A jQuery plugin to provide simple yet fully customisable pagination. + * https://github.com/superRaytin/paginationjs + * + * Homepage: https://paginationjs.com + * + * Copyright 2014, superRaytin + * Released under the MIT license. + */ + +(function(global, $){ + + if(typeof $ === 'undefined'){ + throwError('Pagination requires jQuery.'); + } + + var pluginName = 'pagination'; + + var pluginHookMethod = 'addHook'; + + var eventPrefix = '__pagination-'; + + // Conflict, use backup + if($.fn.pagination){ + pluginName = 'pagination2'; + } + + $.fn[pluginName] = function(options){ + + if(typeof options === 'undefined'){ + return this; + } + + var container = $(this); + + var pagination = { + + initialize: function(){ + var self = this; + + // Save attributes of current instance + if(!container.data('pagination')){ + container.data('pagination', {}); + } + + // Before initialize + if(self.callHook('beforeInit') === false) return; + + // If pagination has been initialized, destroy it + if(container.data('pagination').initialized){ + $('.paginationjs', container).remove(); + } + + // Inline style + if(attributes.inlineStyle === true){ + addStyle(); + } + + // Passed to the callback function + var model = self.model = { + pageRange: attributes.pageRange, + pageSize: attributes.pageSize + }; + + // "dataSource"`s type is unknown, parse it to find true data + self.parseDataSource(attributes.dataSource, function(dataSource){ + + // Whether simulated pagination + self.sync = $.isArray(dataSource); + if(self.sync){ + model.totalNumber = attributes.totalNumber = dataSource.length; + } + + // Obtain the total number of pages + model.totalPage = self.getTotalPage(); + + // Less than one page + if(attributes.hideWhenLessThanOnePage){ + if(model.totalPage <= 1) return; + } + + var el = self.render(true); + + // Extra className + if(attributes.className){ + el.addClass(attributes.className); + } + + model.el = el; + + // Load template + container[attributes.position === 'bottom' ? 'append' : 'prepend'](el); + + // Binding events + self.observer(); + + // initialized flag + container.data('pagination').initialized = true; + + // After initialize + self.callHook('afterInit', el); + + }); + + }, + + render: function(isBoot){ + + var self = this; + var model = self.model; + var el = model.el || $('
'); + var isForced = isBoot !== true; + + // Before render + self.callHook('beforeRender', isForced); + + var currentPage = model.pageNumber || attributes.pageNumber; + var pageRange = attributes.pageRange; + var totalPage = model.totalPage; + + var rangeStart = currentPage - pageRange; + var rangeEnd = currentPage + pageRange; + + if(rangeEnd > totalPage){ + rangeEnd = totalPage; + rangeStart = totalPage - pageRange * 2; + rangeStart = rangeStart < 1 ? 1 : rangeStart; + } + + if(rangeStart <= 1){ + rangeStart = 1; + + rangeEnd = Math.min(pageRange * 2 + 1, totalPage); + } + + el.html(self.createTemplate({ + currentPage: currentPage, + pageRange: pageRange, + totalPage: totalPage, + rangeStart: rangeStart, + rangeEnd: rangeEnd + })); + + // After render + self.callHook('afterRender', isForced); + + return el; + }, + + // Create template + createTemplate: function(args){ + + var self = this; + var currentPage = args.currentPage; + var totalPage = args.totalPage; + var rangeStart = args.rangeStart; + var rangeEnd = args.rangeEnd; + + var totalNumber = attributes.totalNumber; + + var showPrevious = attributes.showPrevious; + var showNext = attributes.showNext; + var showPageNumbers = attributes.showPageNumbers; + var showNavigator = attributes.showNavigator; + var showGoInput = attributes.showGoInput; + var showGoButton = attributes.showGoButton; + + var pageLink = attributes.pageLink; + var prevText = attributes.prevText; + var nextText = attributes.nextText; + var ellipsisText = attributes.ellipsisText; + var goButtonText = attributes.goButtonText; + + var classPrefix = attributes.classPrefix; + var activeClassName = attributes.activeClassName; + var disableClassName = attributes.disableClassName; + var ulClassName = attributes.ulClassName; + + var formatNavigator = $.isFunction(attributes.formatNavigator) ? attributes.formatNavigator() : attributes.formatNavigator; + var formatGoInput = $.isFunction(attributes.formatGoInput) ? attributes.formatGoInput() : attributes.formatGoInput; + var formatGoButton = $.isFunction(attributes.formatGoButton) ? attributes.formatGoButton() : attributes.formatGoButton; + + var autoHidePrevious = $.isFunction(attributes.autoHidePrevious) ? attributes.autoHidePrevious() : attributes.autoHidePrevious; + var autoHideNext = $.isFunction(attributes.autoHideNext) ? attributes.autoHideNext() : attributes.autoHideNext; + + var header = $.isFunction(attributes.header) ? attributes.header() : attributes.header; + var footer = $.isFunction(attributes.footer) ? attributes.footer() : attributes.footer; + + var html = ''; + var goInput = ''; + var goButton = ''; + var formattedString; + var i; + + if(header){ + + formattedString = self.replaceVariables(header, { + currentPage: currentPage, + totalPage: totalPage, + totalNumber: totalNumber + }); + + html += formattedString; + } + + if(showPrevious || showPageNumbers || showNext){ + + html += '
'; + + if(ulClassName){ + html += '