app.js 21.8 KB
Newer Older
A
Abdullah Almsaeed 已提交
1 2
/*! AdminLTE app.js
 * ================
A
almasaeed2010 已提交
3 4 5 6 7 8 9
 * Main JS application file for AdminLTE v2. This file
 * should be included in all pages. It controls some layout
 * options and implements exclusive AdminLTE plugins.
 *
 * @Author  Almsaeed Studio
 * @Support <http://www.almsaeedstudio.com>
 * @Email   <support@almsaeedstudio.com>
A
Abdullah Almsaeed 已提交
10
 * @version 2.3.0
A
almasaeed2010 已提交
11 12 13 14 15 16 17 18 19 20 21 22
 * @license MIT <http://opensource.org/licenses/MIT>
 */

//Make sure jQuery has been loaded before app.js
if (typeof jQuery === "undefined") {
  throw new Error("AdminLTE requires jQuery");
}

/* AdminLTE
 *
 * @type Object
 * @description $.AdminLTE is the main object for the template's app.
A
Abdullah Almsaeed 已提交
23 24 25 26
 *              It's used for implementing functions and options related
 *              to the template. Keeping everything wrapped in an object
 *              prevents conflict with other plugins and is a better
 *              way to organize our code.
A
almasaeed2010 已提交
27
 */
A
Abdullah Almsaeed 已提交
28
$.AdminLTE = {};
A
almasaeed2010 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41

/* --------------------
 * - AdminLTE Options -
 * --------------------
 * Modify these options to suit your implementation
 */
$.AdminLTE.options = {
  //Add slimscroll to navbar menus
  //This requires you to load the slimscroll plugin
  //in every page before app.js
  navbarMenuSlimscroll: true,
  navbarMenuSlimscrollWidth: "3px", //The width of the scroll bar
  navbarMenuHeight: "200px", //The height of the inner menu
D
Dennis Neufeld 已提交
42
  //General animation speed for JS animated elements such as box collapse/expand and
43 44 45
  //sidebar treeview slide up/down. This options accepts an integer as milliseconds,
  //'fast', 'normal', or 'slow'
  animationSpeed: 500,
A
almasaeed2010 已提交
46 47 48 49
  //Sidebar push menu toggle button selector
  sidebarToggleSelector: "[data-toggle='offcanvas']",
  //Activate sidebar push menu
  sidebarPushMenu: true,
A
Abdullah Almsaeed 已提交
50
  //Activate sidebar slimscroll if the fixed layout is set (requires SlimScroll Plugin)
51
  sidebarSlimScroll: true,
52 53 54 55
  //Enable sidebar expand on hover effect for sidebar mini
  //This option is forced to true if both the fixed layout and sidebar mini
  //are used together
  sidebarExpandOnHover: false,
A
almasaeed2010 已提交
56 57 58 59 60
  //BoxRefresh Plugin
  enableBoxRefresh: true,
  //Bootstrap.js tooltip
  enableBSToppltip: true,
  BSTooltipSelector: "[data-toggle='tooltip']",
61
  //Enable Fast Click. Fastclick.js creates a more
A
Abdullah Almsaeed 已提交
62
  //native touch experience with touch devices. If you
A
Abdullah Almsaeed 已提交
63
  //choose to enable the plugin, make sure you load the script
64 65
  //before AdminLTE's app.js
  enableFastclick: true,
A
Abdullah Almsaeed 已提交
66 67 68 69 70 71 72
  //Control Sidebar Options
  enableControlSidebar: true,
  controlSidebarOptions: {
    //Which button should trigger the open/close event
    toggleBtnSelector: "[data-toggle='control-sidebar']",
    //The sidebar selector
    selector: ".control-sidebar",
A
Abdullah Almsaeed 已提交
73 74
    //Enable slide over content
    slide: true
A
Abdullah Almsaeed 已提交
75
  },
A
almasaeed2010 已提交
76 77 78 79 80 81
  //Box Widget Plugin. Enable this plugin
  //to allow boxes to be collapsed and/or removed
  enableBoxWidget: true,
  //Box Widget plugin options
  boxWidgetOptions: {
    boxWidgetIcons: {
A
Abdullah Almsaeed 已提交
82 83 84 85 86 87
      //Collapse icon
      collapse: 'fa-minus',
      //Open icon
      open: 'fa-plus',
      //Remove icon
      remove: 'fa-times'
A
almasaeed2010 已提交
88 89 90 91 92 93 94 95
    },
    boxWidgetSelectors: {
      //Remove button selector
      remove: '[data-widget="remove"]',
      //Collapse button selector
      collapse: '[data-widget="collapse"]'
    }
  },
96 97 98 99 100 101 102
  //Direct Chat plugin options
  directChat: {
    //Enable direct chat by default
    enable: true,
    //The button to open and close the chat contacts pane
    contactToggleSelector: '[data-widget="chat-pane-toggle"]'
  },
A
almasaeed2010 已提交
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
  //Define the set of colors to use globally around the website
  colors: {
    lightBlue: "#3c8dbc",
    red: "#f56954",
    green: "#00a65a",
    aqua: "#00c0ef",
    yellow: "#f39c12",
    blue: "#0073b7",
    navy: "#001F3F",
    teal: "#39CCCC",
    olive: "#3D9970",
    lime: "#01FF70",
    orange: "#FF851B",
    fuchsia: "#F012BE",
    purple: "#8E24AA",
    maroon: "#D81B60",
    black: "#222222",
A
Abdullah Almsaeed 已提交
120
    gray: "#d2d6de"
A
Abdullah Almsaeed 已提交
121 122 123 124 125 126 127 128 129
  },
  //The standard screen sizes that bootstrap uses.
  //If you change these in the variables.less file, change
  //them here too.
  screenSizes: {
    xs: 480,
    sm: 768,
    md: 992,
    lg: 1200
A
almasaeed2010 已提交
130 131 132 133 134 135 136 137 138 139 140
  }
};

