From 1a7ebd093193c6a832005d4e48f4183370f5e4ef Mon Sep 17 00:00:00 2001 From: Brian Tan Date: Mon, 4 Apr 2016 22:30:30 -0400 Subject: [PATCH] [tooltip.js] New option allowHtml Ref pr #8075 Add new option allowHtml (default false) to allow HTML in tooltip. --- js/foundation.tooltip.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/js/foundation.tooltip.js b/js/foundation.tooltip.js index 827fcd298..2dc54b0ee 100644 --- a/js/foundation.tooltip.js +++ b/js/foundation.tooltip.js @@ -39,9 +39,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) + 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': '', @@ -425,7 +431,14 @@ Tooltip.defaults = { * @option * @example 12 */ - hOffset: 12 + hOffset: 12, + /** + * Allow HTML in tooltip. Warning: If you are loading user-generated content into tooltips, + * allowing HTML may open yourself up to XSS attacks. + * @option + * @example false + */ + allowHtml: false }; /** -- 2.47.2