app.js 20.5 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>
10
 * @version 2.1.0
A
almasaeed2010 已提交
11 12 13
 * @license MIT <http://opensource.org/licenses/MIT>
 */

14 15
'use strict';

A
almasaeed2010 已提交
16 17 18 19 20 21 22 23 24
//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 已提交
25 26 27 28
 *              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 已提交
29
 */
A
Abdullah Almsaeed 已提交
30
$.AdminLTE = {};
A
almasaeed2010 已提交
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

/* --------------------
 * - 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
  //Sidebar push menu toggle button selector
  sidebarToggleSelector: "[data-toggle='offcanvas']",
  //Activate sidebar push menu
  sidebarPushMenu: true,
A
Abdullah Almsaeed 已提交
48
  //Activate sidebar slimscroll if the fixed layout is set (requires SlimScroll Plugin)
49
  sidebarSlimScroll: true,
50 51 52 53
  //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 已提交
54 55 56 57 58
  //BoxRefresh Plugin
  enableBoxRefresh: true,
  //Bootstrap.js tooltip
  enableBSToppltip: true,
  BSTooltipSelector: "[data-toggle='tooltip']",
59
  //Enable Fast Click. Fastclick.js creates a more
A
Abdullah Almsaeed 已提交
60
  //native touch experience with touch devices. If you
A
Abdullah Almsaeed 已提交
61
  //choose to enable the plugin, make sure you load the script
62 63
  //before AdminLTE's app.js
  enableFastclick: true,
A
Abdullah Almsaeed 已提交
64 65 66 67 68 69 70
  //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 已提交
71 72
    //Enable slide over content
    slide: true
A
Abdullah Almsaeed 已提交
73
  },
A
almasaeed2010 已提交
74 75 76 77 78 79
  //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 已提交
80 81 82 83 84 85
      //Collapse icon
      collapse: 'fa-minus',
      //Open icon
      open: 'fa-plus',
      //Remove icon
      remove: 'fa-times'
A
almasaeed2010 已提交
86 87 88 89 90 91 92 93
    },
    boxWidgetSelectors: {
      //Remove button selector
      remove: '[data-widget="remove"]',
      //Collapse button selector
      collapse: '[data-widget="collapse"]'
    }
  },
94 95 96 97 98 99 100
  //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 已提交
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
  //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 已提交
118
    gray: "#d2d6de"
A
Abdullah Almsaeed 已提交
119 120 121 122 123 124 125 126 127
  },
  //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 已提交
128 129 130 131 132 133 134 135 136 137 138
  }
};

/* ------------------
 * - Implementation -
 * ------------------
 * The next block of code implements AdminLTE's
 * functions and plugins as specified by the
 * options above.
 */
$(function () {
A
Abdullah Almsaeed 已提交
139 140 141 142 143 144 145
  //Extend options if external options exist
  if (typeof AdminLTEOptions !== "undefined") {
    $.AdminLTE.options = $.extend({},
            $.AdminLTE.options,
            AdminLTEOptions);
  }

A
almasaeed2010 已提交
146 147 148
  //Easy access to options
  var o = $.AdminLTE.options;

A
Abdullah Almsaeed 已提交
149 150 151
  //Set up the object
  _init();

A
almasaeed2010 已提交
152 153 154
  //Activate the layout maker
  $.AdminLTE.layout.activate();

A
Abdullah Almsaeed 已提交
155 156 157
  //Enable sidebar tree view controls
  $.AdminLTE.tree('.sidebar');

A
Abdullah Almsaeed 已提交
158 159
  //Enable control sidebar
  if (o.enableControlSidebar) {
A
Abdullah Almsaeed 已提交
160
    $.AdminLTE.controlSidebar.activate();
A
Abdullah Almsaeed 已提交
161 162
  }

A
almasaeed2010 已提交
163 164 165
  //Add slimscroll to navbar dropdown
  if (o.navbarMenuSlimscroll && typeof $.fn.slimscroll != 'undefined') {
    $(".navbar .menu").slimscroll({
A
Abdullah Almsaeed 已提交
166
      height: o.navbarMenuHeight,
A
almasaeed2010 已提交
167
      alwaysVisible: false,
A
Abdullah Almsaeed 已提交
168
      size: o.navbarMenuSlimscrollWidth
A
almasaeed2010 已提交
169 170 171 172 173
    }).css("width", "100%");
  }

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

  //Activate Bootstrap tooltip
  if (o.enableBSToppltip) {
    $(o.BSTooltipSelector).tooltip();
  }

  //Activate box widget
  if (o.enableBoxWidget) {
    $.AdminLTE.boxWidget.activate();
  }
186 187 188

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

192 193
  //Activate direct chat widget
  if (o.directChat.enable) {
A
Abdullah Almsaeed 已提交
194
    $(o.directChat.contactToggleSelector).on('click', function () {
195 196 197 198 199
      var box = $(this).parents('.direct-chat').first();
      box.toggleClass('direct-chat-contacts-open');
    });
  }

A
almasaeed2010 已提交
200 201 202 203 204 205
  /*
   * INITIALIZE BUTTON TOGGLE
   * ------------------------
   */
  $('.btn-group[data-toggle="btn-toggle"]').each(function () {
    var group = $(this);
A
Abdullah Almsaeed 已提交
206
    $(this).find(".btn").on('click', function (e) {
A
almasaeed2010 已提交
207 208 209 210 211 212 213 214
      group.find(".btn.active").removeClass("active");
      $(this).addClass("active");
      e.preventDefault();
    });

  });
});