/* ------------------
 * - Implementation -
 * ------------------
 * The next block of code implements AdminLTE's
 * functions and plugins as specified by the
 * options above.
 */
$(function () {
A
Abdullah Almsaeed 已提交
141 142
  "use strict";

A
Abdullah Almsaeed 已提交
143 144 145
  //Fix for IE page transitions
  $("body").removeClass("hold-transition");

A
Abdullah Almsaeed 已提交
146 147
  //Extend options if external options exist
  if (typeof AdminLTEOptions !== "undefined") {
148
    $.extend(true,
A
Abdullah Almsaeed 已提交
149 150 151 152
            $.AdminLTE.options,
            AdminLTEOptions);
  }

A
almasaeed2010 已提交
153 154 155
  //Easy access to options
  var o = $.AdminLTE.options;

A
Abdullah Almsaeed 已提交
156 157 158
  //Set up the object
  _init();

A
almasaeed2010 已提交
159 160 161
  //Activate the layout maker
  $.AdminLTE.layout.activate();

A
Abdullah Almsaeed 已提交
162 163 164
  //Enable sidebar tree view controls
  $.AdminLTE.tree('.sidebar');

A
Abdullah Almsaeed 已提交
165 166
  //Enable control sidebar
  if (o.enableControlSidebar) {
A
Abdullah Almsaeed 已提交
167
    $.AdminLTE.controlSidebar.activate();
A
Abdullah Almsaeed 已提交
168 169
  }

A
almasaeed2010 已提交
170 171 172
  //Add slimscroll to navbar dropdown
  if (o.navbarMenuSlimscroll && typeof $.fn.slimscroll != 'undefined') {
    $(".navbar .menu").slimscroll({
A
Abdullah Almsaeed 已提交
173
      height: o.navbarMenuHeight,
A
almasaeed2010 已提交
174
      alwaysVisible: false,
A
Abdullah Almsaeed 已提交
175
      size: o.navbarMenuSlimscrollWidth
A
almasaeed2010 已提交
176 177 178 179 180
    }).css("width", "100%");
  }

  //Activate sidebar push menu
  if (o.sidebarPushMenu) {
181
    $.AdminLTE.pushMenu.activate(o.sidebarToggleSelector);
A
almasaeed2010 已提交
182 183 184 185
  }

  //Activate Bootstrap tooltip
  if (o.enableBSToppltip) {
186 187 188
    $('body').tooltip({
      selector: o.BSTooltipSelector
    });
A
almasaeed2010 已提交
189 190 191 192 193 194
  }

  //Activate box widget
  if (o.enableBoxWidget) {
    $.AdminLTE.boxWidget.activate();
  }
195 196 197

  //Activate fast click
  if (o.enableFastclick && typeof FastClick != 'undefined') {
198 199
    FastClick.attach(document.body);
  }
A
almasaeed2010 已提交
200

201 202
  //Activate direct chat widget
  if (o.directChat.enable) {
203
    $(document).on('click', o.directChat.contactToggleSelector, function () {
204 205 206 207 208
      var box = $(this).parents('.direct-chat').first();
      box.toggleClass('direct-chat-contacts-open');
    });
  }

A
almasaeed2010 已提交
209 210 211 212 213 214
  /*
   * INITIALIZE BUTTON TOGGLE
   * ------------------------
   */
  $('.btn-group[data-toggle="btn-toggle"]').each(function () {
    var group = $(this);
A
Abdullah Almsaeed 已提交
215
    $(this).find(".btn").on('click', function (e) {
A
almasaeed2010 已提交
216 217 218 219 220 221 222 223
      group.find(".btn.active").removeClass("active");
      $(this).addClass("active");
      e.preventDefault();
    });

  });
});

