adminlte.js 27.8 KB
Newer Older
A
Abdullah Almsaeed 已提交
1 2 3 4 5 6 7 8 9
/*! AdminLTE app.js
* ================
* 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 <https://www.almsaeedstudio.com>
* @Email   <abdullah@almsaeedstudio.com>
A
Abdullah Almsaeed 已提交
10
* @version 2.4.8
A
Abdullah Almsaeed 已提交
11 12 13 14 15 16 17 18 19
* @repository git://github.com/almasaeed2010/AdminLTE.git
* @license MIT <http://opensource.org/licenses/MIT>
*/

// Make sure jQuery has been loaded
if (typeof jQuery === 'undefined') {
throw new Error('AdminLTE requires jQuery')
}

A
Abdullah Almsaeed 已提交
20 21 22
/* BoxRefresh()
 * =========
 * Adds AJAX content control to a box.
A
Abdullah Almsaeed 已提交
23
 *
A
Abdullah Almsaeed 已提交
24 25 26
 * @Usage: $('#my-box').boxRefresh(options)
 *         or add [data-widget="box-refresh"] to the box element
 *         Pass any option as data-option="value"
A
Abdullah Almsaeed 已提交
27 28
 */
+function ($) {
29
  'use strict';
A
Abdullah Almsaeed 已提交
30

31
  var DataKey = 'lte.boxrefresh';
A
Abdullah Almsaeed 已提交
32 33

  var Default = {
A
Abdullah Almsaeed 已提交
34 35 36 37 38 39 40 41 42 43
    source         : '',
    params         : {},
    trigger        : '.refresh-btn',
    content        : '.box-body',
    loadInContent  : true,
    responseType   : '',
    overlayTemplate: '<div class="overlay"><div class="fa fa-refresh fa-spin"></div></div>',
    onLoadStart    : function () {
    },
    onLoadDone     : function (response) {
44
      return response;
A
Abdullah Almsaeed 已提交
45
    }
46
  };
A
Abdullah Almsaeed 已提交
47 48

  var Selector = {
A
Abdullah Almsaeed 已提交
49
    data: '[data-widget="box-refresh"]'
50
  };
A
Abdullah Almsaeed 已提交
51

A
Abdullah Almsaeed 已提交
52 53 54
  // BoxRefresh Class Definition
  // =========================
  var BoxRefresh = function (element, options) {
55 56
    this.element  = element;
    this.options  = options;
O
Olda Horák 已提交
57
    this.$overlay = $(options.overlayTemplate);
A
Abdullah Almsaeed 已提交
58

A
Abdullah Almsaeed 已提交
59
    if (options.source === '') {
60
      throw new Error('Source url was not defined. Please specify a url in your BoxRefresh source option.');
A
Abdullah Almsaeed 已提交
61 62
    }

63 64 65
    this._setUpListeners();
    this.load();
  };
A
Abdullah Almsaeed 已提交
66

A
Abdullah Almsaeed 已提交
67
  BoxRefresh.prototype.load = function () {
68 69
    this._addOverlay();
    this.options.onLoadStart.call($(this));
A
Abdullah Almsaeed 已提交
70

A
Abdullah Almsaeed 已提交
71 72
    $.get(this.options.source, this.options.params, function (response) {
      if (this.options.loadInContent) {
O
Olda Horák 已提交
73
        $(this.element).find(this.options.content).html(response);
A
Abdullah Almsaeed 已提交
74
      }
75 76 77 78
      this.options.onLoadDone.call($(this), response);
      this._removeOverlay();
    }.bind(this), this.options.responseType !== '' && this.options.responseType);
  };
A
Abdullah Almsaeed 已提交
79

A
Abdullah Almsaeed 已提交
80
  // Private
A
Abdullah Almsaeed 已提交
81

A
Abdullah Almsaeed 已提交
82
  BoxRefresh.prototype._setUpListeners = function () {
O
Olda Horák 已提交
83
    $(this.element).on('click', this.options.trigger, function (event) {
84 85 86 87
      if (event) event.preventDefault();
      this.load();
    }.bind(this));
  };
A
Abdullah Almsaeed 已提交
88

A
Abdullah Almsaeed 已提交
89
  BoxRefresh.prototype._addOverlay = function () {
90 91
    $(this.element).append(this.$overlay);
  };
A
Abdullah Almsaeed 已提交
92

A
Abdullah Almsaeed 已提交
93
  BoxRefresh.prototype._removeOverlay = function () {
O
Olda Horák 已提交
94
    $(this.$overlay).remove();
95
  };
A
Abdullah Almsaeed 已提交
96 97 98 99 100

  // Plugin Definition
  // =================
  function Plugin(option) {
    return this.each(function () {
101 102
      var $this = $(this);
      var data  = $this.data(DataKey);
A
Abdullah Almsaeed 已提交
103 104

      if (!data) {
105 106
        var options = $.extend({}, Default, $this.data(), typeof option == 'object' && option);
        $this.data(DataKey, (data = new BoxRefresh($this, options)));
A
Abdullah Almsaeed 已提交
107 108
      }

A
Abdullah Almsaeed 已提交
109 110
      if (typeof data == 'string') {
        if (typeof data[option] == 'undefined') {
111
          throw new Error('No method named ' + option);
A
Abdullah Almsaeed 已提交
112
        }
113
        data[option]();
A
Abdullah Almsaeed 已提交
114
      }
115
    });
A
Abdullah Almsaeed 已提交
116 117
  }

118
  var old = $.fn.boxRefresh;
A
Abdullah Almsaeed 已提交
119

120 121
  $.fn.boxRefresh             = Plugin;
  $.fn.boxRefresh.Constructor = BoxRefresh;
A
Abdullah Almsaeed 已提交
122

A
Abdullah Almsaeed 已提交
123
  // No Conflict Mode
A
Abdullah Almsaeed 已提交
124
  // ================
A
Abdullah Almsaeed 已提交
125
  $.fn.boxRefresh.noConflict = function () {
126 127 128
    $.fn.boxRefresh = old;
    return this;
  };
A
Abdullah Almsaeed 已提交
129

A
Abdullah Almsaeed 已提交
130 131
  // BoxRefresh Data API
  // =================
A
Abdullah Almsaeed 已提交
132
  $(window).on('load', function () {
A
Abdullah Almsaeed 已提交
133
    $(Selector.data).each(function () {
134 135 136
      Plugin.call($(this));
    });
  });
A
Abdullah Almsaeed 已提交
137

138
}(jQuery);
A
Abdullah Almsaeed 已提交
139 140


