Skip to content

Commit

Permalink
Added destroy and reload methods for tooltips.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Humphreys committed Apr 27, 2012
1 parent bea4deb commit f428931
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions javascripts/jquery.tooltips.js
Expand Up @@ -17,6 +17,8 @@
return this.each(function() {
var targets, tips, tipTemplate, poll;

$(window).data('tooltips', 'init');

targets = $('.has-tip');
tips = $('.tooltip');
tipTemplate = function(target, content) {
Expand All @@ -39,7 +41,7 @@
tip.fadeOut(150);
});
}
$(window).resize(function() {
$(window).on('resize.tooltip', function() {
var tips = $('.tooltip');
tips.each(function() {
var data, target, tip, classes;
Expand All @@ -57,11 +59,11 @@
});

if (Modernizr.touch) {
$('.tooltip').live('click touchstart touchend', function(e) {
$('.tooltip').on('click.tooltip touchstart.tooltip touchend.tooltip', function(e) {
e.preventDefault();
$(this).fadeOut(150);
});
targets.live('click touchstart touchend', function(e){
targets.on('click.tooltip touchstart.tooltip touchend.tooltip', function(e){
e.preventDefault();
$('.tooltip').hide();
$('span[data-id=' + $(this).data('id') + '].tooltip').fadeIn(150);
Expand All @@ -78,6 +80,19 @@

});
},
reload : function() {
var $self = $(this);
($self.data('tooltips')) ? $self.tooltips('destroy').tooltips('init') : $self.tooltips('init');
},
destroy : function() {
return this.each(function(){
$(window).unbind('.tooltip');
$('.has-tip').unbind('.tooltip');
$('.tooltip').each(function(i){
$($('.has-tip').get(i)).attr('title', $(this).text());
}).remove();
});
},
reposition : function(target, tip, classes) {
var width, nub, nubHeight, nubWidth, row;

Expand Down

0 comments on commit f428931

Please sign in to comment.