Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Upgrading to Bootstrap 4-5+ #62

Open
gregbown opened this issue Jul 22, 2021 · 0 comments
Open

Upgrading to Bootstrap 4-5+ #62

gregbown opened this issue Jul 22, 2021 · 0 comments

Comments

@gregbown
Copy link

gregbown commented Jul 22, 2021

Seems fairly simple
package.json add devDependencies with closure compiler

  "devDependencies": {
    "google-closure-compiler": "^20210601.0.0"
  },

package.json add script to compile, use start since it's easy

  "scripts": {
    "start": "google-closure-compiler --js lib/jquery.bootpag.js --js_output_file lib/jquery.bootpag.min.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  }

lib/jquery.bootpag.js edit markup templating to include latest classes from Bootstrap in this.each method

      return this.each(function() {
        var $bootpag, lp, me = $(this),
          p = ['<ul class="', settings.wrapClass, ' bootpag">'];
        if(settings.firstLastUse){
          p = p.concat(['<li data-lp="1" class="page-item ', settings.firstClass,
            '"><a class="page-link" href="', href(1), '">', settings.first, '</a></li>']);
        }
        if(settings.prev){
          p = p.concat(['<li data-lp="1" class="page-item ', settings.prevClass,
            '"><a class="page-link" href="', href(1), '">', settings.prev, '</a></li>']);
        }
        for(var c = 1; c <= Math.min(settings.total, settings.maxVisible); c++){
          p = p.concat(['<li class="page-item" data-lp="', c, '"><a class="page-link" href="', href(c), '">', c, '</a></li>']);
        }
        if(settings.next){
          lp = settings.leaps && settings.total > settings.maxVisible
            ? Math.min(settings.maxVisible + 1, settings.total) : 2;
          p = p.concat(['<li data-lp="', lp, '" class="page-item ',
            settings.nextClass, '"><a class="page-link" href="', href(lp),
              '">', settings.next, '</a></li>']);
        }
        if(settings.firstLastUse){
          p = p.concat(['<li data-lp="', settings.total, '" class="page-item last"><a class="page-link" href="',
            href(settings.total),'">', settings.last, '</a></li>']);
        }
        p.push('</ul>');
        me.find('ul.bootpag').remove();
        me.append(p.join(''));
        $bootpag = me.find('ul.bootpag');
        me.find('li').click(function paginationClick() {
          var me = $(this);
          if(me.hasClass(settings.disabledClass) || me.hasClass(settings.activeClass)){
            return;
          }
          var page = parseInt(me.attr('data-lp'), 10);
          $owner.find('ul.bootpag').each(function(){
            renderPage($(this), page);
          });
          $owner.trigger('page', page);
        });
        renderPage($bootpag, settings.page);
      });

To build just npm start afterwards

npm start
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant