Sha256: 798f8bd31f2a5fae11ace90418176d8ab04793ab873235d4d79dcffa7be6bb06

Contents?: true

Size: 990 Bytes

Versions: 3

Compression:

Stored size: 990 Bytes

Contents

import ApplicationController from './application_controller'

import cookie from '../core/cookie'

export default class extends ApplicationController {
  static targets = ["inner"]

  connect () {
    this.scrollToActive()
  }

  toggle () {
    const bodyClasses = document.body.classList

    if (bodyClasses.contains('sidebar-expanded') || bodyClasses.contains('sidebar-collapsed')) {
      bodyClasses.remove('sidebar-expanded', 'sidebar-collapsed')
      cookie.delete('trestle:sidebar')
    } else if (document.body.clientWidth >= 1200) {
      bodyClasses.add('sidebar-collapsed')
      cookie.set('trestle:sidebar', 'collapsed')
    } else if (document.body.clientWidth >= 768) {
      bodyClasses.add('sidebar-expanded')
      cookie.set('trestle:sidebar', 'expanded')
    }
  }

  scrollToActive () {
    const active = this.element.getElementsByClassName('active')[0]
    if (active && this.hasInnerTarget) {
      this.innerTarget.scrollTop = active.offsetTop - 100
    }
  }
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
trestle-0.10.0 frontend/js/controllers/sidebar_controller.js
trestle-0.10.0.pre2 frontend/js/controllers/sidebar_controller.js
trestle-0.10.0.pre frontend/js/controllers/sidebar_controller.js