adminlte.js 29.0 KB
Newer Older
A
Abdullah Almsaeed 已提交
1 2 3 4 5 6
/*! 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.
*
R
REJack 已提交
7 8
* @author Colorlib
* @support <https://github.com/ColorlibHQ/AdminLTE/issues>
R
REJack 已提交
9
* @version 2.4.16-pre
R
REJack 已提交
10
* @repository git://github.com/ColorlibHQ/AdminLTE.git
A
Abdullah Almsaeed 已提交
11 12 13 14 15 16 17 18
* @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 已提交
19 20 21
/* BoxRefresh()
 * =========
 * Adds AJAX content control to a box.
A
Abdullah Almsaeed 已提交
22
 *
A
Abdullah Almsaeed 已提交
23 24 25
 * @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 已提交
26 27
 */
+function ($) {
28
  'use strict';
A
Abdullah Almsaeed 已提交
29

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

  var Default = {
A
Abdullah Almsaeed 已提交
33 34 35 36 37 38 39 40 41 42
    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) {
43
      return response;
A
Abdullah Almsaeed 已提交
44
    }
45
  };
A
Abdullah Almsaeed 已提交
46 47

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


A
Abdullah Almsaeed 已提交
140 141 142
/* BoxWidget()
 * ======
 * Adds box widget functions to boxes.
A
Abdullah Almsaeed 已提交
143
 *
A
Abdullah Almsaeed 已提交
144 145 146
 * @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 已提交
147 148
 */
