]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
[tooltip.js] New option allowHtml 8527/head
authorBrian Tan <briantan888@users.noreply.github.com>
Tue, 5 Apr 2016 02:30:30 +0000 (22:30 -0400)
committerBrian Tan <briantan888@users.noreply.github.com>
Tue, 5 Apr 2016 02:30:30 +0000 (22:30 -0400)
Ref pr #8075 Add new option allowHtml (default false) to allow HTML in tooltip.

js/foundation.tooltip.js

index 827fcd298490d4b3cba946564b9c7aa8951e8878..2dc54b0ee7a8846ec230e2236bdc3da8469a21a6 100644 (file)
@@ -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
 };
 
 /**