A
Abdullah Almsaeed 已提交
141 142 143
/* BoxWidget()
 * ======
 * Adds box widget functions to boxes.
A
Abdullah Almsaeed 已提交
144
 *
A
Abdullah Almsaeed 已提交
145 146 147
 * @Usage: $('.my-box').boxWidget(options)
 *         This plugin auto activates on any element using the `.box` class
 *         Pass any option as data-option="value"
A
Abdullah Almsaeed 已提交
148 149
 */
+function ($) {
150
  'use strict';
A
Abdullah Almsaeed 已提交
151

152
  var DataKey = 'lte.boxwidget';
A
Abdullah Almsaeed 已提交
153 154

  var Default = {
A
Abdullah Almsaeed 已提交
155 156 157 158 159 160
    animationSpeed : 500,
    collapseTrigger: '[data-widget="collapse"]',
    removeTrigger  : '[data-widget="remove"]',
    collapseIcon   : 'fa-minus',
    expandIcon     : 'fa-plus',
    removeIcon     : 'fa-times'
161
  };
A
Abdullah Almsaeed 已提交
162 163

  var Selector = {
A
Abdullah Almsaeed 已提交
164 165
    data     : '.box',
    collapsed: '.collapsed-box',
166
    header   : '.box-header',
A
Abdullah Almsaeed 已提交
167 168 169
    body     : '.box-body',
    footer   : '.box-footer',
    tools    : '.box-tools'
170
  };
A
Abdullah Almsaeed 已提交
171 172

  var ClassName = {
A
Abdullah Almsaeed 已提交
173
    collapsed: 'collapsed-box'
174
  };
A
Abdullah Almsaeed 已提交
175 176

  var Event = {
A
Abdullah Almsaeed 已提交
177 178 179
    collapsed: 'collapsed.boxwidget',
    expanded : 'expanded.boxwidget',
    removed  : 'removed.boxwidget'
180
  };
A
Abdullah Almsaeed 已提交
181

A
Abdullah Almsaeed 已提交
182 183 184
  // BoxWidget Class Definition
  // =====================
  var BoxWidget = function (element, options) {
185 186
    this.element = element;
    this.options = options;
A
Abdullah Almsaeed 已提交
187

188 189
    this._setUpListeners();
  };
A
Abdullah Almsaeed 已提交
190

A
Abdullah Almsaeed 已提交
191
  BoxWidget.prototype.toggle = function () {
192
    var isOpen = !$(this.element).is(Selector.collapsed);
A
Abdullah Almsaeed 已提交
193

A
Abdullah Almsaeed 已提交
194
    if (isOpen) {
195
      this.collapse();
A
Abdullah Almsaeed 已提交
196
    } else {
197
      this.expand();
A
Abdullah Almsaeed 已提交
198
    }
199
  };
A
Abdullah Almsaeed 已提交
200

A
Abdullah Almsaeed 已提交
201
  BoxWidget.prototype.expand = function () {
202 203 204
    var expandedEvent = $.Event(Event.expanded);
    var collapseIcon  = this.options.collapseIcon;
    var expandIcon    = this.options.expandIcon;
A
Abdullah Almsaeed 已提交
205

206
    $(this.element).removeClass(ClassName.collapsed);
A
Abdullah Almsaeed 已提交
207

A
Abdullah Almsaeed 已提交
208
    $(this.element)
209 210
      .children(Selector.header + ', ' + Selector.body + ', ' + Selector.footer)
      .children(Selector.tools)
A
Abdullah Almsaeed 已提交
211 212
      .find('.' + expandIcon)
      .removeClass(expandIcon)
213
      .addClass(collapseIcon);
A
Abdullah Almsaeed 已提交
214

215
    $(this.element).children(Selector.body + ', ' + Selector.footer)
A
Abdullah Almsaeed 已提交
216
      .slideDown(this.options.animationSpeed, function () {
217 218 219
        $(this.element).trigger(expandedEvent);
      }.bind(this));
  };
A
Abdullah Almsaeed 已提交
220

A
Abdullah Almsaeed 已提交
221
  BoxWidget.prototype.collapse = function () {
222 223 224
    var collapsedEvent = $.Event(Event.collapsed);
    var collapseIcon   = this.options.collapseIcon;
    var expandIcon     = this.options.expandIcon;
A
Abdullah Almsaeed 已提交
225

A
Abdullah Almsaeed 已提交
226
    $(this.element)
227 228
      .children(Selector.header + ', ' + Selector.body + ', ' + Selector.footer)
      .children(Selector.tools)
A
Abdullah Almsaeed 已提交
229 230
      .find('.' + collapseIcon)
      .removeClass(collapseIcon)
231
      .addClass(expandIcon);
A
Abdullah Almsaeed 已提交
232

233
    $(this.element).children(Selector.body + ', ' + Selector.footer)
A
Abdullah Almsaeed 已提交
234
      .slideUp(this.options.animationSpeed, function () {
235 236 237 238
        $(this.element).addClass(ClassName.collapsed);
        $(this.element).trigger(collapsedEvent);
      }.bind(this));
  };
A
Abdullah Almsaeed 已提交
239

A
Abdullah Almsaeed 已提交
240
  BoxWidget.prototype.remove = function () {
241
    var removedEvent = $.Event(Event.removed);
A
Abdullah Almsaeed 已提交
242

A
Abdullah Almsaeed 已提交
243
    $(this.element).slideUp(this.options.animationSpeed, function () {
244 245 246 247
      $(this.element).trigger(removedEvent);
      $(this.element).remove();
    }.bind(this));
  };
A
Abdullah Almsaeed 已提交
248 249 250

  // Private

A
Abdullah Almsaeed 已提交
251
  BoxWidget.prototype._setUpListeners = function () {
252
    var that = this;
A
Abdullah Almsaeed 已提交
253

A
Abdullah Almsaeed 已提交
254
    $(this.element).on('click', this.options.collapseTrigger, function (event) {
255 256 257 258
      if (event) event.preventDefault();
      that.toggle($(this));
      return false;
    });
A
Abdullah Almsaeed 已提交
259 260

    $(this.element).on('click', this.options.removeTrigger, function (event) {
261 262 263 264 265
      if (event) event.preventDefault();
      that.remove($(this));
      return false;
    });
  };
A
Abdullah Almsaeed 已提交
266 267 268 269 270

  // Plugin Definition
  // =================
  function Plugin(option) {
    return this.each(function () {
271 272
      var $this = $(this);
      var data  = $this.data(DataKey);
A
Abdullah Almsaeed 已提交
273 274

      if (!data) {
275 276
        var options = $.extend({}, Default, $this.data(), typeof option == 'object' && option);
        $this.data(DataKey, (data = new BoxWidget($this, options)));
A
Abdullah Almsaeed 已提交
277 278 279 280
      }

      if (typeof option == 'string') {
        if (typeof data[option] == 'undefined') {
281
          throw new Error('No method named ' + option);
A
Abdullah Almsaeed 已提交
282
        }
283
        data[option]();
A
Abdullah Almsaeed 已提交
284
      }
285
    });
A
Abdullah Almsaeed 已提交
286 287
  }

288
  var old = $.fn.boxWidget;
A
Abdullah Almsaeed 已提交
289

290 291
  $.fn.boxWidget             = Plugin;
  $.fn.boxWidget.Constructor = BoxWidget;
A
Abdullah Almsaeed 已提交
292 293 294

  // No Conflict Mode
  // ================
A
Abdullah Almsaeed 已提交
295
  $.fn.boxWidget.noConflict = function () {
296 297 298
    $.fn.boxWidget = old;
    return this;
  };
A
Abdullah Almsaeed 已提交
299

A
Abdullah Almsaeed 已提交
300 301
  // BoxWidget Data API
  // ==================
A
Abdullah Almsaeed 已提交
302 303
  $(window).on('load', function () {
    $(Selector.data).each(function () {
304 305 306 307
      Plugin.call($(this));
    });
  });
}(jQuery);
A
Abdullah Almsaeed 已提交
308 309 310 311 312 313 314 315 316 317 318


