From af8dda6caa634ca8de7a16d1ec1aeb9b4148bd1d Mon Sep 17 00:00:00 2001 From: Kevin Ball Date: Mon, 26 Sep 2016 09:47:51 -0700 Subject: [PATCH] Add the ability to put html into tooltip --- js/foundation.tooltip.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/js/foundation.tooltip.js b/js/foundation.tooltip.js index 0da2990ad..f71b4aa8c 100644 --- a/js/foundation.tooltip.js +++ b/js/foundation.tooltip.js @@ -40,9 +40,15 @@ class Tooltip { this.options.tipText = this.options.tipText || this.$element.attr('title'); this.template = this.options.template ? $(this.options.template) : this._buildTemplate(elemId); - this.template.appendTo(document.body) - .text(this.options.tipText) - .hide(); + if(this.options.allowHtml) { + this.template.appendTo(document.body) + .html(this.options.tipText) + .hide(); + } else { + this.template.appendTo(document.body) + .text(this.options.tipText) + .hide(); + } this.$element.attr({ 'title': '', @@ -332,7 +338,8 @@ class Tooltip { * @function */ destroy() { - this.$element.attr('title', this.template.text()) + var oldText = this.options.allowHtml ? this.template.html() : this.options.text(); + this.$element.attr('title', oldText) .off('.zf.trigger .zf.tootip') // .removeClass('has-tip') .removeAttr('aria-describedby') @@ -348,6 +355,11 @@ class Tooltip { Tooltip.defaults = { disableForTouch: false, + /** + * Allow html content in tooltip (Unsafe if user generated) + * @example false + */ + allowHtml: false, /** * Time, in ms, before a tooltip should open on hover. * @option @@ -442,4 +454,4 @@ Tooltip.defaults = { // Window exports Foundation.plugin(Tooltip, 'Tooltip'); -}(jQuery); \ No newline at end of file +}(jQuery); -- 2.47.2