|
1 | 1 | /*!
|
2 |
| - * tipso - A Lightweight Responsive jQuery Tooltip Plugin v1.0.6 |
| 2 | + * tipso - A Lightweight Responsive jQuery Tooltip Plugin v1.0.8 |
3 | 3 | * Copyright (c) 2014-2015 Bojan Petkovski
|
4 | 4 | * http://tipso.object505.com
|
5 | 5 | * Licensed under the MIT license
|
|
40 | 40 | tooltipHover : false,
|
41 | 41 | content : null,
|
42 | 42 | ajaxContentUrl : null,
|
43 |
| - ajaxContentBuffer : 0, |
| 43 | + ajaxContentBuffer : 0, |
44 | 44 | contentElementId : null, //Normally used for picking template scripts
|
45 | 45 | useTitle : false, //Use the title tag as tooptip or not
|
46 | 46 | templateEngineFunc: null, //A function that compiles and renders the content
|
|
50 | 50 | };
|
51 | 51 |
|
52 | 52 | function Plugin(element, options) {
|
53 |
| - this.element = $(element); |
| 53 | + this.element = element; |
| 54 | + this.$element = $(this.element); |
54 | 55 | this.doc = $(document);
|
55 | 56 | this.win = $(window);
|
56 | 57 | this.settings = $.extend({}, defaults, options);
|
|
60 | 61 | * data-tipso is an object then use it as extra settings and if it's not
|
61 | 62 | * then use it as a title.
|
62 | 63 | */
|
63 |
| - if (typeof(this.element.data("tipso")) === "object") |
| 64 | + if (typeof(this.$element.data("tipso")) === "object") |
64 | 65 | {
|
65 |
| - $.extend(this.settings, this.element.data("tipso")); |
| 66 | + $.extend(this.settings, this.$element.data("tipso")); |
66 | 67 | }
|
67 | 68 |
|
68 |
| - var data_keys = Object.keys(this.element.data()); |
| 69 | + var data_keys = Object.keys(this.$element.data()); |
69 | 70 | var data_attrs = {};
|
70 | 71 | for (var i = 0; i < data_keys.length; i++)
|
71 | 72 | {
|
|
76 | 77 | }
|
77 | 78 | //lowercase first letter
|
78 | 79 | 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]); |
80 | 81 |
|
81 | 82 | //We cannot use extend for data_attrs because they are automatically
|
82 | 83 | //lowercased. We need to do this manually and extend this.settings with
|
|
92 | 93 |
|
93 | 94 | this._defaults = defaults;
|
94 | 95 | this._name = pluginName;
|
95 |
| - this._title = this.element.attr('title'); |
| 96 | + this._title = this.$element.attr('title'); |
96 | 97 | this.mode = 'hide';
|
97 | 98 | this.ieFade = !supportsTransitions;
|
98 | 99 |
|
|
107 | 108 | $.extend(Plugin.prototype, {
|
108 | 109 | init: function() {
|
109 | 110 | var obj = this,
|
110 |
| - $e = this.element, |
| 111 | + $e = this.$element, |
111 | 112 | $doc = this.doc;
|
112 | 113 | $e.addClass('tipso_style').removeAttr('title');
|
113 | 114 |
|
|
176 | 177 |
|
177 | 178 | if (obj.mode === 'hide') {
|
178 | 179 | if ($.isFunction(obj.settings.onBeforeShow)) {
|
179 |
| - obj.settings.onBeforeShow(this.element, this); |
| 180 | + obj.settings.onBeforeShow(obj.$element, obj.element, obj); |
180 | 181 | }
|
181 | 182 | if (obj.settings.size) {
|
182 | 183 | tipso_bubble.addClass(obj.settings.size);
|
|
221 | 222 | .speed, function() {
|
222 | 223 | obj.mode = 'show';
|
223 | 224 | if ($.isFunction(obj.settings.onShow)) {
|
224 |
| - obj.settings.onShow(this.element, this); |
| 225 | + obj.settings.onShow(obj.$element, obj.element, obj); |
225 | 226 | }
|
226 | 227 | });
|
227 | 228 | } else {
|
|
236 | 237 | });
|
237 | 238 | obj.mode = 'show';
|
238 | 239 | if ($.isFunction(obj.settings.onShow)) {
|
239 |
| - obj.settings.onShow(this.element, this); |
| 240 | + obj.settings.onShow(obj.$element, obj.element, obj); |
240 | 241 | }
|
241 | 242 | $win.off('resize' + '.' + pluginName, null, 'tipsoResizeHandler');
|
242 | 243 | });
|
243 | 244 | }
|
244 | 245 | }, obj.settings.delay);
|
245 | 246 | }
|
246 | 247 | },
|
247 |
| - hide: function() { |
| 248 | + hide: function(force) { |
248 | 249 | var obj = this,
|
249 | 250 | $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 | + } |
251 | 258 |
|
252 | 259 | window.clearTimeout(obj.timeout);
|
253 | 260 | obj.timeout = null;
|
|
258 | 265 | function() {
|
259 | 266 | $(this).remove();
|
260 | 267 | if ($.isFunction(obj.settings.onHide) && obj.mode === 'show') {
|
261 |
| - obj.settings.onHide(this.element, this); |
| 268 | + obj.settings.onHide(obj.$element, obj.element, obj); |
262 | 269 | }
|
263 | 270 | obj.mode = 'hide';
|
264 | 271 | $win.off('resize' + '.' + pluginName, null, 'tipsoResizeHandler');
|
|
271 | 278 | .one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function(){
|
272 | 279 | $(this).removeClass('animated ' + obj.settings.animationOut).remove();
|
273 | 280 | if ($.isFunction(obj.settings.onHide) && obj.mode === 'show') {
|
274 |
| - obj.settings.onHide(this.element, this); |
| 281 | + obj.settings.onHide(obj.$element, obj.element, obj); |
275 | 282 | }
|
276 | 283 | obj.mode = 'hide';
|
277 | 284 | $win.off('resize' + '.' + pluginName, null, 'tipsoResizeHandler');
|
278 | 285 | });
|
279 | 286 | }
|
280 | 287 | }
|
281 |
| - }, obj.settings.hideDelay); |
| 288 | + }, hideDelay); |
| 289 | + }, |
| 290 | + close: function() { |
| 291 | + this.hide(true); |
282 | 292 | },
|
283 | 293 | destroy: function() {
|
284 |
| - var $e = this.element, |
| 294 | + var $e = this.$element, |
285 | 295 | $win = this.win,
|
286 | 296 | $doc = this.doc;
|
287 | 297 | $e.off('.' + pluginName);
|
|
291 | 301 | },
|
292 | 302 | titleContent: function() {
|
293 | 303 | var content,
|
294 |
| - $e = this.element, |
| 304 | + $e = this.$element, |
295 | 305 | obj = this;
|
296 | 306 | if (obj.settings.titleContent)
|
297 | 307 | {
|
|
305 | 315 | },
|
306 | 316 | content: function() {
|
307 | 317 | var content,
|
308 |
| - $e = this.element, |
| 318 | + $e = this.$element, |
309 | 319 | obj = this,
|
310 | 320 | title = this._title;
|
311 | 321 | if (obj.settings.ajaxContentUrl)
|
|
395 | 405 | return false;
|
396 | 406 | })();
|
397 | 407 |
|
398 |
| - function removeCornerClasses(obj) |
399 |
| - { |
| 408 | + function removeCornerClasses(obj) { |
400 | 409 | obj.removeClass("top_right_corner bottom_right_corner top_left_corner bottom_left_corner");
|
401 | 410 | obj.find(".tipso_title").removeClass("top_right_corner bottom_right_corner top_left_corner bottom_left_corner");
|
402 | 411 | }
|
403 | 412 |
|
404 |
| - function reposition(thisthat) |
405 |
| - { |
| 413 | + function reposition(thisthat) { |
406 | 414 | var tipso_bubble = thisthat.tooltip(),
|
407 |
| - $e = thisthat.element, |
| 415 | + $e = thisthat.$element, |
408 | 416 | obj = thisthat,
|
409 | 417 | $win = $(window),
|
410 | 418 | arrow = 10,
|
411 | 419 | pos_top, pos_left, diff;
|
412 | 420 |
|
413 | 421 | var arrow_color = obj.settings.background;
|
414 | 422 | var title_content = obj.titleContent();
|
415 |
| - if (title_content !== undefined && title_content !== '') |
416 |
| - { |
| 423 | + if (title_content !== undefined && title_content !== '') { |
417 | 424 | arrow_color = obj.settings.titleBackground;
|
418 | 425 | }
|
419 | 426 |
|
420 |
| - if ( $e.parent().outerWidth() > $win.outerWidth() ) |
421 |
| - { |
| 427 | + if ($e.parent().outerWidth() > $win.outerWidth()) { |
422 | 428 | $win = $e.parent();
|
423 | 429 | }
|
424 | 430 |
|
|
0 commit comments