A
Abdullah Almsaeed 已提交
224 225 226
/* ----------------------------------
 * - Initialize the AdminLTE Object -
 * ----------------------------------
A
almasaeed2010 已提交
227 228
 * All AdminLTE functions are implemented below.
 */
A
Abdullah Almsaeed 已提交
229
function _init() {
A
Abdullah Almsaeed 已提交
230
  'use strict';
A
Abdullah Almsaeed 已提交
231 232 233 234 235 236 237 238 239 240 241 242
  /* Layout
   * ======
   * Fixes the layout height in case min-height fails.
   *
   * @type Object
   * @usage $.AdminLTE.layout.activate()
   *        $.AdminLTE.layout.fix()
   *        $.AdminLTE.layout.fixSidebar()
   */
  $.AdminLTE.layout = {
    activate: function () {
      var _this = this;
A
almasaeed2010 已提交
243 244
      _this.fix();
      _this.fixSidebar();
A
Abdullah Almsaeed 已提交
245 246 247 248 249 250 251 252 253 254 255 256 257 258
      $(window, ".wrapper").resize(function () {
        _this.fix();
        _this.fixSidebar();
      });
    },
    fix: function () {
      //Get window height and the wrapper height
      var neg = $('.main-header').outerHeight() + $('.main-footer').outerHeight();
      var window_height = $(window).height();
      var sidebar_height = $(".sidebar").height();
      //Set the min-height of the content and sidebar based on the
      //the height of the document.
      if ($("body").hasClass("fixed")) {
        $(".content-wrapper, .right-side").css('min-height', window_height - $('.main-footer').outerHeight());
A
Abdullah Almsaeed 已提交
259
      } else {
A
Abdullah Almsaeed 已提交
260
        var postSetWidth;
A
Abdullah Almsaeed 已提交
261 262
        if (window_height >= sidebar_height) {
          $(".content-wrapper, .right-side").css('min-height', window_height - neg);
A
Abdullah Almsaeed 已提交
263
          postSetWidth = window_height - neg;
A
Abdullah Almsaeed 已提交
264 265
        } else {
          $(".content-wrapper, .right-side").css('min-height', sidebar_height);
A
Abdullah Almsaeed 已提交
266
          postSetWidth = sidebar_height;
A
Abdullah Almsaeed 已提交
267
        }
268

A
Abdullah Almsaeed 已提交
269 270
        //Fix for the control sidebar height
        var controlSidebar = $($.AdminLTE.options.controlSidebarOptions.selector);
271 272
        if (typeof controlSidebar !== "undefined") {
          if (controlSidebar.height() > postSetWidth)
A
Abdullah Almsaeed 已提交
273 274
            $(".content-wrapper, .right-side").css('min-height', controlSidebar.height());
        }
275

A
Abdullah Almsaeed 已提交
276
      }
A
Abdullah Almsaeed 已提交
277 278 279 280 281 282 283 284
    },
    fixSidebar: function () {
      //Make sure the body tag has the .fixed class
      if (!$("body").hasClass("fixed")) {
        if (typeof $.fn.slimScroll != 'undefined') {
          $(".sidebar").slimScroll({destroy: true}).height("auto");
        }
        return;
A
Abdullah Almsaeed 已提交
285 286
      } else if (typeof $.fn.slimScroll == 'undefined' && window.console) {
        window.console.error("Error: the fixed layout requires the slimscroll plugin!");
A
almasaeed2010 已提交
287
      }
A
Abdullah Almsaeed 已提交
288 289 290
      //Enable slimscroll for fixed layout
      if ($.AdminLTE.options.sidebarSlimScroll) {
        if (typeof $.fn.slimScroll != 'undefined') {
D
Dmitri Suvorov 已提交
291
          //Destroy if it exists
A
Abdullah Almsaeed 已提交
292 293 294 295 296 297 298 299
          $(".sidebar").slimScroll({destroy: true}).height("auto");
          //Add slimscroll
          $(".sidebar").slimscroll({
            height: ($(window).height() - $(".main-header").height()) + "px",
            color: "rgba(0,0,0,0.2)",
            size: "3px"
          });
        }
A
almasaeed2010 已提交
300 301
      }
    }
A
Abdullah Almsaeed 已提交
302
  };
A
almasaeed2010 已提交
303

A
Abdullah Almsaeed 已提交
304 305 306 307 308 309 310
  /* PushMenu()
   * ==========
   * Adds the push menu functionality to the sidebar.
   *
   * @type Function
   * @usage: $.AdminLTE.pushMenu("[data-toggle='offcanvas']")
   */
311 312 313 314
  $.AdminLTE.pushMenu = {
    activate: function (toggleBtn) {
      //Get the screen sizes
      var screenSizes = $.AdminLTE.options.screenSizes;
A
Abdullah Almsaeed 已提交
315

316 317 318
      //Enable sidebar toggle
      $(toggleBtn).on('click', function (e) {
        e.preventDefault();
A
Abdullah Almsaeed 已提交
319

320 321
        //Enable sidebar push menu
        if ($(window).width() > (screenSizes.sm - 1)) {
322
          if ($("body").hasClass('sidebar-collapse')) {
323
            $("body").removeClass('sidebar-collapse').trigger('expanded.pushMenu');
324
          } else {
325
            $("body").addClass('sidebar-collapse').trigger('collapsed.pushMenu');
326
          }
327 328 329 330
        }
        //Handle sidebar push menu for small screens
        else {
          if ($("body").hasClass('sidebar-open')) {
331
            $("body").removeClass('sidebar-open').removeClass('sidebar-collapse').trigger('collapsed.pushMenu');
332
          } else {
333
            $("body").addClass('sidebar-open').trigger('expanded.pushMenu');
334 335 336 337 338 339 340
          }
        }
      });

      $(".content-wrapper").click(function () {
        //Enable hide menu when clicking on the content-wrapper on small screens
        if ($(window).width() <= (screenSizes.sm - 1) && $("body").hasClass("sidebar-open")) {
A
Abdullah Almsaeed 已提交
341 342
          $("body").removeClass('sidebar-open');
        }
343
      });
A
Abdullah Almsaeed 已提交
344

345 346 347 348 349
      //Enable expand on hover for sidebar mini
      if ($.AdminLTE.options.sidebarExpandOnHover
              || ($('body').hasClass('fixed')
                      && $('body').hasClass('sidebar-mini'))) {
        this.expandOnHover();
A
Abdullah Almsaeed 已提交
350
      }
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
    },
    expandOnHover: function () {
      var _this = this;
      var screenWidth = $.AdminLTE.options.screenSizes.sm - 1;
      //Expand sidebar on hover
      $('.main-sidebar').hover(function () {
        if ($('body').hasClass('sidebar-mini')
                && $("body").hasClass('sidebar-collapse')
                && $(window).width() > screenWidth) {
          _this.expand();
        }
      }, function () {
        if ($('body').hasClass('sidebar-mini')
                && $('body').hasClass('sidebar-expanded-on-hover')
                && $(window).width() > screenWidth) {
          _this.collapse();
        }
      });
    },
    expand: function () {
      $("body").removeClass('sidebar-collapse').addClass('sidebar-expanded-on-hover');
    },
    collapse: function () {
      if ($('body').hasClass('sidebar-expanded-on-hover')) {
        $('body').removeClass('sidebar-expanded-on-hover').addClass('sidebar-collapse');
      }
    }
A
Abdullah Almsaeed 已提交
378
  };
A
Abdullah Almsaeed 已提交
379

A
Abdullah Almsaeed 已提交
380 381 382 383 384 385 386 387 388 389
  /* Tree()
   * ======
   * Converts the sidebar into a multilevel
   * tree view menu.
   *
   * @type Function
   * @Usage: $.AdminLTE.tree('.sidebar')
   */
  $.AdminLTE.tree = function (menu) {
    var _this = this;
390
    var animationSpeed = $.AdminLTE.options.animationSpeed;
391
    $(document).on('click', menu + ' li a', function (e) {
A
Abdullah Almsaeed 已提交
392 393 394
      //Get the clicked link and the next element
      var $this = $(this);
      var checkElement = $this.next();
A
almasaeed2010 已提交
395

A
Abdullah Almsaeed 已提交
396 397 398
      //Check if the next element is a menu and is visible
      if ((checkElement.is('.treeview-menu')) && (checkElement.is(':visible'))) {
        //Close the menu
399
        checkElement.slideUp(animationSpeed, function () {
A
Abdullah Almsaeed 已提交
400 401 402 403 404 405 406 407 408 409 410
          checkElement.removeClass('menu-open');
          //Fix the layout in case the sidebar stretches over the height of the window
          //_this.layout.fix();
        });
        checkElement.parent("li").removeClass("active");
      }
      //If the menu is not visible
      else if ((checkElement.is('.treeview-menu')) && (!checkElement.is(':visible'))) {
        //Get the parent menu
        var parent = $this.parents('ul').first();
        //Close all open menus within the parent
411
        var ul = parent.find('ul:visible').slideUp(animationSpeed);
A
Abdullah Almsaeed 已提交
412 413 414 415
        //Remove the menu-open class from the parent
        ul.removeClass('menu-open');
        //Get the parent li
        var parent_li = $this.parent("li");
A
almasaeed2010 已提交
416

A
Abdullah Almsaeed 已提交
417
        //Open the target menu and add the menu-open class
418
        checkElement.slideDown(animationSpeed, function () {
A
Abdullah Almsaeed 已提交
419 420 421 422 423 424 425 426 427 428 429 430
          //Add the class active to the parent li
          checkElement.addClass('menu-open');
          parent.find('li.active').removeClass('active');
          parent_li.addClass('active');
          //Fix the layout in case the sidebar stretches over the height of the window
          _this.layout.fix();
        });
      }
      //if this isn't a link, prevent the page from being redirected
      if (checkElement.is('.treeview-menu')) {
        e.preventDefault();
      }
A
almasaeed2010 已提交
431
    });
A
Abdullah Almsaeed 已提交
432
  };
A
Abdullah Almsaeed 已提交
433

434 435
  /* ControlSidebar
   * ==============
A
Abdullah Almsaeed 已提交
436 437
   * Adds functionality to the right sidebar
   *
438
   * @type Object
A
Abdullah Almsaeed 已提交
439
   * @usage $.AdminLTE.controlSidebar.activate(options)
440 441
   */
  $.AdminLTE.controlSidebar = {
A
Abdullah Almsaeed 已提交
442
    //instantiate the object
A
Abdullah Almsaeed 已提交
443
    activate: function () {
A
Abdullah Almsaeed 已提交
444 445 446
      //Get the object
      var _this = this;
      //Update options
A
Abdullah Almsaeed 已提交
447
      var o = $.AdminLTE.options.controlSidebarOptions;
A
Abdullah Almsaeed 已提交
448 449 450 451
      //Get the sidebar
      var sidebar = $(o.selector);
      //The toggle button
      var btn = $(o.toggleBtnSelector);
A
Abdullah Almsaeed 已提交
452

A
Abdullah Almsaeed 已提交
453
      //Listen to the click event
A
Abdullah Almsaeed 已提交
454
      btn.on('click', function (e) {
A
Abdullah Almsaeed 已提交
455
        e.preventDefault();
A
Abdullah Almsaeed 已提交
456
        //If the sidebar is not open
A
Abdullah Almsaeed 已提交
457 458
        if (!sidebar.hasClass('control-sidebar-open')
                && !$('body').hasClass('control-sidebar-open')) {
A
Abdullah Almsaeed 已提交
459
          //Open the sidebar
A
Abdullah Almsaeed 已提交
460
          _this.open(sidebar, o.slide);
A
Abdullah Almsaeed 已提交
461
        } else {
A
Abdullah Almsaeed 已提交
462
          _this.close(sidebar, o.slide);
A
Abdullah Almsaeed 已提交
463 464
        }
      });
A
Abdullah Almsaeed 已提交
465 466

      //If the body has a boxed layout, fix the sidebar bg position
A
Abdullah Almsaeed 已提交
467 468
      var bg = $(".control-sidebar-bg");
      _this._fix(bg);
469

D
Dennis Neufeld 已提交
470
      //If the body has a fixed layout, make the control sidebar fixed
471 472 473
      if ($('body').hasClass('fixed')) {
        _this._fixForFixed(sidebar);
      } else {
D
Dmitri Suvorov 已提交
474
        //If the content height is less than the sidebar's height, force max height
475 476 477 478
        if ($('.content-wrapper, .right-side').height() < sidebar.height()) {
          _this._fixForContent(sidebar);
        }
      }
479
    },
A
Abdullah Almsaeed 已提交
480
    //Open the control sidebar
A
Abdullah Almsaeed 已提交
481
    open: function (sidebar, slide) {
A
Abdullah Almsaeed 已提交
482
      //Slide over content
483
      if (slide) {
A
Abdullah Almsaeed 已提交
484
        sidebar.addClass('control-sidebar-open');
485
      } else {
D
Dennis Neufeld 已提交
486
        //Push the content by adding the open class to the body instead
487
        //of the sidebar itself
A
Abdullah Almsaeed 已提交
488
        $('body').addClass('control-sidebar-open');
489
      }
490
    },
A
Abdullah Almsaeed 已提交
491
    //Close the control sidebar
A
Abdullah Almsaeed 已提交
492
    close: function (sidebar, slide) {
493
      if (slide) {
494
        sidebar.removeClass('control-sidebar-open');
495
      } else {
496
        $('body').removeClass('control-sidebar-open');
497
      }
A
Abdullah Almsaeed 已提交
498 499 500
    },
    _fix: function (sidebar) {
      var _this = this;
A
Abdullah Almsaeed 已提交
501 502 503 504 505 506 507
      if ($("body").hasClass('layout-boxed')) {
        sidebar.css('position', 'absolute');
        sidebar.height($(".wrapper").height());
        $(window).resize(function () {
          _this._fix(sidebar);
        });
      } else {
508 509 510 511
        sidebar.css({
          'position': 'fixed',
          'height': 'auto'
        });
A
Abdullah Almsaeed 已提交
512
      }
513 514 515 516 517 518 519 520 521 522 523
    },
    _fixForFixed: function (sidebar) {
      sidebar.css({
        'position': 'fixed',
        'max-height': '100%',
        'overflow': 'auto',
        'padding-bottom': '50px'
      });
    },
    _fixForContent: function (sidebar) {
      $(".content-wrapper, .right-side").css('min-height', sidebar.height());
A
Abdullah Almsaeed 已提交
524
    }
525
  };
A
almasaeed2010 已提交
526

A
Abdullah Almsaeed 已提交
527 528
  /* BoxWidget
   * =========
D
Dmitri Suvorov 已提交
529
   * BoxWidget is a plugin to handle collapsing and
A
Abdullah Almsaeed 已提交
530 531 532 533
   * removing boxes from the screen.
   *
   * @type Object
   * @usage $.AdminLTE.boxWidget.activate()
D
Dmitri Suvorov 已提交
534
   *        Set all your options in the main $.AdminLTE.options object
A
Abdullah Almsaeed 已提交
535 536
   */
  $.AdminLTE.boxWidget = {
A
Abdullah Almsaeed 已提交
537 538
    selectors: $.AdminLTE.options.boxWidgetOptions.boxWidgetSelectors,
    icons: $.AdminLTE.options.boxWidgetOptions.boxWidgetIcons,
539
    animationSpeed: $.AdminLTE.options.animationSpeed,
P
Pascal Bihler 已提交
540
    activate: function (_box) {
A
Abdullah Almsaeed 已提交
541
      var _this = this;
542
      if (!_box) {
P
Pascal Bihler 已提交
543 544
        _box = document; // activate all boxes per default
      }
A
Abdullah Almsaeed 已提交
545
      //Listen for collapse event triggers
546
      $(_box).on('click', _this.selectors.collapse, function (e) {
A
Abdullah Almsaeed 已提交
547 548
        e.preventDefault();
        _this.collapse($(this));
A
almasaeed2010 已提交
549
      });
A
Abdullah Almsaeed 已提交
550 551

      //Listen for remove event triggers
552
      $(_box).on('click', _this.selectors.remove, function (e) {
A
Abdullah Almsaeed 已提交
553 554
        e.preventDefault();
        _this.remove($(this));
A
almasaeed2010 已提交
555
      });
A
Abdullah Almsaeed 已提交
556 557
    },
    collapse: function (element) {
A
Abdullah Almsaeed 已提交
558
      var _this = this;
A
Abdullah Almsaeed 已提交
559 560 561
      //Find the box parent
      var box = element.parents(".box").first();
      //Find the body and the footer
562
      var box_content = box.find("> .box-body, > .box-footer, > form  >.box-body, > form > .box-footer");
A
Abdullah Almsaeed 已提交
563
      if (!box.hasClass("collapsed-box")) {
A
Abdullah Almsaeed 已提交
564
        //Convert minus into plus
A
Abdullah Almsaeed 已提交
565 566 567 568
        element.children(":first")
                .removeClass(_this.icons.collapse)
                .addClass(_this.icons.open);
        //Hide the content
569
        box_content.slideUp(_this.animationSpeed, function () {
A
Abdullah Almsaeed 已提交
570 571 572 573
          box.addClass("collapsed-box");
        });
      } else {
        //Convert plus into minus
A
Abdullah Almsaeed 已提交
574 575 576 577
        element.children(":first")
                .removeClass(_this.icons.open)
                .addClass(_this.icons.collapse);
        //Show the content
578
        box_content.slideDown(_this.animationSpeed, function () {
A
Abdullah Almsaeed 已提交
579 580 581 582
          box.removeClass("collapsed-box");
        });
      }
    },
583
    remove: function (element) {
A
Abdullah Almsaeed 已提交
584 585
      //Find the box parent
      var box = element.parents(".box").first();
586
      box.slideUp(this.animationSpeed);
A
Abdullah Almsaeed 已提交
587
    }
A
Abdullah Almsaeed 已提交
588 589
  };
}
A
almasaeed2010 已提交
590 591 592 593 594 595 596 597 598 599

