Вход Регистрация
Файл: templates/modern/js/datagrid-pagination.js
Строк: 202
<?php
/**
 * @preserve
 * bootpag - jQuery plugin for dynamic pagination
 *
 * Copyright (c) 2015 botmonster@7items.com
 * @modified InstantSoft, https://instantcms.ru/ for InstantCMS
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Project home:
 *   http://botmonster.com/jquery-bootpag/
 *
 * Version:  1.0.8
 *
 */
(function($, window) {

    $.fn.
bootpag = function(options){

        var 
$owner this,
            
settings = $.extend({
                
total0,
                
page1,
                
maxVisiblenull,
                
leapstrue,
                
hiddenClass'd-none',
                
href'javascript:void(0);',
                
hrefVariable'{{number}}',
                
next'&rarr;',
                
prev'&larr;',
                
firstLastUsefalse,
                
first'<span aria-hidden="true">&larr;</span>',
                
last'<span aria-hidden="true">&rarr;</span>',
                
wrapClass'pagination pagination-sm justify-content-start',
                
activeClass'active',
                
disabledClass'disabled',
                
nextClass'next',
                
prevClass'prev',
                
lastClass'last',
                
firstClass'first',
                
stayCentertrue
            
},
            
$owner.data('settings') || {},
            
options || {});

        if(
settings.total <= 0){
            return 
this;
        }

        if(!$.
isNumeric(settings.maxVisible) && !settings.maxVisible){
            
settings.maxVisible parseInt(settings.total10);
        }

        
$owner.data('settings'settings);

        function 
renderPage($bootpagpage){
            var 
middleIndex Math.round(settings.maxVisible 2) - 1;
            
page parseInt(page10);
            var 
lp,
                
maxV settings.maxVisible == settings.maxVisible,
                
step settings.maxVisible == 1,
                
vis Math.floor((page 1) / maxV) * maxV,
                
$page $bootpag.find('li');
            
settings.page page page page settings.total settings.total page;
            
$page.removeClass(settings.activeClass);
            
lp page :
                    
settings.leaps && page >= settings.maxVisible ?
                        
Math.floor((page 1) / maxV) * maxV page 1;

            if(
settings.firstLastUse) {
                
$page
                    
.first()
                    .
toggleClass(settings.disabledClasspage === 1);
            }

            var 
lfirst $page.first();
            if(
settings.firstLastUse) {
                
lfirst lfirst.next();
            }

            
lfirst
                
.toggleClass(settings.disabledClasspage === 1)
                .
attr('data-lp'lp)
                .
find('a').attr('href'href(lp));

            var 
step settings.maxVisible == 1;

            
lp page settings.total settings.total :
                    
settings.leaps && page <= settings.total settings.maxVisible ?
                        
vis settings.maxVisible steppage 1;

            var 
llast $page.last();
            if(
settings.firstLastUse) {
                
llast llast.prev();
            }

            
llast
                
.toggleClass(settings.disabledClasspage === settings.total)
                .
attr('data-lp'lp)
                .
find('a').attr('href'href(lp));

            
$page
                
.last()
                .
toggleClass(settings.disabledClasspage === settings.total);


            var 
$currPage $page.filter('[data-lp='+page+']');

            var 
clist "." + [settings.nextClass,
                               
settings.prevClass,
                               
settings.firstClass,
                               
settings.lastClass].join(",.");
            if(!
$currPage.not(clist).length || settings.stayCenter){
                var 
page <= vis ? -settings.maxVisible 0;
                
$page.not(clist).each(function (index) {
                    
lp index vis d;

                    var 
lpMiddleIndex middleIndex vis d;
                    var 
test = (page lpMiddleIndex) - (middleIndex index) + 1;

                    if (
index === 0) {
                        
test;
                        var 
tempLp index vis d;

                        if (
tempLp <= || tempLp >= settings.total 1) {
                            
page <= vis ? -settings.maxVisible 0;
                        }

                        
lp index vis d;
                    }

                    $(
this)
                        .
attr('data-lp'lp)
                        .
toggleClass(settings.hiddenClasslp settings.total)
                        .
find('a').html(lp).attr('href'href(lp));
                });
                
$currPage $page.filter('[data-lp='+page+']');
            }
            
$currPage.not(clist).addClass(settings.activeClass);
            
$owner.data('settings'settings);
        }

        function 
href(c){

            return 
settings.href.replace(settings.hrefVariablec);
        }

        return 
this.each(function(){

            var 
$bootpaglpme = $(this),
                
= ['<ul class="'settings.wrapClass' bootpag">'];

            if(
settings.firstLastUse){
                
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.concat(['<li data-lp="1" class="page-item 'settings.prevClass,
                       
'"><a class="page-link" href="'href(1), '">'settings.prev'</a></li>']);
            }
            for(var 
1<= Math.min(settings.totalsettings.maxVisible); c++){
                
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 1settings.total) : 2;
                
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.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').on('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($bootpagsettings.page);
        });
    }

})(
jQuerywindow);
?>
Онлайн: 2
Реклама