lib/assets/javascripts/tao/ui/popover/element.coffee in tao_ui-0.2.10 vs lib/assets/javascripts/tao/ui/popover/element.coffee in tao_ui-0.3.0

- old
+ new

@@ -5,11 +5,11 @@ class Tao.Popover.Element extends TaoComponent @tag 'tao-popover' - @attribute 'active', type: 'boolean', observe: true + @attribute 'active', 'disabled', type: 'boolean', observe: true @attribute 'targetSelector', 'targetTraversal' @attribute 'triggerSelector', 'triggerTraversal' @@ -17,18 +17,23 @@ @attribute 'boundarySelector', 'direction', 'size' @attribute 'offset', type: 'number', default: 0 - @attribute 'autoHide', 'autoDestroy', 'withArrow', 'disabled', type: 'boolean' + @attribute 'autoHide', 'autoDestroy', 'withArrow', 'autoActivate', type: 'boolean' _connected: -> @_initTarget() @_initTrigger() @_initSize() - @_activeChanged() if @active + if @autoActivate + @reflow() + @active = true + else if @active + @_activeChanged() + _initTarget: -> @target = if @targetTraversal && @targetSelector @jq[@targetTraversal]?(@targetSelector) else if @targetSelector $ @targetSelector @@ -81,16 +86,20 @@ reset() null _activeChanged: -> if @active - @target.addClass 'tao-popover-active' + @target.addClass "#{@constructor._tag}-active" @_enableAutoHide() if @autoHide @namespacedTrigger 'show' else - @target.removeClass 'tao-popover-active' + @target.removeClass "#{@constructor._tag}-active" @_disableAutoHide() if @autoHide @namespacedTrigger 'hide' + + _beforeDisabledChanged: (disabled) -> + @active = false if disabled && @active + null _enableAutoHide: -> $(document).on "mousedown.tao-popover-#{@taoId}", (e) => return unless @active target = e.target