app.js 18 KB
Newer Older
Manggar Mahardhika's avatar
Manggar Mahardhika committed
1
/* ------------------------------------------------------------------------------
Muhamad's avatar
Muhamad committed
2 3 4 5 6 7 8 9 10
*
*  # Template JS core
*
*  Core JS file with default functionality configuration
*
*  Version: 1.3
*  Latest update: Aug 10, 2016
*
* ---------------------------------------------------------------------------- */
Manggar Mahardhika's avatar
Manggar Mahardhika committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96


// Allow CSS transitions when page is loaded
$(window).on('load', function() {
    $('body').removeClass('no-transitions');
});


$(function() {

    // Disable CSS transitions on page load
    $('body').addClass('no-transitions');



    // ========================================
    //
    // Content area height
    //
    // ========================================


    // Calculate min height
    function containerHeight() {
        var availableHeight = $(window).height() - $('.page-container').offset().top - $('.navbar-fixed-bottom').outerHeight();

        $('.page-container').attr('style', 'min-height:' + availableHeight + 'px');
    }

    // Initialize
    containerHeight();




    // ========================================
    //
    // Heading elements
    //
    // ========================================


    // Heading elements toggler
    // -------------------------

    // Add control button toggler to page and panel headers if have heading elements
    $('.panel-footer').has('> .heading-elements:not(.not-collapsible)').prepend('<a class="heading-elements-toggle"><i class="icon-more"></i></a>');
    $('.page-title, .panel-title').parent().has('> .heading-elements:not(.not-collapsible)').children('.page-title, .panel-title').append('<a class="heading-elements-toggle"><i class="icon-more"></i></a>');


    // Toggle visible state of heading elements
    $('.page-title .heading-elements-toggle, .panel-title .heading-elements-toggle').on('click', function() {
        $(this).parent().parent().toggleClass('has-visible-elements').children('.heading-elements').toggleClass('visible-elements');
    });
    $('.panel-footer .heading-elements-toggle').on('click', function() {
        $(this).parent().toggleClass('has-visible-elements').children('.heading-elements').toggleClass('visible-elements');
    });



    // Breadcrumb elements toggler
    // -------------------------

    // Add control button toggler to breadcrumbs if has elements
    $('.breadcrumb-line').has('.breadcrumb-elements').prepend('<a class="breadcrumb-elements-toggle"><i class="icon-menu-open"></i></a>');


    // Toggle visible state of breadcrumb elements
    $('.breadcrumb-elements-toggle').on('click', function() {
        $(this).parent().children('.breadcrumb-elements').toggleClass('visible-elements');
    });




    // ========================================
    //
    // Navbar
    //
    // ========================================


    // Navbar navigation
    // -------------------------

    // Prevent dropdown from closing on click
Muhamad's avatar
Muhamad committed
97
    $(document).on('click', '.dropdown-content', function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
98 99 100 101
        e.stopPropagation();
    });

    // Disabled links
Muhamad's avatar
Muhamad committed
102
    $('.navbar-nav .disabled a').on('click', function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
103 104 105 106 107
        e.preventDefault();
        e.stopPropagation();
    });

    // Show tabs inside dropdowns
Muhamad's avatar
Muhamad committed
108
    $('.dropdown-content a[data-toggle="tab"]').on('click', function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
        $(this).tab('show');
    });




    // ========================================
    //
    // Element controls
    //
    // ========================================


    // Reload elements
    // -------------------------

    // Panels
Muhamad's avatar
Muhamad committed
126
    $('.panel [data-action=reload]').click(function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
127 128
        e.preventDefault();
        var block = $(this).parent().parent().parent().parent().parent();
Muhamad's avatar
Muhamad committed
129
        $(block).block({ 
Manggar Mahardhika's avatar
Manggar Mahardhika committed
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
            message: '<i class="icon-spinner2 spinner"></i>',
            overlayCSS: {
                backgroundColor: '#fff',
                opacity: 0.8,
                cursor: 'wait',
                'box-shadow': '0 0 0 1px #ddd'
            },
            css: {
                border: 0,
                padding: 0,
                backgroundColor: 'none'
            }
        });

        // For demo purposes
Muhamad's avatar
Muhamad committed
145 146 147
        window.setTimeout(function () {
           $(block).unblock();
        }, 2000); 
Manggar Mahardhika's avatar
Manggar Mahardhika committed
148 149 150 151
    });


    // Sidebar categories