+function ($) {
149
  'use strict';
A
Abdullah Almsaeed 已提交
150

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  // Private

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

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

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

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

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

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

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

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

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

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


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

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

  var Default = {
R
REJack 已提交
332
    controlsidebarSlide: true
333
  };
A
Abdullah Almsaeed 已提交
334 335 336 337 338 339 340 341 342

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

  var ClassName = {
R
REJack 已提交
346 347
    open: 'control-sidebar-open',
    transition: 'control-sidebar-hold-transition',
A
Abdullah Almsaeed 已提交
348
    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

  ControlSidebar.prototype.expand = function () {
392
    $(Selector.sidebar).show();
R
REJack 已提交
393 394 395 396 397
    if (!this.options.controlsidebarSlide) {
      $('body').addClass(ClassName.transition).addClass(ClassName.open).delay(50).queue(function(){
        $('body').removeClass(ClassName.transition);
        $(this).dequeue()
      })
A
Abdullah Almsaeed 已提交
398
    } else {
399
      $(Selector.sidebar).addClass(ClassName.open);
A
Abdullah Almsaeed 已提交
400 401
    }

402

403 404
    $(this.element).trigger($.Event(Event.expanded));
  };
A
Abdullah Almsaeed 已提交
405 406

  ControlSidebar.prototype.collapse = function () {
R
REJack 已提交
407 408 409 410 411 412 413 414
    if (!this.options.controlsidebarSlide) {
      $('body').addClass(ClassName.transition).removeClass(ClassName.open).delay(50).queue(function(){
        $('body').removeClass(ClassName.transition);
        $(this).dequeue()
      })
    } else {
      $(Selector.sidebar).removeClass(ClassName.open);
    }
415
    $(Selector.sidebar).fadeOut();
416 417
    $(this.element).trigger($.Event(Event.collapsed));
  };
A
Abdullah Almsaeed 已提交
418 419 420

  ControlSidebar.prototype.fix = function () {
    if ($('body').is(Selector.boxed)) {
421
      this._fixForBoxed($(Selector.bg));
A
Abdullah Almsaeed 已提交
422
    }
423
  };
A
Abdullah Almsaeed 已提交
424 425 426 427 428 429 430

  // Private

  ControlSidebar.prototype._fixForBoxed = function (bg) {
    bg.css({
      position: 'absolute',
      height  : $(Selector.wrapper).height()
431 432
    });
  };
A
Abdullah Almsaeed 已提交
433 434 435 436 437

  // Plugin Definition
  // =================
  function Plugin(option) {
    return this.each(function () {
438 439
      var $this = $(this);
      var data  = $this.data(DataKey);
A
Abdullah Almsaeed 已提交
440 441

      if (!data) {
442 443
        var options = $.extend({}, Default, $this.data(), typeof option == 'object' && option);
        $this.data(DataKey, (data = new ControlSidebar($this, options)));
A
Abdullah Almsaeed 已提交
444 445
      }

446 447
      if (typeof option == 'string') data.toggle();
    });
A
Abdullah Almsaeed 已提交
448 449
  }

450
  var old = $.fn.controlSidebar;
A
Abdullah Almsaeed 已提交
451

452 453
  $.fn.controlSidebar             = Plugin;
  $.fn.controlSidebar.Constructor = ControlSidebar;
A
Abdullah Almsaeed 已提交
454 455 456 457

  // No Conflict Mode
  // ================
  $.fn.controlSidebar.noConflict = function () {
458 459 460
    $.fn.controlSidebar = old;
    return this;
  };
A
Abdullah Almsaeed 已提交
461 462 463 464

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

469
}(jQuery);
A
Abdullah Almsaeed 已提交
470 471


A
Abdullah Almsaeed 已提交
472 473 474
/* DirectChat()
 * ===============
 * Toggles the state of the control sidebar
A
Abdullah Almsaeed 已提交
475
 *
A
Abdullah Almsaeed 已提交
476 477
 * @Usage: $('#my-chat-box').directChat()
 *         or add [data-widget="direct-chat"] to the trigger
A
Abdullah Almsaeed 已提交
478 479
 */
+function ($) {
480
  'use strict';
A
Abdullah Almsaeed 已提交
481

482
  var DataKey = 'lte.directchat';
A
Abdullah Almsaeed 已提交
483

A
Abdullah Almsaeed 已提交
484 485 486
  var Selector = {
    data: '[data-widget="chat-pane-toggle"]',
    box : '.direct-chat'
487
  };
A
Abdullah Almsaeed 已提交
488

A
Abdullah Almsaeed 已提交
489 490
  var ClassName = {
    open: 'direct-chat-contacts-open'
491
  };
A
Abdullah Almsaeed 已提交
492 493 494 495

  // DirectChat Class Definition
  // ===========================
  var DirectChat = function (element) {
496 497
    this.element = element;
  };
A
Abdullah Almsaeed 已提交
498 499

  DirectChat.prototype.toggle = function ($trigger) {
500 501
    $trigger.parents(Selector.box).first().toggleClass(ClassName.open);
  };
A
Abdullah Almsaeed 已提交
502 503 504 505 506

  // Plugin Definition
  // =================
  function Plugin(option) {
    return this.each(function () {
507 508
      var $this = $(this);
      var data  = $this.data(DataKey);
A
Abdullah Almsaeed 已提交
509 510

      if (!data) {
511
        $this.data(DataKey, (data = new DirectChat($this)));
A
Abdullah Almsaeed 已提交
512 513
      }

514 515
      if (typeof option == 'string') data.toggle($this);
    });
A
Abdullah Almsaeed 已提交
516 517
  }

518
  var old = $.fn.directChat;
A
Abdullah Almsaeed 已提交
519

520 521
  $.fn.directChat             = Plugin;
  $.fn.directChat.Constructor = DirectChat;
A
Abdullah Almsaeed 已提交
522 523 524 525

  // No Conflict Mode
  // ================
  $.fn.directChat.noConflict = function () {
526 527 528
    $.fn.directChat = old;
    return this;
  };
A
Abdullah Almsaeed 已提交
529 530 531 532

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

537
}(jQuery);
A
Abdullah Almsaeed 已提交
538 539 540 541 542 543 544 545 546 547 548


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

551
  var DataKey = 'lte.pushmenu';
A
Abdullah Almsaeed 已提交
552 553 554 555 556

  var Default = {
    collapseScreenSize   : 767,
    expandOnHover        : false,
    expandTransitionDelay: 200
557
  };
A
Abdullah Almsaeed 已提交
558 559 560 561 562 563 564 565 566 567 568

  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'
569
  };
A
Abdullah Almsaeed 已提交
570 571 572 573 574 575 576 577

  var ClassName = {
    collapsed    : 'sidebar-collapse',
    open         : 'sidebar-open',
    mini         : 'sidebar-mini',
    expanded     : 'sidebar-expanded-on-hover',
    expandFeature: 'sidebar-mini-expand-feature',
    layoutFixed  : 'fixed'
578
  };