/* ------------------
 * - Custom Plugins -
 * ------------------
 * All custom plugins are defined below.
 */

/*
 * BOX REFRESH BUTTON
 * ------------------
D
Dmitri Suvorov 已提交
600
 * This is a custom plugin to use with the component BOX. It allows you to add
A
almasaeed2010 已提交
601 602
 * a refresh button to the box. It converts the box's state to a loading state.
 *
A
Abdullah Almsaeed 已提交
603
 * @type plugin
A
almasaeed2010 已提交
604 605 606 607
 * @usage $("#box-widget").boxRefresh( options );
 */
(function ($) {

A
Abdullah Almsaeed 已提交
608 609
  "use strict";

A
almasaeed2010 已提交
610 611 612 613
  $.fn.boxRefresh = function (options) {

    // Render options
    var settings = $.extend({
D
Dmitri Suvorov 已提交
614
      //Refresh button selector
A
almasaeed2010 已提交
615 616 617 618 619
      trigger: ".refresh-btn",
      //File source to be loaded (e.g: ajax/src.php)
      source: "",
      //Callbacks
      onLoadStart: function (box) {
A
Abdullah Almsaeed 已提交
620
        return box;
A
almasaeed2010 已提交
621 622
      }, //Right after the button has been clicked
      onLoadDone: function (box) {
A
Abdullah Almsaeed 已提交
623
        return box;
A
almasaeed2010 已提交
624 625 626 627 628
      } //When the source has been loaded

    }, options);

    //The overlay
A
Abdullah Almsaeed 已提交
629
    var overlay = $('<div class="overlay"><div class="fa fa-refresh fa-spin"></div></div>');
A
almasaeed2010 已提交
630 631 632 633

    return this.each(function () {
      //if a source is specified
      if (settings.source === "") {
A
Abdullah Almsaeed 已提交
634 635
        if (window.console) {
          window.console.log("Please specify a source first - boxRefresh()");
A
almasaeed2010 已提交
636 637 638 639 640 641 642 643 644
        }
        return;
      }
      //the box
      var box = $(this);
      //the button
      var rBtn = box.find(settings.trigger).first();

      //On trigger click
A
Abdullah Almsaeed 已提交
645
      rBtn.on('click', function (e) {
A
almasaeed2010 已提交
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674
        e.preventDefault();
        //Add loading overlay
        start(box);

        //Perform ajax call
        box.find(".box-body").load(settings.source, function () {
          done(box);
        });
      });
    });

    function start(box) {
      //Add overlay and loading img
      box.append(overlay);

      settings.onLoadStart.call(box);
    }

    function done(box) {
      //Remove overlay and loading img
      box.find(overlay).remove();

      settings.onLoadDone.call(box);
    }

  };

})(jQuery);

