Changeset 4248
- Timestamp:
- 03/04/08 13:52:32 (5 months ago)
- Files:
-
- Trunk/core/js/Dom.js (modified) (1 diff)
- Trunk/core/js/Popup.js (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
Trunk/core/js/Dom.js
r3543 r4248 358 358 } 359 359 360 360 // Returns true if the element e has a given ancestor element 361 function 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 9 9 Popup.create = function(root,elem,theClass) 10 10 { 11 Popup.remove(); 11 var stackPosition = this.find(root,"popup"); 12 Popup.remove(stackPosition+1); 12 13 var popup = createTiddlyElement(document.body,elem ? elem : "ol","popup",theClass ? theClass : "popup"); 14 popup.stackPosition = stackPosition; 13 15 Popup.stack.push({root: root, popup: popup}); 14 16 return popup; … … 25 27 }; 26 28 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} 35 Popup.show = function(valign,halign,offset) 28 36 { 29 37 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); 31 39 addClass(curr.root,"highlight"); 32 40 if(config.options.chkAnimate && anim && typeof Scroller == "function") … … 36 44 }; 37 45 38 Popup.place = function(root,popup, offset)46 Popup.place = function(root,popup,valign,halign,offset) 39 47 { 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 } 41 56 var rootLeft = findPosX(root); 42 57 var rootTop = findPosY(root); 43 var rootHeight = root.offsetHeight;44 58 var popupLeft = rootLeft + offset.x; 45 var popupTop = rootTop + rootHeight +offset.y;59 var popupTop = rootTop + offset.y; 46 60 var winWidth = findWindowWidth(); 47 61 if(popup.offsetWidth > winWidth*0.75) … … 49 63 var popupWidth = popup.offsetWidth; 50 64 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 } 53 71 popup.style.left = popupLeft + "px"; 54 72 popup.style.top = popupTop + "px"; … … 56 74 }; 57 75 58 Popup. remove = function()76 Popup.find = function(e) 59 77 { 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 86 Popup.remove = function(pos) 87 { 88 if(!pos) var pos = 0; 89 if(Popup.stack.length > pos) { 90 Popup.removeFrom(pos); 62 91 } 63 92 }; … … 72 101 Popup.stack = Popup.stack.slice(0,from); 73 102 }; 74