adminlte.js 28.3 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 180 181 182 183
        collapsing: 'collapsing.boxwidget',
        collapsed: 'collapsed.boxwidget',
        expanding: 'expanding.boxwidget',
        expanded: 'expanded.boxwidget',
        removing: 'removing.boxwidget',
        removed: 'removed.boxwidget'        
    };
A
Abdullah Almsaeed 已提交
184

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

191 192
    this._setUpListeners();
  };
A
Abdullah Almsaeed 已提交
193

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

A
Abdullah Almsaeed 已提交
197
    if (isOpen) {
198
      this.collapse();
A
Abdullah Almsaeed 已提交
199
    } else {
200
      this.expand();
A
Abdullah Almsaeed 已提交
201
    }
202
  };
A
Abdullah Almsaeed 已提交
203

A
Abdullah Almsaeed 已提交
204
  BoxWidget.prototype.expand = function () {
205
    var expandedEvent = $.Event(Event.expanded);
A
Abdullah Almsaeed 已提交
206
    var expandingEvent = $.Event(Event.expanding);
207 208
    var collapseIcon  = this.options.collapseIcon;
    var expandIcon    = this.options.expandIcon;
A
Abdullah Almsaeed 已提交
209

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

A
Abdullah Almsaeed 已提交
212
    $(this.element)
213 214
      .children(Selector.header + ', ' + Selector.body + ', ' + Selector.footer)
      .children(Selector.tools)
A
Abdullah Almsaeed 已提交
215 216
      .find('.' + expandIcon)
      .removeClass(expandIcon)
217
      .addClass(collapseIcon);
A
Abdullah Almsaeed 已提交
218

219
    $(this.element).children(Selector.body + ', ' + Selector.footer)
A
Abdullah Almsaeed 已提交
220
      .slideDown(this.options.animationSpeed, function () {
221
        $(this.element).trigger(expandedEvent);
A
Abdullah Almsaeed 已提交
222 223
      }.bind(this))
      .trigger(expandingEvent);
224
  };
A
Abdullah Almsaeed 已提交
225

A
Abdullah Almsaeed 已提交
226
  BoxWidget.prototype.collapse = function () {
227
    var collapsedEvent = $.Event(Event.collapsed);
A
Abdullah Almsaeed 已提交
228
    var collapsingEvent = $.Event(Event.collapsing);
229 230
    var collapseIcon   = this.options.collapseIcon;
    var expandIcon     = this.options.expandIcon;
A
Abdullah Almsaeed 已提交
231

A
Abdullah Almsaeed 已提交
232
    $(this.element)
233 234
      .children(Selector.header + ', ' + Selector.body + ', ' + Selector.footer)
      .children(Selector.tools)
A
Abdullah Almsaeed 已提交
235 236
      .find('.' + collapseIcon)
      .removeClass(collapseIcon)
237
      .addClass(expandIcon);
A
Abdullah Almsaeed 已提交
238

239
    $(this.element).children(Selector.body + ', ' + Selector.footer)
A
Abdullah Almsaeed 已提交
240
      .slideUp(this.options.animationSpeed, function () {
241 242
        $(this.element).addClass(ClassName.collapsed);
        $(this.element).trigger(collapsedEvent);
A
Abdullah Almsaeed 已提交
243 244
      }.bind(this))
      .trigger(expandingEvent);
245
  };
A
Abdullah Almsaeed 已提交
246

A
Abdullah Almsaeed 已提交
247
  BoxWidget.prototype.remove = function () {
248
    var removedEvent = $.Event(Event.removed);
A
Abdullah Almsaeed 已提交
249
    var removingEvent = $.Event(Event.removing);
A
Abdullah Almsaeed 已提交
250

A
Abdullah Almsaeed 已提交
251
    $(this.element).slideUp(this.options.animationSpeed, function () {
252 253
      $(this.element).trigger(removedEvent);
      $(this.element).remove();
A
Abdullah Almsaeed 已提交
254 255
    }.bind(this))
    .trigger(removingEvent);
256
  };
A
Abdullah Almsaeed 已提交
257 258 259

  // Private

A
Abdullah Almsaeed 已提交
260
  BoxWidget.prototype._setUpListeners = function () {
261
    var that = this;
A
Abdullah Almsaeed 已提交
262

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

    $(this.element).on('click', this.options.removeTrigger, function (event) {
270 271 272 273 274
      if (event) event.preventDefault();
      that.remove($(this));
      return false;
    });
  };
A
Abdullah Almsaeed 已提交
275 276 277 278 279

  // Plugin Definition
  // =================
  function Plugin(option) {
    return this.each(function () {
280 281
      var $this = $(this);
      var data  = $this.data(DataKey);
A
Abdullah Almsaeed 已提交
282 283

      if (!data) {
284 285
        var options = $.extend({}, Default, $this.data(), typeof option == 'object' && option);
        $this.data(DataKey, (data = new BoxWidget($this, options)));
A
Abdullah Almsaeed 已提交
286 287 288 289
      }

      if (typeof option == 'string') {
        if (typeof data[option] == 'undefined') {
290
          throw new Error('No method named ' + option);
A
Abdullah Almsaeed 已提交
291
        }
292
        data[option]();
A
Abdullah Almsaeed 已提交
293
      }
294
    });
A
Abdullah Almsaeed 已提交
295 296
  }

297
  var old = $.fn.boxWidget;
A
Abdullah Almsaeed 已提交
298

299 300
  $.fn.boxWidget             = Plugin;
  $.fn.boxWidget.Constructor = BoxWidget;
A
Abdullah Almsaeed 已提交
301 302 303

  // No Conflict Mode
  // ================
A
Abdullah Almsaeed 已提交
304
  $.fn.boxWidget.noConflict = function () {
305 306 307
    $.fn.boxWidget = old;
    return this;
  };
A
Abdullah Almsaeed 已提交
308

A
Abdullah Almsaeed 已提交
309 310
  // BoxWidget Data API
  // ==================
A
Abdullah Almsaeed 已提交
311 312
  $(window).on('load', function () {
    $(Selector.data).each(function () {
313 314 315 316
      Plugin.call($(this));
    });
  });
}(jQuery);
A
Abdullah Almsaeed 已提交
317 318 319 320 321 322 323 324 325 326 327


/* 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 ($) {
328
  'use strict';
A
Abdullah Almsaeed 已提交
329

330
  var DataKey = 'lte.controlsidebar';
A
Abdullah Almsaeed 已提交
331 332 333

  var Default = {
    slide: true
334
  };
A
Abdullah Almsaeed 已提交
335 336 337 338 339 340 341 342 343

  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'
344
  };
A
Abdullah Almsaeed 已提交
345 346 347 348

  var ClassName = {
    open : 'control-sidebar-open',
    fixed: 'fixed'
349
  };
A
Abdullah Almsaeed 已提交
350 351 352 353

  var Event = {
    collapsed: 'collapsed.controlsidebar',
    expanded : 'expanded.controlsidebar'
354
  };
A
Abdullah Almsaeed 已提交
355 356 357 358

  // ControlSidebar Class Definition
  // ===============================
  var ControlSidebar = function (element, options) {
359 360 361
    this.element         = element;
    this.options         = options;
    this.hasBindedResize = false;
A
Abdullah Almsaeed 已提交
362

363 364
    this.init();
  };
A
Abdullah Almsaeed 已提交
365 366 367 368 369

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

373
    this.fix();
A
Abdullah Almsaeed 已提交
374
    $(window).resize(function () {
375 376 377
      this.fix();
    }.bind(this));
  };
A
Abdullah Almsaeed 已提交
378 379

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

382
    this.fix();
A
Abdullah Almsaeed 已提交
383 384

    if (!$(Selector.sidebar).is(Selector.open) && !$('body').is(Selector.open)) {
385
      this.expand();
A
Abdullah Almsaeed 已提交
386
    } else {
387
      this.collapse();
A
Abdullah Almsaeed 已提交
388
    }
389
  };
A
Abdullah Almsaeed 已提交
390 391 392

  ControlSidebar.prototype.expand = function () {
    if (!this.options.slide) {
393
      $('body').addClass(ClassName.open);
A
Abdullah Almsaeed 已提交
394
    } else {
395
      $(Selector.sidebar).addClass(ClassName.open);
A
Abdullah Almsaeed 已提交
396 397
    }

398 399
    $(this.element).trigger($.Event(Event.expanded));
  };
A
Abdullah Almsaeed 已提交
400 401

  ControlSidebar.prototype.collapse = function () {
402 403 404
    $('body, ' + Selector.sidebar).removeClass(ClassName.open);
    $(this.element).trigger($.Event(Event.collapsed));
  };
A
Abdullah Almsaeed 已提交
405 406 407

  ControlSidebar.prototype.fix = function () {
    if ($('body').is(Selector.boxed)) {
408
      this._fixForBoxed($(Selector.bg));
A
Abdullah Almsaeed 已提交
409
    }
410
  };
A
Abdullah Almsaeed 已提交
411 412 413 414 415 416 417

  // Private

  ControlSidebar.prototype._fixForBoxed = function (bg) {
    bg.css({
      position: 'absolute',
      height  : $(Selector.wrapper).height()
418 419
    });
  };
A
Abdullah Almsaeed 已提交
420 421 422 423 424

  // Plugin Definition
  // =================
  function Plugin(option) {
    return this.each(function () {
425 426
      var $this = $(this);
      var data  = $this.data(DataKey);
A
Abdullah Almsaeed 已提交
427 428

      if (!data) {
429 430
        var options = $.extend({}, Default, $this.data(), typeof option == 'object' && option);
        $this.data(DataKey, (data = new ControlSidebar($this, options)));
A
Abdullah Almsaeed 已提交
431 432
      }

433 434
      if (typeof option == 'string') data.toggle();
    });
A
Abdullah Almsaeed 已提交
435 436
  }

437
  var old = $.fn.controlSidebar;
A
Abdullah Almsaeed 已提交
438

439 440
  $.fn.controlSidebar             = Plugin;
  $.fn.controlSidebar.Constructor = ControlSidebar;
A
Abdullah Almsaeed 已提交
441 442 443 444

  // No Conflict Mode
  // ================
  $.fn.controlSidebar.noConflict = function () {
445 446 447
    $.fn.controlSidebar = old;
    return this;
  };
A
Abdullah Almsaeed 已提交
448 449 450 451

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

456
}(jQuery);
A
Abdullah Almsaeed 已提交
457 458


A
Abdullah Almsaeed 已提交
459 460 461
/* DirectChat()
 * ===============
 * Toggles the state of the control sidebar
A
Abdullah Almsaeed 已提交
462
 *
A
Abdullah Almsaeed 已提交
463 464
 * @Usage: $('#my-chat-box').directChat()
 *         or add [data-widget="direct-chat"] to the trigger
A
Abdullah Almsaeed 已提交
465 466
 */