P
Pascal Bihler 已提交
675 676 677 678 679 680 681 682 683 684 685
/*
 * EXPLICIT BOX ACTIVATION
 * -----------------------
 * This is a custom plugin to use with the component BOX. It allows you to activate
 * a box inserted in the DOM after the app.js was loaded.
 *
 * @type plugin
 * @usage $("#box-widget").activateBox();
 */
(function ($) {

A
Abdullah Almsaeed 已提交
686 687
  'use strict';

P
Pascal Bihler 已提交
688 689 690 691 692 693
  $.fn.activateBox = function () {
    $.AdminLTE.boxWidget.activate(this);
  };

})(jQuery);

A
almasaeed2010 已提交
694 695 696 697 698 699 700 701 702 703
/*
 * TODO LIST CUSTOM PLUGIN
 * -----------------------
 * This plugin depends on iCheck plugin for checkbox and radio inputs
 *
 * @type plugin
 * @usage $("#todo-widget").todolist( options );
 */
(function ($) {

A
Abdullah Almsaeed 已提交
704 705
  'use strict';

A
almasaeed2010 已提交
706 707 708 709 710
  $.fn.todolist = function (options) {
    // Render options
    var settings = $.extend({
      //When the user checks the input
      onCheck: function (ele) {
A
Abdullah Almsaeed 已提交
711
        return ele;
A
almasaeed2010 已提交
712 713 714
      },
      //When the user unchecks the input
      onUncheck: function (ele) {
A
Abdullah Almsaeed 已提交
715
        return ele;
A
almasaeed2010 已提交
716 717 718 719 720 721
      }
    }, options);

    return this.each(function () {

      if (typeof $.fn.iCheck != 'undefined') {
A
Abdullah Almsaeed 已提交
722
        $('input', this).on('ifChecked', function () {
A
almasaeed2010 已提交
723 724 725 726 727
          var ele = $(this).parents("li").first();
          ele.toggleClass("done");
          settings.onCheck.call(ele);
        });

A
Abdullah Almsaeed 已提交
728
        $('input', this).on('ifUnchecked', function () {
A
almasaeed2010 已提交
729 730 731 732 733
          var ele = $(this).parents("li").first();
          ele.toggleClass("done");
          settings.onUncheck.call(ele);
        });
      } else {
A
Abdullah Almsaeed 已提交
734
        $('input', this).on('change', function () {
A
almasaeed2010 已提交
735 736
          var ele = $(this).parents("li").first();
          ele.toggleClass("done");
A
Abdullah Almsaeed 已提交
737 738 739 740 741
          if ($('input', ele).is(":checked")) {
            settings.onCheck.call(ele);
          } else {
            settings.onUncheck.call(ele);
          }
A
almasaeed2010 已提交
742 743 744 745
        });
      }
    });
  };
A
Abdullah Almsaeed 已提交
746
}(jQuery));