| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 | /** * -------------------------------------------- * AdminLTE Layout.js * License MIT * -------------------------------------------- */import $ from 'jquery'/** * Constants * ==================================================== */const NAME = 'Layout'const DATA_KEY = 'lte.layout'const JQUERY_NO_CONFLICT = $.fn[NAME]const SELECTOR_HEADER = '.main-header'const SELECTOR_MAIN_SIDEBAR = '.main-sidebar'const SELECTOR_SIDEBAR = '.main-sidebar .sidebar'const SELECTOR_CONTENT = '.content-wrapper'const SELECTOR_CONTROL_SIDEBAR_CONTENT = '.control-sidebar-content'const SELECTOR_CONTROL_SIDEBAR_BTN = '[data-widget="control-sidebar"]'const SELECTOR_FOOTER = '.main-footer'const SELECTOR_PUSHMENU_BTN = '[data-widget="pushmenu"]'const SELECTOR_LOGIN_BOX = '.login-box'const SELECTOR_REGISTER_BOX = '.register-box'const CLASS_NAME_SIDEBAR_FOCUSED = 'sidebar-focused'const CLASS_NAME_LAYOUT_FIXED = 'layout-fixed'const CLASS_NAME_CONTROL_SIDEBAR_SLIDE_OPEN = 'control-sidebar-slide-open'const CLASS_NAME_CONTROL_SIDEBAR_OPEN = 'control-sidebar-open'const Default = {  scrollbarTheme: 'os-theme-light',  scrollbarAutoHide: 'l',  panelAutoHeight: true,  loginRegisterAutoHeight: true}/** * Class Definition * ==================================================== */class Layout {  constructor(element, config) {    this._config = config    this._element = element    this._init()  }  // Public  fixLayoutHeight(extra = null) {    const $body = $('body')    let controlSidebar = 0    if ($body.hasClass(CLASS_NAME_CONTROL_SIDEBAR_SLIDE_OPEN) || $body.hasClass(CLASS_NAME_CONTROL_SIDEBAR_OPEN) || extra === 'control_sidebar') {      controlSidebar = $(SELECTOR_CONTROL_SIDEBAR_CONTENT).height()    }    const heights = {      window: $(window).height(),      header: $(SELECTOR_HEADER).length !== 0 ? $(SELECTOR_HEADER).outerHeight() : 0,      footer: $(SELECTOR_FOOTER).length !== 0 ? $(SELECTOR_FOOTER).outerHeight() : 0,      sidebar: $(SELECTOR_SIDEBAR).length !== 0 ? $(SELECTOR_SIDEBAR).height() : 0,      controlSidebar    }    const max = this._max(heights)    let offset = this._config.panelAutoHeight    if (offset === true) {      offset = 0    }    const $contentSelector = $(SELECTOR_CONTENT)    if (offset !== false) {      if (max === heights.controlSidebar) {        $contentSelector.css('min-height', (max + offset))      } else if (max === heights.window) {        $contentSelector.css('min-height', (max + offset) - heights.header - heights.footer)      } else {        $contentSelector.css('min-height', (max + offset) - heights.header)      }      if (this._isFooterFixed()) {        $contentSelector.css('min-height', parseFloat($contentSelector.css('min-height')) + heights.footer)      }    }    if (!$body.hasClass(CLASS_NAME_LAYOUT_FIXED)) {      return    }    if (offset !== false) {      $contentSelector.css('min-height', (max + offset) - heights.header - heights.footer)    }    if (typeof $.fn.overlayScrollbars !== 'undefined') {      $(SELECTOR_SIDEBAR).overlayScrollbars({        className: this._config.scrollbarTheme,        sizeAutoCapable: true,        scrollbars: {          autoHide: this._config.scrollbarAutoHide,          clickScrolling: true        }      })    }  }  fixLoginRegisterHeight() {    const $body = $('body')    const $selector = $(`${SELECTOR_LOGIN_BOX}, ${SELECTOR_REGISTER_BOX}`)    if ($selector.length === 0) {      $body.css('height', 'auto')      $('html').css('height', 'auto')    } else {      const boxHeight = $selector.height()      if ($body.css('min-height') !== boxHeight) {        $body.css('min-height', boxHeight)      }    }  }  // Private  _init() {    // Activate layout height watcher    this.fixLayoutHeight()    if (this._config.loginRegisterAutoHeight === true) {      this.fixLoginRegisterHeight()    } else if (this._config.loginRegisterAutoHeight === parseInt(this._config.loginRegisterAutoHeight, 10)) {      setInterval(this.fixLoginRegisterHeight, this._config.loginRegisterAutoHeight)    }    $(SELECTOR_SIDEBAR)      .on('collapsed.lte.treeview expanded.lte.treeview', () => {        this.fixLayoutHeight()      })    $(SELECTOR_PUSHMENU_BTN)      .on('collapsed.lte.pushmenu shown.lte.pushmenu', () => {        this.fixLayoutHeight()      })    $(SELECTOR_CONTROL_SIDEBAR_BTN)      .on('collapsed.lte.controlsidebar', () => {        this.fixLayoutHeight()      })      .on('expanded.lte.controlsidebar', () => {        this.fixLayoutHeight('control_sidebar')      })    $(window).resize(() => {      this.fixLayoutHeight()    })    setTimeout(() => {      $('body.hold-transition').removeClass('hold-transition')    }, 50)  }  _max(numbers) {    // Calculate the maximum number in a list    let max = 0    Object.keys(numbers).forEach(key => {      if (numbers[key] > max) {        max = numbers[key]      }    })    return max  }  _isFooterFixed() {    return $(SELECTOR_FOOTER).css('position') === 'fixed'  }  // Static  static _jQueryInterface(config = '') {    return this.each(function () {      let data = $(this).data(DATA_KEY)      const _options = $.extend({}, Default, $(this).data())      if (!data) {        data = new Layout($(this), _options)        $(this).data(DATA_KEY, data)      }      if (config === 'init' || config === '') {        data._init()      } else if (config === 'fixLayoutHeight' || config === 'fixLoginRegisterHeight') {        data[config]()      }    })  }}/** * Data API * ==================================================== */$(window).on('load', () => {  Layout._jQueryInterface.call($('body'))})$(`${SELECTOR_SIDEBAR} a`).on('focusin', () => {  $(SELECTOR_MAIN_SIDEBAR).addClass(CLASS_NAME_SIDEBAR_FOCUSED)})$(`${SELECTOR_SIDEBAR} a`).on('focusout', () => {  $(SELECTOR_MAIN_SIDEBAR).removeClass(CLASS_NAME_SIDEBAR_FOCUSED)})/** * jQuery API * ==================================================== */$.fn[NAME] = Layout._jQueryInterface$.fn[NAME].Constructor = Layout$.fn[NAME].noConflict = function () {  $.fn[NAME] = JQUERY_NO_CONFLICT  return Layout._jQueryInterface}export default Layout
 |