-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.bubbles.js
More file actions
176 lines (170 loc) · 7.02 KB
/
jquery.bubbles.js
File metadata and controls
176 lines (170 loc) · 7.02 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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/**
* This function shows the bubble on mouseover on the element, given certain a config map:
* text: - the html to be included in the bubble in the top half, will have id='jquerybubbles_bubble_text'
* subtext: - the html to be included in the bubble in the bottom half, will have id='jquerybubbles_bubble_subtext'
* side: - the side of the element the bubble will appear to. Can be either 'left', 'right', 'top' or 'bottom'
*
*/
(function() {
function Bubblify() {
this.initialize.apply(this, arguments)
}
Bubblify.prototype = {
initialize : function(container, config){
var cont = $(container);
cont.bind('mouseover', function(){
show_bubble_at_element($(container), config.text, config.subtext, config.side);
});
cont.bind('mouseout', function(){
hide_bubble();
});
}
};
jQuery.fn.bubbleify = function(config) {
return this.each(function() {
new Bubblify(this, config);
});
};
})(jQuery);
/**
* This plugin transforms an element into a step for a tutorial.
* config = {
* text: - the text to display in the bubble (see bubbleify())
* subtext: - the subtext to display in the bubble (see bubbleify())
* side: - the side to wich to display the bubble, can be 'up', 'bottom', 'left' or 'right' (see bubbleify())
* next: - the jQuery object that receives the next step
* finish: - the event type that will accomplish this step and trigger the next
* finish_receiver: - (optional) the receiver of the finish event. By default set to <this>
* finish_callback(): - (optional) a function to execute once this step is finished.
* finish_condition(finish_event): - (optional) a function which evaluation has to return true for the step to be considered completed.
* The function is passed the finish event.
* }
*/
(function() {
function Tutorialstep() {
this.initialize.apply(this, arguments)
}
Tutorialstep.prototype = {
initialize : function(container, config){
var cont = $(container);
var start_callback = function(event){
if(event.target != container){
return true;
}
cont.unbind('tutorialstep', start_callback);
show_bubble_at_element($(container), config.text, config.subtext, config.side);
if(config.finish_receiver){
config.finish_receiver.bind(config.finish, end_callback);
}else{
cont.bind(config.finish, end_callback)
}
event.stopPropagation();
return false;
}
var end_callback = function(event){
if(config.finish_condition){
if(!config.finish_condition(event)){
if(config.finish_callback){
config.finish_callback();
}
return true;
}
}
if(config.finish_receiver){
config.finish_receiver.unbind(config.finish, end_callback);
}else{
cont.unbind(config.finish, end_callback)
} hide_bubble();
if(config.finish_callback){
config.finish_callback();
}
try{
config.next.trigger('tutorialstep');
}catch(Exception){}
}
cont.bind('tutorialstep', start_callback);
}
};
jQuery.fn.tutorialstep = function(config) {
return this.each(function() {
new Tutorialstep(this, config);
});
};
})(jQuery);
function show_bubble_at_element(element, text, subtext, side){
var id_bubble = $('#jquerybubbles_bubble');
var id_bubble_arrow = $('#jquerybubbles_bubble_arrow');
var id_bubble_text = $('#jquerybubbles_bubble_text');
var id_bubble_subtext = $('#jquerybubbles_bubble_subtext');
if(id_bubble.length == 0){
id_bubble_text = $('<div id="jquerybubbles_bubble_text"></div>');
id_bubble_subtext = $('<div id="jquerybubbles_bubble_subtext"></div>');
id_bubble_arrow=$('<div id="jquerybubbles_bubble_arrow"></div>');
id_bubble = $('<div id="jquerybubbles_bubble" style="border-radius: 1px"></div>')
.append(id_bubble_text)
.append(id_bubble_subtext)
.append(id_bubble_arrow);
$('body').prepend(id_bubble);
}
id_bubble_text.html(text);
id_bubble_subtext.html(subtext);
var offset_x;
var offset_y;
element.show();
switch(side){
case 'left':
offset_x = -20 - id_bubble.outerWidth();
offset_y = (element.outerHeight()-id_bubble.outerHeight())/2;
id_bubble_arrow.css({
'border-color': 'transparent transparent transparent #2A2A2A',
'right': '-25px',
'left': '',
'top': (id_bubble.outerHeight()-20)/2+'px',
'bottom': ''
});
break;
case 'right':
offset_x = 20 + element.outerWidth();
offset_y = (element.outerHeight()-id_bubble.outerHeight())/2;
id_bubble_arrow.css({
'border-color': 'transparent #2A2A2A transparent transparent',
'left': '-25px',
'right': '',
'top': (id_bubble.outerHeight()-20)/2+'px',
'bottom': ''
});
break;
case 'top':
offset_x = (element.outerWidth()-id_bubble.outerWidth())/2;
offset_y = -25 - id_bubble.outerHeight();
id_bubble_arrow.css({
'border-color': ' #2A2A2A transparent transparent transparent',
'left': (id_bubble.outerWidth()-20)/2+'px',
'right': '',
'top': '',
'bottom': '-25px'
});
break;
case 'bottom':
offset_x = (element.outerWidth()-id_bubble.outerWidth())/2;
offset_y = 25 + element.outerHeight();
id_bubble_arrow.css({
'border-color': 'transparent transparent #2A2A2A transparent',
'left': (id_bubble.outerWidth()-20)/2+'px',
'right': '',
'top': '-25px',
'bottom': ''
});
break;
}
id_bubble.effect('highlight', {times: 2, color: 'darkgrey'});
var pos_x = element.offset().left + offset_x;
var pos_y = element.offset().top + offset_y;
id_bubble.css({
left: pos_x,
top: Math.max(0, pos_y)
});
}
function hide_bubble(){
$('#jquerybubbles_bubble').hide();
}