ICEfaces
  1. ICEfaces
  2. ICE-3658

Prevent menus from displaying off the top of the browser viewport

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.8
    • Fix Version/s: 1.8.1
    • Component/s: ICE-Components
    • Labels:
      None
    • Environment:
      all

      Description

      When a menubar is displayed at the right border of the browser window, the menu is shown outside of the window so that the user needs to scroll in order to see the menu.
      This should be avoided by showing the menu on the left side of the menubar instead of the right side.

      A patch to menu.js that works for us (not thoroughly tested):
       show: function(supermenu,submenu,submenuDiv) {
           supermenu=$(supermenu);
           submenu=$(submenu);
           submenuDiv=$(submenuDiv);
      if (submenu) {
      var menu = $(submenu);
      //menu is already visible, don't do anything
                  if (menu && menu.style.display=='') return;
                  Ice.Menu.showMenuWithId(submenu);
                  if (submenuDiv) {
                       // ICE-3196
                      var left;
                                      //check if menu is too far to the right
      if (Ice.Menu.getPosition(supermenu,'Left')+supermenu.offsetWidth+submenu.offsetWidth>document.documentElement.scrollLeft+document.body.clientWidth){
      left=-submenu.offsetWidth;
      }else{
      left=supermenu.offsetWidth;
      }
                                     //check if menu is too far on the botton
      var top=0;
      if (Ice.Menu.getPosition(supermenu,'Top')+submenu.offsetHeight>document.documentElement.scrollTop+document.body.clientHeight){
      top=-submenu.offsetHeight+supermenu.offsetHeight;
      }
                      submenu.clonePosition(supermenu, {setWidth:false, setHeight:false, offsetTop:top, offsetLeft:left});
                      submenu.clonePosition(submenuDiv, {setTop:false, setLeft:false, setWidth:false, setHeight:false});
                  } else {
                       // ICE-3196
                      submenu.clonePosition(supermenu, {setWidth:false, setHeight:false, offsetTop:supermenu.offsetHeight});
                  }
                  Ice.Menu.showIframe(submenu); // ICE-2066, ICE-2912
      }
              Ice.Menu.currentMenu = submenu;
          },
      1. ScreenHunter_01.jpg
        77 kB
      2. ScreenHunter_01.jpg
        70 kB
      3. ScreenHunter_05.jpg
        69 kB

        Issue Links

          Activity

          Hide
          Stefan Niederhauser added a comment -

          This is fixed in 1.8.0 (see ICE-3620).
          One last thing is that if the menu is displayed upwards, it is possible that the top part of it is outside the viewport.
          Simply add a check if submenu.offsetTop<0 and if so, set submenu.style.top='0px';

          Show
          Stefan Niederhauser added a comment - This is fixed in 1.8.0 (see ICE-3620 ). One last thing is that if the menu is displayed upwards, it is possible that the top part of it is outside the viewport. Simply add a check if submenu.offsetTop<0 and if so, set submenu.style.top='0px';
          Hide
          Ken Fyten added a comment -

          Please review the suggested contributed fix for this in the previous comment and commit if appropriate.

          Show
          Ken Fyten added a comment - Please review the suggested contributed fix for this in the previous comment and commit if appropriate.
          Hide
          yip.ng added a comment -

          Doesn't work. offsetTop is with reference to the positioning context (document if no positioning context), not the viewport. The viewport can be far below the document start. In that case offsetTop will always be > 0. See attached ScreenHunter_01.jpg.

          Show
          yip.ng added a comment - Doesn't work. offsetTop is with reference to the positioning context (document if no positioning context), not the viewport. The viewport can be far below the document start. In that case offsetTop will always be > 0. See attached ScreenHunter_01.jpg.
          Hide
          yip.ng added a comment -

          Further, top is also relative to positioning context, not viewport. Setting top to 0 won't necessarily align with top of viewport. See attached screehshot.

          Show
          yip.ng added a comment - Further, top is also relative to positioning context, not viewport. Setting top to 0 won't necessarily align with top of viewport. See attached screehshot.
          Hide
          yip.ng added a comment - - edited

          Fixed using more complicated positioning and viewport calculations. See attached screenshot ScreenHunter_05.jpg.

          Show
          yip.ng added a comment - - edited Fixed using more complicated positioning and viewport calculations. See attached screenshot ScreenHunter_05.jpg.

            People

            • Assignee:
              yip.ng
              Reporter:
              Stefan Niederhauser
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: