3 Replies Latest reply on Jul 14, 2014 7:12 PM by D. Marantis

    Position of the context menu or the clicked menu item

    D. Marantis Newbie

      how can i get the position of the context menu (<rich:contextMenu>) or of the clicked menu item (<rich:menuItem>)?

       

      (for example to open then a popup panel on the position of the clicked context menu)

        • 1. Re: Position of the context menu or the clicked menu item
          D. Marantis Newbie

          ... or alternative ...

           

          how can i get the mouse position when the menu item was clicked?

          • 2. Re: Re: Position of the context menu or the clicked menu item
            Michal Petrov Master

            You can capture the mouse click event:

             

            <rich:menuItem … onclick="captureEvent(event)"/>
            
            <h:outputScript>
                captureEvent = function (e) {
                    mouseX = e.pageX;
                    mouseY = e.pageY;
            
                    …
                };
            </h:outputScript>
            

            The parameter in the onclick has to be named "event".

            • 3. Re: Position of the context menu or the clicked menu item
              D. Marantis Newbie

              Big thx Petrov!^^

               

              nice tip for the 2nd question.

               

              but ...

               

              for the 1st question the answer should be something like this ...

               

              <script type="text/javascript">
              //<![CDATA[
                function savePosition(mnuItem) {
                  var x = mnuItem.element.offset().left;
                  var y = mnuItem.element.offset().top;
                  ...
                }
              //]]>
              </script>
              
              
              
              
              <h:form id="idForm">
                <rich:tree id="idTree" ...> </rich:tree>
                <rich:contextMenu id="idContextMenu" target="idTree" mode="ajax">
                  <rich:menuItem id="idContextMenuItem1" mode="ajax"
                                     onbeforedomupdate="savePosition(#{rich:component('idContextMenuItem1')})"
                                     oncomplete="#{rich:component('popup')}.show()"/>
                  ...
                </rich:contextMenu>
              </h:form>
              
              
              
              

               

              but it doesn't work cause LEFT ist ALWAYS just ZERO! (only the value of TOP is ok)

               

              Is this a BUG?!