/* ControlSidebar()
 * ===============
 * Toggles the state of the control sidebar
 *
 * @Usage: $('#control-sidebar-trigger').controlSidebar(options)
 *         or add [data-toggle="control-sidebar"] to the trigger
 *         Pass any option as data-option="value"
 */
+function ($) {
319
  'use strict';
A
Abdullah Almsaeed 已提交
320

321
  var DataKey = 'lte.controlsidebar';
A
Abdullah Almsaeed 已提交
322 323 324

  var Default = {
    slide: true
325
  };
A
Abdullah Almsaeed 已提交
326 327 328 329 330 331 332 333 334

  var Selector = {
    sidebar: '.control-sidebar',
    data   : '[data-toggle="control-sidebar"]',
    open   : '.control-sidebar-open',
    bg     : '.control-sidebar-bg',
    wrapper: '.wrapper',
    content: '.content-wrapper',
    boxed  : '.layout-boxed'
335
  };
A
Abdullah Almsaeed 已提交
336 337 338 339

  var ClassName = {
    open : 'control-sidebar-open',
    fixed: 'fixed'
340
  };
A
Abdullah Almsaeed 已提交
341 342 343 344

  var Event = {
    collapsed: 'collapsed.controlsidebar',
    expanded : 'expanded.controlsidebar'
345
  };
A
Abdullah Almsaeed 已提交
346 347 348 349

  // ControlSidebar Class Definition
  // ===============================
  var ControlSidebar = function (element, options) {
350 351 352
    this.element         = element;
    this.options         = options;
    this.hasBindedResize = false;
A
Abdullah Almsaeed 已提交
353

354 355
    this.init();
  };
A
Abdullah Almsaeed 已提交
356 357 358 359 360

  ControlSidebar.prototype.init = function () {
    // Add click listener if the element hasn't been
    // initialized using the data API
    if (!$(this.element).is(Selector.data)) {
361
      $(this).on('click', this.toggle);
A
Abdullah Almsaeed 已提交
362 363
    }

364
    this.fix();
A
Abdullah Almsaeed 已提交
365
    $(window).resize(function () {
366 367 368
      this.fix();
    }.bind(this));
  };
A
Abdullah Almsaeed 已提交
369 370

  ControlSidebar.prototype.toggle = function (event) {
371
    if (event) event.preventDefault();
A
Abdullah Almsaeed 已提交
372

373
    this.fix();
A
Abdullah Almsaeed 已提交
374 375

    if (!$(Selector.sidebar).is(Selector.open) && !$('body').is(Selector.open)) {
376
      this.expand();
A
Abdullah Almsaeed 已提交
377
    } else {
378
      this.collapse();
A
Abdullah Almsaeed 已提交
379
    }
380
  };
A
Abdullah Almsaeed 已提交
381 382 383

  ControlSidebar.prototype.expand = function () {
    if (!this.options.slide) {
384
      $('body').addClass(ClassName.open);
A
Abdullah Almsaeed 已提交
385
    } else {
386
      $(Selector.sidebar).addClass(ClassName.open);
A
Abdullah Almsaeed 已提交
387 388
    }

389 390
    $(this.element).trigger($.Event(Event.expanded));
  };
A
Abdullah Almsaeed 已提交
391 392

  ControlSidebar.prototype.collapse = function () {
393 394 395
    $('body, ' + Selector.sidebar).removeClass(ClassName.open);
    $(this.element).trigger($.Event(Event.collapsed));
  };
A
Abdullah Almsaeed 已提交
396 397 398

  ControlSidebar.prototype.fix = function () {
    if ($('body').is(Selector.boxed)) {
399
      this._fixForBoxed($(Selector.bg));
A
Abdullah Almsaeed 已提交
400
    }
401
  };
A
Abdullah Almsaeed 已提交
402 403 404 405 406 407 408

  // Private

  ControlSidebar.prototype._fixForBoxed = function (bg) {
    bg.css({
      position: 'absolute',
      height  : $(Selector.wrapper).height()
409 410
    });
  };
A
Abdullah Almsaeed 已提交
411 412 413 414 415

  // Plugin Definition
  // =================
  function Plugin(option) {
    return this.each(function () {
416 417
      var $this = $(this);
      var data  = $this.data(DataKey);
A
Abdullah Almsaeed 已提交
418 419

      if (!data) {
420 421
        var options = $.extend({}, Default, $this.data(), typeof option == 'object' && option);
        $this.data(DataKey, (data = new ControlSidebar($this, options)));
A
Abdullah Almsaeed 已提交
422 423
      }

424 425
      if (typeof option == 'string') data.toggle();
    });
A
Abdullah Almsaeed 已提交
426 427
  }

428
  var old = $.fn.controlSidebar;
A
Abdullah Almsaeed 已提交
429

430 431
  $.fn.controlSidebar             = Plugin;
  $.fn.controlSidebar.Constructor = ControlSidebar;
A
Abdullah Almsaeed 已提交
432 433 434 435

  // No Conflict Mode
  // ================
  $.fn.controlSidebar.noConflict = function () {
436 437 438
    $.fn.controlSidebar = old;
    return this;
  };
A
Abdullah Almsaeed 已提交
439 440 441 442

  // ControlSidebar Data API
  // =======================
  $(document).on('click', Selector.data, function (event) {
443 444 445
    if (event) event.preventDefault();
    Plugin.call($(this), 'toggle');
  });
A
Abdullah Almsaeed 已提交
446

447
}(jQuery);
A
Abdullah Almsaeed 已提交
448 449


