Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save lucmarcio/cfbd3b09b0ffe7516ce49812d0667d51 to your computer and use it in GitHub Desktop.
Save lucmarcio/cfbd3b09b0ffe7516ce49812d0667d51 to your computer and use it in GitHub Desktop.
Vue.directive('s-tooltip', {
bind: function bsTooltipCreate(el, binding) {
let trigger;
console.log("v-tooltip");
console.dir(el);
if (binding.modifiers.focus || binding.modifiers.hover || binding.modifiers.click) {
const t = [];
if (binding.modifiers.focus) t.push('focus');
if (binding.modifiers.hover) t.push('hover');
if (binding.modifiers.click) t.push('click');
trigger = t.join(' ');
}
$(el).tooltip({
title: binding.value,
placement: binding.arg,
trigger: trigger,
html: binding.modifiers.html
});
},
update: function bsTooltipUpdate(el, binding) {
const $el = $(el);
$el.attr('title', binding.value).tooltip('fixTitle');
const data = $el.data('bs.tooltip');
if (binding.modifiers.live) { // update live without flickering (but it doesn't reposition)
if (data.$tip) {
if (data.options.html) data.$tip.find('.tooltip-inner').html(binding.value);
else data.$tip.find('.tooltip-inner').text(binding.value);
}
} else {
if (data.inState.hover || data.inState.focus || data.inState.click) $el.tooltip('show');
}
},
unbind(el, binding) {
$(el).tooltip('destroy');
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment