开发者

jQuery context menu etc

开发者 https://www.devze.com 2023-02-18 20:19 出处:网络
Okay.. So I am doing some grid work and I have several functions being used. Everything is working except when I click a context menu it does not trigger an alert.

Okay.. So I am doing some grid work and I have several functions being used. Everything is working except when I click a context menu it does not trigger an alert. After looking closer at the documentation. A "#Selector" should be used here instead of document...

// Show menu when #myDiv is clicked
            jQuery(document).contextMenu({
                menu: 'myMenu'
            },
                function(action, el, pos){      
                      alert('Action: ' + action + '\n\n');
            });

when i change

            jQuery(document).contextMenu({

to

// Show menu when #myDiv is clicked
            jQuery("#grid").contextMenu({

This will fire the selected context alert..But now when I generate a draggable container

jQuery("#grid").append("<div id='container"+container+"' class='container' style='border: 2px solid black;width:100px;heig开发者_StackOverflowht:100px;position: absolute !important;left:100px;top:"+Math.floor(Math.random()*601)+"px'><p style='background-color:lightblue;margin:0px'>------<span style='background-color:white'>"+container+"</span>------</p><br/>a</div>");   
jQuery('#debug_container').html('Container Added'); 
jQuery('.container').draggable({handle: 'p',grid: [ 8,8 ],
                           containment: "#grid",
                           drag: function() {
                                    var currentID = jQuery(this).attr('id').substr(9, 1);        
                                    setContainer(currentID);                               
                                }                   
                          });       

It will not let it go ondrop... The original will allow the drop but won't alert. I would like both..

As always, any help much appreciated.


After some more debugging I found the root of my problem came from jquery.contextMenu.js on line 37

jQuery(this).mousedown( function(e) {
            var evt = e;
            evt.stopPropagation();
            jQuery(this).mouseup( function(e) {

//Doing this fixed my issue ==>// e.stopPropagation();

  var srcElement = jQuery(this);
                jQuery(this).unbind('mouseup');
                if( evt.button == 2 ) {
                    // Hide context menus that may be showing
                    jQuery(".contextMenu").hide();
                    // Get this context menu
                    var menu = jQuery('#' + o.menu);
0

精彩评论

暂无评论...
验证码 换一张
取 消