A
Abdullah Almsaeed 已提交
579 580 581 582

  var Event = {
    expanded : 'expanded.pushMenu',
    collapsed: 'collapsed.pushMenu'
583
  };
A
Abdullah Almsaeed 已提交
584 585 586 587

  // PushMenu Class Definition
  // =========================
  var PushMenu = function (options) {
588 589 590
    this.options = options;
    this.init();
  };
A
Abdullah Almsaeed 已提交
591 592 593 594

  PushMenu.prototype.init = function () {
    if (this.options.expandOnHover
      || ($('body').is(Selector.mini + Selector.layoutFixed))) {
595 596
      this.expandOnHover();
      $('body').addClass(ClassName.expandFeature);
A
Abdullah Almsaeed 已提交
597 598 599 600 601
    }

    $(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)) {
602
        this.close();
A
Abdullah Almsaeed 已提交
603
      }
604
    }.bind(this));
A
Abdullah Almsaeed 已提交
605 606 607

    // __Fix for android devices
    $(Selector.searchInput).click(function (e) {
608 609 610
      e.stopPropagation();
    });
  };
A
Abdullah Almsaeed 已提交
611

A
Abdullah Almsaeed 已提交
612
  PushMenu.prototype.toggle = function () {
613 614
    var windowWidth = $(window).width();
    var isOpen      = !$('body').hasClass(ClassName.collapsed);
A
Abdullah Almsaeed 已提交
615

A
Abdullah Almsaeed 已提交
616
    if (windowWidth <= this.options.collapseScreenSize) {
617
      isOpen = $('body').hasClass(ClassName.open);
A
Abdullah Almsaeed 已提交
618
    }
A
Abdullah Almsaeed 已提交
619

A
Abdullah Almsaeed 已提交
620
    if (!isOpen) {
621
      this.open();
A
Abdullah Almsaeed 已提交
622
    } else {
623
      this.close();
A
Abdullah Almsaeed 已提交
624
    }
625
  };
A
Abdullah Almsaeed 已提交
626

A
Abdullah Almsaeed 已提交
627
  PushMenu.prototype.open = function () {
628
    var windowWidth = $(window).width();
A
Abdullah Almsaeed 已提交
629

A
Abdullah Almsaeed 已提交
630 631
    if (windowWidth > this.options.collapseScreenSize) {
      $('body').removeClass(ClassName.collapsed)
632
        .trigger($.Event(Event.expanded));
A
Abdullah Almsaeed 已提交
633 634 635
    }
    else {
      $('body').addClass(ClassName.open)
636
        .trigger($.Event(Event.expanded));
A
Abdullah Almsaeed 已提交
637
    }
638
  };
A
Abdullah Almsaeed 已提交
639

A
Abdullah Almsaeed 已提交
640
  PushMenu.prototype.close = function () {
641
    var windowWidth = $(window).width();
A
Abdullah Almsaeed 已提交
642 643
    if (windowWidth > this.options.collapseScreenSize) {
      $('body').addClass(ClassName.collapsed)
644
        .trigger($.Event(Event.collapsed));
A
Abdullah Almsaeed 已提交
645 646
    } else {
      $('body').removeClass(ClassName.open + ' ' + ClassName.collapsed)
647
        .trigger($.Event(Event.collapsed));
A
Abdullah Almsaeed 已提交
648
    }
649
  };
A
Abdullah Almsaeed 已提交
650

A
Abdullah Almsaeed 已提交
651 652 653 654
  PushMenu.prototype.expandOnHover = function () {
    $(Selector.mainSidebar).hover(function () {
      if ($('body').is(Selector.mini + Selector.collapsed)
        && $(window).width() > this.options.collapseScreenSize) {
655
        this.expand();
A
Abdullah Almsaeed 已提交
656 657 658
      }
    }.bind(this), function () {
      if ($('body').is(Selector.expanded)) {
659
        this.collapse();
A
Abdullah Almsaeed 已提交
660
      }
661 662
    }.bind(this));
  };
A
Abdullah Almsaeed 已提交
663

