Skip to content

Commit 3623c24

Browse files
committed
Improve mobile functionality
1 parent 7a80595 commit 3623c24

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

jTippy.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,26 @@
7474
}
7575
else if( existing.trigger === 'focus' )
7676
{
77-
existing.dom_wrapped.off('focus', existing.show);
78-
existing.dom_wrapped.off('blur', existing.hide);
77+
existing.dom_wrapped.off('touchstart focus', existing.show);
78+
existing.dom_wrapped.off('touchend blur', existing.hide);
7979
}
8080
else if( existing.trigger === 'hover' )
8181
{
82-
existing.dom_wrapped.off('mouseenter', existing.show);
83-
existing.dom_wrapped.off('mouseleave', existing.hide);
82+
existing.dom_wrapped.off('touchstart mouseenter', existing.show);
83+
existing.dom_wrapped.off('touchend mouseleave', existing.hide);
8484
}
8585
else if( existing.trigger === 'hoverfocus' )
8686
{
8787
existing.dom_wrapped.off('focus', existing.hoverfocusFocusShow);
8888
existing.dom_wrapped.off('blur', existing.hoverfocusBlur);
8989

90-
existing.dom_wrapped.off('mouseenter', existing.show);
91-
existing.dom_wrapped.off('mouseleave', existing.hoverfocusHide);
90+
existing.dom_wrapped.off('touchstart mouseenter', existing.show);
91+
existing.dom_wrapped.off('touchend mouseleave', existing.hoverfocusHide);
92+
}
93+
94+
//hide on click if not click
95+
if( existing.trigger !== 'click' ) {
96+
existing.dom_wrapped.off('touchstart mousedown', helper.hide);
9297
}
9398

9499
//attach resize handler to reposition tooltip
@@ -102,7 +107,7 @@
102107
}
103108
},
104109
//initialize the plugin on this element
105-
initialize: function(){
110+
initialize: function() {
106111
//attach on handler to show tooltip
107112
//use touchstart and mousedown just like if you click outside the tooltip to close it
108113
//this way it blocks the hide if you click the button a second time to close the tooltip
@@ -113,21 +118,26 @@
113118
}
114119
else if( helper.trigger === 'focus' )
115120
{
116-
helper.dom_wrapped.on('focus', helper.show);
117-
helper.dom_wrapped.on('blur', helper.hide);
121+
helper.dom_wrapped.on('touchstart focus', helper.show);
122+
helper.dom_wrapped.on('touchend blur', helper.hide);
118123
}
119124
else if( helper.trigger === 'hover' )
120125
{
121-
helper.dom_wrapped.on('mouseenter', helper.show);
122-
helper.dom_wrapped.on('mouseleave', helper.hide);
126+
helper.dom_wrapped.on('touchstart mouseenter', helper.show);
127+
helper.dom_wrapped.on('touchend mouseleave', helper.hide);
123128
}
124129
else if( helper.trigger === 'hoverfocus' )
125130
{
126131
helper.dom_wrapped.on('focus', helper.hoverfocusFocusShow);
127132
helper.dom_wrapped.on('blur', helper.hoverfocusBlur);
128133

129-
helper.dom_wrapped.on('mouseenter', helper.show);
130-
helper.dom_wrapped.on('mouseleave', helper.hoverfocusHide);
134+
helper.dom_wrapped.on('touchstart mouseenter', helper.show);
135+
helper.dom_wrapped.on('touchend mouseleave', helper.hoverfocusHide);
136+
}
137+
138+
//hide on click if not click
139+
if( helper.trigger !== 'click' ) {
140+
helper.dom_wrapped.on('touchstart mousedown', helper.hide);
131141
}
132142

133143
if( !$.jTippy.body_click_initialized )
@@ -165,7 +175,6 @@
165175
//on click of element, prevent default
166176
preventDefaultHandler: function(e){
167177
e.preventDefault();
168-
//prevent click following href
169178
return false;
170179
},
171180
//toggle tooltip visibility (used for click event)

jTippy.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.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jtippy",
3-
"version": "1.3.3",
3+
"version": "1.3.4",
44
"description": "jQuery tooltip plugin",
55
"repository": {
66
"type": "git",

0 commit comments

Comments
 (0)