Skip to content

Commit cd6dcc8

Browse files
committed
Test with iPad and cleanups
1 parent 079f127 commit cd6dcc8

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

Gruntfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ module.exports = function (grunt) {
4646
connect: {
4747
demo: {
4848
options: {
49+
hostname: "*", // make accessible from everywhere
4950
port: 8080,
5051
base: "./",
5152
keepalive: true

demo/index.html

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,25 @@
2323
body{
2424
font-family: "Trebuchet MS", "Helvetica", "Arial", "Verdana", "sans-serif";
2525
font-size: .8em;
26+
/* Prevent tablets from selecting text on taphold, etc:
27+
Note:
28+
If only the potential menu trigger elements should be protected, simply
29+
use the 'preventSelect: true' option.
30+
But we disable it more globally for table pcs, because the whole line
31+
or paragraph will still be selected otherwise.
32+
33+
*/
34+
-webkit-user-select: none;
35+
-khtml-user-select: none;
36+
-moz-user-select: none;
37+
-ms-user-select: none;
38+
user-select: none;
2639
}
2740

2841
.hasmenu, .hasmenu2 {
2942
border: 1px solid #008;
3043
margin: 3px;
31-
padding: 2px;
44+
padding: 5px;
3245
width: 30px;
3346
}
3447

jquery.ui-contextmenu.js

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
// $menu = $(menu);
2323
// return $menu.data("ui-menu") || $menu.data("menu");
2424
// }
25-
var NS = ".contextmenu",
26-
supportSelectstart = "onselectstart" in document.createElement("div");
25+
var supportSelectstart = "onselectstart" in document.createElement("div");
2726

2827
/** Return command without leading '#' (default to ""). */
2928
function normCommand(cmd){
@@ -53,20 +52,22 @@
5352
},
5453
/** Construtcor */
5554
_create: function () {
56-
var opts = this.options,
57-
eventNames = "contextmenu" + NS,
58-
targetId = this.element.uniqueId().attr("id");
55+
var eventNames, targetId,
56+
opts = this.options;
5957

58+
console.log(this.element)
59+
6060
this.$headStyle = null;
6161
this.orgMenu = null;
6262
this.currentTarget = null;
63-
64-
if(opts.taphold){
65-
eventNames += " taphold" + NS;
66-
}
63+
this.ns = "." + this.widgetName;
64+
6765
if(opts.preventSelect){
6866
// Create a global style for all potential menu targets
69-
this.$headStyle = $("<style>")
67+
// If the contextmenu was bound to `document`, we apply the
68+
// selector relative to the <body> tag instead
69+
targetId = ($(this.element).is(document) ? $("body") : this.element).uniqueId().attr("id");
70+
this.$headStyle = $("<style class='ui-contextmenu-style'>")
7071
.prop("type", "text/css")
7172
.html("#" + targetId + " " + opts.delegate + " { " +
7273
"-webkit-user-select: none; " +
@@ -78,7 +79,7 @@
7879
.appendTo("head");
7980
// TODO: the selectstart is not supported by FF?
8081
if(supportSelectstart){
81-
this.element.delegate(opts.delegate, "selectstart" + NS, function(event){
82+
this.element.delegate(opts.delegate, "selectstart" + this.ns, function(event){
8283
event.preventDefault();
8384
});
8485
}
@@ -111,8 +112,13 @@
111112
}
112113
}, this)
113114
});
115+
116+
eventNames = "contextmenu" + this.ns;
117+
if(opts.taphold){
118+
eventNames += " taphold" + this.ns;
119+
}
114120
this.element.delegate(opts.delegate, eventNames, $.proxy(this._openMenu, this));
115-
// emulate a 'taphold' event
121+
116122
this._trigger("init");
117123
},
118124
/** Destructor, called on $().contextmenu("destroy"). */
@@ -148,11 +154,11 @@
148154
return false;
149155
}
150156
// Register global event handlers that close the dropdown-menu
151-
$(document).bind("keydown" + NS, function(event){
157+
$(document).bind("keydown" + this.ns, function(event){
152158
if( event.which === $.ui.keyCode.ESCAPE ){
153159
self._closeMenu();
154160
}
155-
}).bind("mousedown" + NS + " touchstart" + NS, function(event){
161+
}).bind("mousedown" + this.ns + " touchstart" + this.ns, function(event){
156162
// Close menu when clicked outside menu
157163
if( !$(event.target).closest(".ui-menu-item").length ){
158164
self._closeMenu();
@@ -187,9 +193,9 @@
187193
});
188194

189195
$(document)
190-
.unbind("mousedown" + NS)
191-
.unbind("touchstart" + NS)
192-
.unbind("keydown" + NS);
196+
.unbind("mousedown" + this.ns)
197+
.unbind("touchstart" + this.ns)
198+
.unbind("keydown" + this.ns);
193199
},
194200
/** Handle $().contextmenu("option", key, value) calls. */
195201
_setOption: function(key, value){

jquery.ui-contextmenu.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.

0 commit comments

Comments
 (0)