vendor/assets/javascripts/mercury/tooltip.js.coffee in mercury-rails-0.2.3 vs vendor/assets/javascripts/mercury/tooltip.js.coffee in mercury-rails-0.3.1

- old
+ new

@@ -1,13 +1,13 @@ @Mercury.tooltip = (forElement, content, options = {}) -> Mercury.tooltip.show(forElement, content, options) return Mercury.tooltip -jQuery.extend Mercury.tooltip, { +jQuery.extend Mercury.tooltip, show: (@forElement, @content, @options = {}) -> - @document = jQuery(@forElement.get(0).ownerDocument) + @document = @forElement.get(0).ownerDocument @initialize() if @visible then @update() else @appear() initialize: -> @@ -21,20 +21,25 @@ @element = jQuery('<div>', {class: 'mercury-tooltip'}) @element.appendTo(jQuery(@options.appendTo).get(0) ? 'body') bindEvents: -> - Mercury.bind 'resize', => @position() if @visible - @document.scroll => @position() if @visible - for parent in @forElement.parentsUntil(jQuery('body', @document)) - if parent.scrollHeight > parent.clientHeight - jQuery(parent).scroll => @position() if @visible - @element.mousedown (event) -> + Mercury.on 'resize', => @position() if @visible + + @element.on 'mousedown', (event) -> event.preventDefault() event.stopPropagation() + for parent in @forElement.parentsUntil(jQuery('body', @document)) + continue unless parent.scrollHeight > parent.clientHeight + jQuery(parent).on 'scroll', => + @position() if @visible + jQuery(@document).on 'scroll', => + @position() if @visible + + appear: -> @update() @element.show() @element.animate {opacity: 1}, 200, 'easeInOutSine', => @@ -65,6 +70,5 @@ hide: -> return unless @initialized @element.hide() @visible = false -}