comparison src/DML/MainVisBundle/Resources/assets/marionette/modules/TooltipModule.js @ 0:493bcb69166c

added public content
author Daniel Wolff
date Tue, 09 Feb 2016 20:54:02 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:493bcb69166c
1 /* global ChordVis */
2 'use strict';
3
4 App.module('TooltipModule', function (TooltipModule, App, Backbone, Marionette, $, _) {
5 var renderFunctions = {};
6
7 var OBJECT_TYPE_CHORD_SEQUENCE = 1;
8
9 TooltipModule.addInitializer(function() {
10
11
12 TooltipModule.TooltipView = Backbone.View.extend({
13
14 initialize: function(options) {
15 var _this = this;
16
17 _this.$tooltip = $("<div/>").addClass("tooltip").appendTo("body");
18 },
19
20 update: function(mouseEvent, title, target) {
21 var _this = this;
22 // removing the tooltip
23 if (!mouseEvent || mouseEvent.type == "mouseout" || mouseEvent.type == "mouseup" || !title) {
24 _this.previousTarget = null;
25 _this.$tooltip.addClass("tooltip_animation_slow-opacity");
26 _this.$tooltip.removeClass("tooltip_state_visible");
27 } else {
28 if (target != _this.previousTarget) {
29 _this.$tooltip.removeClass("tooltip_animation_slow-opacity");
30 _this.$tooltip.addClass("tooltip_state_visible");
31
32 _this.$tooltip.html(title);
33 }
34
35 _this.$tooltip.position({
36 of: mouseEvent,
37 my: "left+20 topt+20",
38 collision: "flip flip"
39 });
40 };
41 }
42 // update: function(mouseEvent, object) {
43 // var _this = this;
44 // var objectType = null;
45 // if (object && object.sequenceAsObject && object.sequenceAsObject && object.sequenceAsObject.frequency && object.sequenceAsObject.chordsInOrder) {
46 // objectType = OBJECT_TYPE_CHORD_SEQUENCE;
47 // }
48 // if (!mouseEvent || mouseEvent.type == "mouseout" || !objectType) {
49 // _this.previousObject = null;
50 // _this.$tooltip.addClass("tooltip_animation_slow-opacity");
51 // _this.$tooltip.removeClass("tooltip_state_visible");
52 // } else {
53 // if (object != _this.previousObject) {
54 // _this.$tooltip.removeClass("tooltip_animation_slow-opacity");
55 // _this.$tooltip.addClass("tooltip_state_visible");
56 // // Chord sequence
57 // if (objectType == OBJECT_TYPE_CHORD_SEQUENCE) {
58 // _this.previousObject = object;
59 //
60 // var chordIds = _.pluck(object.sequenceAsObject.chordsInOrder, "id");
61 // var chordTitles = [];
62 // for (var i = 0; i < chordIds.length; i++) {
63 // chordTitles.push(_this.bankOfChords.get(chordIds[i]).getNormalisedId());
64 // }
65 // var frequency = object.sequenceAsObject.frequency;
66 // _this.$tooltip.html(_.str.sprintf("%s<br/>in %s%% of recordings", chordTitles.join(" → "), _.str.numberFormat(frequency, 2)));
67 // }
68 // }
69 //
70 // _this.$tooltip.position({
71 // of: mouseEvent,
72 // my: "left+20 topt+20",
73 // collision: "flip flip"
74 // });
75 // };
76 // }
77 });
78
79 TooltipModule.tooltipView = new TooltipModule.TooltipView();
80
81 TooltipModule._updateTooltipForDOMNodeWithExTitle = function(mouseEvent) {
82 TooltipModule.tooltipView.update(mouseEvent, $(this).attr("tooltip-title"), this);
83 };
84
85
86 TooltipModule.update = function(mouseEvent, title, target) {
87 TooltipModule.tooltipView.update(mouseEvent, title, target);
88 };
89
90 TooltipModule.convertTitlesToTooltips = function($container) {
91 $container.find("[title]").each(function(){
92 var $this = $(this);
93 $this
94 .attr("tooltip-title", $this.attr("title"))
95 .removeAttr("title");
96 if (App.options.enableTooltipsForControlsWithTitles) {
97 $this
98 .on('mouseover', TooltipModule._updateTooltipForDOMNodeWithExTitle)
99 .on('mouseout', TooltipModule._updateTooltipForDOMNodeWithExTitle)
100 .on('mousemove', TooltipModule._updateTooltipForDOMNodeWithExTitle)
101 .on('mouseup', TooltipModule._updateTooltipForDOMNodeWithExTitle);
102 }
103
104 });
105 };
106 });
107 });