+function ($) {
467
  'use strict';
A
Abdullah Almsaeed 已提交
468

469
  var DataKey = 'lte.directchat';
A
Abdullah Almsaeed 已提交
470

A
Abdullah Almsaeed 已提交
471 472 473
  var Selector = {
    data: '[data-widget="chat-pane-toggle"]',
    box : '.direct-chat'
474
  };
A
Abdullah Almsaeed 已提交
475

A
Abdullah Almsaeed 已提交
476 477
  var ClassName = {
    open: 'direct-chat-contacts-open'
478
  };
A
Abdullah Almsaeed 已提交
479 480 481 482

  // DirectChat Class Definition
  // ===========================
  var DirectChat = function (element) {
483 484
    this.element = element;
  };
A
Abdullah Almsaeed 已提交
485 486

  DirectChat.prototype.toggle = function ($trigger) {
487 488
    $trigger.parents(Selector.box).first().toggleClass(ClassName.open);
  };
A
Abdullah Almsaeed 已提交
489 490 491 492 493

  // Plugin Definition
  // =================
  function Plugin(option) {
    return this.each(function () {
494 495
      var $this = $(this);
      var data  = $this.data(DataKey);
A
Abdullah Almsaeed 已提交
496 497

      if (!data) {
498
        $this.data(DataKey, (data = new DirectChat($this)));
A
Abdullah Almsaeed 已提交
499 500
      }

501 502
      if (typeof option == 'string') data.toggle($this);
    });
A
Abdullah Almsaeed 已提交
503 504
  }

505
  var old = $.fn.directChat;
A
Abdullah Almsaeed 已提交
506

507 508
  $.fn.directChat             = Plugin;
  $.fn.directChat.Constructor = DirectChat;
A
Abdullah Almsaeed 已提交
509 510 511 512

  // No Conflict Mode
  // ================
  $.fn.directChat.noConflict = function () {
513 514 515
    $.fn.directChat = old;
    return this;
  };
A
Abdullah Almsaeed 已提交
516 517 518 519

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

524
}(jQuery);
A
Abdullah Almsaeed 已提交
525 526 527 528 529 530 531 532 533 534 535 536