Muhamad's avatar
Muhamad committed
152
    $('.category-title [data-action=reload]').click(function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
153 154
        e.preventDefault();
        var block = $(this).parent().parent().parent().parent();
Muhamad's avatar
Muhamad committed
155
        $(block).block({ 
Manggar Mahardhika's avatar
Manggar Mahardhika committed
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
            message: '<i class="icon-spinner2 spinner"></i>',
            overlayCSS: {
                backgroundColor: '#000',
                opacity: 0.5,
                cursor: 'wait',
                'box-shadow': '0 0 0 1px #000'
            },
            css: {
                border: 0,
                padding: 0,
                backgroundColor: 'none',
                color: '#fff'
            }
        });

        // For demo purposes
Muhamad's avatar
Muhamad committed
172 173 174 175
        window.setTimeout(function () {
           $(block).unblock();
        }, 2000); 
    }); 
Manggar Mahardhika's avatar
Manggar Mahardhika committed
176 177 178


    // Light sidebar categories
Muhamad's avatar
Muhamad committed
179
    $('.sidebar-default .category-title [data-action=reload]').click(function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
180 181
        e.preventDefault();
        var block = $(this).parent().parent().parent().parent();
Muhamad's avatar
Muhamad committed
182
        $(block).block({ 
Manggar Mahardhika's avatar
Manggar Mahardhika committed
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197
            message: '<i class="icon-spinner2 spinner"></i>',
            overlayCSS: {
                backgroundColor: '#fff',
                opacity: 0.8,
                cursor: 'wait',
                'box-shadow': '0 0 0 1px #ddd'
            },
            css: {
                border: 0,
                padding: 0,
                backgroundColor: 'none'
            }
        });

        // For demo purposes
Muhamad's avatar
Muhamad committed
198 199 200 201
        window.setTimeout(function () {
           $(block).unblock();
        }, 2000); 
    }); 
Manggar Mahardhika's avatar
Manggar Mahardhika committed
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220



    // Collapse elements
    // -------------------------

    //
    // Sidebar categories
    //

    // Hide if collapsed by default
    $('.category-collapsed').children('.category-content').hide();


    // Rotate icon if collapsed by default
    $('.category-collapsed').find('[data-action=collapse]').addClass('rotate-180');


    // Collapse on click
Muhamad's avatar
Muhamad committed
221
    $('.category-title [data-action=collapse]').click(function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
        e.preventDefault();
        var $categoryCollapse = $(this).parent().parent().parent().nextAll();
        $(this).parents('.category-title').toggleClass('category-collapsed');
        $(this).toggleClass('rotate-180');

        containerHeight(); // adjust page height

        $categoryCollapse.slideToggle(150);
    });


    //
    // Panels
    //

    // Hide if collapsed by default
    $('.panel-collapsed').children('.panel-heading').nextAll().hide();


    // Rotate icon if collapsed by default
    $('.panel-collapsed').find('[data-action=collapse]').addClass('rotate-180');


    // Collapse on click
Muhamad's avatar
Muhamad committed
246
    $('.panel [data-action=collapse]').click(function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
        e.preventDefault();
        var $panelCollapse = $(this).parent().parent().parent().parent().nextAll();
        $(this).parents('.panel').toggleClass('panel-collapsed');
        $(this).toggleClass('rotate-180');

        containerHeight(); // recalculate page height

        $panelCollapse.slideToggle(150);
    });



    // Remove elements
    // -------------------------

    // Panels
Muhamad's avatar
Muhamad committed
263
    $('.panel [data-action=close]').click(function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
264 265 266 267 268 269 270 271 272 273 274 275
        e.preventDefault();
        var $panelClose = $(this).parent().parent().parent().parent().parent();

        containerHeight(); // recalculate page height

        $panelClose.slideUp(150, function() {
            $(this).remove();
        });
    });


    // Sidebar categories