A
Abdullah Almsaeed 已提交
450 451 452
/* DirectChat()
 * ===============
 * Toggles the state of the control sidebar
A
Abdullah Almsaeed 已提交
453
 *
A
Abdullah Almsaeed 已提交
454 455
 * @Usage: $('#my-chat-box').directChat()
 *         or add [data-widget="direct-chat"] to the trigger
A
Abdullah Almsaeed 已提交
456 457
 */
+function ($) {
458
  'use strict';
A
Abdullah Almsaeed 已提交
459

460
  var DataKey = 'lte.directchat';
A
Abdullah Almsaeed 已提交
461

A
Abdullah Almsaeed 已提交
462 463 464
  var Selector = {
    data: '[data-widget="chat-pane-toggle"]',
    box : '.direct-chat'
465
  };
A
Abdullah Almsaeed 已提交
466

A
Abdullah Almsaeed 已提交
467 468
  var ClassName = {
    open: 'direct-chat-contacts-open'
469
  };
A
Abdullah Almsaeed 已提交
470 471 472 473

  // DirectChat Class Definition
  // ===========================
  var DirectChat = function (element) {
474 475
    this.element = element;
  };
A
Abdullah Almsaeed 已提交
476 477

  DirectChat.prototype.toggle = function ($trigger) {
478 479
    $trigger.parents(Selector.box).first().toggleClass(ClassName.open);
  };
A
Abdullah Almsaeed 已提交
480 481 482 483 484

  // Plugin Definition
  // =================
  function Plugin(option) {
    return this.each(function () {
485 486
      var $this = $(this);
      var data  = $this.data(DataKey);
A
Abdullah Almsaeed 已提交
487 488

      if (!data) {
489
        $this.data(DataKey, (data = new DirectChat($this)));
A
Abdullah Almsaeed 已提交
490 491
      }

492 493
      if (typeof option == 'string') data.toggle($this);
    });
A
Abdullah Almsaeed 已提交
494 495
  }

496
  var old = $.fn.directChat;
A
Abdullah Almsaeed 已提交
497

498 499
  $.fn.directChat             = Plugin;
  $.fn.directChat.Constructor = DirectChat;
A
Abdullah Almsaeed 已提交
500 501 502 503

  // No Conflict Mode
  // ================
  $.fn.directChat.noConflict = function () {
504 505 506
    $.fn.directChat = old;
    return this;
  };
A
Abdullah Almsaeed 已提交
507 508 509 510

  // DirectChat Data API
  // ===================
  $(document).on('click', Selector.data, function (event) {
511 512 513
    if (event) event.preventDefault();
    Plugin.call($(this), 'toggle');
  });
A
Abdullah Almsaeed 已提交
514

515
}(jQuery);
A
Abdullah Almsaeed 已提交
516 517 518 519 520 521 522 523 524 525 526 527


/* Layout()
 * ========
 * Implements AdminLTE layout.
 * Fixes the layout height in case min-height fails.
 *
 * @usage activated automatically upon window load.
 *        Configure any options by passing data-option="value"
 *        to the body tag.
 */
+function ($) {
528
  'use strict';
A
Abdullah Almsaeed 已提交
529

530
  var DataKey = 'lte.layout';
A
Abdullah Almsaeed 已提交
531 532 533 534

  var Default = {
    slimscroll : true,
    resetHeight: true
535
  };
A
Abdullah Almsaeed 已提交
536 537 538 539 540 541 542 543 544 545 546 547

  var Selector = {
    wrapper       : '.wrapper',
    contentWrapper: '.content-wrapper',
    layoutBoxed   : '.layout-boxed',
    mainFooter    : '.main-footer',
    mainHeader    : '.main-header',
    sidebar       : '.sidebar',
    controlSidebar: '.control-sidebar',
    fixed         : '.fixed',
    sidebarMenu   : '.sidebar-menu',
    logo          : '.main-header .logo'
548
  };
A
Abdullah Almsaeed 已提交
549 550

  var ClassName = {
A
Abdullah Almsaeed 已提交
551 552
    fixed         : 'fixed',
    holdTransition: 'hold-transition'
553
  };
A
Abdullah Almsaeed 已提交
554

A
Abdullah Almsaeed 已提交
555
  var Layout = function (options) {
556 557 558 559
    this.options      = options;
    this.bindedResize = false;
    this.activate();
  };
A
Abdullah Almsaeed 已提交
560

A
Abdullah Almsaeed 已提交
561
  Layout.prototype.activate = function () {
562 563
    this.fix();
    this.fixSidebar();
A
Abdullah Almsaeed 已提交
564

565
    $('body').removeClass(ClassName.holdTransition);
A
Abdullah Almsaeed 已提交
566 567 568 569 570

    if (this.options.resetHeight) {
      $('body, html, ' + Selector.wrapper).css({
        'height'    : 'auto',
        'min-height': '100%'
571
      });
A
Abdullah Almsaeed 已提交
572 573 574 575
    }

    if (!this.bindedResize) {
      $(window).resize(function () {
576 577
        this.fix();
        this.fixSidebar();
A
Abdullah Almsaeed 已提交
578 579

        $(Selector.logo + ', ' + Selector.sidebar).one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function () {
580 581 582 583
          this.fix();
          this.fixSidebar();
        }.bind(this));
      }.bind(this));
A
Abdullah Almsaeed 已提交
584

585
      this.bindedResize = true;
A
Abdullah Almsaeed 已提交
586 587 588
    }

    $(Selector.sidebarMenu).on('expanded.tree', function () {
589 590 591
      this.fix();
      this.fixSidebar();
    }.bind(this));
A
Abdullah Almsaeed 已提交
592 593

    $(Selector.sidebarMenu).on('collapsed.tree', function () {
594 595 596 597
      this.fix();
      this.fixSidebar();
    }.bind(this));
  };
