adminlte.js 27.2 KB
Newer Older
A
Abdullah Almsaeed 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*! 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>
* @version 2.4.0
* @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 29 30
 */
+function ($) {
  'use strict'

A
Abdullah Almsaeed 已提交
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 44 45
    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) {
      return response
    }
A
Abdullah Almsaeed 已提交
46 47 48
  }

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

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

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

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

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

A
Abdullah Almsaeed 已提交
71 72 73 74 75 76 77 78
    $.get(this.options.source, this.options.params, function (response) {
      if (this.options.loadInContent) {
        $(this.options.content).html(response)
      }
      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 83 84 85
  BoxRefresh.prototype._setUpListeners = function () {
    $(this.element).on('click', Selector.trigger, function (event) {
      if (event) event.preventDefault()
      this.load()
A
Abdullah Almsaeed 已提交
86 87 88
    }.bind(this))
  }

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

A
Abdullah Almsaeed 已提交
93 94
  BoxRefresh.prototype._removeOverlay = function () {
    $(this.element).remove(this.$overlay)
A
Abdullah Almsaeed 已提交
95 96 97 98 99 100 101 102 103 104
  }

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

      if (!data) {
A
Abdullah Almsaeed 已提交
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') {
A
Abdullah Almsaeed 已提交
111 112 113 114 115 116 117
          throw new Error('No method named ' + option)
        }
        data[option]()
      }
    })
  }

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

A
Abdullah Almsaeed 已提交
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 126
  $.fn.boxRefresh.noConflict = function () {
    $.fn.boxRefresh = old
A
Abdullah Almsaeed 已提交
127 128 129
    return this
  }

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

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


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 150 151
 */
+function ($) {
  'use strict'

A
Abdullah Almsaeed 已提交
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'
A
Abdullah Almsaeed 已提交
161 162 163
  }

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

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

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

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

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

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

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

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

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

A
Abdullah Almsaeed 已提交
207 208 209 210 211
    $(this.element)
      .find(Selector.tools)
      .find('.' + expandIcon)
      .removeClass(expandIcon)
      .addClass(collapseIcon)
A
Abdullah Almsaeed 已提交
212

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

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

A
Abdullah Almsaeed 已提交
224 225 226 227 228
    $(this.element)
      .find(Selector.tools)
      .find('.' + collapseIcon)
      .removeClass(collapseIcon)
      .addClass(expandIcon)
A
Abdullah Almsaeed 已提交
229

A
Abdullah Almsaeed 已提交
230 231 232 233 234
    $(this.element).find(Selector.body + ', ' + Selector.footer)
      .slideUp(this.options.animationSpeed, function () {
        $(this.element).addClass(ClassName.collapsed)
        $(this.element).trigger(collapsedEvent)
      }.bind(this))
A
Abdullah Almsaeed 已提交
235 236
  }

A
Abdullah Almsaeed 已提交
237 238
  BoxWidget.prototype.remove = function () {
    var removedEvent = $.Event(Event.removed)
A
Abdullah Almsaeed 已提交
239

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

  // Private

A
Abdullah Almsaeed 已提交
248
  BoxWidget.prototype._setUpListeners = function () {
A
Abdullah Almsaeed 已提交
249 250
    var that = this

A
Abdullah Almsaeed 已提交
251 252 253 254 255 256 257 258
    $(this.element).on('click', this.options.collapseTrigger, function (event) {
      if (event) event.preventDefault()
      that.toggle()
    })

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

  // 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)
A
Abdullah Almsaeed 已提交
271 272 273 274 275 276 277 278
        $this.data(DataKey, (data = new BoxWidget($this, options)))
      }

      if (typeof option == 'string') {
        if (typeof data[option] == 'undefined') {
          throw new Error('No method named ' + option)
        }
        data[option]()
A
Abdullah Almsaeed 已提交
279 280 281 282
      }
    })
  }

A
Abdullah Almsaeed 已提交
283
  var old = $.fn.boxWidget
A
Abdullah Almsaeed 已提交
284

A
Abdullah Almsaeed 已提交
285 286
  $.fn.boxWidget             = Plugin
  $.fn.boxWidget.Constructor = BoxWidget
A
Abdullah Almsaeed 已提交
287 288 289

  // No Conflict Mode
  // ================
A
Abdullah Almsaeed 已提交
290 291
  $.fn.boxWidget.noConflict = function () {
    $.fn.boxWidget = old
A
Abdullah Almsaeed 已提交
292 293 294
    return this
  }

A
Abdullah Almsaeed 已提交
295 296
  // BoxWidget Data API
  // ==================
A
Abdullah Almsaeed 已提交
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445
  $(window).on('load', function () {
    $(Selector.data).each(function () {
      Plugin.call($(this))
    })
  })

}(jQuery)


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

  var DataKey = 'lte.controlsidebar'

  var Default = {
    slide: true
  }

  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'
  }

  var ClassName = {
    open : 'control-sidebar-open',
    fixed: 'fixed'
  }

  var Event = {
    collapsed: 'collapsed.controlsidebar',
    expanded : 'expanded.controlsidebar'
  }

  // ControlSidebar Class Definition
  // ===============================
  var ControlSidebar = function (element, options) {
    this.element         = element
    this.options         = options
    this.hasBindedResize = false

    this.init()
  }

  ControlSidebar.prototype.init = function () {
    // Add click listener if the element hasn't been
    // initialized using the data API
    if (!$(this.element).is(Selector.data)) {
      $(this).on('click', this.toggle)
    }

    this.fix()
    $(window).resize(function () {
      this.fix()
    }.bind(this))
  }

  ControlSidebar.prototype.toggle = function (event) {
    if (event) event.preventDefault()

    this.fix()

    if (!$(Selector.sidebar).is(Selector.open) && !$('body').is(Selector.open)) {
      this.expand()
    } else {
      this.collapse()
    }
  }

  ControlSidebar.prototype.expand = function () {
    if (!this.options.slide) {
      $('body').addClass(ClassName.open)
    } else {
      $(Selector.sidebar).addClass(ClassName.open)
    }

    $(this.element).trigger($.Event(Event.expanded))
  }

  ControlSidebar.prototype.collapse = function () {
    $('body, ' + Selector.sidebar).removeClass(ClassName.open)
    $(this.element).trigger($.Event(Event.collapsed))
  }

  ControlSidebar.prototype.fix = function () {
    if ($('body').is(Selector.boxed)) {
      this._fixForBoxed($(Selector.bg))
    }
  }

  // Private

  ControlSidebar.prototype._fixForBoxed = function (bg) {
    bg.css({
      position: 'absolute',
      height  : $(Selector.wrapper).height()
    })
  }

  // 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 ControlSidebar($this, options)))
      }

      if (typeof option == 'string') data.toggle()
    })
  }

  var old = $.fn.controlSidebar

  $.fn.controlSidebar             = Plugin
  $.fn.controlSidebar.Constructor = ControlSidebar

  // No Conflict Mode
  // ================
  $.fn.controlSidebar.noConflict = function () {
    $.fn.controlSidebar = old
    return this
  }

  // ControlSidebar Data API
  // =======================
  $(document).on('click', Selector.data, function (event) {
    if (event) event.preventDefault()
    Plugin.call($(this), 'toggle')
  })

}(jQuery)


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

A
Abdullah Almsaeed 已提交
456
  var DataKey = 'lte.directchat'
A
Abdullah Almsaeed 已提交
457

A
Abdullah Almsaeed 已提交
458 459 460
  var Selector = {
    data: '[data-widget="chat-pane-toggle"]',
    box : '.direct-chat'
A
Abdullah Almsaeed 已提交
461 462
  }

