Created
June 8, 2021 13:07
-
-
Save lucmarcio/cfbd3b09b0ffe7516ce49812d0667d51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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