]> git.ipfire.org Git - thirdparty/foundation/foundation-sites.git/commitdiff
change default behavior of tooltips
authorCorey Snyder <corey@tangerineindustries.com>
Tue, 3 May 2016 17:02:02 +0000 (13:02 -0400)
committerCorey Snyder <corey@tangerineindustries.com>
Tue, 3 May 2016 17:02:02 +0000 (13:02 -0400)
js/foundation.tooltip.js

index dc17c3c73afc6dd5f7ef42b82db622f4811d977f..1998979f08e8687c792028f2520762801d8eec93 100644 (file)
@@ -40,7 +40,7 @@ class Tooltip {
     this.template = this.options.template ? $(this.options.template) : this._buildTemplate(elemId);
 
     this.template.appendTo(document.body)
-        .text(this.options.tipText)
+        .html(this.options.tipText)
         .hide();
 
     this.$element.attr({
@@ -248,10 +248,28 @@ class Tooltip {
         }
       })
       .on('mouseleave.zf.tooltip', function(e) {
-        clearTimeout(_this.timeout);
-        if (!isFocus || (_this.isClick && !_this.options.clickOpen)) {
-          _this.hide();
-        }
+               if (_this.options.tipHoverable) {
+                       _this.timeout = setTimeout(function () {
+                               clearTimeout(_this.timeout);
+                               if ($template.is(":hover")) {
+                                 $template.on('mouseleave', function (e) {
+                                        if (!isFocus || !_this.isClick && _this.options.clickOpen) {
+                                               _this.hide();
+                                        }
+                                        $template.off('mouseleave');
+                                 });
+                               } else {
+                                       if (!isFocus || !_this.isClick && _this.options.clickOpen) {
+                                         _this.hide();
+                                       }
+                               }
+                       }, 200); //min required to capture
+               } else {
+                       clearTimeout(_this.timeout);
+                       if (!isFocus || !_this.isClick && _this.options.clickOpen) {
+                         _this.hide();
+                       }
+               }
       });
     }
 
@@ -259,7 +277,7 @@ class Tooltip {
       this.$element.on('mousedown.zf.tooltip', function(e) {
         e.stopImmediatePropagation();
         if (_this.isClick) {
-          _this.hide();
+          //_this.hide();
           // _this.isClick = false;
         } else {
           _this.isClick = true;
@@ -431,7 +449,13 @@ Tooltip.defaults = {
    * @option
    * @example 12
    */
-  hOffset: 12
+  hOffset: 12,
+  /**
+        * Should the tip remain open if hover
+        * @option
+        * @example false
+        */
+        tipHoverable: false
 };
 
 /**