/* 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 ($) {
537
  'use strict';
A
Abdullah Almsaeed 已提交
538

539
  var DataKey = 'lte.layout';
A
Abdullah Almsaeed 已提交
540 541 542 543

  var Default = {
    slimscroll : true,
    resetHeight: true
544
  };
A
Abdullah Almsaeed 已提交
545 546 547 548 549 550 551 552 553 554 555 556

  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'
557
  };
A
Abdullah Almsaeed 已提交
558 559

  var ClassName = {
A
Abdullah Almsaeed 已提交
560 561
    fixed         : 'fixed',
    holdTransition: 'hold-transition'
562
  };
A
Abdullah Almsaeed 已提交
563

A
Abdullah Almsaeed 已提交
564
  var Layout = function (options) {
565 566 567 568
    this.options      = options;
    this.bindedResize = false;
    this.activate();
  };
A
Abdullah Almsaeed 已提交
569

A
Abdullah Almsaeed 已提交
570
  Layout.prototype.activate = function () {
571 572
    this.fix();
    this.fixSidebar();
A
Abdullah Almsaeed 已提交
573

574
    $('body').removeClass(ClassName.holdTransition);
A
Abdullah Almsaeed 已提交
575 576 577 578 579

    if (this.options.resetHeight) {
      $('body, html, ' + Selector.wrapper).css({
        'height'    : 'auto',
        'min-height': '100%'
580
      });
A
Abdullah Almsaeed 已提交
581 582 583 584
    }

    if (!this.bindedResize) {
      $(window).resize(function () {
585 586
        this.fix();
        this.fixSidebar();
A
Abdullah Almsaeed 已提交
587 588

        $(Selector.logo + ', ' + Selector.sidebar).one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function () {
589 590 591 592
          this.fix();
          this.fixSidebar();
        }.bind(this));
      }.bind(this));
A
Abdullah Almsaeed 已提交
593

594
      this.bindedResize = true;
A
Abdullah Almsaeed 已提交
595 596 597
    }

    $(Selector.sidebarMenu).on('expanded.tree', function () {
598 599 600
      this.fix();
      this.fixSidebar();
    }.bind(this));
A
Abdullah Almsaeed 已提交
601 602

    $(Selector.sidebarMenu).on('collapsed.tree', function () {
603 604 605 606
      this.fix();
      this.fixSidebar();
    }.bind(this));
  };
A
Abdullah Almsaeed 已提交
607

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

A
Abdullah Almsaeed 已提交
612
    // Get window height and the wrapper height
A
Abdullah Almsaeed 已提交
613 614 615
    var footerHeight = $(Selector.mainFooter).outerHeight() || 0;
    var headerHeight  = $(Selector.mainHeader).outerHeight() || 0;
    var neg           = headerHeight + footerHeight;
616 617
    var windowHeight  = $(window).height();
    var sidebarHeight = $(Selector.sidebar).height() || 0;
A
Abdullah Almsaeed 已提交
618 619 620 621

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

626
      if (windowHeight >= sidebarHeight + headerHeight) {
627 628
        $(Selector.contentWrapper).css('min-height', windowHeight - neg);
        postSetHeight = windowHeight - neg;
A
Abdullah Almsaeed 已提交
629
      } else {
630 631
        $(Selector.contentWrapper).css('min-height', sidebarHeight);
        postSetHeight = sidebarHeight;
A
Abdullah Almsaeed 已提交
632 633 634
      }

      // Fix for the control sidebar height
635
      var $controlSidebar = $(Selector.controlSidebar);
A
Abdullah Almsaeed 已提交
636 637
      if (typeof $controlSidebar !== 'undefined') {
        if ($controlSidebar.height() > postSetHeight)
638
          $(Selector.contentWrapper).css('min-height', $controlSidebar.height());
A
Abdullah Almsaeed 已提交
639
      }
A
Abdullah Almsaeed 已提交
640
    }
641
  };
A
Abdullah Almsaeed 已提交
642

A
Abdullah Almsaeed 已提交
643 644 645 646
  Layout.prototype.fixSidebar = function () {
    // Make sure the body tag has the .fixed class
    if (!$('body').hasClass(ClassName.fixed)) {
      if (typeof $.fn.slimScroll !== 'undefined') {
647
        $(Selector.sidebar).slimScroll({ destroy: true }).height('auto');
A
Abdullah Almsaeed 已提交
648
      }
649
      return;
A
Abdullah Almsaeed 已提交
650
    }
A
Abdullah Almsaeed 已提交
651

A
Abdullah Almsaeed 已提交
652 653 654 655
    // Enable slimscroll for fixed layout
    if (this.options.slimscroll) {
      if (typeof $.fn.slimScroll !== 'undefined') {
        // Destroy if it exists
656
        // $(Selector.sidebar).slimScroll({ destroy: true }).height('auto')
A
Abdullah Almsaeed 已提交
657

A
Abdullah Almsaeed 已提交
658 659
        // Add slimscroll
        $(Selector.sidebar).slimScroll({
660 661
          height: ($(window).height() - $(Selector.mainHeader).height()) + 'px'
        });
A
Abdullah Almsaeed 已提交
662 663
      }
    }
664
  };
A
Abdullah Almsaeed 已提交
665

A
Abdullah Almsaeed 已提交
666 667 668 669
  // Plugin Definition
  // =================
  function Plugin(option) {
    return this.each(function () {
670 671
      var $this = $(this);
      var data  = $this.data(DataKey);
A
Abdullah Almsaeed 已提交
672 673

      if (!data) {
674 675
        var options = $.extend({}, Default, $this.data(), typeof option === 'object' && option);
        $this.data(DataKey, (data = new Layout(options)));
A
Abdullah Almsaeed 已提交
676 677 678 679
      }

      if (typeof option === 'string') {
        if (typeof data[option] === 'undefined') {
680
          throw new Error('No method named ' + option);
A
Abdullah Almsaeed 已提交
681
        }
682
        data[option]();
A
Abdullah Almsaeed 已提交
683
      }
684
    });
A
Abdullah Almsaeed 已提交
685 686
  }

687
  var old = $.fn.layout;
A
Abdullah Almsaeed 已提交
688

689 690
  $.fn.layout            = Plugin;
  $.fn.layout.Constuctor = Layout;
A
Abdullah Almsaeed 已提交
691 692 693 694

  // No conflict mode
  // ================
  $.fn.layout.noConflict = function () {
695 696 697
    $.fn.layout = old;
    return this;
  };
A
Abdullah Almsaeed 已提交
698 699 700 701

  // Layout DATA-API
  // ===============
  $(window).on('load', function () {
702 703 704
    Plugin.call($('body'));
  });
}(jQuery);
A
Abdullah Almsaeed 已提交
705 706 707 708 709 710 711 712 713 714 715


/* 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 ($) {
716
  'use strict';
A
Abdullah Almsaeed 已提交
717

718
  var DataKey = 'lte.pushmenu';
A
Abdullah Almsaeed 已提交
719 720 721 722 723

  var Default = {
    collapseScreenSize   : 767,
    expandOnHover        : false,
    expandTransitionDelay: 200
724
  };
A
Abdullah Almsaeed 已提交
725 726 727 728 729 730 731 732 733 734 735

  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'
736
  };
A
Abdullah Almsaeed 已提交
737 738 739 740 741 742 743 744

  var ClassName = {
    collapsed    : 'sidebar-collapse',
    open         : 'sidebar-open',
    mini         : 'sidebar-mini',
    expanded     : 'sidebar-expanded-on-hover',
    expandFeature: 'sidebar-mini-expand-feature',
    layoutFixed  : 'fixed'
745
  };
A
Abdullah Almsaeed 已提交
746 747 748 749

  var Event = {
    expanded : 'expanded.pushMenu',
    collapsed: 'collapsed.pushMenu'
750
  };
A
Abdullah Almsaeed 已提交
751 752 753 754

  // PushMenu Class Definition
  // =========================
  var PushMenu = function (options) {
755 756 757
    this.options = options;
    this.init();
  };
A
Abdullah Almsaeed 已提交
758 759 760 761

  PushMenu.prototype.init = function () {
    if (this.options.expandOnHover
      || ($('body').is(Selector.mini + Selector.layoutFixed))) {
762 763
      this.expandOnHover();
      $('body').addClass(ClassName.expandFeature);
A
Abdullah Almsaeed 已提交
764 765 766 767 768
    }

    $(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)) {
769
        this.close();
A
Abdullah Almsaeed 已提交
770
      }
771
    }.bind(this));
A
Abdullah Almsaeed 已提交
772 773 774

    // __Fix for android devices
    $(Selector.searchInput).click(function (e) {
775 776 777
      e.stopPropagation();
    });
  };
A
Abdullah Almsaeed 已提交
778

A
Abdullah Almsaeed 已提交
779
  PushMenu.prototype.toggle = function () {
780 781
    var windowWidth = $(window).width();
    var isOpen      = !$('body').hasClass(ClassName.collapsed);
A
Abdullah Almsaeed 已提交
782

A
Abdullah Almsaeed 已提交
783
    if (windowWidth <= this.options.collapseScreenSize) {
784
      isOpen = $('body').hasClass(ClassName.open);
A
Abdullah Almsaeed 已提交
785
    }
A
Abdullah Almsaeed 已提交
786

A
Abdullah Almsaeed 已提交
787
    if (!isOpen) {
788
      this.open();
A
Abdullah Almsaeed 已提交
789
    } else {
790
      this.close();
A
Abdullah Almsaeed 已提交
791
    }
792
  };
A
Abdullah Almsaeed 已提交
793

A
Abdullah Almsaeed 已提交
794
  PushMenu.prototype.open = function () {
795
    var windowWidth = $(window).width();
A
Abdullah Almsaeed 已提交
796

A
Abdullah Almsaeed 已提交
797 798
    if (windowWidth > this.options.collapseScreenSize) {
      $('body').removeClass(ClassName.collapsed)
799
        .trigger($.Event(Event.expanded));
A
Abdullah Almsaeed 已提交
800 801 802
    }
    else {
      $('body').addClass(ClassName.open)
803
        .trigger($.Event(Event.expanded));
A
Abdullah Almsaeed 已提交
804
    }
805
  };
A
Abdullah Almsaeed 已提交
806

A
Abdullah Almsaeed 已提交
807
  PushMenu.prototype.close = function () {
808
    var windowWidth = $(window).width();
A
Abdullah Almsaeed 已提交
809 810
    if (windowWidth > this.options.collapseScreenSize) {
      $('body').addClass(ClassName.collapsed)
811
        .trigger($.Event(Event.collapsed));
A
Abdullah Almsaeed 已提交
812 813
    } else {
      $('body').removeClass(ClassName.open + ' ' + ClassName.collapsed)
814
        .trigger($.Event(Event.collapsed));
A
Abdullah Almsaeed 已提交
815
    }
816
  };
A
Abdullah Almsaeed 已提交
817

A
Abdullah Almsaeed 已提交
818 819 820 821
  PushMenu.prototype.expandOnHover = function () {
    $(Selector.mainSidebar).hover(function () {
      if ($('body').is(Selector.mini + Selector.collapsed)
        && $(window).width() > this.options.collapseScreenSize) {
822
        this.expand();
A
Abdullah Almsaeed 已提交
823 824 825
      }
    }.bind(this), function () {
      if ($('body').is(Selector.expanded)) {
826
        this.collapse();
A
Abdullah Almsaeed 已提交
827
      }
828 829
    }.bind(this));
  };
A
Abdullah Almsaeed 已提交
830

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

A
Abdullah Almsaeed 已提交
838 839 840
  PushMenu.prototype.collapse = function () {
    setTimeout(function () {
      $('body').removeClass(ClassName.expanded)
841 842 843
        .addClass(ClassName.collapsed);
    }, this.options.expandTransitionDelay);
  };
A
Abdullah Almsaeed 已提交
844

A
Abdullah Almsaeed 已提交
845 846
  // PushMenu Plugin Definition
  // ==========================
A
Abdullah Almsaeed 已提交
847 848
  function Plugin(option) {
    return this.each(function () {
849 850
      var $this = $(this);
      var data  = $this.data(DataKey);
A
Abdullah Almsaeed 已提交
851 852

      if (!data) {
853 854
        var options = $.extend({}, Default, $this.data(), typeof option == 'object' && option);
        $this.data(DataKey, (data = new PushMenu(options)));
A
Abdullah Almsaeed 已提交
855 856
      }

857 858
      if (option === 'toggle') data.toggle();
    });
A
Abdullah Almsaeed 已提交
859 860
  }

861
  var old = $.fn.pushMenu;
A
Abdullah Almsaeed 已提交
862

863 864
  $.fn.pushMenu             = Plugin;
  $.fn.pushMenu.Constructor = PushMenu;
A
Abdullah Almsaeed 已提交
865 866 867

  // No Conflict Mode
  // ================
A
Abdullah Almsaeed 已提交
868
  $.fn.pushMenu.noConflict = function () {
869 870 871
    $.fn.pushMenu = old;
    return this;
  };
A
Abdullah Almsaeed 已提交
872

A
Abdullah Almsaeed 已提交
873 874 875
  // Data API
  // ========
  $(document).on('click', Selector.button, function (e) {
876 877 878
    e.preventDefault();
    Plugin.call($(this), 'toggle');
  });
A
Abdullah Almsaeed 已提交
879
  $(window).on('load', function () {
880 881 882
    Plugin.call($(Selector.button));
  });
}(jQuery);
A
Abdullah Almsaeed 已提交
883 884 885 886 887 888 889 890 891 892 893


/* 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 ($) {
894
  'use strict';
A
Abdullah Almsaeed 已提交
895

896
  var DataKey = 'lte.todolist';
A
Abdullah Almsaeed 已提交
897 898

  var Default = {
A
Abdullah Almsaeed 已提交
899
    onCheck  : function (item) {
900
      return item;
A
Abdullah Almsaeed 已提交
901
    },
A
Abdullah Almsaeed 已提交
902
    onUnCheck: function (item) {
903
      return item;
A
Abdullah Almsaeed 已提交
904
    }
905
  };
A
Abdullah Almsaeed 已提交
906 907 908

  var Selector = {
    data: '[data-widget="todo-list"]'
909
  };
A
Abdullah Almsaeed 已提交
910 911 912

  var ClassName = {
    done: 'done'
913
  };
A
Abdullah Almsaeed 已提交
914 915 916 917

  // TodoList Class Definition
  // =========================
  var TodoList = function (element, options) {
918 919
    this.element = element;
    this.options = options;
A
Abdullah Almsaeed 已提交
920

921 922
    this._setUpListeners();
  };
A
Abdullah Almsaeed 已提交
923 924

  TodoList.prototype.toggle = function (item) {
925
    item.parents(Selector.li).first().toggleClass(ClassName.done);
A
Abdullah Almsaeed 已提交
926
    if (!item.prop('checked')) {
927 928
      this.unCheck(item);
      return;
A
Abdullah Almsaeed 已提交
929 930
    }

931 932
    this.check(item);
  };
A
Abdullah Almsaeed 已提交
933 934

  TodoList.prototype.check = function (item) {
935 936
    this.options.onCheck.call(item);
  };
A
Abdullah Almsaeed 已提交
937 938

  TodoList.prototype.unCheck = function (item) {
939 940
    this.options.onUnCheck.call(item);
  };
A
Abdullah Almsaeed 已提交
941 942 943 944

  // Private

  TodoList.prototype._setUpListeners = function () {
945
    var that = this;
A
Abdullah Almsaeed 已提交
946
    $(this.element).on('change ifChanged', 'input:checkbox', function () {
947 948 949
      that.toggle($(this));
    });
  };
A
Abdullah Almsaeed 已提交
950 951 952 953 954

  // Plugin Definition
  // =================
  function Plugin(option) {
    return this.each(function () {
955 956
      var $this = $(this);
      var data  = $this.data(DataKey);
A
Abdullah Almsaeed 已提交
957 958

      if (!data) {
959 960
        var options = $.extend({}, Default, $this.data(), typeof option == 'object' && option);
        $this.data(DataKey, (data = new TodoList($this, options)));
A
Abdullah Almsaeed 已提交
961 962 963 964
      }

      if (typeof data == 'string') {
        if (typeof data[option] == 'undefined') {
965
          throw new Error('No method named ' + option);
A
Abdullah Almsaeed 已提交
966
        }
967
        data[option]();
A
Abdullah Almsaeed 已提交
968
      }
969
    });
A
Abdullah Almsaeed 已提交
970 971
  }

972
  var old = $.fn.todoList;
A
Abdullah Almsaeed 已提交
973

974 975
  $.fn.todoList             = Plugin;
  $.fn.todoList.Constructor = TodoList;
A
Abdullah Almsaeed 已提交
976 977 978 979

  // No Conflict Mode
  // ================
  $.fn.todoList.noConflict = function () {
980 981 982
    $.fn.todoList = old;
    return this;
  };
A
Abdullah Almsaeed 已提交
983 984 985 986 987

  // TodoList Data API
  // =================
  $(window).on('load', function () {
    $(Selector.data).each(function () {
988 989 990
      Plugin.call($(this));
    });
  });
A
Abdullah Almsaeed 已提交
991

992
}(jQuery);
A
Abdullah Almsaeed 已提交
993 994


A
Abdullah Almsaeed 已提交
995 996 997 998
/* Tree()
 * ======
 * Converts a nested list into a multilevel
 * tree view menu.
A
Abdullah Almsaeed 已提交
999
 *
A
Abdullah Almsaeed 已提交
1000 1001 1002
 * @Usage: $('.my-menu').tree(options)
 *         or add [data-widget="tree"] to the ul element
 *         Pass any option as data-option="value"
A
Abdullah Almsaeed 已提交
1003 1004
 */