A
Abdullah Almsaeed 已提交
598

A
Abdullah Almsaeed 已提交
599 600
  Layout.prototype.fix = function () {
    // Remove overflow from .wrapper if layout-boxed exists
601
    $(Selector.layoutBoxed + ' > ' + Selector.wrapper).css('overflow', 'hidden');
A
Abdullah Almsaeed 已提交
602

A
Abdullah Almsaeed 已提交
603
    // Get window height and the wrapper height
A
Abdullah Almsaeed 已提交
604 605 606
    var footerHeight = $(Selector.mainFooter).outerHeight() || 0;
    var headerHeight  = $(Selector.mainHeader).outerHeight() || 0;
    var neg           = headerHeight + footerHeight;
607 608
    var windowHeight  = $(window).height();
    var sidebarHeight = $(Selector.sidebar).height() || 0;
A
Abdullah Almsaeed 已提交
609 610 611 612

    // Set the min-height of the content and sidebar based on
    // the height of the document.
    if ($('body').hasClass(ClassName.fixed)) {
613
      $(Selector.contentWrapper).css('min-height', windowHeight - footerHeight);
A
Abdullah Almsaeed 已提交
614
    } else {
615
      var postSetHeight;
A
Abdullah Almsaeed 已提交
616

617
      if (windowHeight >= sidebarHeight + headerHeight) {
618 619
        $(Selector.contentWrapper).css('min-height', windowHeight - neg);
        postSetHeight = windowHeight - neg;
A
Abdullah Almsaeed 已提交
620
      } else {
621 622
        $(Selector.contentWrapper).css('min-height', sidebarHeight);
        postSetHeight = sidebarHeight;
A
Abdullah Almsaeed 已提交
623 624 625
      }

      // Fix for the control sidebar height
626
      var $controlSidebar = $(Selector.controlSidebar);
A
Abdullah Almsaeed 已提交
627 628
      if (typeof $controlSidebar !== 'undefined') {
        if ($controlSidebar.height() > postSetHeight)
629
          $(Selector.contentWrapper).css('min-height', $controlSidebar.height());
A
Abdullah Almsaeed 已提交
630
      }
A
Abdullah Almsaeed 已提交
631
    }
632
  };
A
Abdullah Almsaeed 已提交
633

A
Abdullah Almsaeed 已提交
634 635 636 637
  Layout.prototype.fixSidebar = function () {
    // Make sure the body tag has the .fixed class
    if (!$('body').hasClass(ClassName.fixed)) {
      if (typeof $.fn.slimScroll !== 'undefined') {
638
        $(Selector.sidebar).slimScroll({ destroy: true }).height('auto');
A
Abdullah Almsaeed 已提交
639
      }
640
      return;
A
Abdullah Almsaeed 已提交
641
    }
A
Abdullah Almsaeed 已提交
642

A
Abdullah Almsaeed 已提交
643 644 645 646
    // Enable slimscroll for fixed layout
    if (this.options.slimscroll) {
      if (typeof $.fn.slimScroll !== 'undefined') {
        // Destroy if it exists
647
        // $(Selector.sidebar).slimScroll({ destroy: true }).height('auto')
A
Abdullah Almsaeed 已提交
648

A
Abdullah Almsaeed 已提交
649 650
        // Add slimscroll
        $(Selector.sidebar).slimScroll({
651 652
          height: ($(window).height() - $(Selector.mainHeader).height()) + 'px'
        });
A
Abdullah Almsaeed 已提交
653 654
      }
    }
655
  };
A
Abdullah Almsaeed 已提交
656

A
Abdullah Almsaeed 已提交
657 658 659 660
  // Plugin Definition
  // =================
  function Plugin(option) {
    return this.each(function () {
661 662
      var $this = $(this);
      var data  = $this.data(DataKey);
A
Abdullah Almsaeed 已提交
663 664

      if (!data) {
665 666
        var options = $.extend({}, Default, $this.data(), typeof option === 'object' && option);
        $this.data(DataKey, (data = new Layout(options)));
A
Abdullah Almsaeed 已提交
667 668 669 670
      }

      if (typeof option === 'string') {
        if (typeof data[option] === 'undefined') {
671
          throw new Error('No method named ' + option);
A
Abdullah Almsaeed 已提交
672
        }
673
        data[option]();
A
Abdullah Almsaeed 已提交
674
      }
675
    });
A
Abdullah Almsaeed 已提交
676 677
  }

678
  var old = $.fn.layout;
A
Abdullah Almsaeed 已提交
679

680 681
  $.fn.layout            = Plugin;
  $.fn.layout.Constuctor = Layout;
A
Abdullah Almsaeed 已提交
682 683 684 685

  // No conflict mode
  // ================
  $.fn.layout.noConflict = function () {
686 687 688
    $.fn.layout = old;
    return this;
  };
A
Abdullah Almsaeed 已提交
689 690 691 692

  // Layout DATA-API
  // ===============
  $(window).on('load', function () {
693 694 695
    Plugin.call($('body'));
  });
}(jQuery);
A
Abdullah Almsaeed 已提交
696 697 698 699 700 701 702 703 704 705 706


/* PushMenu()
 * ==========
 * Adds the push menu functionality to the sidebar.
 *
 * @usage: $('.btn').pushMenu(options)
 *          or add [data-toggle="push-menu"] to any button
 *          Pass any option as data-option="value"
 */