Muhamad's avatar
Muhamad committed
276
    $('.category-title [data-action=close]').click(function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
        e.preventDefault();
        var $categoryClose = $(this).parent().parent().parent().parent();

        containerHeight(); // recalculate page height

        $categoryClose.slideUp(150, function() {
            $(this).remove();
        });
    });




    // ========================================
    //
    // Main navigation
    //
    // ========================================


    // Main navigation
    // -------------------------

    // Add 'active' class to parent list item in all levels
    $('.navigation').find('li.active').parents('li').addClass('active');

    // Hide all nested lists
    $('.navigation').find('li').not('.active, .category-title').has('ul').children('ul').addClass('hidden-ul');

    // Highlight children links
    $('.navigation').find('li').has('ul').children('a').addClass('has-ul');

    // Add active state to all dropdown parent levels
    $('.dropdown-menu:not(.dropdown-content), .dropdown-menu:not(.dropdown-content) .dropdown-submenu').has('li.active').addClass('active').parents('.navbar-nav .dropdown:not(.language-switch), .navbar-nav .dropup:not(.language-switch)').addClass('active');

Muhamad's avatar
Muhamad committed
312
    
Manggar Mahardhika's avatar
Manggar Mahardhika committed
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328

    // Main navigation tooltips positioning
    // -------------------------

    // Left sidebar
    $('.navigation-main > .navigation-header > i').tooltip({
        placement: 'right',
        container: 'body'
    });



    // Collapsible functionality
    // -------------------------

    // Main navigation
Muhamad's avatar
Muhamad committed
329
    $('.navigation-main').find('li').has('ul').children('a').on('click', function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
330 331 332 333 334 335 336 337 338 339 340
        e.preventDefault();

        // Collapsible
        $(this).parent('li').not('.disabled').not($('.sidebar-xs').not('.sidebar-xs-indicator').find('.navigation-main').children('li')).toggleClass('active').children('ul').slideToggle(250);

        // Accordion
        if ($('.navigation-main').hasClass('navigation-accordion')) {
            $(this).parent('li').not('.disabled').not($('.sidebar-xs').not('.sidebar-xs-indicator').find('.navigation-main').children('li')).siblings(':has(.has-ul)').removeClass('active').children('ul').slideUp(250);
        }
    });

Muhamad's avatar
Muhamad committed
341
        
Manggar Mahardhika's avatar
Manggar Mahardhika committed
342
    // Alternate navigation
Muhamad's avatar
Muhamad committed
343
    $('.navigation-alt').find('li').has('ul').children('a').on('click', function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
344 345 346 347 348 349 350 351 352
        e.preventDefault();

        // Collapsible
        $(this).parent('li').not('.disabled').toggleClass('active').children('ul').slideToggle(200);

        // Accordion
        if ($('.navigation-alt').hasClass('navigation-accordion')) {
            $(this).parent('li').not('.disabled').siblings(':has(.has-ul)').removeClass('active').children('ul').slideUp(200);
        }
Muhamad's avatar
Muhamad committed
353
    }); 
Manggar Mahardhika's avatar
Manggar Mahardhika committed
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368




    // ========================================
    //
    // Sidebars
    //
    // ========================================


    // Mini sidebar
    // -------------------------

    // Toggle mini sidebar
Muhamad's avatar
Muhamad committed
369
    $('.sidebar-main-toggle').on('click', function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
370 371 372 373 374 375 376 377 378 379 380 381
        e.preventDefault();

        // Toggle min sidebar class
        $('body').toggleClass('sidebar-xs');
    });



    // Sidebar controls
    // -------------------------

    // Disable click in disabled navigation items
Muhamad's avatar
Muhamad committed
382
    $(document).on('click', '.navigation .disabled a', function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
383 384 385 386 387
        e.preventDefault();
    });


    // Adjust page height on sidebar control button click
Muhamad's avatar
Muhamad committed
388
    $(document).on('click', '.sidebar-control', function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
389 390 391 392 393
        containerHeight();
    });


    // Hide main sidebar in Dual Sidebar
Muhamad's avatar
Muhamad committed
394
    $(document).on('click', '.sidebar-main-hide', function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
395 396 397 398 399 400
        e.preventDefault();
        $('body').toggleClass('sidebar-main-hidden');
    });


    // Toggle second sidebar in Dual Sidebar
Muhamad's avatar
Muhamad committed
401
    $(document).on('click', '.sidebar-secondary-hide', function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
402 403 404 405 406
        e.preventDefault();
        $('body').toggleClass('sidebar-secondary-hidden');
    });


Muhamad's avatar
Muhamad committed
407 408 409 410 411 412 413
    // Hide detached sidebar
    $(document).on('click', '.sidebar-detached-hide', function (e) {
        e.preventDefault();
        $('body').toggleClass('sidebar-detached-hidden');
    });