+function ($) {
1005
  'use strict';
A
Abdullah Almsaeed 已提交
1006

1007
  var DataKey = 'lte.tree';
A
Abdullah Almsaeed 已提交
1008 1009 1010 1011 1012 1013

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

  var Selector = {
A
Abdullah Almsaeed 已提交
1017 1018 1019 1020 1021 1022 1023
    tree        : '.tree',
    treeview    : '.treeview',
    treeviewMenu: '.treeview-menu',
    open        : '.menu-open, .active',
    li          : 'li',
    data        : '[data-widget="tree"]',
    active      : '.active'
1024
  };
A
Abdullah Almsaeed 已提交
1025 1026

  var ClassName = {
A
Abdullah Almsaeed 已提交
1027 1028
    open: 'menu-open',
    tree: 'tree'
1029
  };
A
Abdullah Almsaeed 已提交
1030

A
Abdullah Almsaeed 已提交
1031 1032 1033
  var Event = {
    collapsed: 'collapsed.tree',
    expanded : 'expanded.tree'
1034
  };
A
Abdullah Almsaeed 已提交
1035 1036 1037 1038

  // Tree Class Definition
  // =====================
  var Tree = function (element, options) {
1039 1040
    this.element = element;
    this.options = options;
A
Abdullah Almsaeed 已提交
1041

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

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

1046 1047
    this._setUpListeners();
  };
A
Abdullah Almsaeed 已提交
1048

A
Abdullah Almsaeed 已提交
1049
  Tree.prototype.toggle = function (link, event) {
1050 1051 1052
    var treeviewMenu = link.next(Selector.treeviewMenu);
    var parentLi     = link.parent();
    var isOpen       = parentLi.hasClass(ClassName.open);
A
Abdullah Almsaeed 已提交
1053 1054

    if (!parentLi.is(Selector.treeview)) {
1055
      return;
A
Abdullah Almsaeed 已提交
1056 1057
    }

1058
    if (!this.options.followLink || link.attr('href') === '#') {
1059
      event.preventDefault();
A
Abdullah Almsaeed 已提交
1060 1061 1062
    }

    if (isOpen) {
1063
      this.collapse(treeviewMenu, parentLi);
A
Abdullah Almsaeed 已提交
1064
    } else {
1065
      this.expand(treeviewMenu, parentLi);
A
Abdullah Almsaeed 已提交
1066
    }
1067
  };
A
Abdullah Almsaeed 已提交
1068 1069

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

    if (this.options.accordion) {
1073 1074 1075
      var openMenuLi = parent.siblings(Selector.open);
      var openTree   = openMenuLi.children(Selector.treeviewMenu);
      this.collapse(openTree, openMenuLi);
A
Abdullah Almsaeed 已提交
1076 1077
    }

1078
    parent.addClass(ClassName.open);
A
Abdullah Almsaeed 已提交
1079
    tree.slideDown(this.options.animationSpeed, function () {
1080
     setTimeout(() => $(this.element).trigger(expandedEvent),0) 
1081 1082
    }.bind(this));
  };
