<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/**
 * Created by lucky51 on 2017/9/26 0026.
 * github:https://github.com/lucky51/am-pagination
 */

 (function (root, factory) {
  if (typeof define === 'function' &amp;&amp; define.amd) {
    // AMD
    define(['jquery'], factory);
  }
  else if (typeof exports === 'object') {
    // CommonJS
    module.exports = factory(require('jquery'));
  } else {
    root.amPagination = factory(root.jQuery);
  }
}(this, function ($) {
  var Pager = function (ele, opts) {
    var options = $.extend({}, $.fn.pagination.default, opts);
    this.ele = ele;

    this.container=function(self){
      if(self.checkTag(self.ele,'UL')){
        return self.ele;
      }else{
        var hasul =self.ele.find('ul');
        if(hasul.length&gt;0){
          hasul.empty();
          return hasul;
        }else{
          var ctr = $('&lt;ul  /&gt;');
          self.ele.append(ctr);
          return ctr
        }
      }
    };
    this.onChangePage=function(fn){
      if(fn&amp;&amp;typeof fn==='function'){
        this.ele.on('am.pagination.change',fn);
      }
      return this;
    };
    this.maxSize = options.maxSize || this.ele.data('maxSize');
    this._page = -1;
    this.totals =options.totals;
    this.currPage = function () {
      return this._page + 1;
    };
    if (options.page &amp;&amp; options.page &gt; 0) {
      this._page = options.page - 1;
    } else if (this.ele.data('page')) {
      this._page = parseInt(this.ele.data('page'));
    }

    this.pageSize = options.pageSize;
    this.selectPage = function (selpage,tsource) {
      options.page =selpage;
      this.ele.trigger({
        type: 'am.pagination.change',
        page: selpage,
        pageSize: this.pageSize,
        totals: this.totals,
        tiggerSource:tsource||'code'
      });
      this._page = selpage - 1;
      this.fill();
      this.ele.trigger('am.context.change');
    };
    this.context = function () {
      return options;
    };
    this.render = function (rdopts) {
      if (rdopts.hasOwnProperty("totals")) {
        this.totals = options.totals = rdopts["totals"];
        if (this.totals === 0) {
          this.totals = options.totals =1;
        }
      }
      if (rdopts.hasOwnProperty("pageSize")) {
        this.pageSize = options.pageSize = rdopts["pageSize"];
      }
      if (rdopts.hasOwnProperty("page")) {
        var rpage = options.page = rdopts["page"];
        this._page = options.page - 1;
      }
      this.selectPage(this.currPage());
    };
    this.changeContext=function(){
      this.ele.attr('data-pagination',JSON.stringify(this.context()));
    };
    this.ele.on('am.context.change',$.proxy(this.changeContext,this));
    this.click = function (e) {
      e.preventDefault();
      var currpage = '';
      var $self = $(e.target);
      var $p = $self.parent('li');
      if($p.hasClass('am-disabled')||$p.hasClass('disabled')){return;}
      if ($p.hasClass('pager-first')) {
        this.selectPage(1,'manual');
      }
      else if ($p.hasClass('pager-prev')) {
        currpage = this.currPage() - 1;
        this.selectPage(currpage,'manual');
      }
      else if ($p.hasClass('pager-next')) {
        currpage = this.currPage() + 1;
        this.selectPage(currpage,'manual');
      }
      else if ($p.hasClass('pager-last')) {
        var pageCount = Math.ceil(this.totals / this.pageSize);
        this.selectPage(pageCount,'manual');
      }
      else {
        if ($p.hasClass('am-active')||$p.hasClass('active')) {return;}
        this.selectPage(parseInt($self.text()),'manual');
      }
    };

    this.fill = function () {
      if (this.pageSize &lt;= 0){
        throw Error('pageSize invalid!');
      }
      if (this.totals &lt; 0) {
        throw Error('totals invalid!');
      }
      var el =this.container(this);
      if(this.totals===0){
        if(options.hideIfEmpty===true){
          if(!el.is(':hidden')){
            el.hide();
          }
        }
      }else{
        if(el.is(':hidden')){
          el.show();
        }
      }
      var pageCount = Math.ceil(this.totals / this.pageSize);
      if (this._page &lt; 0) {
        this._page = 0;
      }
      if (this._page &gt; pageCount - 1) {
        this._page = pageCount - 1;
      }
      var spage = -1, epage = -1;
      if (options.rotate === true) {
        if (this.maxSize % 2 !== 0) {
          var ps = Math.floor(this.maxSize / 2);

          if (this._page - ps &gt;= 0) {
            spage = this._page - ps;
            if (this._page + ps &gt; pageCount - 1) {
              epage = pageCount - 1;
            } else {
              epage = this._page + ps;
            }

          } else {
            spage = 0;
            epage = this.maxSize - 1;
          }
        } else {
          var m = this.maxSize / 2;

          if (this._page - m &gt;= 0) {
            spage = this._page - m;
            if (this._page + (m - 1) &lt; pageCount) {
              epage = this._page + (m - 1);
            } else {
              epage = pageCount - 1;
            }
          } else {
            epage = this.maxSize - 1;
            spage = 0;
          }
        }
        epage = epage + 1;
      } else {
        spage = this._page - this._page % this.maxSize;
        epage = spage + this.maxSize;
      }

      epage = epage &gt; pageCount ? pageCount : epage;

      this.createUITmp({
        cpgidx:this._page,
        ctotals:this.totals,
        cboundaryLinks:options.boundaryLinks,
        cfirstText:options.firstText,
        cpageCount:pageCount,
        clastText:options.lastText,
        cprevText:options.prevText,
        cnextText:options.nextText,
        cuiType:options.theme,
        cbtnSize:options.btnSize,
        cdirectionLinks:options.directionLinks,
        cspage:spage,
        cepage:epage

      },this.container(this));


    };
    this.container(this).on('click', 'li&gt;a', $.proxy(this.click, this));
    this.selectPage(options.page);
  };

  Pager.Global={
    checkDom:function(obj){
      return  typeof HTMLElement === 'object' ?function(obj){ return obj instanceof HTMLElement;}: function(obj){    return obj &amp;&amp; typeof obj === 'object' &amp;&amp; obj.nodeType === 1 &amp;&amp; typeof obj.nodeName === 'string';    };
    },
    check$:function(obj){
      if(!obj)return false;
      return obj instanceof $;
    },
    addClassOnce:function(elem,classname){
      if(!elem.hasClass(classname)){
        elem.addClass(classname);
      }

    }
  };
  Pager.prototype={
    constructor:Pager,
    checkTag:function($obj,htmtag){
      if($obj instanceof $){
        return  $obj.get(0).tagName===htmtag;
      }else if(Pager.Global["checkDom"]($obj)){
        return $obj.tagName===htmtag;
      }else if(typeof $obj==='string'){
        return $($obj).get(0).tagName===htmtag;
      }
      return false;
    },
    createUITmp:function(copts,celem){ //cpgidx,ctotals,cboundaryLinks,cfirstText,cpageCount,clastText,cprevText,cnextText,cuiType,cspage,cepage

      var htm =[];
      if(copts.cuiType==='amazeui'){
        Pager.Global["addClassOnce"](celem,'am-pagination');
        if(copts.cbtnSize==="sm"){
          Pager.Global["addClassOnce"](celem,'am-pagination-sm');
        }else if(copts.cbtnSize==="lg"){
          Pager.Global["addClassOnce"](celem,'am-pagination-lg');
        }

        if (copts.cboundaryLinks === true) {
          htm.push('&lt;li  class=" pager-first ' + (copts.cpgidx === 0 || copts.ctotals&lt;=0 ? 'am-disabled' : '') + '" &gt;&lt;a href="#"&gt;' + copts.cfirstText + '&lt;/a&gt;&lt;/li&gt;');
        }

        if (copts.cdirectionLinks === true) {
          htm.push('&lt;li  class=" pager-prev   ' + (copts.cpgidx === 0 ||copts.ctotals&lt;= 0? 'am-disabled' : '') + '  "&gt;&lt;a href="#"&gt;' + copts.cprevText + '&lt;/a&gt;&lt;/li&gt;');
        }

        if (copts.cspage !== 0) {
          htm.push('&lt;li&gt;&lt;span&gt;...&lt;/span&gt;&lt;/li&gt;');
        }
        for (var i = copts.cspage; i &lt; copts.cepage; i++) {
          htm.push('&lt;li ' + (copts.cpgidx === i ? 'class="am-active"' : "") + '&gt;&lt;a href="#"&gt;' + (i + 1) + '&lt;/a&gt;&lt;/li&gt;');
        }
        if (copts.cepage !== copts.cpageCount) {
          htm.push('&lt;li&gt;&lt;span&gt;...&lt;/span&gt;&lt;/li&gt;');
        }
        if (copts.cdirectionLinks === true) {
          htm.push(' &lt;li class="pager-next ' + (copts.cpgidx === copts.cpageCount - 1 || copts.ctotals &lt;= 0 ? 'am-disabled ' : '') + '"&gt;&lt;a href="#"&gt;' + copts.cnextText + '&lt;/a&gt;&lt;/li&gt;');
        }
        if (copts.cboundaryLinks === true) {
          htm.push(' &lt;li class=" pager-last ' + (copts.cpgidx === copts.cpageCount - 1 || copts.ctotals &lt;= 0? 'am-disabled' : '') + '"&gt;&lt;a href="#"&gt;' + copts.clastText + '&lt;/a&gt;&lt;/li&gt;');
        }
      }else if(copts.cuiType==='bootstrap'){
        Pager.Global["addClassOnce"](celem,'pagination');
        if(copts.cbtnSize==="sm"){
          Pager.Global["addClassOnce"](celem,'pagination-sm');
        }else if(copts.cbtnSize==="lg"){
          Pager.Global["addClassOnce"](celem,'pagination-lg');
        }
        if(!celem.hasClass('pagination')){
          celem.addClass('pagination');
        }
        if (copts.cboundaryLinks === true) {
          htm.push('&lt;li  class=" pager-first ' + (copts.cpgidx === 0 || copts.ctotals&lt;=0 ? 'disabled' : '') + '" &gt;&lt;a href="#"&gt;' + copts.cfirstText + '&lt;/a&gt;&lt;/li&gt;');
        }

        if (copts.cdirectionLinks === true) {
          htm.push('&lt;li  class=" pager-prev   ' + (copts.cpgidx === 0 ||copts.ctotals&lt;= 0? 'disabled' : '') + '  "&gt;&lt;a href="#"&gt;' + copts.cprevText + '&lt;/a&gt;&lt;/li&gt;');
        }

        if (copts.cspage !== 0) {
          htm.push('&lt;li&gt;&lt;span&gt;...&lt;/span&gt;&lt;/li&gt;');
        }
        for (var i = copts.cspage; i &lt; copts.cepage; i++) {
          htm.push('&lt;li ' + (copts.cpgidx === i ? 'class="active"' : "") + '&gt;&lt;a href="#"&gt;' + (i + 1) + '&lt;/a&gt;&lt;/li&gt;');
        }
        if (copts.cepage !== copts.cpageCount) {
          htm.push('&lt;li&gt;&lt;span&gt;...&lt;/span&gt;&lt;/li&gt;');
        }
        if (copts.cdirectionLinks === true) {
          htm.push(' &lt;li class="pager-next ' + (copts.cpgidx === copts.cpageCount - 1 || copts.ctotals &lt;= 0 ? 'disabled ' : '') + '"&gt;&lt;a href="#"&gt;' + copts.cnextText + '&lt;/a&gt;&lt;/li&gt;');
        }
        if (copts.cboundaryLinks === true) {
          htm.push(' &lt;li class=" pager-last ' + (copts.cpgidx === copts.cpageCount - 1 || copts.ctotals &lt;= 0? 'disabled' : '') + '"&gt;&lt;a href="#"&gt;' + copts.clastText + '&lt;/a&gt;&lt;/li&gt;');
        }
      }else{
        Pager.Global["addClassOnce"](celem,'am-pagination-default');
        if(copts.cbtnSize==="sm"){
          Pager.Global["addClassOnce"](celem,'am-pagination-default-sm');
        }else if(copts.cbtnSize==="lg"){
          Pager.Global["addClassOnce"](celem,'am-pagination-default-lg');
        }

        if (copts.cboundaryLinks === true) {
          htm.push('&lt;li  class=" pager-first ' + (copts.cpgidx === 0 || copts.ctotals&lt;=0 ? 'disabled' : '') + '" &gt;&lt;a href="#"&gt;' + copts.cfirstText + '&lt;/a&gt;&lt;/li&gt;');
        }

        if (copts.cdirectionLinks === true) {
          htm.push('&lt;li  class=" pager-prev   ' + (copts.cpgidx === 0 ||copts.ctotals&lt;= 0? 'disabled' : '') + '  "&gt;&lt;a href="#"&gt;' + copts.cprevText + '&lt;/a&gt;&lt;/li&gt;');
        }

        if (copts.cspage !== 0) {
          htm.push('&lt;li&gt;&lt;span&gt;...&lt;/span&gt;&lt;/li&gt;');
        }
        for (var i = copts.cspage; i &lt; copts.cepage; i++) {
          htm.push('&lt;li ' + (copts.cpgidx === i ? 'class="active"' : "") + '&gt;&lt;a href="#"&gt;' + (i + 1) + '&lt;/a&gt;&lt;/li&gt;');
        }
        if (copts.cepage !== copts.cpageCount) {
          htm.push('&lt;li&gt;&lt;span&gt;...&lt;/span&gt;&lt;/li&gt;');
        }
        if (copts.cdirectionLinks === true) {
          htm.push(' &lt;li class="pager-next ' + (copts.cpgidx === copts.cpageCount - 1 || copts.ctotals &lt;= 0 ? 'disabled ' : '') + '"&gt;&lt;a href="#"&gt;' + copts.cnextText + '&lt;/a&gt;&lt;/li&gt;');
        }
        if (copts.cboundaryLinks === true) {
          htm.push(' &lt;li class=" pager-last ' + (copts.cpgidx === copts.cpageCount - 1 || copts.ctotals &lt;= 0? 'disabled' : '') + '"&gt;&lt;a href="#"&gt;' + copts.clastText + '&lt;/a&gt;&lt;/li&gt;');
        }
      }
      this.container(this).empty();
      this.container(this).append($(htm.join('')));

    }
  };
  $.fn.pagination = function (popts) {
    var pger ={};
    var args =arguments;
    if(!this.attr('data-pagination')){
      pger = new Pager(this, popts);
      var jstr =JSON.stringify(pger.context());
      this.attr('data-pagination',jstr);
    }else{
      var  pgeropts = this.attr('data-pagination');
      var pgch =JSON.parse(pgeropts);
      var newOpts= (function(){return args.length!==0;})()&amp;&amp; $.extend({},pgch,popts);
      pger =new Pager(this,newOpts===false?pgch:newOpts);
    }
    return pger;

  };

  $.fn.pagination.default = {
    maxSize: 7,
    totals: 100,
    page: 1,
    pageSize: 10,
    lastText: '&amp;raquo;&amp;raquo;', //&amp;raquo;
    firstText: '&amp;laquo;&amp;laquo;',
    prevText: '&amp;laquo;',//&amp;laquo;
    nextText: '&amp;raquo;',
    rotate: true,
    directionLinks: true,
    boundaryLinks: true,
    theme:'',
    btnSize:'',
    hideIfEmpty:false

  };
  var gpger =function (selector, pots) {
    var $sel ={};
    if(selector instanceof $){
      $sel = selector;
    }else if(Pager.Global["checkDom"](selector)){
      $sel =$(selector);
    }else if(typeof selector==='string'){
      $sel=$(selector);
    }
    return $.fn.pagination.call($sel, pots);
  };
  return gpger;
}));
</pre></body></html>