Manggar Mahardhika's avatar
Manggar Mahardhika committed
414
    // Hide all sidebars
Muhamad's avatar
Muhamad committed
415
    $(document).on('click', '.sidebar-all-hide', function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
416 417 418 419 420 421 422 423 424 425 426 427
        e.preventDefault();

        $('body').toggleClass('sidebar-all-hidden');
    });



    //
    // Opposite sidebar
    //

    // Collapse main sidebar if opposite sidebar is visible
Muhamad's avatar
Muhamad committed
428
    $(document).on('click', '.sidebar-opposite-toggle', function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
429 430 431 432 433 434 435 436 437 438 439 440 441
        e.preventDefault();

        // Opposite sidebar visibility
        $('body').toggleClass('sidebar-opposite-visible');

        // If visible
        if ($('body').hasClass('sidebar-opposite-visible')) {

            // Make main sidebar mini
            $('body').addClass('sidebar-xs');

            // Hide children lists
            $('.navigation-main').children('li').children('ul').css('display', '');
Muhamad's avatar
Muhamad committed
442 443
        }
        else {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
444 445 446 447 448 449 450 451

            // Make main sidebar default
            $('body').removeClass('sidebar-xs');
        }
    });


    // Hide main sidebar if opposite sidebar is shown
Muhamad's avatar
Muhamad committed
452
    $(document).on('click', '.sidebar-opposite-main-hide', function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
453 454 455 456
        e.preventDefault();

        // Opposite sidebar visibility
        $('body').toggleClass('sidebar-opposite-visible');
Muhamad's avatar
Muhamad committed
457
        
Manggar Mahardhika's avatar
Manggar Mahardhika committed
458 459 460 461 462
        // If visible
        if ($('body').hasClass('sidebar-opposite-visible')) {

            // Hide main sidebar
            $('body').addClass('sidebar-main-hidden');
Muhamad's avatar
Muhamad committed
463 464
        }
        else {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
465 466 467 468 469 470 471 472

            // Show main sidebar
            $('body').removeClass('sidebar-main-hidden');
        }
    });


    // Hide secondary sidebar if opposite sidebar is shown
Muhamad's avatar
Muhamad committed
473
    $(document).on('click', '.sidebar-opposite-secondary-hide', function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
474 475 476 477 478 479 480 481 482 483 484
        e.preventDefault();

        // Opposite sidebar visibility
        $('body').toggleClass('sidebar-opposite-visible');

        // If visible
        if ($('body').hasClass('sidebar-opposite-visible')) {

            // Hide secondary
            $('body').addClass('sidebar-secondary-hidden');

Muhamad's avatar
Muhamad committed
485 486
        }
        else {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
487 488 489 490 491 492 493 494

            // Show secondary
            $('body').removeClass('sidebar-secondary-hidden');
        }
    });


    // Hide all sidebars if opposite sidebar is shown
Muhamad's avatar
Muhamad committed
495
    $(document).on('click', '.sidebar-opposite-hide', function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
496 497 498 499 500 501 502 503 504 505 506 507 508
        e.preventDefault();

        // Toggle sidebars visibility
        $('body').toggleClass('sidebar-all-hidden');

        // If hidden
        if ($('body').hasClass('sidebar-all-hidden')) {

            // Show opposite
            $('body').addClass('sidebar-opposite-visible');

            // Hide children lists
            $('.navigation-main').children('li').children('ul').css('display', '');
Muhamad's avatar
Muhamad committed
509 510
        }
        else {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
511 512 513 514 515 516 517 518

            // Hide opposite
            $('body').removeClass('sidebar-opposite-visible');
        }
    });


    // Keep the width of the main sidebar if opposite sidebar is visible
Muhamad's avatar
Muhamad committed
519
    $(document).on('click', '.sidebar-opposite-fix', function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
520 521 522 523 524 525 526 527 528 529 530 531
        e.preventDefault();

        // Toggle opposite sidebar visibility
        $('body').toggleClass('sidebar-opposite-visible');
    });



    // Mobile sidebar controls
    // -------------------------

    // Toggle main sidebar
Muhamad's avatar
Muhamad committed
532
    $('.sidebar-mobile-main-toggle').on('click', function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
533
        e.preventDefault();
Muhamad's avatar
Muhamad committed
534
        $('body').toggleClass('sidebar-mobile-main').removeClass('sidebar-mobile-secondary sidebar-mobile-opposite sidebar-mobile-detached');
Manggar Mahardhika's avatar
Manggar Mahardhika committed
535 536 537 538
    });


    // Toggle secondary sidebar