A
Abdullah Almsaeed 已提交
1083 1084

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

1087
    //tree.find(Selector.open).removeClass(ClassName.open);
1088
    parentLi.removeClass(ClassName.open);
D
Daniel Vilanova Yamuza 已提交
1089
    tree.slideUp(this.options.animationSpeed, function () {
1090
      //tree.find(Selector.open + ' > ' + Selector.treeview).slideUp();
1091
      setTimeout(() => $(this.element).trigger(collapsedEvent), 0);
1092 1093
    }.bind(this));
  };
A
Abdullah Almsaeed 已提交
1094 1095

  // Private
1096

A
Abdullah Almsaeed 已提交
1097
  Tree.prototype._setUpListeners = function () {
1098
    var that = this;
A
Abdullah Almsaeed 已提交
1099 1100

    $(this.element).on('click', this.options.trigger, function (event) {
1101 1102 1103
      that.toggle($(this), event);
    });
  };
A
Abdullah Almsaeed 已提交
1104 1105 1106 1107 1108

  // Plugin Definition
  // =================
  function Plugin(option) {
    return this.each(function () {
1109 1110
      var $this = $(this);
      var data  = $this.data(DataKey);
A
Abdullah Almsaeed 已提交
1111 1112

      if (!data) {
1113 1114
        var options = $.extend({}, Default, $this.data(), typeof option == 'object' && option);
        $this.data(DataKey, new Tree($this, options));
A
Abdullah Almsaeed 已提交
1115
      }
1116
    });
A
Abdullah Almsaeed 已提交
1117 1118
  }

1119
  var old = $.fn.tree;
A
Abdullah Almsaeed 已提交
1120

1121 1122
  $.fn.tree             = Plugin;
  $.fn.tree.Constructor = Tree;
A
Abdullah Almsaeed 已提交
1123 1124 1125

  // No Conflict Mode
  // ================
A
Abdullah Almsaeed 已提交
1126
  $.fn.tree.noConflict = function () {
1127 1128 1129
    $.fn.tree = old;
    return this;
  };
A
Abdullah Almsaeed 已提交
1130

A
Abdullah Almsaeed 已提交
1131 1132 1133 1134
  // Tree Data API
  // =============
  $(window).on('load', function () {
    $(Selector.data).each(function () {
1135 1136 1137
      Plugin.call($(this));
    });
  });
A
Abdullah Almsaeed 已提交
1138

1139
}(jQuery);