A
Abdullah Almsaeed 已提交
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
  var ClassName = {
    open: 'direct-chat-contacts-open'
  }

  // DirectChat Class Definition
  // ===========================
  var DirectChat = function (element) {
    this.element = element
  }

  DirectChat.prototype.toggle = function ($trigger) {
    $trigger.parents(Selector.box).first().toggleClass(ClassName.open)
  }

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

      if (!data) {
        $this.data(DataKey, (data = new DirectChat($this)))
      }

      if (typeof option == 'string') data.toggle($this)
    })
  }

  var old = $.fn.directChat

  $.fn.directChat             = Plugin
  $.fn.directChat.Constructor = DirectChat

  // No Conflict Mode
  // ================
  $.fn.directChat.noConflict = function () {
    $.fn.directChat = old
    return this
  }

  // DirectChat Data API
  // ===================
  $(document).on('click', Selector.data, function (event) {
    if (event) event.preventDefault()
    Plugin.call($(this), 'toggle')
  })

}(jQuery)


/* 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',
    sidebar       : '.sidebar',
    controlSidebar: '.control-sidebar',
    fixed         : '.fixed',
    sidebarMenu   : '.sidebar-menu',
    logo          : '.main-header .logo'
A
Abdullah Almsaeed 已提交
544 545 546
  }

  var ClassName = {
A
Abdullah Almsaeed 已提交
547 548
    fixed         : 'fixed',
    holdTransition: 'hold-transition'
A
Abdullah Almsaeed 已提交
549 550
  }

A
Abdullah Almsaeed 已提交
551 552 553 554
  var Layout = function (options) {
    this.options      = options
    this.bindedResize = false
    this.activate()
A
Abdullah Almsaeed 已提交
555 556
  }

A
Abdullah Almsaeed 已提交
557 558 559
  Layout.prototype.activate = function () {
    this.fix()
    this.fixSidebar()
A
Abdullah Almsaeed 已提交
560

A
Abdullah Almsaeed 已提交
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
    $('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))
A
Abdullah Almsaeed 已提交
593 594
  }

A
Abdullah Almsaeed 已提交
595 596 597
  Layout.prototype.fix = function () {
    // Remove overflow from .wrapper if layout-boxed exists
    $(Selector.layoutBoxed + ' > ' + Selector.wrapper).css('overflow', 'hidden')
A
Abdullah Almsaeed 已提交
598

A
Abdullah Almsaeed 已提交
599 600 601 602 603 604 605 606 607 608
    // Get window height and the wrapper height
    var footerHeight  = $(Selector.mainFooter).outerHeight() || 0
    var neg           = $(Selector.mainHeader).outerHeight() + footerHeight
    var windowHeight  = $(window).height()
    var sidebarHeight = $(Selector.sidebar).height() || 0

    // 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)
A
Abdullah Almsaeed 已提交
609
    } else {
A
Abdullah Almsaeed 已提交
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
      var postSetHeight

      if (windowHeight >= sidebarHeight) {
        $(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())
      }
A
Abdullah Almsaeed 已提交
626 627 628
    }
  }

A
Abdullah Almsaeed 已提交
629 630 631 632 633 634 635 636
  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
    }
A
Abdullah Almsaeed 已提交
637

A
Abdullah Almsaeed 已提交
638 639 640 641
    // Enable slimscroll for fixed layout
    if (this.options.slimscroll) {
      if (typeof $.fn.slimScroll !== 'undefined') {
        // Destroy if it exists
642
        // $(Selector.sidebar).slimScroll({ destroy: true }).height('auto')
A
Abdullah Almsaeed 已提交
643

A
Abdullah Almsaeed 已提交
644 645 646 647 648 649 650 651 652
        // Add slimscroll
        $(Selector.sidebar).slimScroll({
          height: ($(window).height() - $(Selector.mainHeader).height()) + 'px',
          color : 'rgba(0,0,0,0.2)',
          size  : '3px'
        })
      }
    }
  }
A
Abdullah Almsaeed 已提交
653

A
Abdullah Almsaeed 已提交
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764
  // 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)


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

  var DataKey = 'lte.pushmenu'

  var Default = {
    collapseScreenSize   : 767,
    expandOnHover        : false,
    expandTransitionDelay: 200
  }

  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'
  }

  var ClassName = {
    collapsed    : 'sidebar-collapse',
    open         : 'sidebar-open',
    mini         : 'sidebar-mini',
    expanded     : 'sidebar-expanded-on-hover',
    expandFeature: 'sidebar-mini-expand-feature',
    layoutFixed  : 'fixed'
  }

  var Event = {
    expanded : 'expanded.pushMenu',
    collapsed: 'collapsed.pushMenu'
  }

  // PushMenu Class Definition
  // =========================
  var PushMenu = function (options) {
    this.options = options
    this.init()
  }

  PushMenu.prototype.init = function () {
    if (this.options.expandOnHover
      || ($('body').is(Selector.mini + Selector.layoutFixed))) {
      this.expandOnHover()
      $('body').addClass(ClassName.expandFeature)
    }

    $(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)) {
        this.close()
      }
    }.bind(this))

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

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

A
Abdullah Almsaeed 已提交
771 772 773
    if (windowWidth <= this.options.collapseScreenSize) {
      isOpen = $('body').hasClass(ClassName.open)
    }
A
Abdullah Almsaeed 已提交
774

A
Abdullah Almsaeed 已提交
775 776 777 778 779
    if (!isOpen) {
      this.open()
    } else {
      this.close()
    }
A
Abdullah Almsaeed 已提交
780 781
  }

A
Abdullah Almsaeed 已提交
782 783
  PushMenu.prototype.open = function () {
    var windowWidth = $(window).width()
A
Abdullah Almsaeed 已提交
784

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

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

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

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

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

A
Abdullah Almsaeed 已提交
833 834
  // PushMenu Plugin Definition
  // ==========================
A
Abdullah Almsaeed 已提交
835 836 837 838 839 840 841
  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)
A
Abdullah Almsaeed 已提交
842
        $this.data(DataKey, (data = new PushMenu(options)))
A
Abdullah Almsaeed 已提交
843 844
      }

845
      if (option === 'toggle') data.toggle()
A
Abdullah Almsaeed 已提交
846 847 848
    })
  }

A
Abdullah Almsaeed 已提交
849
  var old = $.fn.pushMenu
A
Abdullah Almsaeed 已提交
850

A
Abdullah Almsaeed 已提交
851 852
  $.fn.pushMenu             = Plugin
  $.fn.pushMenu.Constructor = PushMenu
A
Abdullah Almsaeed 已提交
853 854 855

  // No Conflict Mode
  // ================
A
Abdullah Almsaeed 已提交
856 857
  $.fn.pushMenu.noConflict = function () {
    $.fn.pushMenu = old
A
Abdullah Almsaeed 已提交
858 859 860
    return this
  }

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


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

  var DataKey = 'lte.todolist'

  var Default = {
A
Abdullah Almsaeed 已提交
887 888
    onCheck  : function (item) {
      return item
A
Abdullah Almsaeed 已提交
889
    },
A
Abdullah Almsaeed 已提交
890 891
    onUnCheck: function (item) {
      return item
A
Abdullah Almsaeed 已提交
892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
    }
  }

  var Selector = {
    data: '[data-widget="todo-list"]'
  }

  var ClassName = {
    done: 'done'
  }

  // TodoList Class Definition
  // =========================
  var TodoList = function (element, options) {
    this.element = element
    this.options = options

    this._setUpListeners()
  }

  TodoList.prototype.toggle = function (item) {
    item.parents(Selector.li).first().toggleClass(ClassName.done)
    if (!item.prop('checked')) {
      this.unCheck(item)
      return
    }

    this.check(item)
  }

  TodoList.prototype.check = function (item) {
    this.options.onCheck.call(item)
  }

  TodoList.prototype.unCheck = function (item) {
    this.options.onUnCheck.call(item)
  }

  // Private

  TodoList.prototype._setUpListeners = function () {
    var that = this
    $(this.element).on('change ifChanged', 'input:checkbox', function () {
      that.toggle($(this))
    })
  }

  // 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 TodoList($this, options)))
      }

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

  var old = $.fn.todoList

  $.fn.todoList         = Plugin
  $.fn.todoList.Constructor = TodoList

  // No Conflict Mode
  // ================
  $.fn.todoList.noConflict = function () {
    $.fn.todoList = old
    return this
  }

  // TodoList Data API
  // =================
  $(window).on('load', function () {
    $(Selector.data).each(function () {
      Plugin.call($(this))
    })
  })

}(jQuery)
A
Abdullah Almsaeed 已提交
981 982


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

A
Abdullah Almsaeed 已提交
995 996 997 998 999 1000 1001 1002
  var DataKey = 'lte.tree'

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

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

  var ClassName = {
A
Abdullah Almsaeed 已提交
1015 1016
    open: 'menu-open',
    tree: 'tree'
A
Abdullah Almsaeed 已提交
1017 1018
  }

A
Abdullah Almsaeed 已提交
1019 1020 1021 1022 1023 1024 1025 1026
  var Event = {
    collapsed: 'collapsed.tree',
    expanded : 'expanded.tree'
  }

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

    $(this.element).addClass(ClassName.tree)

    $(Selector.treeview + Selector.active, this.element).addClass(ClassName.open)

    this._setUpListeners()
A
Abdullah Almsaeed 已提交
1035 1036
  }

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

    if (!parentLi.is(Selector.treeview)) {
      return
    }

1046
    if (!this.options.followLink || link.attr('href') === '#') {
A
Abdullah Almsaeed 已提交
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
      event.preventDefault()
    }

    if (isOpen) {
      this.collapse(treeviewMenu, parentLi)
    } else {
      this.expand(treeviewMenu, parentLi)
    }
  }

  Tree.prototype.expand = function (tree, parent) {
    var expandedEvent = $.Event(Event.expanded)

    if (this.options.accordion) {
      var openMenuLi = parent.siblings(Selector.open)
      var openTree   = openMenuLi.children(Selector.treeviewMenu)
      this.collapse(openTree, openMenuLi)
    }

    parent.addClass(ClassName.open)
    tree.slideDown(this.options.animationSpeed, function () {
      $(this.element).trigger(expandedEvent)
    }.bind(this))
  }

  Tree.prototype.collapse = function (tree, parentLi) {
    var collapsedEvent = $.Event(Event.collapsed)

    tree.find(Selector.open).removeClass(ClassName.open)
    parentLi.removeClass(ClassName.open)
    tree.slideUp(this.options.animationSpeed, function () {
      tree.find(Selector.open + ' > ' + Selector.treeview).slideUp()
      $(this.element).trigger(collapsedEvent)
    }.bind(this))
  }

  // Private

  Tree.prototype._setUpListeners = function () {
    var that = this

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

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

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

A
Abdullah Almsaeed 已提交
1107
  var old = $.fn.tree
A
Abdullah Almsaeed 已提交
1108

A
Abdullah Almsaeed 已提交
1109 1110
  $.fn.tree             = Plugin
  $.fn.tree.Constructor = Tree
A
Abdullah Almsaeed 已提交
1111 1112 1113

  // No Conflict Mode
  // ================
A
Abdullah Almsaeed 已提交
1114 1115
  $.fn.tree.noConflict = function () {
    $.fn.tree = old
A
Abdullah Almsaeed 已提交
1116 1117 1118
    return this
  }

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

}(jQuery)