Changeset 1038 for trunk/plugins


Ignore:
Timestamp:
09/29/08 19:03:36 (11 years ago)
Author:
ray
Message:

#721 [ContextMenu?] do not overflow window boundaries

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/ContextMenu/context-menu.js

    r999 r1038  
    353353        div.oncontextmenu = function() { return false; }; 
    354354        div.className = "htmlarea-context-menu"; 
    355         if (!Xinha.is_ie) 
    356                 div.style.left = div.style.top = "0px"; 
     355        if (!Xinha.is_ie) { 
     356            div.style.visibility = "hidden"; 
     357            div.style.left = div.style.top = "-200px"; 
     358        } 
    357359        doc.body.appendChild(div); 
    358360 
     
    449451 
    450452        if (!Xinha.is_ie) { 
    451     /* FIXME: I think this is to stop the popup from running off the bottom of the screen? 
    452                 var dx = x + div.offsetWidth - window.innerWidth + 4; 
    453                 var dy = y + div.offsetHeight - window.innerHeight + 4; 
    454     // alert('dy= (' + y + '+' + div.offsetHeight + '-' + window.innerHeight + ' + 4 ) = ' + dy); 
    455                 if (dx > 0) x -= dx; 
    456                 if (dy > 0) y -= dy; 
    457     */ 
    458                 div.style.left = x + "px"; 
    459                 div.style.top = y + "px"; 
     453            /* keep then menu from overflowing the client window boundaries */  
     454         
     455            /*  provide a virtual margin to leave a swoosh of air between the 
     456                meny and the window edge. This should probably go into the menu 
     457                container css as margin 10px instead... 
     458             */ 
     459            var margin = 10; 
     460             
     461            if (y + div.offsetHeight + margin > window.innerHeight) 
     462                y = window.innerHeight - div.offsetHeight - margin; 
     463            if (x + div.offsetWidth + margin > window.innerWidth) 
     464                x = window.innerWidth - div.offsetWidth - margin; 
     465             
     466            div.style.left = x + "px"; 
     467            div.style.top = y + "px"; 
     468            div.style.visibility = "visible"; 
     469 
    460470        } else { 
    461471    // To get the size we need to display the popup with some width/height 
Note: See TracChangeset for help on using the changeset viewer.