So I've been playing a lot with various types of popup divs in TW over the last few days: lightboxes, dynamic tooltips etc.
One of the things that I realized is that with just a little refactoring, the exisiting popup code could be used for a lot of it.
For example, in Popup.create, we could pass it two extra optional arguments. The first to determine the dom element being created, instead of the default "ol" and the second for a class, instead of "popup".
The default can still be the old values, maintaining backwards compatibility.
Something like this:
Popup.create = function(root
,elem,theClass)
{
Popup.remove();
var popup = createTiddlyElement(document.body,elem? elem :"ol","popup",
theClass? theClass :"popup");
Popup.stack.push({root: root, popup: popup});
return popup;
}
Perhaps even a custom id!
Similary, Popup.show performs two main functions:
1) determining the position of the popup
2) displaying the popup and scrolling to ensure its visibility of required.
If the code for determing the position was factored out into a separate function, it could be very useful as well.
I realize these arent the biggest of functions to start off with, but its a real shame to have rewrite the code when its already there.
Cheers,
Saq