A
Abdullah Almsaeed 已提交
664 665 666
  PushMenu.prototype.expand = function () {
    setTimeout(function () {
      $('body').removeClass(ClassName.collapsed)
667 668 669
        .addClass(ClassName.expanded);
    }, this.options.expandTransitionDelay);
  };
A
Abdullah Almsaeed 已提交
670

A
Abdullah Almsaeed 已提交
671 672 673
  PushMenu.prototype.collapse = function () {
    setTimeout(function () {
      $('body').removeClass(ClassName.expanded)
674 675 676
        .addClass(ClassName.collapsed);
    }, this.options.expandTransitionDelay);
  };
A
Abdullah Almsaeed 已提交
677

A
Abdullah Almsaeed 已提交
678 679
  // PushMenu Plugin Definition
  // ==========================
A
Abdullah Almsaeed 已提交
680 681
  function Plugin(option) {
    return this.each(function () {
682 683
      var $this = $(this);
      var data  = $this.data(DataKey);
A
Abdullah Almsaeed 已提交
684 685

      if (!data) {
686 687
        var options = $.extend({}, Default, $this.data(), typeof option == 'object' && option);
        $this.data(DataKey, (data = new PushMenu(options)));
A
Abdullah Almsaeed 已提交
688 689
      }

690 691
      if (option === 'toggle') data.toggle();
    });
A
Abdullah Almsaeed 已提交
692 693
  }

694
  var old = $.fn.pushMenu;
A
Abdullah Almsaeed 已提交
695

696 697
  $.fn.pushMenu             = Plugin;
  $.fn.pushMenu.Constructor = PushMenu;
A
Abdullah Almsaeed 已提交
698 699 700

  // No Conflict Mode
  // ================
A
Abdullah Almsaeed 已提交
701
  $.fn.pushMenu.noConflict = function () {
702 703 704
    $.fn.pushMenu = old;
    return this;
  };
A
Abdullah Almsaeed 已提交
705

A
Abdullah Almsaeed 已提交
706 707 708
  // Data API
  // ========
  $(document).on('click', Selector.button, function (e) {
709 710 711
    e.preventDefault();
    Plugin.call($(this), 'toggle');
  });
A
Abdullah Almsaeed 已提交
712
  $(window).on('load', function () {
713 714 715
    Plugin.call($(Selector.button));
  });
}(jQuery);
A
Abdullah Almsaeed 已提交
716 717 718 719 720 721 722 723 724 725 726


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

729
  var DataKey = 'lte.todolist';
A
Abdullah Almsaeed 已提交
730 731

  var Default = {
A
Abdullah Almsaeed 已提交
732
    onCheck  : function (item) {
733
      return item;
A
Abdullah Almsaeed 已提交
734
    },
A
Abdullah Almsaeed 已提交
735
    onUnCheck: function (item) {
736
      return item;
A
Abdullah Almsaeed 已提交
737
    }
738
  };
A
Abdullah Almsaeed 已提交
739 740 741

  var Selector = {
    data: '[data-widget="todo-list"]'
742
  };
A
Abdullah Almsaeed 已提交
743 744 745

  var ClassName = {
    done: 'done'
746
  };
A
Abdullah Almsaeed 已提交
747 748 749 750

  // TodoList Class Definition
  // =========================
  var TodoList = function (element, options) {
751 752
    this.element = element;
    this.options = options;
A
Abdullah Almsaeed 已提交
753

754 755
    this._setUpListeners();
  };
A
Abdullah Almsaeed 已提交
756 757

  TodoList.prototype.toggle = function (item) {
758
    item.parents(Selector.li).first().toggleClass(ClassName.done);
A
Abdullah Almsaeed 已提交
759
    if (!item.prop('checked')) {
760 761
      this.unCheck(item);
      return;
A
Abdullah Almsaeed 已提交
762 763
    }

764 765
    this.check(item);
  };
A
Abdullah Almsaeed 已提交
766 767

  TodoList.prototype.check = function (item) {
768 769
    this.options.onCheck.call(item);
  };
A
Abdullah Almsaeed 已提交
770 771

  TodoList.prototype.unCheck = function (item) {
772 773
    this.options.onUnCheck.call(item);
  };
