lib/assets/javascripts/tao/ui/popover/element.coffee in tao_ui-0.2.4 vs lib/assets/javascripts/tao/ui/popover/element.coffee in tao_ui-0.2.5
- old
+ new
@@ -7,12 +7,14 @@
@tag 'tao-popover'
@attribute 'active', type: 'boolean', observe: true
- @attribute 'targetSelector', 'targetTraversal', 'triggerSelector', 'triggerTraversal'
+ @attribute 'targetSelector', 'targetTraversal'
+ @attribute 'triggerSelector', 'triggerTraversal'
+
@attribute 'triggerAction', default: 'click'
@attribute 'boundarySelector', 'direction', 'size'
@attribute 'arrowAlign', default: 'center'
@@ -43,10 +45,12 @@
else if @triggerSelector
$ @triggerSelector
else
@target
+ return unless @triggerEl && @triggerEl.length > 0
+
if @triggerAction == 'click'
@triggerEl.on 'click.tao-popover', (e) =>
@toggleActive()
else if @triggerAction == 'hover'
@triggerEl.on 'mouseenter.tao-popover', (e) =>
@@ -58,13 +62,15 @@
@jq.width(@size) if @size
_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: ->
@@ -97,10 +103,25 @@
@jq.css
top: @position.top
left: @position.left
@
+ resetAttributes: ->
+ @active = false
+ @triggerEl?.off '.tao-popover'
+ @target = null
+ @triggerEl = null
+
+ for attr in _.toArray(@attributes)
+ unless attr.name in ['class', 'tao-id']
+ @jq.removeAttr attr.name
+
+ setContent: (content) ->
+ @jq.find('.tao-popover-content').empty()
+ .append content
+ @
+
toggleActive: ->
@active = !@active
@
beforeCache: ->
@@ -109,14 +130,15 @@
else
@active = false
remove: ->
@trigger 'tao:beforeRemove'
+ @target.removeClass 'tao-popover-active'
@jq.remove()
@trigger 'tao:remove'
@
_disconnected: ->
- @triggerEl.off '.tao-popover'
+ @triggerEl?.off '.tao-popover'
$(document).off ".tao-popover-#{@taoId}"
TaoComponent.register Tao.Popover.Element