jquery mobile taphold simplecontextmenu position is wrong -
i using jquery plugin called simple-context-menu jquery mobile context menu. happy , prefer on jquery mobile context menus possess (for me) far nested markup , requires many redundant css class tags. "simple context menu" requires simple array why superior needs.
however
on right click works intended, when try utilise "taphold" instead of right click menu appears in wrong place (far , right)
$(function() { $('.touchablefile').contextpopup({ title: 'file options', items: [ {label:'go to', icon:'/images/txt.png', action:function() { alert('clicked 1') } }, {label:'rename', icon:'/images/txt.png', action:function() { alert('clicked 1') } }, {label:'delete', icon:'/images/txt.png', action:function() { alert('clicked 2') } } ] }); $(".touchablefile").on("taphold", function(e) { $(this).triggerhandler('contextmenu'); }); }); how can taphold implement same mousex mousey real right click?
taphold custom event doesn't carry originalevent object. object holds values of .pagex , .pagey. therefore, need use touchstart event .pagex , .pagey position values use them later once taphold triggered.
you need minor js modifications context menu, follows.
in js file, place below code before line this.bind('contextmenu', function(e) {. code retrieve x & y position
var touchx, touchy; this.on("touchstart", function (e) { e.preventdefault(); touchx = e.originalevent.touches[0].pagex; touchy = e.originalevent.touches[0].pagey; }); then change
this.bind('contextmenu', function (e) { var menu = createmenu(e) .show(); var left = e.pagex + 5, top = e.pagey; to
this.on('taphold', function (e) { var menu = createmenu(e) .show(); var left = touchx + 5, top = touchy; demo (1)
(1) tested on iphone 5 - safari mobile
Comments
Post a Comment