A
Abdullah Almsaeed 已提交
774 775 776 777

  // Private

  TodoList.prototype._setUpListeners = function () {
778
    var that = this;
A
Abdullah Almsaeed 已提交
779
    $(this.element).on('change ifChanged', 'input:checkbox', function () {
780 781 782
      that.toggle($(this));
    });
  };
A
Abdullah Almsaeed 已提交
783 784 785 786 787

  // Plugin Definition
  // =================
  function Plugin(option) {
    return this.each(function () {
788 789
      var $this = $(this);
      var data  = $this.data(DataKey);
A
Abdullah Almsaeed 已提交
790 791

      if (!data) {
792 793
        var options = $.extend({}, Default, $this.data(), typeof option == 'object' && option);
        $this.data(DataKey, (data = new TodoList($this, options)));
A
Abdullah Almsaeed 已提交
794 795 796 797
      }

      if (typeof data == 'string') {
        if (typeof data[option] == 'undefined') {
798
          throw new Error('No method named ' + option);
A
Abdullah Almsaeed 已提交
799
        }
800
        data[option]();
A
Abdullah Almsaeed 已提交
801
      }
802
    });
A
Abdullah Almsaeed 已提交
803 804
  }

805
  var old = $.fn.todoList;
A
Abdullah Almsaeed 已提交
806

807 808
  $.fn.todoList             = Plugin;
  $.fn.todoList.Constructor = TodoList;
A
Abdullah Almsaeed 已提交
809 810 811 812

  // No Conflict Mode
  // ================
  $.fn.todoList.noConflict = function () {
813 814 815
    $.fn.todoList = old;
    return this;
  };
A
Abdullah Almsaeed 已提交
816 817 818 819 820

  // TodoList Data API
  // =================
  $(window).on('load', function () {
    $(Selector.data).each(function () {
821 822 823
      Plugin.call($(this));
    });
  });
A
Abdullah Almsaeed 已提交
824

825
}(jQuery);
A
Abdullah Almsaeed 已提交
826 827


A
Abdullah Almsaeed 已提交
828 829 830 831
/* Tree()
 * ======
 * Converts a nested list into a multilevel
 * tree view menu.
A
Abdullah Almsaeed 已提交
832
 *
A
Abdullah Almsaeed 已提交
833 834 835
 * @Usage: $('.my-menu').tree(options)
 *         or add [data-widget="tree"] to the ul element
 *         Pass any option as data-option="value"
A
Abdullah Almsaeed 已提交
836 837
 */
+function ($) {
838
  'use strict';
A
Abdullah Almsaeed 已提交
839

840
  var DataKey = 'lte.tree';
A
Abdullah Almsaeed 已提交
841 842 843 844 845 846

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

  var Selector = {
A
Abdullah Almsaeed 已提交
850 851 852 853 854 855 856
    tree        : '.tree',
    treeview    : '.treeview',
    treeviewMenu: '.treeview-menu',
    open        : '.menu-open, .active',
    li          : 'li',
    data        : '[data-widget="tree"]',
    active      : '.active'
857
  };
A
Abdullah Almsaeed 已提交
858 859

  var ClassName = {
A
Abdullah Almsaeed 已提交
860 861
    open: 'menu-open',
    tree: 'tree'
862
  };
A
Abdullah Almsaeed 已提交
863

A
Abdullah Almsaeed 已提交
864 865 866
  var Event = {
    collapsed: 'collapsed.tree',
    expanded : 'expanded.tree'
867
  };
A
Abdullah Almsaeed 已提交
868 869 870 871

  // Tree Class Definition
  // =====================
  var Tree = function (element, options) {
872 873
    this.element = element;
    this.options = options;
A
Abdullah Almsaeed 已提交
874

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

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

879 880
    this._setUpListeners();
  };
A
Abdullah Almsaeed 已提交
881

A
Abdullah Almsaeed 已提交
882
  Tree.prototype.toggle = function (link, event) {
883 884 885
    var treeviewMenu = link.next(Selector.treeviewMenu);
    var parentLi     = link.parent();
    var isOpen       = parentLi.hasClass(ClassName.open);
A
Abdullah Almsaeed 已提交
886 887

    if (!parentLi.is(Selector.treeview)) {
888
      return;
A
Abdullah Almsaeed 已提交
889 890
    }

891
    if (!this.options.followLink || link.attr('href') === '#') {
892
      event.preventDefault();
A
Abdullah Almsaeed 已提交
893 894 895
    }

    if (isOpen) {
896
      this.collapse(treeviewMenu, parentLi);
A
Abdullah Almsaeed 已提交
897
    } else {
898
      this.expand(treeviewMenu, parentLi);
A
Abdullah Almsaeed 已提交
899
    }
900
  };
A
Abdullah Almsaeed 已提交
901 902

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

    if (this.options.accordion) {
906 907 908
      var openMenuLi = parent.siblings(Selector.open);
      var openTree   = openMenuLi.children(Selector.treeviewMenu);
      this.collapse(openTree, openMenuLi);
A
Abdullah Almsaeed 已提交
909 910
    }

911
    parent.addClass(ClassName.open);
A
Abdullah Almsaeed 已提交
912
    tree.slideDown(this.options.animationSpeed, function () {
R
REJack 已提交
913
      $(this.element).trigger(expandedEvent);
R
REJack 已提交
914
      parent.height('auto');
915 916
    }.bind(this));
  };
