Sha256: b8b0ccf00f8fc9db2d813214c648034ed627d41657da692eba3ec7c75ef978bd

Contents?: true

Size: 1.34 KB

Versions: 12

Compression:

Stored size: 1.34 KB

Contents

class window.ViewLayout
  constructor: ->
    @wrap = $('#main')
    @initElements()
    @css_classes = @control.find('.btn').map(-> $(this).data('css')).get().join(' ')
    @initHandlers()
    @restoreMainCss(true)
    $(document).on 'pjax:end', =>
      @initElements()
      @restoreMainCss()

  initElements: ->
    @control = $('#view_layout')
    @sidebar_on = $('#toggle_sidebar_on')
    @sidebar_off = $('#toggle_sidebar_off')

  initHandlers: ->
    self = this
    $(document).on 'click', '#toggle_sidebar_off', =>
      @wrap.addClass('hide_sidebar')
      @storeMainCss()

    $(document).on 'click', '#toggle_sidebar_on', =>
      @wrap.removeClass('hide_sidebar')
      @storeMainCss()

    $(document).on 'click', '#view_layout .btn', ->
      $el = $(this)
      $el.toggleClass('active').siblings().removeClass('active')
      self.wrap.removeClass(self.css_classes).toggleClass($el.data('css'), $el.hasClass('active'))
      self.storeMainCss()

  storeMainCss: ->
    storeData('view_layout', @wrap.prop('className'))

  restoreMainCss: (wrap=false) =>
    css = fetchData('view_layout')
    if css
      @wrap.prop('className', css) if wrap
      @control.find("[data-css='#{css_class}']").addClass('active') for css_class in css.split(' ')

$ ->
  if $('#list')[0] && !$('#list').hasClass('skip_view_layout')
    window.view_layout = new ViewLayout()

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ab_admin-0.11.0 app/assets/javascripts/ab_admin/core/view_layout.js.coffee
ab_admin-0.10.0 app/assets/javascripts/ab_admin/core/view_layout.js.coffee
ab_admin-0.9.0 app/assets/javascripts/ab_admin/core/view_layout.js.coffee
ab_admin-0.8.3 app/assets/javascripts/ab_admin/core/view_layout.js.coffee
ab_admin-0.8.2 app/assets/javascripts/ab_admin/core/view_layout.js.coffee
ab_admin-0.8.1 app/assets/javascripts/ab_admin/core/view_layout.js.coffee
ab_admin-0.8.0 app/assets/javascripts/ab_admin/core/view_layout.js.coffee
ab_admin-0.7.0 app/assets/javascripts/ab_admin/core/view_layout.js.coffee
ab_admin-0.6.1 app/assets/javascripts/ab_admin/core/view_layout.js.coffee
ab_admin-0.6.0 app/assets/javascripts/ab_admin/core/view_layout.js.coffee
ab_admin-0.5.0 app/assets/javascripts/ab_admin/core/view_layout.js.coffee
ab_admin-0.4.0 app/assets/javascripts/ab_admin/core/view_layout.js.coffee