Skip to content

Commit 5735fc7

Browse files
committed
Fixed calback $element,element issue, added new method close, close #35
1 parent 12ddd17 commit 5735fc7

File tree

6 files changed

+47
-36
lines changed

6 files changed

+47
-36
lines changed

README.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -83,26 +83,31 @@ To use css3 animation effects please include [Animate.css](http://daneden.github
8383
// Hide the tipso tooltip
8484
$('.tipso').tipso('hide');
8585

86+
// Hide/Close the tipso tooltip from inside the tooltip and/or without hideDelay timeout
87+
$('.tipso').tipso('close');
88+
// or as alternative
89+
$('.tipso').tipso('hide', true);
90+
8691
// Destroy tipso tooltip
8792
$('.tipso').tipso('destroy');
8893

8994
// Add a callback before tipso is shown
9095
$('.tipso').tipso({
91-
onBeforeShow: function(){
96+
onBeforeShow: function ($element, element) {
9297
// Your code
9398
}
9499
});
95100

96101
// Add a callback when tipso is shown
97102
$('.tipso').tipso({
98-
onShow: function(){
103+
onShow: function ($element, element) {
99104
// Your code
100105
}
101106
});
102107

103108
// Add a callback when tipso is hidden
104109
$('.tipso').tipso({
105-
onHide: function(){
110+
onHide: function ($element, element) {
106111
// Your code
107112
}
108113
});

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tipso",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "A Lightweight Responsive jQuery Tooltip Plugin",
55
"main": ["src/tipso.min.js", "src/tipso.css"],
66
"keywords": [

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"mobile",
1111
"lightweight"
1212
],
13-
"version": "1.0.7",
13+
"version": "1.0.8",
1414
"author": "Bojan Petkovski (http://object505.com/)",
1515
"licenses": [
1616
{

src/tipso.js

+35-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* tipso - A Lightweight Responsive jQuery Tooltip Plugin v1.0.6
2+
* tipso - A Lightweight Responsive jQuery Tooltip Plugin v1.0.8
33
* Copyright (c) 2014-2015 Bojan Petkovski
44
* http://tipso.object505.com
55
* Licensed under the MIT license
@@ -40,7 +40,7 @@
4040
tooltipHover : false,
4141
content : null,
4242
ajaxContentUrl : null,
43-
ajaxContentBuffer : 0,
43+
ajaxContentBuffer : 0,
4444
contentElementId : null, //Normally used for picking template scripts
4545
useTitle : false, //Use the title tag as tooptip or not
4646
templateEngineFunc: null, //A function that compiles and renders the content
@@ -50,7 +50,8 @@
5050
};
5151

5252
function Plugin(element, options) {
53-
this.element = $(element);
53+
this.element = element;
54+
this.$element = $(this.element);
5455
this.doc = $(document);
5556
this.win = $(window);
5657
this.settings = $.extend({}, defaults, options);
@@ -60,12 +61,12 @@
6061
* data-tipso is an object then use it as extra settings and if it's not
6162
* then use it as a title.
6263
*/
63-
if (typeof(this.element.data("tipso")) === "object")
64+
if (typeof(this.$element.data("tipso")) === "object")
6465
{
65-
$.extend(this.settings, this.element.data("tipso"));
66+
$.extend(this.settings, this.$element.data("tipso"));
6667
}
6768

68-
var data_keys = Object.keys(this.element.data());
69+
var data_keys = Object.keys(this.$element.data());
6970
var data_attrs = {};
7071
for (var i = 0; i < data_keys.length; i++)
7172
{
@@ -76,7 +77,7 @@
7677
}
7778
//lowercase first letter
7879
key = key.charAt(0).toLowerCase() + key.slice(1);
79-
data_attrs[key] = this.element.data(data_keys[i]);
80+
data_attrs[key] = this.$element.data(data_keys[i]);
8081

8182
//We cannot use extend for data_attrs because they are automatically
8283
//lowercased. We need to do this manually and extend this.settings with
@@ -92,7 +93,7 @@
9293

9394
this._defaults = defaults;
9495
this._name = pluginName;
95-
this._title = this.element.attr('title');
96+
this._title = this.$element.attr('title');
9697
this.mode = 'hide';
9798
this.ieFade = !supportsTransitions;
9899

@@ -107,7 +108,7 @@
107108
$.extend(Plugin.prototype, {
108109
init: function() {
109110
var obj = this,
110-
$e = this.element,
111+
$e = this.$element,
111112
$doc = this.doc;
112113
$e.addClass('tipso_style').removeAttr('title');
113114

@@ -176,7 +177,7 @@
176177

177178
if (obj.mode === 'hide') {
178179
if ($.isFunction(obj.settings.onBeforeShow)) {
179-
obj.settings.onBeforeShow(this.element, this);
180+
obj.settings.onBeforeShow(obj.$element, obj.element, obj);
180181
}
181182
if (obj.settings.size) {
182183
tipso_bubble.addClass(obj.settings.size);
@@ -221,7 +222,7 @@
221222
.speed, function() {
222223
obj.mode = 'show';
223224
if ($.isFunction(obj.settings.onShow)) {
224-
obj.settings.onShow(this.element, this);
225+
obj.settings.onShow(obj.$element, obj.element, obj);
225226
}
226227
});
227228
} else {
@@ -236,18 +237,24 @@
236237
});
237238
obj.mode = 'show';
238239
if ($.isFunction(obj.settings.onShow)) {
239-
obj.settings.onShow(this.element, this);
240+
obj.settings.onShow(obj.$element, obj.element, obj);
240241
}
241242
$win.off('resize' + '.' + pluginName, null, 'tipsoResizeHandler');
242243
});
243244
}
244245
}, obj.settings.delay);
245246
}
246247
},
247-
hide: function() {
248+
hide: function(force) {
248249
var obj = this,
249250
$win = this.win,
250-
tipso_bubble = this.tooltip();
251+
tipso_bubble = this.tooltip(),
252+
hideDelay = obj.settings.hideDelay;
253+
254+
if (force) {
255+
hideDelay = 0;
256+
obj.mode = 'show';
257+
}
251258

252259
window.clearTimeout(obj.timeout);
253260
obj.timeout = null;
@@ -258,7 +265,7 @@
258265
function() {
259266
$(this).remove();
260267
if ($.isFunction(obj.settings.onHide) && obj.mode === 'show') {
261-
obj.settings.onHide(this.element, this);
268+
obj.settings.onHide(obj.$element, obj.element, obj);
262269
}
263270
obj.mode = 'hide';
264271
$win.off('resize' + '.' + pluginName, null, 'tipsoResizeHandler');
@@ -271,17 +278,20 @@
271278
.one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
272279
$(this).removeClass('animated ' + obj.settings.animationOut).remove();
273280
if ($.isFunction(obj.settings.onHide) && obj.mode === 'show') {
274-
obj.settings.onHide(this.element, this);
281+
obj.settings.onHide(obj.$element, obj.element, obj);
275282
}
276283
obj.mode = 'hide';
277284
$win.off('resize' + '.' + pluginName, null, 'tipsoResizeHandler');
278285
});
279286
}
280287
}
281-
}, obj.settings.hideDelay);
288+
}, hideDelay);
289+
},
290+
close: function() {
291+
this.hide(true);
282292
},
283293
destroy: function() {
284-
var $e = this.element,
294+
var $e = this.$element,
285295
$win = this.win,
286296
$doc = this.doc;
287297
$e.off('.' + pluginName);
@@ -291,7 +301,7 @@
291301
},
292302
titleContent: function() {
293303
var content,
294-
$e = this.element,
304+
$e = this.$element,
295305
obj = this;
296306
if (obj.settings.titleContent)
297307
{
@@ -305,7 +315,7 @@
305315
},
306316
content: function() {
307317
var content,
308-
$e = this.element,
318+
$e = this.$element,
309319
obj = this,
310320
title = this._title;
311321
if (obj.settings.ajaxContentUrl)
@@ -395,30 +405,26 @@
395405
return false;
396406
})();
397407

398-
function removeCornerClasses(obj)
399-
{
408+
function removeCornerClasses(obj) {
400409
obj.removeClass("top_right_corner bottom_right_corner top_left_corner bottom_left_corner");
401410
obj.find(".tipso_title").removeClass("top_right_corner bottom_right_corner top_left_corner bottom_left_corner");
402411
}
403412

404-
function reposition(thisthat)
405-
{
413+
function reposition(thisthat) {
406414
var tipso_bubble = thisthat.tooltip(),
407-
$e = thisthat.element,
415+
$e = thisthat.$element,
408416
obj = thisthat,
409417
$win = $(window),
410418
arrow = 10,
411419
pos_top, pos_left, diff;
412420

413421
var arrow_color = obj.settings.background;
414422
var title_content = obj.titleContent();
415-
if (title_content !== undefined && title_content !== '')
416-
{
423+
if (title_content !== undefined && title_content !== '') {
417424
arrow_color = obj.settings.titleBackground;
418425
}
419426

420-
if ( $e.parent().outerWidth() > $win.outerWidth() )
421-
{
427+
if ($e.parent().outerWidth() > $win.outerWidth()) {
422428
$win = $e.parent();
423429
}
424430

0 commit comments

Comments
 (0)