Muhamad's avatar
Muhamad committed
539
    $('.sidebar-mobile-secondary-toggle').on('click', function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
540
        e.preventDefault();
Muhamad's avatar
Muhamad committed
541
        $('body').toggleClass('sidebar-mobile-secondary').removeClass('sidebar-mobile-main sidebar-mobile-opposite sidebar-mobile-detached');
Manggar Mahardhika's avatar
Manggar Mahardhika committed
542 543 544 545
    });


    // Toggle opposite sidebar
Muhamad's avatar
Muhamad committed
546 547 548 549 550 551 552 553
    $('.sidebar-mobile-opposite-toggle').on('click', function (e) {
        e.preventDefault();
        $('body').toggleClass('sidebar-mobile-opposite').removeClass('sidebar-mobile-main sidebar-mobile-secondary sidebar-mobile-detached');
    });


    // Toggle detached sidebar
    $('.sidebar-mobile-detached-toggle').on('click', function (e) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
554
        e.preventDefault();
Muhamad's avatar
Muhamad committed
555
        $('body').toggleClass('sidebar-mobile-detached').removeClass('sidebar-mobile-main sidebar-mobile-secondary sidebar-mobile-opposite');
Manggar Mahardhika's avatar
Manggar Mahardhika committed
556 557 558 559 560 561 562 563 564 565
    });



    // Mobile sidebar setup
    // -------------------------

    $(window).on('resize', function() {
        setTimeout(function() {
            containerHeight();
Muhamad's avatar
Muhamad committed
566 567
            
            if($(window).width() <= 768) {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
568 569 570 571 572

                // Add mini sidebar indicator
                $('body').addClass('sidebar-xs-indicator');

                // Place right sidebar before content
Muhamad's avatar
Muhamad committed
573
                $('.sidebar-opposite').insertBefore('.content-wrapper');
Manggar Mahardhika's avatar
Manggar Mahardhika committed
574

Muhamad's avatar
Muhamad committed
575 576
                // Place detached sidebar before content
                $('.sidebar-detached').insertBefore('.content-wrapper');
Manggar Mahardhika's avatar
Manggar Mahardhika committed
577 578 579 580 581 582 583

                // Add mouse events for dropdown submenus
                $('.dropdown-submenu').on('mouseenter', function() {
                    $(this).children('.dropdown-menu').addClass('show');
                }).on('mouseleave', function() {
                    $(this).children('.dropdown-menu').removeClass('show');
                });
Muhamad's avatar
Muhamad committed
584 585
            }
            else {
Manggar Mahardhika's avatar
Manggar Mahardhika committed
586 587 588 589 590 591 592 593

                // Remove mini sidebar indicator
                $('body').removeClass('sidebar-xs-indicator');

                // Revert back right sidebar
                $('.sidebar-opposite').insertAfter('.content-wrapper');

                // Remove all mobile sidebar classes
Muhamad's avatar
Muhamad committed
594 595 596 597 598 599 600 601 602 603 604
                $('body').removeClass('sidebar-mobile-main sidebar-mobile-secondary sidebar-mobile-detached sidebar-mobile-opposite');

                // Revert left detached position
                if($('body').hasClass('has-detached-left')) {
                    $('.sidebar-detached').insertBefore('.container-detached');
                }

                // Revert right detached position
                else if($('body').hasClass('has-detached-right')) {
                    $('.sidebar-detached').insertAfter('.container-detached');
                }
Manggar Mahardhika's avatar
Manggar Mahardhika committed
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635

                // Remove visibility of heading elements on desktop
                $('.page-header-content, .panel-heading, .panel-footer').removeClass('has-visible-elements');
                $('.heading-elements').removeClass('visible-elements');

                // Disable appearance of dropdown submenus
                $('.dropdown-submenu').children('.dropdown-menu').removeClass('show');
            }
        }, 100);
    }).resize();




    // ========================================
    //
    // Other code
    //
    // ========================================


    // Plugins
    // -------------------------

    // Popover
    $('[data-popup="popover"]').popover();


    // Tooltip
    $('[data-popup="tooltip"]').tooltip();

Muhamad's avatar
Muhamad committed
636
});