A
Abdullah Almsaeed 已提交
917 918

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

921
    //tree.find(Selector.open).removeClass(ClassName.open);
922
    parentLi.removeClass(ClassName.open);
D
Daniel Vilanova Yamuza 已提交
923
    tree.slideUp(this.options.animationSpeed, function () {
924
      //tree.find(Selector.open + ' > ' + Selector.treeview).slideUp();
R
REJack 已提交
925
      $(this.element).trigger(collapsedEvent);
926 927 928

      // Collapse child items
      parentLi.find(Selector.treeview).removeClass(ClassName.open).find(Selector.treeviewMenu).hide();
929 930
    }.bind(this));
  };
A
Abdullah Almsaeed 已提交
931 932

  // Private
933

A
Abdullah Almsaeed 已提交
934
  Tree.prototype._setUpListeners = function () {
935
    var that = this;
A
Abdullah Almsaeed 已提交
936 937

    $(this.element).on('click', this.options.trigger, function (event) {
938 939 940
      that.toggle($(this), event);
    });
  };
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, new Tree($this, options));
A
Abdullah Almsaeed 已提交
952
      }
953
    });
A
Abdullah Almsaeed 已提交
954 955
  }

956
  var old = $.fn.tree;
A
Abdullah Almsaeed 已提交
957

958 959
  $.fn.tree             = Plugin;
  $.fn.tree.Constructor = Tree;
A
Abdullah Almsaeed 已提交
960 961 962

  // No Conflict Mode
  // ================
A
Abdullah Almsaeed 已提交
963
  $.fn.tree.noConflict = function () {
964 965 966
    $.fn.tree = old;
    return this;
  };
A
Abdullah Almsaeed 已提交
967

A
Abdullah Almsaeed 已提交
968 969 970 971
  // Tree Data API
  // =============
  $(window).on('load', function () {
    $(Selector.data).each(function () {
972 973 974
      Plugin.call($(this));
    });
  });
A
Abdullah Almsaeed 已提交
975

976
}(jQuery);
977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003


