Skip to content

Commit 4a02b0f

Browse files
author
Guillaume Chau
committed
chore: v2.0.0
1 parent d8412fb commit 4a02b0f

4 files changed

Lines changed: 142 additions & 30 deletions

File tree

dist/v-tooltip.esm.js

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ function addClasses(el, classes) {
109109
}
110110
});
111111

112-
if (el instanceof SVGElement) {
112+
if (el.prototype && el instanceof SVGElement) {
113113
el.setAttribute('class', classList.join(' '));
114114
} else {
115115
el.className = classList.join(' ');
@@ -141,7 +141,7 @@ function removeClasses(el, classes) {
141141
}
142142
});
143143

144-
if (el instanceof SVGElement) {
144+
if (el.prototype && el instanceof SVGElement) {
145145
el.setAttribute('class', classList.join(' '));
146146
} else {
147147
el.className = classList.join(' ');
@@ -244,7 +244,9 @@ function () {
244244

245245
// apply user options over default ones
246246
_options = _objectSpread({}, DEFAULT_OPTIONS, _options);
247-
_reference.jquery && (_reference = _reference[0]); // cache reference and options
247+
_reference.jquery && (_reference = _reference[0]);
248+
this.show = this.show.bind(this);
249+
this.hide = this.hide.bind(this); // cache reference and options
248250

249251
this.reference = _reference;
250252
this.options = _options; // set initial state
@@ -375,7 +377,12 @@ function () {
375377
this._isDisposed = false;
376378
this._enableDocumentTouch = events.indexOf('manual') === -1; // set event listeners
377379

378-
this._setEventListeners(this.reference, events, this.options);
380+
this._setEventListeners(this.reference, events, this.options); // title attribute
381+
382+
383+
this.$_originalTitle = this.reference.getAttribute('title');
384+
this.reference.removeAttribute('title');
385+
this.reference.setAttribute('data-original-title', this.$_originalTitle);
379386
}
380387
/**
381388
* Creates a new tooltip node
@@ -624,22 +631,39 @@ function () {
624631
_this5._tooltipNode.removeEventListener('click', _this5.hide); // Don't remove popper instance, just the HTML element
625632

626633

627-
_this5._tooltipNode.parentNode.removeChild(_this5._tooltipNode);
628-
629-
_this5._tooltipNode = null;
634+
_this5._removeTooltipNode();
630635
}
631636
}, disposeTime);
632637
}
633638

634639
removeClasses(this.reference, ['v-tooltip-open']);
635640
return this;
636641
}
642+
}, {
643+
key: "_removeTooltipNode",
644+
value: function _removeTooltipNode() {
645+
if (!this._tooltipNode) return;
646+
var parentNode = this._tooltipNode.parentNode;
647+
648+
if (parentNode) {
649+
parentNode.removeChild(this._tooltipNode);
650+
this.reference.removeAttribute('aria-describedby');
651+
}
652+
653+
this._tooltipNode = null;
654+
}
637655
}, {
638656
key: "_dispose",
639657
value: function _dispose() {
640658
var _this6 = this;
641659

642-
this._isDisposed = true; // remove event listeners first to prevent any unexpected behaviour
660+
this._isDisposed = true;
661+
this.reference.removeAttribute('data-original-title');
662+
663+
if (this.$_originalTitle) {
664+
this.reference.setAttribute('title', this.$_originalTitle);
665+
} // remove event listeners first to prevent any unexpected behaviour
666+
643667

644668
this._events.forEach(function (_ref) {
645669
var func = _ref.func,
@@ -661,9 +685,7 @@ function () {
661685
this.popperInstance.destroy(); // destroy tooltipNode if removeOnDestroy is not set, as popperInstance.destroy() already removes the element
662686

663687
if (!this.popperInstance.options.removeOnDestroy) {
664-
this._tooltipNode.parentNode.removeChild(this._tooltipNode);
665-
666-
this._tooltipNode = null;
688+
this._removeTooltipNode();
667689
}
668690
} else {
669691
this._noLongerOpen();
@@ -1335,6 +1357,9 @@ var script = {
13351357
this.show();
13361358
}
13371359
},
1360+
deactivated: function deactivated() {
1361+
this.hide();
1362+
},
13381363
beforeDestroy: function beforeDestroy() {
13391364
this.dispose();
13401365
},
@@ -1451,11 +1476,27 @@ var script = {
14511476
this.popperInstance = new Popper(reference, popoverNode, popperOptions); // Fix position
14521477

14531478
requestAnimationFrame(function () {
1479+
if (_this3.hidden) {
1480+
_this3.hidden = false;
1481+
1482+
_this3.$_hide();
1483+
1484+
return;
1485+
}
1486+
14541487
if (!_this3.$_isDisposed && _this3.popperInstance) {
14551488
_this3.popperInstance.scheduleUpdate(); // Show the tooltip
14561489

14571490

14581491
requestAnimationFrame(function () {
1492+
if (_this3.hidden) {
1493+
_this3.hidden = false;
1494+
1495+
_this3.$_hide();
1496+
1497+
return;
1498+
}
1499+
14591500
if (!_this3.$_isDisposed) {
14601501
_this3.isOpen = true;
14611502
} else {
@@ -1583,6 +1624,7 @@ var script = {
15831624
!_this5.$_preventOpen && _this5.show({
15841625
event: event
15851626
});
1627+
_this5.hidden = false;
15861628
};
15871629

15881630
_this5.$_events.push({
@@ -1602,6 +1644,8 @@ var script = {
16021644
_this5.hide({
16031645
event: event
16041646
});
1647+
1648+
_this5.hidden = true;
16051649
};
16061650

16071651
_this5.$_events.push({
@@ -1880,14 +1924,14 @@ var __vue_render__ = function() {
18801924
var _c = _vm._self._c || _h;
18811925
return _c("div", { staticClass: "v-popover", class: _vm.cssClass }, [
18821926
_c(
1883-
"span",
1927+
"div",
18841928
{
18851929
ref: "trigger",
18861930
staticClass: "trigger",
18871931
staticStyle: { display: "inline-block" },
18881932
attrs: {
18891933
"aria-describedby": _vm.popoverId,
1890-
tabindex: _vm.trigger.indexOf("focus") !== -1 ? 0 : -1
1934+
tabindex: _vm.trigger.indexOf("focus") !== -1 ? 0 : undefined
18911935
}
18921936
},
18931937
[_vm._t("default")],
@@ -1904,7 +1948,19 @@ var __vue_render__ = function() {
19041948
},
19051949
attrs: {
19061950
id: _vm.popoverId,
1907-
"aria-hidden": _vm.isOpen ? "false" : "true"
1951+
"aria-hidden": _vm.isOpen ? "false" : "true",
1952+
tabindex: _vm.autoHide ? 0 : undefined
1953+
},
1954+
on: {
1955+
keyup: function($event) {
1956+
if (
1957+
!$event.type.indexOf("key") &&
1958+
_vm._k($event.keyCode, "esc", 27, $event.key, ["Esc", "Escape"])
1959+
) {
1960+
return null
1961+
}
1962+
_vm.autoHide && _vm.hide();
1963+
}
19081964
}
19091965
},
19101966
[

dist/v-tooltip.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/v-tooltip.umd.js

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,7 +2713,7 @@
27132713
}
27142714
});
27152715

2716-
if (el instanceof SVGElement) {
2716+
if (el.prototype && el instanceof SVGElement) {
27172717
el.setAttribute('class', classList.join(' '));
27182718
} else {
27192719
el.className = classList.join(' ');
@@ -2745,7 +2745,7 @@
27452745
}
27462746
});
27472747

2748-
if (el instanceof SVGElement) {
2748+
if (el.prototype && el instanceof SVGElement) {
27492749
el.setAttribute('class', classList.join(' '));
27502750
} else {
27512751
el.className = classList.join(' ');
@@ -2848,7 +2848,9 @@
28482848

28492849
// apply user options over default ones
28502850
_options = _objectSpread({}, DEFAULT_OPTIONS, _options);
2851-
_reference.jquery && (_reference = _reference[0]); // cache reference and options
2851+
_reference.jquery && (_reference = _reference[0]);
2852+
this.show = this.show.bind(this);
2853+
this.hide = this.hide.bind(this); // cache reference and options
28522854

28532855
this.reference = _reference;
28542856
this.options = _options; // set initial state
@@ -2979,7 +2981,12 @@
29792981
this._isDisposed = false;
29802982
this._enableDocumentTouch = events.indexOf('manual') === -1; // set event listeners
29812983

2982-
this._setEventListeners(this.reference, events, this.options);
2984+
this._setEventListeners(this.reference, events, this.options); // title attribute
2985+
2986+
2987+
this.$_originalTitle = this.reference.getAttribute('title');
2988+
this.reference.removeAttribute('title');
2989+
this.reference.setAttribute('data-original-title', this.$_originalTitle);
29832990
}
29842991
/**
29852992
* Creates a new tooltip node
@@ -3228,22 +3235,39 @@
32283235
_this5._tooltipNode.removeEventListener('click', _this5.hide); // Don't remove popper instance, just the HTML element
32293236

32303237

3231-
_this5._tooltipNode.parentNode.removeChild(_this5._tooltipNode);
3232-
3233-
_this5._tooltipNode = null;
3238+
_this5._removeTooltipNode();
32343239
}
32353240
}, disposeTime);
32363241
}
32373242

32383243
removeClasses(this.reference, ['v-tooltip-open']);
32393244
return this;
32403245
}
3246+
}, {
3247+
key: "_removeTooltipNode",
3248+
value: function _removeTooltipNode() {
3249+
if (!this._tooltipNode) return;
3250+
var parentNode = this._tooltipNode.parentNode;
3251+
3252+
if (parentNode) {
3253+
parentNode.removeChild(this._tooltipNode);
3254+
this.reference.removeAttribute('aria-describedby');
3255+
}
3256+
3257+
this._tooltipNode = null;
3258+
}
32413259
}, {
32423260
key: "_dispose",
32433261
value: function _dispose() {
32443262
var _this6 = this;
32453263

3246-
this._isDisposed = true; // remove event listeners first to prevent any unexpected behaviour
3264+
this._isDisposed = true;
3265+
this.reference.removeAttribute('data-original-title');
3266+
3267+
if (this.$_originalTitle) {
3268+
this.reference.setAttribute('title', this.$_originalTitle);
3269+
} // remove event listeners first to prevent any unexpected behaviour
3270+
32473271

32483272
this._events.forEach(function (_ref) {
32493273
var func = _ref.func,
@@ -3265,9 +3289,7 @@
32653289
this.popperInstance.destroy(); // destroy tooltipNode if removeOnDestroy is not set, as popperInstance.destroy() already removes the element
32663290

32673291
if (!this.popperInstance.options.removeOnDestroy) {
3268-
this._tooltipNode.parentNode.removeChild(this._tooltipNode);
3269-
3270-
this._tooltipNode = null;
3292+
this._removeTooltipNode();
32713293
}
32723294
} else {
32733295
this._noLongerOpen();
@@ -4052,6 +4074,9 @@
40524074
this.show();
40534075
}
40544076
},
4077+
deactivated: function deactivated() {
4078+
this.hide();
4079+
},
40554080
beforeDestroy: function beforeDestroy() {
40564081
this.dispose();
40574082
},
@@ -4168,11 +4193,27 @@
41684193
this.popperInstance = new Popper(reference, popoverNode, popperOptions); // Fix position
41694194

41704195
requestAnimationFrame(function () {
4196+
if (_this3.hidden) {
4197+
_this3.hidden = false;
4198+
4199+
_this3.$_hide();
4200+
4201+
return;
4202+
}
4203+
41714204
if (!_this3.$_isDisposed && _this3.popperInstance) {
41724205
_this3.popperInstance.scheduleUpdate(); // Show the tooltip
41734206

41744207

41754208
requestAnimationFrame(function () {
4209+
if (_this3.hidden) {
4210+
_this3.hidden = false;
4211+
4212+
_this3.$_hide();
4213+
4214+
return;
4215+
}
4216+
41764217
if (!_this3.$_isDisposed) {
41774218
_this3.isOpen = true;
41784219
} else {
@@ -4300,6 +4341,7 @@
43004341
!_this5.$_preventOpen && _this5.show({
43014342
event: event
43024343
});
4344+
_this5.hidden = false;
43034345
};
43044346

43054347
_this5.$_events.push({
@@ -4319,6 +4361,8 @@
43194361
_this5.hide({
43204362
event: event
43214363
});
4364+
4365+
_this5.hidden = true;
43224366
};
43234367

43244368
_this5.$_events.push({
@@ -4597,14 +4641,14 @@
45974641
var _c = _vm._self._c || _h;
45984642
return _c("div", { staticClass: "v-popover", class: _vm.cssClass }, [
45994643
_c(
4600-
"span",
4644+
"div",
46014645
{
46024646
ref: "trigger",
46034647
staticClass: "trigger",
46044648
staticStyle: { display: "inline-block" },
46054649
attrs: {
46064650
"aria-describedby": _vm.popoverId,
4607-
tabindex: _vm.trigger.indexOf("focus") !== -1 ? 0 : -1
4651+
tabindex: _vm.trigger.indexOf("focus") !== -1 ? 0 : undefined
46084652
}
46094653
},
46104654
[_vm._t("default")],
@@ -4621,7 +4665,19 @@
46214665
},
46224666
attrs: {
46234667
id: _vm.popoverId,
4624-
"aria-hidden": _vm.isOpen ? "false" : "true"
4668+
"aria-hidden": _vm.isOpen ? "false" : "true",
4669+
tabindex: _vm.autoHide ? 0 : undefined
4670+
},
4671+
on: {
4672+
keyup: function($event) {
4673+
if (
4674+
!$event.type.indexOf("key") &&
4675+
_vm._k($event.keyCode, "esc", 27, $event.key, ["Esc", "Escape"])
4676+
) {
4677+
return null
4678+
}
4679+
_vm.autoHide && _vm.hide();
4680+
}
46254681
}
46264682
},
46274683
[

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "v-tooltip",
3-
"version": "2.0.0-rc.33",
3+
"version": "2.0.0",
44
"description": "Easy tooltips with Vue 2.x",
55
"author": "Guillaume Chau <guillaume.b.chau@gmail.com>",
66
"scripts": {

0 commit comments

Comments
 (0)