Sha256: 259200b5ba0e06d6d890ea40fdfaec43b3bed33b23060282a744336891565508

Contents?: true

Size: 1.32 KB

Versions: 6

Compression:

Stored size: 1.32 KB

Contents

class @Mercury.Toolbar.ButtonGroup

  constructor: (@name, @options = {}) ->
    @build()
    @bindEvents()
    @regions = @options._regions
    return @element


  build: ->
    @element = jQuery('<div>', {class: "mercury-button-group mercury-#{@name}-group"})
    if @options._context || @options._regions
      @element.addClass('disabled')


  bindEvents: ->
    Mercury.on 'region:update', (event, options) =>
      context = Mercury.Toolbar.ButtonGroup.contexts[@name]
      if context
        if options.region && jQuery.type(options.region.currentElement) == 'function'
          element = options.region.currentElement()
          if element.length && context.call(@, element, options.region.element)
            @element.removeClass('disabled')
          else
            @element.addClass('disabled')

    Mercury.on 'region:focused', (event, options) =>
      if @regions && options.region && options.region.type()
        if @regions.indexOf(options.region.type()) > -1
          @element.removeClass('disabled') unless @options._context
        else
          @element.addClass('disabled')

    Mercury.on 'region:blurred', (event, options) =>
      @element.addClass('disabled') if @options.regions



# ButtonGroup contexts
@Mercury.Toolbar.ButtonGroup.contexts =

  table: (node, region) -> !!node.closest('table', region).length

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
kiteditor-1.0.12 app/assets/javascripts/mercury/toolbar.button_group.js.coffee
mercury-rails-0.9.0 app/assets/javascripts/mercury/toolbar.button_group.js.coffee
mercury-rails-0.8.0 app/assets/javascripts/mercury/toolbar.button_group.js.coffee
mercury-rails-0.7.1 app/assets/javascripts/mercury/toolbar.button_group.js.coffee
mercury-rails-0.7.0 app/assets/javascripts/mercury/toolbar.button_group.js.coffee
mercury-rails-0.6.0 app/assets/javascripts/mercury/toolbar.button_group.js.coffee