A
Abdullah Almsaeed 已提交
215 216 217
/* ----------------------------------
 * - Initialize the AdminLTE Object -
 * ----------------------------------
A
almasaeed2010 已提交
218 219
 * All AdminLTE functions are implemented below.
 */
A
Abdullah Almsaeed 已提交
220
function _init() {
A
almasaeed2010 已提交
221

A
Abdullah Almsaeed 已提交
222 223 224 225 226 227 228 229 230 231 232 233
  /* 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 已提交
234 235
      _this.fix();
      _this.fixSidebar();
A
Abdullah Almsaeed 已提交
236 237 238 239 240 241 242 243 244 245 246 247 248 249
      $(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 已提交
250
      } else {
A
Abdullah Almsaeed 已提交
251
        var postSetWidth;
A
Abdullah Almsaeed 已提交
252 253
        if (window_height >= sidebar_height) {
          $(".content-wrapper, .right-side").css('min-height', window_height - neg);
A
Abdullah Almsaeed 已提交
254
          postSetWidth = window_height - neg;
A
Abdullah Almsaeed 已提交
255 256
        } else {
          $(".content-wrapper, .right-side").css('min-height', sidebar_height);
A
Abdullah Almsaeed 已提交
257
          postSetWidth = sidebar_height;
A
Abdullah Almsaeed 已提交
258
        }
259

A
Abdullah Almsaeed 已提交
260 261
        //Fix for the control sidebar height
        var controlSidebar = $($.AdminLTE.options.controlSidebarOptions.selector);
262 263
        if (typeof controlSidebar !== "undefined") {
          if (controlSidebar.height() > postSetWidth)
A
Abdullah Almsaeed 已提交
264 265
            $(".content-wrapper, .right-side").css('min-height', controlSidebar.height());
        }
266

A
Abdullah Almsaeed 已提交
267
      }
A
Abdullah Almsaeed 已提交
268 269 270 271 272 273 274 275 276 277
    },
    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;
      } else if (typeof $.fn.slimScroll == 'undefined' && console) {
        console.error("Error: the fixed layout requires the slimscroll plugin!");
A
almasaeed2010 已提交
278
      }
A
Abdullah Almsaeed 已提交
279 280 281 282 283 284 285 286 287 288 289 290
      //Enable slimscroll for fixed layout
      if ($.AdminLTE.options.sidebarSlimScroll) {
        if (typeof $.fn.slimScroll != 'undefined') {
          //Distroy if it exists
          $(".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 已提交
291 292
      }
    }
A
Abdullah Almsaeed 已提交
293
  };
A
almasaeed2010 已提交
294

A
Abdullah Almsaeed 已提交
295 296 297 298 299 300 301
  /* PushMenu()
   * ==========
   * Adds the push menu functionality to the sidebar.
   *
   * @type Function
   * @usage: $.AdminLTE.pushMenu("[data-toggle='offcanvas']")
   */
302 303 304 305
  $.AdminLTE.pushMenu = {
    activate: function (toggleBtn) {
      //Get the screen sizes
      var screenSizes = $.AdminLTE.options.screenSizes;
A
Abdullah Almsaeed 已提交
306

307 308 309
      //Enable sidebar toggle
      $(toggleBtn).on('click', function (e) {
        e.preventDefault();
A
Abdullah Almsaeed 已提交
310

311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
        //Enable sidebar push menu
        if ($(window).width() > (screenSizes.sm - 1)) {
          $("body").toggleClass('sidebar-collapse');
        }
        //Handle sidebar push menu for small screens
        else {
          if ($("body").hasClass('sidebar-open')) {
            $("body").removeClass('sidebar-open');
            $("body").removeClass('sidebar-collapse')
          } else {
            $("body").addClass('sidebar-open');
          }
        }
      });

      $(".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 已提交
329 330
          $("body").removeClass('sidebar-open');
        }
331
      });
A
Abdullah Almsaeed 已提交
332

333 334 335 336 337
      //Enable expand on hover for sidebar mini
      if ($.AdminLTE.options.sidebarExpandOnHover
              || ($('body').hasClass('fixed')
                      && $('body').hasClass('sidebar-mini'))) {
        this.expandOnHover();
A
Abdullah Almsaeed 已提交
338
      }
A
almasaeed2010 已提交
339

340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
    },
    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 已提交