+function ($) {
707
  'use strict';
A
Abdullah Almsaeed 已提交
708

709
  var DataKey = 'lte.pushmenu';
A
Abdullah Almsaeed 已提交
710 711 712 713 714

  var Default = {
    collapseScreenSize   : 767,
    expandOnHover        : false,
    expandTransitionDelay: 200
715
  };
A
Abdullah Almsaeed 已提交
716 717 718 719 720 721 722 723 724 725 726

  var Selector = {
    collapsed     : '.sidebar-collapse',
    open          : '.sidebar-open',
    mainSidebar   : '.main-sidebar',
    contentWrapper: '.content-wrapper',
    searchInput   : '.sidebar-form .form-control',
    button        : '[data-toggle="push-menu"]',
    mini          : '.sidebar-mini',
    expanded      : '.sidebar-expanded-on-hover',
    layoutFixed   : '.fixed'
727
  };
A
Abdullah Almsaeed 已提交
728 729 730 731 732 733 734 735

  var ClassName = {
    collapsed    : 'sidebar-collapse',
    open         : 'sidebar-open',
    mini         : 'sidebar-mini',
    expanded     : 'sidebar-expanded-on-hover',
    expandFeature: 'sidebar-mini-expand-feature',
    layoutFixed  : 'fixed'
736
  };
A
Abdullah Almsaeed 已提交
737 738 739 740

  var Event = {
    expanded : 'expanded.pushMenu',
    collapsed: 'collapsed.pushMenu'
741
  };
A
Abdullah Almsaeed 已提交
742 743 744 745

  // PushMenu Class Definition
  // =========================
  var PushMenu = function (options) {
746 747 748
    this.options = options;
    this.init();
  };
A
Abdullah Almsaeed 已提交
749 750 751 752

  PushMenu.prototype.init = function () {
    if (this.options.expandOnHover
      || ($('body').is(Selector.mini + Selector.layoutFixed))) {
753 754
      this.expandOnHover();
      $('body').addClass(ClassName.expandFeature);
A
Abdullah Almsaeed 已提交
755 756 757 758 759
    }

    $(Selector.contentWrapper).click(function () {
      // Enable hide menu when clicking on the content-wrapper on small screens
      if ($(window).width() <= this.options.collapseScreenSize && $('body').hasClass(ClassName.open)) {
760
        this.close();
A
Abdullah Almsaeed 已提交
761
      }
762
    }.bind(this));
A
Abdullah Almsaeed 已提交
763 764 765

    // __Fix for android devices
    $(Selector.searchInput).click(function (e) {
766 767 768
      e.stopPropagation();
    });
  };
A
Abdullah Almsaeed 已提交
769

A
Abdullah Almsaeed 已提交
770
  PushMenu.prototype.toggle = function () {
771 772
    var windowWidth = $(window).width();
    var isOpen      = !$('body').hasClass(ClassName.collapsed);
A
Abdullah Almsaeed 已提交
773

A
Abdullah Almsaeed 已提交
774
    if (windowWidth <= this.options.collapseScreenSize) {
775
      isOpen = $('body').hasClass(ClassName.open);
A
Abdullah Almsaeed 已提交
776
    }
A
Abdullah Almsaeed 已提交
777

A
Abdullah Almsaeed 已提交
778
    if (!isOpen) {
779
      this.open();
A
Abdullah Almsaeed 已提交
780
    } else {
781
      this.close();
A
Abdullah Almsaeed 已提交
782
    }
783
  };
A
Abdullah Almsaeed 已提交
784

A
Abdullah Almsaeed 已提交
785
  PushMenu.prototype.open = function () {
786
    var windowWidth = $(window).width();
A
Abdullah Almsaeed 已提交
787

A
Abdullah Almsaeed 已提交
788 789
    if (windowWidth > this.options.collapseScreenSize) {
      $('body').removeClass(ClassName.collapsed)
790
        .trigger($.Event(Event.expanded));
A
Abdullah Almsaeed 已提交
791 792 793
    }
    else {
      $('body').addClass(ClassName.open)
794
        .trigger($.Event(Event.expanded));
A
Abdullah Almsaeed 已提交
795
    }
796
  };
A
Abdullah Almsaeed 已提交
797

A
Abdullah Almsaeed 已提交
798
  PushMenu.prototype.close = function () {
799
    var windowWidth = $(window).width();
A
Abdullah Almsaeed 已提交
800 801
    if (windowWidth > this.options.collapseScreenSize) {
      $('body').addClass(ClassName.collapsed)
802
        .trigger($.Event(Event.collapsed));
A
Abdullah Almsaeed 已提交
803 804
    } else {
      $('body').removeClass(ClassName.open + ' ' + ClassName.collapsed)
805
        .trigger($.Event(Event.collapsed));
A
Abdullah Almsaeed 已提交
806
    }
807
  };
A
Abdullah Almsaeed 已提交
808

A
Abdullah Almsaeed 已提交
809 810 811 812
  PushMenu.prototype.expandOnHover = function () {
    $(Selector.mainSidebar).hover(function () {
      if ($('body').is(Selector.mini + Selector.collapsed)
        && $(window).width() > this.options.collapseScreenSize) {
813
        this.expand();
A
Abdullah Almsaeed 已提交
814 815 816
      }
    }.bind(this), function () {
      if ($('body').is(Selector.expanded)) {
817
        this.collapse();
A
Abdullah Almsaeed 已提交
818
      }
819 820
    }.bind(this));
  };
A
Abdullah Almsaeed 已提交
821

A
Abdullah Almsaeed 已提交
822 823 824
  PushMenu.prototype.expand = function () {
    setTimeout(function () {
      $('body').removeClass(ClassName.collapsed)
825 826 827
        .addClass(ClassName.expanded);
    }, this.options.expandTransitionDelay);
  };
A
Abdullah Almsaeed 已提交
828

A
Abdullah Almsaeed 已提交
829 830 831
  PushMenu.prototype.collapse = function () {
    setTimeout(function () {
      $('body').removeClass(ClassName.expanded)
832 833 834
        .addClass(ClassName.collapsed);
    }, this.options.expandTransitionDelay);
  };
A
Abdullah Almsaeed 已提交
835

A
Abdullah Almsaeed 已提交
836 837
  // PushMenu Plugin Definition
  // ==========================
A
Abdullah Almsaeed 已提交
838 839
  function Plugin(option) {
    return this.each(function () {
840 841
      var $this = $(this);
      var data  = $this.data(DataKey);
A
Abdullah Almsaeed 已提交
842 843

      if (!data) {
844 845
        var options = $.extend({}, Default, $this.data(), typeof option == 'object' && option);
        $this.data(DataKey, (data = new PushMenu(options)));
A
Abdullah Almsaeed 已提交
846 847
      }

848 849
      if (option === 'toggle') data.toggle();
    });
A
Abdullah Almsaeed 已提交
850 851
  }

852
  var old = $.fn.pushMenu;
A
Abdullah Almsaeed 已提交
853

854 855
  $.fn.pushMenu             = Plugin;
  $.fn.pushMenu.Constructor = PushMenu;
A
Abdullah Almsaeed 已提交
856 857 858

  // No Conflict Mode
  // ================
A
Abdullah Almsaeed 已提交
859
  $.fn.pushMenu.noConflict = function () {
860 861 862
    $.fn.pushMenu = old;
    return this;
  };
A
Abdullah Almsaeed 已提交
863

A
Abdullah Almsaeed 已提交
864 865 866
  // Data API
  // ========
  $(document).on('click', Selector.button, function (e) {
867 868 869
    e.preventDefault();
    Plugin.call($(this), 'toggle');
  });
A
Abdullah Almsaeed 已提交
870
  $(window).on('load', function () {
871 872 873
    Plugin.call($(Selector.button));
  });
}(jQuery);
A
Abdullah Almsaeed 已提交
874 875 876 877 878 879 880 881 882 883 884


