Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: How to get the mouse position?

  1. #1
    Sencha User
    Join Date
    Jul 2012
    Location
    France
    Posts
    159
    Answers
    2

    Default How to get the mouse position?

    Hi,

    I would like to open a context menu at the mouse position.

    PHP Code:
    panel.getEl().on('contextmenu', function (e) {
                            
    e.preventDefault();
                            
    contextMenu.showAt(/*mousePosition*/);
                        }); 
    Last edited by Elfayer; 13 Jul 2012 at 7:44 AM. Reason: New thread

  2. #2
    Sencha User friend's Avatar
    Join Date
    Apr 2011
    Posts
    895
    Answers
    106

    Default

    Code:
    panel.getEl().on('contextmenu', function (e) {
      e.preventDefault();
      var coordinatesArray = e.getXY();
      contextMenu.showAt(coordinatesArray[0], coordinatesArray[1]);
    });
    Last edited by friend; 13 Jul 2012 at 10:32 AM. Reason: formatting

  3. #3
    Sencha User
    Join Date
    Jul 2012
    Location
    France
    Posts
    159
    Answers
    2

    Default

    This doesn't work..

    In fact, i have that:

    Code:
    'panelCenter': {
                    render: function (panel) {
                        var mask = new Ext.LoadMask(panel, { msg: "Loading..." });
                        mask.show();
                        var i = 0;
                        this.getUsersStore().on('load', function () { i++; if (i === 2) { mask.hide(); } });
                        this.getApplicationsStore().on('load', function () { i++; if (i === 2) { mask.hide(); } });
    
                        panel.getEl().on('contextmenu', function (e) {
                            e.preventDefault();
                            contextMenu.show();
                        });
    With a "contextMenu.show();" it's working, but menu appears at 0, 0.
    With your code, nothing happen.

    EDIT: It's the "showAt()" that doesn't work. I displayed the "coordinatesArray" and the values are good. But if i try : contextMenu.showAt(50, 50), it doesn't work either.

  4. #4
    Sencha Premium User suzuki1100nz's Avatar
    Join Date
    Apr 2011
    Location
    New Zealand
    Posts
    716
    Answers
    45

    Default

    Your code example doesnt show you using e.getXY(...).
    When you debug what values do you get for X and Y

  5. #5
    Sencha User
    Join Date
    Jul 2012
    Location
    France
    Posts
    159
    Answers
    2

    Default

    Code:
    panel.getEl().on('contextmenu', function (e) {
                            e.preventDefault();
                            var mouseCoord = e.getXY();
                            alert(mouseCoord[0] + ", " + mouseCoord[1]);
                            contextMenu.showAt(50, 50);
    I get the value of the mouse position.
    This doesn't display anything.

  6. #6
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,102
    Answers
    113

    Default

    Code:
    var position = e.getXY();
    menu.showAt(position);
    or simply:
    menu.showAt(e.getXY());

  7. #7
    Sencha User
    Join Date
    Jul 2012
    Location
    France
    Posts
    159
    Answers
    2

    Default

    Code:
    panel.getEl().on('contextmenu', function (e) {
                            e.preventDefault();
                            var mouseCoord = e.getXY();
                            contextMenu.showAt(mouseCoord);
                        });
    Nothing

  8. #8
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,102
    Answers
    113

    Default

    Try this:

    Code:
    panel.on('itemcontextmenu', function (e) {
                             e.preventDefault();
                             var mouseCoord = e.getXY();
                             contextMenu.showAt(mouseCoord);
                         });

  9. #9
    Sencha User
    Join Date
    Jul 2012
    Location
    France
    Posts
    159
    Answers
    2

    Default

    It's worse. I just remove the "getEl()" and it doesn't display anything even only with "show".

  10. #10
    Touch Premium Member
    Join Date
    Jun 2011
    Posts
    1,102
    Answers
    113

    Default

    Did you also change the event name from contextmenu to itemcontextmenu? Which version are you using. I am using 4.0.7 and adding a context menu for a grid panel. Its working for me.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •