Daniel@0: /* global ChordVis */ Daniel@0: 'use strict'; Daniel@0: Daniel@0: App.module('TooltipModule', function (TooltipModule, App, Backbone, Marionette, $, _) { Daniel@0: var renderFunctions = {}; Daniel@0: Daniel@0: var OBJECT_TYPE_CHORD_SEQUENCE = 1; Daniel@0: Daniel@0: TooltipModule.addInitializer(function() { Daniel@0: Daniel@0: Daniel@0: TooltipModule.TooltipView = Backbone.View.extend({ Daniel@0: Daniel@0: initialize: function(options) { Daniel@0: var _this = this; Daniel@0: Daniel@0: _this.$tooltip = $("
").addClass("tooltip").appendTo("body"); Daniel@0: }, Daniel@0: Daniel@0: update: function(mouseEvent, title, target) { Daniel@0: var _this = this; Daniel@0: // removing the tooltip Daniel@0: if (!mouseEvent || mouseEvent.type == "mouseout" || mouseEvent.type == "mouseup" || !title) { Daniel@0: _this.previousTarget = null; Daniel@0: _this.$tooltip.addClass("tooltip_animation_slow-opacity"); Daniel@0: _this.$tooltip.removeClass("tooltip_state_visible"); Daniel@0: } else { Daniel@0: if (target != _this.previousTarget) { Daniel@0: _this.$tooltip.removeClass("tooltip_animation_slow-opacity"); Daniel@0: _this.$tooltip.addClass("tooltip_state_visible"); Daniel@0: Daniel@0: _this.$tooltip.html(title); Daniel@0: } Daniel@0: Daniel@0: _this.$tooltip.position({ Daniel@0: of: mouseEvent, Daniel@0: my: "left+20 topt+20", Daniel@0: collision: "flip flip" Daniel@0: }); Daniel@0: }; Daniel@0: } Daniel@0: // update: function(mouseEvent, object) { Daniel@0: // var _this = this; Daniel@0: // var objectType = null; Daniel@0: // if (object && object.sequenceAsObject && object.sequenceAsObject && object.sequenceAsObject.frequency && object.sequenceAsObject.chordsInOrder) { Daniel@0: // objectType = OBJECT_TYPE_CHORD_SEQUENCE; Daniel@0: // } Daniel@0: // if (!mouseEvent || mouseEvent.type == "mouseout" || !objectType) { Daniel@0: // _this.previousObject = null; Daniel@0: // _this.$tooltip.addClass("tooltip_animation_slow-opacity"); Daniel@0: // _this.$tooltip.removeClass("tooltip_state_visible"); Daniel@0: // } else { Daniel@0: // if (object != _this.previousObject) { Daniel@0: // _this.$tooltip.removeClass("tooltip_animation_slow-opacity"); Daniel@0: // _this.$tooltip.addClass("tooltip_state_visible"); Daniel@0: // // Chord sequence Daniel@0: // if (objectType == OBJECT_TYPE_CHORD_SEQUENCE) { Daniel@0: // _this.previousObject = object; Daniel@0: // Daniel@0: // var chordIds = _.pluck(object.sequenceAsObject.chordsInOrder, "id"); Daniel@0: // var chordTitles = []; Daniel@0: // for (var i = 0; i < chordIds.length; i++) { Daniel@0: // chordTitles.push(_this.bankOfChords.get(chordIds[i]).getNormalisedId()); Daniel@0: // } Daniel@0: // var frequency = object.sequenceAsObject.frequency; Daniel@0: // _this.$tooltip.html(_.str.sprintf("%s
in %s%% of recordings", chordTitles.join(" → "), _.str.numberFormat(frequency, 2))); Daniel@0: // } Daniel@0: // } Daniel@0: // Daniel@0: // _this.$tooltip.position({ Daniel@0: // of: mouseEvent, Daniel@0: // my: "left+20 topt+20", Daniel@0: // collision: "flip flip" Daniel@0: // }); Daniel@0: // }; Daniel@0: // } Daniel@0: }); Daniel@0: Daniel@0: TooltipModule.tooltipView = new TooltipModule.TooltipView(); Daniel@0: Daniel@0: TooltipModule._updateTooltipForDOMNodeWithExTitle = function(mouseEvent) { Daniel@0: TooltipModule.tooltipView.update(mouseEvent, $(this).attr("tooltip-title"), this); Daniel@0: }; Daniel@0: Daniel@0: Daniel@0: TooltipModule.update = function(mouseEvent, title, target) { Daniel@0: TooltipModule.tooltipView.update(mouseEvent, title, target); Daniel@0: }; Daniel@0: Daniel@0: TooltipModule.convertTitlesToTooltips = function($container) { Daniel@0: $container.find("[title]").each(function(){ Daniel@0: var $this = $(this); Daniel@0: $this Daniel@0: .attr("tooltip-title", $this.attr("title")) Daniel@0: .removeAttr("title"); Daniel@0: if (App.options.enableTooltipsForControlsWithTitles) { Daniel@0: $this Daniel@0: .on('mouseover', TooltipModule._updateTooltipForDOMNodeWithExTitle) Daniel@0: .on('mouseout', TooltipModule._updateTooltipForDOMNodeWithExTitle) Daniel@0: .on('mousemove', TooltipModule._updateTooltipForDOMNodeWithExTitle) Daniel@0: .on('mouseup', TooltipModule._updateTooltipForDOMNodeWithExTitle); Daniel@0: } Daniel@0: Daniel@0: }); Daniel@0: }; Daniel@0: }); Daniel@0: });