/* TodoList()
 * =========
 * Converts a list into a todoList.
 *
 * @Usage: $('.my-list').todoList(options)
 *         or add [data-widget="todo-list"] to the ul element
 *         Pass any option as data-option="value"
 */
+function ($) {
885
  'use strict';
A
Abdullah Almsaeed 已提交
886

887
  var DataKey = 'lte.todolist';
A
Abdullah Almsaeed 已提交
888 889

  var Default = {
A
Abdullah Almsaeed 已提交
890
    onCheck  : function (item) {
891
      return item;
A
Abdullah Almsaeed 已提交
892
    },
A
Abdullah Almsaeed 已提交
893
    onUnCheck: function (item) {
894
      return item;
A
Abdullah Almsaeed 已提交
895
    }
896
  };
A
Abdullah Almsaeed 已提交
897 898 899

  var Selector = {
    data: '[data-widget="todo-list"]'
900
  };
A
Abdullah Almsaeed 已提交
901 902 903

  var ClassName = {
    done: 'done'
904
  };
A
Abdullah Almsaeed 已提交
905 906 907 908

  // TodoList Class Definition
  // =========================
  var TodoList = function (element, options) {
909 910
    this.element = element;
    this.options = options;
A
Abdullah Almsaeed 已提交
911

912 913
    this._setUpListeners();
  };
A
Abdullah Almsaeed 已提交
914 915

  TodoList.prototype.toggle = function (item) {
916
    item.parents(Selector.li).first().toggleClass(ClassName.done);
A
Abdullah Almsaeed 已提交
917
    if (!item.prop('checked')) {
918 919
      this.unCheck(item);
      return;
A
Abdullah Almsaeed 已提交
920 921
    }

922 923
    this.check(item);
  };
A
Abdullah Almsaeed 已提交
924 925

  TodoList.prototype.check = function (item) {
926 927
    this.options.onCheck.call(item);
  };
A
Abdullah Almsaeed 已提交
928 929

  TodoList.prototype.unCheck = function (item) {
930 931
    this.options.onUnCheck.call(item);
  };
A
Abdullah Almsaeed 已提交
932 933 934 935

  // Private

  TodoList.prototype._setUpListeners = function () {
936
    var that = this;
A
Abdullah Almsaeed 已提交
937
    $(this.element).on('change ifChanged', 'input:checkbox', function () {
938 939 940
      that.toggle($(this));
    });
  };
A
Abdullah Almsaeed 已提交
941 942 943 944 945

  // Plugin Definition
  // =================
  function Plugin(option) {
    return this.each(function () {
946 947
      var $this = $(this);
      var data  = $this.data(DataKey);
A
Abdullah Almsaeed 已提交
948 949

      if (!data) {
950 951
        var options = $.extend({}, Default, $this.data(), typeof option == 'object' && option);
        $this.data(DataKey, (data = new TodoList($this, options)));
A
Abdullah Almsaeed 已提交
952 953 954 955
      }

      if (typeof data == 'string') {
        if (typeof data[option] == 'undefined') {
956
          throw new Error('No method named ' + option);
A
Abdullah Almsaeed 已提交
957
        }
958
        data[option]();
A
Abdullah Almsaeed 已提交
959
      }
960
    });
A
Abdullah Almsaeed 已提交
961 962
  }

963
  var old = $.fn.todoList;
A
Abdullah Almsaeed 已提交
964

965 966
  $.fn.todoList             = Plugin;
  $.fn.todoList.Constructor = TodoList;
A
Abdullah Almsaeed 已提交
967 968 969 970

  // No Conflict Mode
  // ================
  $.fn.todoList.noConflict = function () {
971 972 973
    $.fn.todoList = old;
    return this;
  };
A
Abdullah Almsaeed 已提交
974 975 976 977 978

  // TodoList Data API
  // =================
  $(window).on('load', function () {
    $(Selector.data).each(function () {
979 980 981
      Plugin.call($(this));
    });
  });
A
Abdullah Almsaeed 已提交
982

983
}(jQuery);
A
Abdullah Almsaeed 已提交
984 985


A
Abdullah Almsaeed 已提交
986 987 988 989
/* Tree()
 * ======
 * Converts a nested list into a multilevel
 * tree view menu.
A
Abdullah Almsaeed 已提交
990
 *
A
Abdullah Almsaeed 已提交
991 992 993
 * @Usage: $('.my-menu').tree(options)
 *         or add [data-widget="tree"] to the ul element
 *         Pass any option as data-option="value"
A
Abdullah Almsaeed 已提交
994 995
 */
