Skip to content

Commit

Permalink
Merge pull request #11114 from ncoden/feat/tooltip-disable-for-touch-…
Browse files Browse the repository at this point in the history
…9995

feat: add back official `disableForTouch` option for Tooltip #9995
  • Loading branch information
ncoden authored Apr 3, 2018
2 parents 28f9d91 + aa58961 commit ed581e1
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions js/foundation.tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,15 @@ class Tooltip extends Positionable {
* @private
*/
_events() {
var _this = this;
var $template = this.template;
const _this = this;
const hasTouch = 'ontouchstart' in window || (typeof window.ontouchstart !== 'undefined');
const $template = this.template;
var isFocus = false;

if (!this.options.disableHover) {
// `disableForTouch: Fully disable the tooltip on touch devices
if (hasTouch && this.options.disableForTouch) return;

if (!this.options.disableHover) {
this.$element
.on('mouseenter.zf.tooltip', function(e) {
if (!_this.isActive) {
Expand All @@ -213,6 +216,13 @@ class Tooltip extends Positionable {
});
}

if (hasTouch) {
this.$element
.on('tap.zf.tooltip touchend.zf.tooltip', function (e) {
_this.isActive ? _this.hide() : _this.show();
});
}

if (this.options.clickOpen) {
this.$element.on('mousedown.zf.tooltip', function(e) {
e.stopImmediatePropagation();
Expand All @@ -233,13 +243,6 @@ class Tooltip extends Positionable {
});
}

if (!this.options.disableForTouch) {
this.$element
.on('tap.zf.tooltip touchend.zf.tooltip', function(e) {
_this.isActive ? _this.hide() : _this.show();
});
}

this.$element.on({
// 'toggle.zf.trigger': this.toggle.bind(this),
// 'close.zf.trigger': this.hide.bind(this)
Expand Down Expand Up @@ -300,7 +303,6 @@ class Tooltip extends Positionable {
}

Tooltip.defaults = {
disableForTouch: false,
/**
* Time, in ms, before a tooltip should open on hover.
* @option
Expand Down Expand Up @@ -329,6 +331,15 @@ Tooltip.defaults = {
* @default false
*/
disableHover: false,
/**
* Disable the tooltip for touch devices.
* This can be useful to make elements with a tooltip on it trigger their
* action on the first tap instead of displaying the tooltip.
* @option
* @type {booelan}
* @default false
*/
disableForTouch: false,
/**
* Optional addtional classes to apply to the tooltip template on init.
* @option
Expand Down

0 comments on commit ed581e1

Please sign in to comment.