* @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) {
});
}
+ 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();
});
}
- 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)
}
Tooltip.defaults = {
- disableForTouch: false,
/**
* Time, in ms, before a tooltip should open on hover.
* @option
* @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