forked from dsjoerg/ggtracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathggtipper.js
More file actions
78 lines (70 loc) · 2.54 KB
/
ggtipper.js
File metadata and controls
78 lines (70 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
gg.directive('ggtipper', function() {
return {
restrict: 'C',
scope: {},
link: function(scope, elm, attrs) {
// console.log("yo");
if($(elm).data('gravity')) {
gravity = $(elm).data('gravity');
} else {
gravity = $.fn.tipsy.autoBounds(10, 'sw');
}
// scope.showItCalled = _.once(function() { mixpanel.track("tooltip " + $(elm).next().children().first().attr('id')); });
scope.showIt = function() {
// scope.showItCalled();
$(elm).tipsy("show");
scope.shown = true;
}
if ($(elm).hasClass("clicky")) {
// console.log("whoa");
trigger = "manual";
scope.toggle = function() {
// console.log("no!");
if (scope.shown) {
$(elm).tipsy("hide");
delete scope.shown;
} else {
scope.showIt();
}
};
} else {
trigger = "hover";
}
$(elm).tipsy({
className: 'htmltip',
title: function(){
if($(elm).data('content')) { return $(elm).data('content'); }
return $(elm).next().html();
},
html: true,
opacity: 1.0,
offset: 10,
gravity: gravity,
trigger: trigger
});
// TODO track hovers. Hack tipsy?
// Or use a different class?
// Or use mixpanel.track_links https://mixpanel.com/docs/integration-libraries/javascript
// TODO how to make it so that clicking anywhere in the
// browser window makes the tooltip go away? maybe i should
// just be using bootstrap popover instead anyway.
//
// or copy their approach. it involves detailed
// understanding of jQuery event propagation.
//
// https://github.com/twitter/bootstrap/blob/master/js/bootstrap-dropdown.js
//
// $('html').on('click.ggtipper', function () {
// console.log("click in the tipper!");
// scope.hide();
// });
//
// scope.hide = function() {
// console.log("hiding!");
// $(elm).tipsy("hide");
// delete scope.shown;
// }
//
}
};
});