367
  };
A
Abdullah Almsaeed 已提交
368

A
Abdullah Almsaeed 已提交
369 370 371 372 373 374 375 376 377 378
  /* Tree()
   * ======
   * Converts the sidebar into a multilevel
   * tree view menu.
   *
   * @type Function
   * @Usage: $.AdminLTE.tree('.sidebar')
   */
  $.AdminLTE.tree = function (menu) {
    var _this = this;
A
almasaeed2010 已提交
379

A
Abdullah Almsaeed 已提交
380
    $("li a", $(menu)).on('click', function (e) {
A
Abdullah Almsaeed 已提交
381 382 383
      //Get the clicked link and the next element
      var $this = $(this);
      var checkElement = $this.next();
A
almasaeed2010 已提交
384

A
Abdullah Almsaeed 已提交
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
      //Check if the next element is a menu and is visible
      if ((checkElement.is('.treeview-menu')) && (checkElement.is(':visible'))) {
        //Close the menu
        checkElement.slideUp('normal', 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('normal');
        //Remove the menu-open class from the parent
        ul.removeClass('menu-open');
        //Get the parent li
        var parent_li = $this.parent("li");
A
almasaeed2010 已提交
405

A
Abdullah Almsaeed 已提交
406 407 408 409 410 411 412 413 414 415 416 417 418 419
        //Open the target menu and add the menu-open class
        checkElement.slideDown('normal', 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
almasaeed2010 已提交
420
    });
A
Abdullah Almsaeed 已提交
421
  };
A
Abdullah Almsaeed 已提交
422

423 424
  /* ControlSidebar
   * ==============
A
Abdullah Almsaeed 已提交
425 426
   * Adds functionality to the right sidebar
   *
427
   * @type Object
A
Abdullah Almsaeed 已提交
428
   * @usage $.AdminLTE.controlSidebar.activate(options)
429 430
   */
  $.AdminLTE.controlSidebar = {
A
Abdullah Almsaeed 已提交
431
    //instantiate the object
A
Abdullah Almsaeed 已提交
432
    activate: function () {
A
Abdullah Almsaeed 已提交
433 434 435
      //Get the object
      var _this = this;
      //Update options
A
Abdullah Almsaeed 已提交
436
      var o = $.AdminLTE.options.controlSidebarOptions;
A
Abdullah Almsaeed 已提交
437 438 439 440
      //Get the sidebar
      var sidebar = $(o.selector);
      //The toggle button
      var btn = $(o.toggleBtnSelector);
A
Abdullah Almsaeed 已提交
441

A
Abdullah Almsaeed 已提交
442
      //Listen to the click event
A
Abdullah Almsaeed 已提交
443
      btn.on('click', function (e) {
A
Abdullah Almsaeed 已提交
444
        e.preventDefault();
A
Abdullah Almsaeed 已提交
445
        //If the sidebar is not open
A
Abdullah Almsaeed 已提交
446 447
        if (!sidebar.hasClass('control-sidebar-open')
                && !$('body').hasClass('control-sidebar-open')) {
A
Abdullah Almsaeed 已提交
448
          //Open the sidebar
A
Abdullah Almsaeed 已提交
449
          _this.open(sidebar, o.slide);
A
Abdullah Almsaeed 已提交
450
        } else {
A
Abdullah Almsaeed 已提交
451
          _this.close(sidebar, o.slide);
A
Abdullah Almsaeed 已提交
452 453
        }
      });
A
Abdullah Almsaeed 已提交
454 455

      //If the body has a boxed layout, fix the sidebar bg position
A
Abdullah Almsaeed 已提交
456 457
      var bg = $(".control-sidebar-bg");
      _this._fix(bg);
458 459 460 461 462 463 464 465 466 467

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

A
Abdullah Almsaeed 已提交
520 521 522 523 524 525 526 527 528 529
  /* BoxWidget
   * =========
   * BoxWidget is plugin to handle collapsing and
   * removing boxes from the screen.
   *
   * @type Object
   * @usage $.AdminLTE.boxWidget.activate()
   *        Set all of your option in the main $.AdminLTE.options object
   */
  $.AdminLTE.boxWidget = {
A
Abdullah Almsaeed 已提交
530 531
    selectors: $.AdminLTE.options.boxWidgetOptions.boxWidgetSelectors,
    icons: $.AdminLTE.options.boxWidgetOptions.boxWidgetIcons,
A
Abdullah Almsaeed 已提交
532 533 534
    activate: function () {
      var _this = this;
      //Listen for collapse event triggers
A
Abdullah Almsaeed 已提交
535
      $(_this.selectors.collapse).on('click', function (e) {
A
Abdullah Almsaeed 已提交
536 537
        e.preventDefault();
        _this.collapse($(this));
A
almasaeed2010 已提交
538
      });
A
Abdullah Almsaeed 已提交
539 540

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

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

/*
 * BOX REFRESH BUTTON
 * ------------------
 * This is a custom plugin to use with the compenet BOX. It allows you to add
 * a refresh button to the box. It converts the box's state to a loading state.
 *
A
Abdullah Almsaeed 已提交
592
 * @type plugin
A
almasaeed2010 已提交
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
 * @usage $("#box-widget").boxRefresh( options );
 */
(function ($) {

  $.fn.boxRefresh = function (options) {

    // Render options
    var settings = $.extend({
      //Refressh button selector
      trigger: ".refresh-btn",
      //File source to be loaded (e.g: ajax/src.php)
      source: "",
      //Callbacks
      onLoadStart: function (box) {
      }, //Right after the button has been clicked
      onLoadDone: function (box) {
      } //When the source has been loaded

    }, options);

    //The overlay
A
Abdullah Almsaeed 已提交
614
    var overlay = $('<div class="overlay"><div class="fa fa-refresh fa-spin"></div></div>');
A
almasaeed2010 已提交
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629

    return this.each(function () {
      //if a source is specified
      if (settings.source === "") {
        if (console) {
          console.log("Please specify a source first - boxRefresh()");
        }
        return;
      }
      //the box
      var box = $(this);
      //the button
      var rBtn = box.find(settings.trigger).first();

      //On trigger click
A
Abdullah Almsaeed 已提交
630
      rBtn.on('click', function (e) {
A
almasaeed2010 已提交
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 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 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
        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);

/*
 * TODO LIST CUSTOM PLUGIN
 * -----------------------
 * This plugin depends on iCheck plugin for checkbox and radio inputs
 *
 * @type plugin
 * @usage $("#todo-widget").todolist( options );
 */
(function ($) {

  $.fn.todolist = function (options) {
    // Render options
    var settings = $.extend({
      //When the user checks the input
      onCheck: function (ele) {
      },
      //When the user unchecks the input
      onUncheck: function (ele) {
      }
    }, options);

    return this.each(function () {

      if (typeof $.fn.iCheck != 'undefined') {
        $('input', this).on('ifChecked', function (event) {
          var ele = $(this).parents("li").first();
          ele.toggleClass("done");
          settings.onCheck.call(ele);
        });

        $('input', this).on('ifUnchecked', function (event) {
          var ele = $(this).parents("li").first();
          ele.toggleClass("done");
          settings.onUncheck.call(ele);
        });
      } else {
        $('input', this).on('change', function (event) {
          var ele = $(this).parents("li").first();
          ele.toggleClass("done");
          settings.onCheck.call(ele);
        });
      }
    });
  };
A
almasaeed2010 已提交
704
}(jQuery));