+function ($) {
996
  'use strict';
A
Abdullah Almsaeed 已提交
997

998
  var DataKey = 'lte.tree';
A
Abdullah Almsaeed 已提交
999 1000 1001 1002 1003 1004

  var Default = {
    animationSpeed: 500,
    accordion     : true,
    followLink    : false,
    trigger       : '.treeview a'
1005
  };
A
Abdullah Almsaeed 已提交
1006 1007

  var Selector = {
A
Abdullah Almsaeed 已提交
1008 1009 1010 1011 1012 1013 1014
    tree        : '.tree',
    treeview    : '.treeview',
    treeviewMenu: '.treeview-menu',
    open        : '.menu-open, .active',
    li          : 'li',
    data        : '[data-widget="tree"]',
    active      : '.active'
1015
  };
A
Abdullah Almsaeed 已提交
1016 1017

  var ClassName = {
A
Abdullah Almsaeed 已提交
1018 1019
    open: 'menu-open',
    tree: 'tree'
1020
  };
A
Abdullah Almsaeed 已提交
1021

A
Abdullah Almsaeed 已提交
1022 1023 1024
  var Event = {
    collapsed: 'collapsed.tree',
    expanded : 'expanded.tree'
1025
  };
A
Abdullah Almsaeed 已提交
1026 1027 1028 1029

  // Tree Class Definition
  // =====================
  var Tree = function (element, options) {
1030 1031
    this.element = element;
    this.options = options;
A
Abdullah Almsaeed 已提交
1032

1033
    $(this.element).addClass(ClassName.tree);
A
Abdullah Almsaeed 已提交
1034

1035
    $(Selector.treeview + Selector.active, this.element).addClass(ClassName.open);
A
Abdullah Almsaeed 已提交
1036

1037 1038
    this._setUpListeners();
  };
A
Abdullah Almsaeed 已提交
1039

A
Abdullah Almsaeed 已提交
1040
  Tree.prototype.toggle = function (link, event) {
1041 1042 1043
    var treeviewMenu = link.next(Selector.treeviewMenu);
    var parentLi     = link.parent();
    var isOpen       = parentLi.hasClass(ClassName.open);
A
Abdullah Almsaeed 已提交
1044 1045

    if (!parentLi.is(Selector.treeview)) {
1046
      return;
A
Abdullah Almsaeed 已提交
1047 1048
    }

1049
    if (!this.options.followLink || link.attr('href') === '#') {
1050
      event.preventDefault();
A
Abdullah Almsaeed 已提交
1051 1052 1053
    }

    if (isOpen) {
1054
      this.collapse(treeviewMenu, parentLi);
A
Abdullah Almsaeed 已提交
1055
    } else {
1056
      this.expand(treeviewMenu, parentLi);
A
Abdullah Almsaeed 已提交
1057
    }
1058
  };
A
Abdullah Almsaeed 已提交
1059 1060

  Tree.prototype.expand = function (tree, parent) {
1061
    var expandedEvent = $.Event(Event.expanded);
A
Abdullah Almsaeed 已提交
1062 1063

    if (this.options.accordion) {
1064 1065 1066
      var openMenuLi = parent.siblings(Selector.open);
      var openTree   = openMenuLi.children(Selector.treeviewMenu);
      this.collapse(openTree, openMenuLi);
A
Abdullah Almsaeed 已提交
1067 1068
    }

1069
    parent.addClass(ClassName.open);
A
Abdullah Almsaeed 已提交
1070
    tree.slideDown(this.options.animationSpeed, function () {
1071 1072 1073
      $(this.element).trigger(expandedEvent);
    }.bind(this));
  };
A
Abdullah Almsaeed 已提交
1074 1075

  Tree.prototype.collapse = function (tree, parentLi) {
1076
    var collapsedEvent = $.Event(Event.collapsed);
A
Abdullah Almsaeed 已提交
1077

1078
    //tree.find(Selector.open).removeClass(ClassName.open);
1079
    parentLi.removeClass(ClassName.open);
A
Abdullah Almsaeed 已提交
1080
    tree.slideUp(this.options.animationSpeed, function () {
1081
      //tree.find(Selector.open + ' > ' + Selector.treeview).slideUp();
1082 1083 1084
      $(this.element).trigger(collapsedEvent);
    }.bind(this));
  };
A
Abdullah Almsaeed 已提交
1085 1086

  // Private
1087

A
Abdullah Almsaeed 已提交
1088
  Tree.prototype._setUpListeners = function () {
1089
    var that = this;
A
Abdullah Almsaeed 已提交
1090 1091

    $(this.element).on('click', this.options.trigger, function (event) {
1092 1093 1094
      that.toggle($(this), event);
    });
  };
A
Abdullah Almsaeed 已提交
1095 1096 1097 1098 1099

  // Plugin Definition
  // =================
  function Plugin(option) {
    return this.each(function () {
1100 1101
      var $this = $(this);
      var data  = $this.data(DataKey);
A
Abdullah Almsaeed 已提交
1102 1103

      if (!data) {
1104 1105
        var options = $.extend({}, Default, $this.data(), typeof option == 'object' && option);
        $this.data(DataKey, new Tree($this, options));
A
Abdullah Almsaeed 已提交
1106
      }
1107
    });
A
Abdullah Almsaeed 已提交
1108 1109
  }

1110
  var old = $.fn.tree;
A
Abdullah Almsaeed 已提交
1111

1112 1113
  $.fn.tree             = Plugin;
  $.fn.tree.Constructor = Tree;
A
Abdullah Almsaeed 已提交
1114 1115 1116

  // No Conflict Mode
  // ================
A
Abdullah Almsaeed 已提交
1117
  $.fn.tree.noConflict = function () {
1118 1119 1120
    $.fn.tree = old;
    return this;
  };
A
Abdullah Almsaeed 已提交
1121

A
Abdullah Almsaeed 已提交
1122 1123 1124 1125
  // Tree Data API
  // =============
  $(window).on('load', function () {
    $(Selector.data).each(function () {
1126 1127 1128
      Plugin.call($(this));
    });
  });
A
Abdullah Almsaeed 已提交
1129

1130
}(jQuery);