EGL Development User Group

EGL Development User Group

EGL Development User Group

The EGL Development User Group is dedicated to sharing news, knowledge, and insights regarding the EGL language and Business Developer product. Consisting of IBMers, HCL, and users, this community collaborates to advance the EGL ecosystem.

 View Only
Expand all | Collapse all

disable right click

  • 1.  disable right click

    Posted Wed February 25, 2015 02:13 AM

    Hello,

    I would like to disable right click on a Widget. How is that possible?

    Thanks

     

    michaeldefox


  • 2.  Re: disable right click

    Posted Wed February 25, 2015 02:25 AM

    Hi Michael,

    What's the reason for disabling right click? It is generally disadvised to disable mouse buttons on web applications.

    That being said, it should be possible with an externaltype javascript function which looks like the code below (untested)

    "disableRightClick": function (widget) {   widget.onmousedown=function(event){      if (event.button == 2) {         alert("Right Click Disabled");          return false;         }   }}

     

    Bram_Callewaert


  • 3.  Re: disable right click

    Posted Wed February 25, 2015 04:02 AM

    Ok, I created function disableRightClick() returns(boolean); in the externalType file .egl

    But how can I call disableRightClick()  if I want to disable only a specific widget?

     

    Thanks

     

    michaeldefox


  • 4.  Re: disable right click

    Posted Wed February 25, 2015 04:05 AM

    The disableRightClick takes 1 parameter: a widget.

    Bram_Callewaert


  • 5.  Re: disable right click

    Posted Wed February 25, 2015 04:53 AM

    result boolean;

    result = disableRightClick{box};

    This is how I call the function but i get that error "The type disableRightClick cannot be resolved"

    Any ideas?

     

    michaeldefox


  • 6.  Re: disable right click

    Posted Wed February 25, 2015 05:38 AM

    Hi Michael,

    While I do think the solution guus has provided is cleaner, I have tested and expanded my example.

    You first need to create a .js file somewhere under webcontent and adapt the source below to your paths:

    egl.defineClass('CustomJavascript', 'BrowserFunctions',                                         {                     "eze$$initializeDOMElement": function(){                },                "constructor": function(){                },                "disableRightClick": function (widget) {                    widget.eze$$DOMElement.oncontextmenu = function (event){                        if (event.button == 2){                                alert("Right Click Disabled");                                return false;                             }                    };                     widget.eze$$DOMElement.onclick = function (event){                      if (event.button == 2) {                         alert("Right Click Disabled");                          return false;                         }                    };                 }});

    Then you need to create a egl file with the following content (again, adapt to your directory structure)

    package com.molcy.egl.ExternalTypes;externalType BrowserFunctions extends Widget type JavaScriptObject {        relativePath = "CustomJavascript",                javaScriptName = "BrowserFunctions"         }                function disableRightClick(w Widget in);        end

    Then use the externaltype in a handler like the following one:

    package com.molcy.egl.handlers;import com.ibm.egl.rui.widgets.Box;import com.ibm.egl.rui.widgets.Div;import com.molcy.egl.ExternalTypes.BrowserFunctions;handler DisableRightClick type RUIhandler {initialUI = [ alles ],onConstructionFunction = start, cssFile="css/FileUploadRui.css", title="DisableRightClick"}            alles Box{                columns = 2,                 children= [                        div1, div2                                      ]        };                div1 Div{width = 200, height = 200, backgroundcolor = "red"};        div2 Div{width = 200, height = 200, backgroundcolor = "green"};                b BrowserFunctions{};                 function start()                b.disableRightClick(div1);         end             end

    Kind regards,

     

    Bram

    Bram_Callewaert


  • 7.  Re: disable right click

    Posted Wed February 25, 2015 02:54 AM

    I expect you want to disable the browser's default context menu, is that right?

    Does the code in attache file do want you want? 

    gweis


  • 8.  Re: disable right click

    Posted Wed February 25, 2015 03:59 AM

    I want to disable right click on a pop window which is a Box widget. But only for that window not in the entire website.

     

    I should have been more specific. i m really sorry and thanks for your response

    michaeldefox


  • 9.  Re: disable right click

    Posted Wed February 25, 2015 04:02 AM

    Hi Guus,

    your solution is a lot easier and seems better than my proposal.

     

    Kind regards,

     

    Bram

    Bram_Callewaert


  • 10.  Re: disable right click

    Posted Wed February 25, 2015 04:10 AM

    Hi Bram,
    Thanks. I'm just trying to avoid programming EGL-external js-code as much as possible, and this seemed to answer Michael's question using just EGL-code.
    Kind regards,
    Guus

    gweis


  • 11.  Re: disable right click

    Posted Wed February 25, 2015 05:18 AM

    Thanks a lot both of you! It works for me!

    Thanks!

    michaeldefox