app.js 22.4 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.4
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
  //before AdminLTE's app.js
A
-  
Abdullah Almsaeed 已提交
65
  enableFastclick: false,
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
      $.AdminLTE.options,
      AdminLTEOptions);
A
Abdullah Almsaeed 已提交
151 152
  }

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
      //Enable sidebar toggle
317
      $(document).on('click', toggleBtn, function (e) {
318
        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
      //Enable expand on hover for sidebar mini
      if ($.AdminLTE.options.sidebarExpandOnHover
A
-  
Abdullah Almsaeed 已提交
347 348
        || ($('body').hasClass('fixed')
        && $('body').hasClass('sidebar-mini'))) {
349
        this.expandOnHover();
A
Abdullah Almsaeed 已提交
350
      }
351 352 353 354 355 356 357
    },
    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')
A
-  
Abdullah Almsaeed 已提交
358 359
          && $("body").hasClass('sidebar-collapse')
          && $(window).width() > screenWidth) {
360 361 362 363
          _this.expand();
        }
      }, function () {
        if ($('body').hasClass('sidebar-mini')
A
-  
Abdullah Almsaeed 已提交
364 365
          && $('body').hasClass('sidebar-expanded-on-hover')
          && $(window).width() > screenWidth) {
366 367 368 369 370 371 372 373 374 375 376 377
          _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).off('click', menu + ' li a')
A
Abdullah Almsaeed 已提交
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432
      .on('click', menu + ' li a', function (e) {
        //Get the clicked link and the next element
        var $this = $(this);
        var checkElement = $this.next();

        //Check if the next element is a menu and is visible
        if ((checkElement.is('.treeview-menu')) && (checkElement.is(':visible')) && (!$('body').hasClass('sidebar-collapse'))) {
          //Close the menu
          checkElement.slideUp(animationSpeed, function () {
            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
          var ul = parent.find('ul:visible').slideUp(animationSpeed);
          //Remove the menu-open class from the parent
          ul.removeClass('menu-open');
          //Get the parent li
          var parent_li = $this.parent("li");

          //Open the target menu and add the menu-open class
          checkElement.slideDown(animationSpeed, function () {
            //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
Abdullah Almsaeed 已提交
433
  };
A
Abdullah Almsaeed 已提交
434

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

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

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

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

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

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

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

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

A
Abdullah Almsaeed 已提交
613 614
  "use strict";

A
almasaeed2010 已提交
615 616 617 618
  $.fn.boxRefresh = function (options) {

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

    }, options);

    //The overlay
A
Abdullah Almsaeed 已提交
634
    var overlay = $('<div class="overlay"><div class="fa fa-refresh fa-spin"></div></div>');
A
almasaeed2010 已提交
635 636 637 638

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

      //On trigger click
A
Abdullah Almsaeed 已提交
650
      rBtn.on('click', function (e) {
A
almasaeed2010 已提交
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
        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);

A
-  
Abdullah Almsaeed 已提交
680
/*
S
simivar 已提交
681
 * EXPLICIT BOX CONTROLS
P
Pascal Bihler 已提交
682 683
 * -----------------------
 * This is a custom plugin to use with the component BOX. It allows you to activate
S
simivar 已提交
684
 * a box inserted in the DOM after the app.js was loaded, toggle and remove box.
P
Pascal Bihler 已提交
685 686 687
 *
 * @type plugin
 * @usage $("#box-widget").activateBox();
S
simivar 已提交
688 689
 * @usage $("#box-widget").toggleBox();
 * @usage $("#box-widget").removeBox();
P
Pascal Bihler 已提交
690 691 692
 */
(function ($) {

A
Abdullah Almsaeed 已提交
693 694
  'use strict';

P
Pascal Bihler 已提交
695 696 697
  $.fn.activateBox = function () {
    $.AdminLTE.boxWidget.activate(this);
  };
698

A
-  
Abdullah Almsaeed 已提交
699
  $.fn.toggleBox = function () {
S
simivar 已提交
700 701 702
    var button = $($.AdminLTE.boxWidget.selectors.collapse, this);
    $.AdminLTE.boxWidget.collapse(button);
  };
703

A
-  
Abdullah Almsaeed 已提交
704
  $.fn.removeBox = function () {
S
simivar 已提交
705 706 707
    var button = $($.AdminLTE.boxWidget.selectors.remove, this);
    $.AdminLTE.boxWidget.remove(button);
  };
P
Pascal Bihler 已提交
708 709 710

})(jQuery);

A
almasaeed2010 已提交
711 712 713 714 715 716 717 718 719 720
/*
 * 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 已提交
721 722
  'use strict';

A
almasaeed2010 已提交
723 724 725 726 727
  $.fn.todolist = function (options) {
    // Render options
    var settings = $.extend({
      //When the user checks the input
      onCheck: function (ele) {
A
Abdullah Almsaeed 已提交
728
        return ele;
A
almasaeed2010 已提交
729 730 731
      },
      //When the user unchecks the input
      onUncheck: function (ele) {
A
Abdullah Almsaeed 已提交
732
        return ele;
A
almasaeed2010 已提交
733 734 735 736 737 738
      }
    }, options);

    return this.each(function () {

      if (typeof $.fn.iCheck != 'undefined') {
A
Abdullah Almsaeed 已提交
739
        $('input', this).on('ifChecked', function () {
A
almasaeed2010 已提交
740 741 742 743 744
          var ele = $(this).parents("li").first();
          ele.toggleClass("done");
          settings.onCheck.call(ele);
        });

A
Abdullah Almsaeed 已提交
745
        $('input', this).on('ifUnchecked', function () {
A
almasaeed2010 已提交
746 747 748 749 750
          var ele = $(this).parents("li").first();
          ele.toggleClass("done");
          settings.onUncheck.call(ele);
        });
      } else {
A
Abdullah Almsaeed 已提交
751
        $('input', this).on('change', function () {
A
almasaeed2010 已提交
752 753
          var ele = $(this).parents("li").first();
          ele.toggleClass("done");
A
Abdullah Almsaeed 已提交
754 755 756 757 758
          if ($('input', ele).is(":checked")) {
            settings.onCheck.call(ele);
          } else {
            settings.onUncheck.call(ele);
          }
A
almasaeed2010 已提交
759 760 761 762
        });
      }
    });
  };
S
simivar 已提交
763
}(jQuery));