lib/assets/javascripts/tao/ui/popover/element.coffee in tao_ui-0.2.5 vs lib/assets/javascripts/tao/ui/popover/element.coffee in tao_ui-0.2.6

- old
+ new

@@ -15,20 +15,14 @@ @attribute 'triggerAction', default: 'click' @attribute 'boundarySelector', 'direction', 'size' - @attribute 'arrowAlign', default: 'center' - - @attribute 'arrowVerticalAlign', default: 'middle' - @attribute 'offset', type: 'number', default: 0 - @attribute 'autoHide', type: 'boolean' + @attribute 'autoHide', 'autoDestroy', 'withArrow', 'disabled', type: 'boolean' - @attribute 'autoDestroy', type: 'boolean' - _connected: -> @_initTarget() @_initTrigger() @_initSize() @_activeChanged() if @active @@ -50,30 +44,54 @@ return unless @triggerEl && @triggerEl.length > 0 if @triggerAction == 'click' @triggerEl.on 'click.tao-popover', (e) => @toggleActive() + null else if @triggerAction == 'hover' @triggerEl.on 'mouseenter.tao-popover', (e) => @active = true + null .on 'mouseleave.tao-popover', (e) => @active = false + null _initSize: -> @jq.width(@size) if @size + _beforeActiveChanged: (active) -> + return false if @disabled + + if active + @jq.show() + @refresh() + @reflow() + else + reset = => + if @autoDestroy + @remove() + else + @jq.hide() + + # in case the popover is hidden too fast + if @jq.is(':visible') + if @jq.css('opacity') * 1 == 0 + reset() + else + @one 'transitionend', -> + reset() + null + _activeChanged: -> if @active - @refresh() @target.addClass 'tao-popover-active' @_enableAutoHide() if @autoHide @trigger 'tao:show' else @target.removeClass 'tao-popover-active' @_disableAutoHide() if @autoHide @trigger 'tao:hide' - @jq.remove() if @autoDestroy _enableAutoHide: -> $(document).on "mousedown.tao-popover-#{@taoId}", (e) => return unless @active target = $ e.target @@ -94,12 +112,11 @@ @position = new Position popover: @jq target: @target direction: @direction.split('-') - arrowAlign: @arrowAlign - arrowVerticalAlign: @arrowVerticalAlign + withArrow: @withArrow offset: @offset @jq.css top: @position.top left: @position.left @@ -126,9 +143,10 @@ beforeCache: -> if @autoDestroy @remove() else + @jq.hide() @active = false remove: -> @trigger 'tao:beforeRemove' @target.removeClass 'tao-popover-active'