TiddlyWiki.org

Changeset 4248

Show
Ignore:
Timestamp:
03/04/08 13:52:32 (5 months ago)
Author:
JeremyRuston
Message:

Added support for nested popups (ticket #354)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Trunk/core/js/Dom.js

    r3543 r4248  
    358358} 
    359359 
    360  
     360// Returns true if the element e has a given ancestor element 
     361function isDescendant(e,ancestor) 
     362
     363        while(e) { 
     364                if(e === ancestor) 
     365                        return true; 
     366                e = e.parentNode; 
     367        } 
     368        return false; 
     369
  • Trunk/core/js/Popup.js

    r3530 r4248  
    99Popup.create = function(root,elem,theClass) 
    1010{ 
    11         Popup.remove(); 
     11        var stackPosition = this.find(root,"popup"); 
     12        Popup.remove(stackPosition+1); 
    1213        var popup = createTiddlyElement(document.body,elem ? elem : "ol","popup",theClass ? theClass : "popup"); 
     14        popup.stackPosition = stackPosition; 
    1315        Popup.stack.push({root: root, popup: popup}); 
    1416        return popup; 
     
    2527}; 
    2628 
    27 Popup.show = function(unused1,unused2) 
     29//# valign : 'top' or 'bottom' (optional) 
     30//#   defaults to 'bottom' for regular popups, 'top' for nested popups 
     31//# halign : 'left' or 'right' (optional) 
     32//#   defaults to 'left' for regular popups, 'right' for nested popups 
     33//# offset : {x: number, y: number} (optional) 
     34//#   defaults to {x:0,y:0} 
     35Popup.show = function(valign,halign,offset) 
    2836{ 
    2937        var curr = Popup.stack[Popup.stack.length-1]; 
    30         this.place(curr.root,curr.popup); 
     38        this.place(curr.root,curr.popup,valign,halign,offset); 
    3139        addClass(curr.root,"highlight"); 
    3240        if(config.options.chkAnimate && anim && typeof Scroller == "function") 
     
    3644}; 
    3745 
    38 Popup.place = function(root,popup,offset) 
     46Popup.place = function(root,popup,valign,halign,offset)  
    3947{ 
    40         if(!offset) var offset = {x:0, y:0}; 
     48        if(!offset) 
     49                var offset = {x:0,y:0}; 
     50        if(popup.stackPosition >= 0 && !valign && !halign) { 
     51                offset.x = offset.x + root.offsetWidth; 
     52        } else { 
     53                offset.x = (halign == 'right') ? offset.x + root.offsetWidth : offset.x; 
     54                offset.y = (valign == 'top') ? offset.y : offset.y + root.offsetHeight; 
     55        } 
    4156        var rootLeft = findPosX(root); 
    4257        var rootTop = findPosY(root); 
    43         var rootHeight = root.offsetHeight; 
    4458        var popupLeft = rootLeft + offset.x; 
    45         var popupTop = rootTop + rootHeight + offset.y; 
     59        var popupTop = rootTop + offset.y; 
    4660        var winWidth = findWindowWidth(); 
    4761        if(popup.offsetWidth > winWidth*0.75) 
     
    4963        var popupWidth = popup.offsetWidth; 
    5064        var scrollWidth = winWidth - document.body.offsetWidth; 
    51         if(popupLeft + popupWidth > winWidth - scrollWidth - 1) 
    52                 popupLeft = winWidth - popupWidth - scrollWidth - 1; 
     65        if(popupLeft + popupWidth > winWidth - scrollWidth - 1) { 
     66                if(halign == 'right') 
     67                        popupLeft = popupLeft - root.offsetWidth - popupWidth; 
     68                else 
     69                        popupLeft = winWidth - popupWidth - scrollWidth - 1; 
     70        } 
    5371        popup.style.left = popupLeft + "px"; 
    5472        popup.style.top = popupTop + "px"; 
     
    5674}; 
    5775 
    58 Popup.remove = function(
     76Popup.find = function(e
    5977{ 
    60         if(Popup.stack.length > 0) { 
    61                 Popup.removeFrom(0); 
     78        var pos = -1; 
     79        for (var t=this.stack.length-1; t>=0; t--) { 
     80                if(isDescendant(e,this.stack[t].popup)) 
     81                        pos = i; 
     82        } 
     83        return pos;              
     84}; 
     85 
     86Popup.remove = function(pos) 
     87
     88        if(!pos) var pos = 0; 
     89        if(Popup.stack.length > pos) { 
     90                Popup.removeFrom(pos); 
    6291        } 
    6392}; 
     
    72101        Popup.stack = Popup.stack.slice(0,from); 
    73102}; 
    74