-
Notifications
You must be signed in to change notification settings - Fork 1
/
depage-tooltip.js
141 lines (123 loc) · 4.02 KB
/
depage-tooltip.js
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* @require framework/shared/jquery-1.12.3.min.js
* @require framework/shared/depage-jquery-plugins/depage-markerbox.js
*
* @file depage-tool-tip
*
* Tooltip box extends Marker box
*
* copyright (c) 2006-2012 Frank Hellenkamp [[email protected]]
*
* @author Ben Wallis
*/
(function($){
if(!$.depage){
$.depage = {};
};
/**
* tooltip
*
* @param el - file input
* @param index
* @param options
*/
$.depage.tooltip = function(el, index, options){
// To avoid scope issues, use 'base' instead of 'this' to reference this class from internal events and functions.
var base = this;
// Access to jQuery and DOM versions of element
base.$el = $(el);
base.el = el;
var showTimeout = null;
// Add a reverse reference to the DOM object
base.$el.data("depage.tooltip", base);
// {{{ init
/**
* Init
*
* Get the plugin options.
*
* @return void
*/
base.init = function(){
base.options = $.extend({}, $.depage.tooltip.defaultOptions, options);
$.extend(base, $.depage.markerbox(base.options));
base.tip();
};
// }}}
// {{{ tip()
/**
* tip
*
* @return void
*/
base.tip = function(){
base.$el
.bind('click.tooltip', function(e) {
clearTimeout(showTimeout);
base.hide();
})
.bind('mouseenter.tooltip', function(e) {
clearTimeout(showTimeout);
showTimeout = setTimeout(function() {
base.show();
}, base.options.fadeinTimeout);
base.$el.attr("data-temp-title", base.$el.attr("title"));
base.$el.removeAttr("title");
return false;
})
.bind('mouseleave.tooltip', function(e) {
clearTimeout(showTimeout);
var hideIfOut = function(e) {
// FF does not have toElement, and only relatedTarget on mouseleave - e.target is for mousemove
if ($(e.toElement || e.relatedTarget || e.target).parents('#depage-tooltip').length === 0) {
base.hide();
base.$el.attr("title", base.$el.attr("data-temp-title"));
return true;
}
return false;
};
if (!hideIfOut(e)) {
var $document = $(document);
// workaround for mouseleave events caused by the dialogue appearance
$document.bind('mousemove.tooltip', function(e){
if(hideIfOut(e)){
$document.unbind('mousemove.tooltip');
}
});
}
return false;
});
};
/// }}}
base.init();
return base;
};
// }}}
/**
* Default Options
*
* id - the id of the dialogue element wrapper to display
* message - message the dialouge will display
* buttons - buttons to supply (with corresponding event triggered)
* classes - css classes to supply to the wrapper and content elements
*
*/
$.depage.tooltip.defaultOptions = {
id : 'depage-tooltip',
classes : 'depage-tooltip',
icon: '',
title: '',
message: '',
direction : 'TL',
directionMarker : null,
fadeinTimeout: 500,
fadeinDuration: 200,
fadeoutDuration: 200
};
$.fn.depageTooltip = function(options){
return this.each(function(index){
(new $.depage.tooltip(this, index, options));
});
};
})(jQuery);
/* vim:set ft=javascript sw=4 sts=4 fdm=marker : */