|
15 | 15 | return $menu.data("ui-menu") || $menu.data("menu"); |
16 | 16 | } |
17 | 17 | $.widget("ui.contextmenu", { |
18 | | - version: "0.1.0", |
| 18 | + version: "0.0.1", |
19 | 19 | options: { |
20 | 20 | delegate: "[data-menu]", // selector |
21 | 21 | menu: null, // selector or jQuery or a function returning such |
| 22 | + taphold: 2000, // open menu after 2000 ms long touch |
22 | 23 | // Events: |
23 | 24 | beforeopen: $.noop, // menu about to open; return `false` to prevent opening |
24 | 25 | blur: $.noop, // menu option lost focus |
|
30 | 31 | select: $.noop // menu option was selected; return `false` to prevent closing |
31 | 32 | }, |
32 | 33 | _create: function () { |
33 | | - this.element.delegate(this.options.delegate, "contextmenu.contextmenu", $.proxy(this._openMenu, this)); |
| 34 | + this.element.delegate(this.options.delegate, "contextmenu.contextmenu", $.proxy(this._openMenu, this)); |
| 35 | + // emulate a 'taphold' event |
| 36 | + /* |
| 37 | + this.element.delegate(this.options.delegate, "mousedown.contextmenu", $.proxy(function(event, ui){ |
| 38 | + var self = this; |
| 39 | + console.log("Event ", event.type, this.timer); |
| 40 | + if(this.timer){ |
| 41 | + console.log(" clear " + this.timer); |
| 42 | + clearTimeout(this.timer); |
| 43 | + this.timer = null; |
| 44 | + } |
| 45 | + this.timer = setTimeout(function(){ |
| 46 | + console.log("Timeout ", event.type, self.timer); |
| 47 | + self.open.call(self, $(event.target)); |
| 48 | + self.timer = null; |
| 49 | + }, this.options.taphold); |
| 50 | + console.log("Event started ", event.type, this.timer); |
| 51 | + }, this)); |
| 52 | + this.element.delegate(this.options.delegate, "mouseup.contextmenu", $.proxy(function(){ |
| 53 | + if(this.timer){ |
| 54 | + console.log("Event ", event.type, "clear" + this.timer); |
| 55 | + clearTimeout(this.timer); |
| 56 | + this.timer = null; |
| 57 | + } |
| 58 | + }, this)); |
| 59 | + */ |
34 | 60 | this._trigger("init"); |
35 | 61 | }, |
36 | 62 | /** Return menu jQuery object. */ |
|
108 | 134 | _closeMenu: function(){ |
109 | 135 | var self = this, |
110 | 136 | $menu = this._getMenu(); |
| 137 | + if(this.timer){ |
| 138 | + clearTimeout(this.timer); |
| 139 | + this.timer = null; |
| 140 | + } |
111 | 141 | $menu.fadeOut(function() { |
112 | 142 | self._trigger("close"); |
113 | 143 | }); |
|
0 commit comments