/* 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 ($) {
  'use strict';

  var DataKey = 'lte.layout';

  var Default = {
    slimscroll : true,
    resetHeight: true
  };

  var Selector = {
    wrapper       : '.wrapper',
    contentWrapper: '.content-wrapper',
    layoutBoxed   : '.layout-boxed',
    mainFooter    : '.main-footer',
    mainHeader    : '.main-header',
1004 1005
    mainSidebar   : '.main-sidebar',
    slimScrollDiv : 'slimScrollDiv',
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
    sidebar       : '.sidebar',
    controlSidebar: '.control-sidebar',
    fixed         : '.fixed',
    sidebarMenu   : '.sidebar-menu',
    logo          : '.main-header .logo'
  };

  var ClassName = {
    fixed         : 'fixed',
    holdTransition: 'hold-transition'
  };

  var Layout = function (options) {
    this.options      = options;
    this.bindedResize = false;
    this.activate();
  };

  Layout.prototype.activate = function () {
    this.fix();
    this.fixSidebar();

    $('body').removeClass(ClassName.holdTransition);

    if (this.options.resetHeight) {
      $('body, html, ' + Selector.wrapper).css({
        'height'    : 'auto',
        'min-height': '100%'
      });
    }

    if (!this.bindedResize) {
      $(window).resize(function () {
        this.fix();
        this.fixSidebar();

        $(Selector.logo + ', ' + Selector.sidebar).one('webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend', function () {
          this.fix();
          this.fixSidebar();
        }.bind(this));
      }.bind(this));

      this.bindedResize = true;
    }

    $(Selector.sidebarMenu).on('expanded.tree', function () {
      this.fix();
      this.fixSidebar();
    }.bind(this));

    $(Selector.sidebarMenu).on('collapsed.tree', function () {
      this.fix();
      this.fixSidebar();
    }.bind(this));
  };

  Layout.prototype.fix = function () {
    // Remove overflow from .wrapper if layout-boxed exists
    $(Selector.layoutBoxed + ' > ' + Selector.wrapper).css('overflow', 'hidden');

    // Get window height and the wrapper height
1067
    var footerHeight  = $(Selector.mainFooter).outerHeight() || 0;
1068 1069 1070
    var headerHeight  = $(Selector.mainHeader).outerHeight() || 0;
    var neg           = headerHeight + footerHeight;
    var windowHeight  = $(window).height();
1071
    var sidebarHeight = $(Selector.sidebar).outerHeight() || 0;
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112

    // Set the min-height of the content and sidebar based on
    // the height of the document.
    if ($('body').hasClass(ClassName.fixed)) {
      $(Selector.contentWrapper).css('min-height', windowHeight - footerHeight);
    } else {
      var postSetHeight;

      if (windowHeight >= sidebarHeight + headerHeight) {
        $(Selector.contentWrapper).css('min-height', windowHeight - neg);
        postSetHeight = windowHeight - neg;
      } else {
        $(Selector.contentWrapper).css('min-height', sidebarHeight);
        postSetHeight = sidebarHeight;
      }

      // Fix for the control sidebar height
      var $controlSidebar = $(Selector.controlSidebar);
      if (typeof $controlSidebar !== 'undefined') {
        if ($controlSidebar.height() > postSetHeight)
          $(Selector.contentWrapper).css('min-height', $controlSidebar.height());
      }
    }
  };

  Layout.prototype.fixSidebar = function () {
    // Make sure the body tag has the .fixed class
    if (!$('body').hasClass(ClassName.fixed)) {
      if (typeof $.fn.slimScroll !== 'undefined') {
        $(Selector.sidebar).slimScroll({ destroy: true }).height('auto');
      }
      return;
    }

    // Enable slimscroll for fixed layout
    if (this.options.slimscroll) {
      if (typeof $.fn.slimScroll !== 'undefined') {
        // Destroy if it exists
        // $(Selector.sidebar).slimScroll({ destroy: true }).height('auto')

        // Add slimscroll
1113 1114 1115 1116 1117
        if ($(Selector.mainSidebar).find(Selector.slimScrollDiv).length === 0) {
          $(Selector.sidebar).slimScroll({
            height: ($(window).height() - $(Selector.mainHeader).height()) + 'px'
          });
        }
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160
      }
    }
  };

  // Plugin Definition
  // =================
  function Plugin(option) {
    return this.each(function () {
      var $this = $(this);
      var data  = $this.data(DataKey);

      if (!data) {
        var options = $.extend({}, Default, $this.data(), typeof option === 'object' && option);
        $this.data(DataKey, (data = new Layout(options)));
      }

      if (typeof option === 'string') {
        if (typeof data[option] === 'undefined') {
          throw new Error('No method named ' + option);
        }
        data[option]();
      }
    });
  }

  var old = $.fn.layout;

  $.fn.layout            = Plugin;
  $.fn.layout.Constuctor = Layout;

  // No conflict mode
  // ================
  $.fn.layout.noConflict = function () {
    $.fn.layout = old;
    return this;
  };

  // Layout DATA-API
  // ===============
  $(window).on('load', function () {
    Plugin.call($('body'));
  });
}(jQuery);