| Div-isive popups | |||
| Posted at: Wed, 30 Sep 2009 22:01:17 by The Watcher | |||
|
So, as part of a semi-Sekrit Projekt, I have been working on trying to get an arbitrary number of <div>s in a web page to behave as popups: they remain hidden until the mouse hovers over specific elements in the page, at which point they appear. This is not, of itself, all that complicated to do - there's a plethora of solutions out there for this. Of course, this is me, it's not that simple. I need a bunch of Extra Features for this:
The first three of these are not too bad, especially as mootools - a javascript framework to provide a lot of nice new features - can help with things like easy to use timed events, and fading. The problem was the last point on the list. Mootools provides a few methods to obtain the location of elements on a page (so that you can position one element relative to another). It even provides a position() function that should make the process of positioning one element relative to another trivial. Unfortunately, they are all crap. They either produce different coordinates in different browsers, or completely incorrect coordinates, or bugger all. And so, I set about making my own code to work it out. There's a fair amount of code out there on the net to do this, too. Again, all the ones I tried fall down in some situations, and I ran into the problem with my own code too: the coordinates returned looked correct - screenshotting the browser window, and plotting the coordinates in a graphics program appeared to show the correct place - but when the left and top of the popup div were set to the coordinates, the popup would consistently appear a significant distance below or to the left of the location it should be. It took me a couple of hours to finally realise what the problem was, and now it seems so obvious I've no idea why I didn't realise it before: all the solutions I had run into and tried had the unstated, implicit assumption that the element being positioned was in the top level of the document, or all of its parent elements has their css position attribute set to 'relative' or 'inherit'. If one of the parent elements had 'position: absolute' (as the 'main content' container div in my pages does), then the position of the div needs to be relative to that, not the page! Once I'd realised this, the following code represents the solution to locating the position of an element in a page (and it appears to work fine in firefox, Seamonkey, Opera, and Safari. I haven't tried it in IE because, frankly, I don't care it works there or not):
mootools-core is needed for the getStyle() function, but that could be replaced if that causes a problem. For an example of it in action, the mockup page for the system it will be used in can be found here. Leave the mouse over the first columns of the top three rows to see the popup effect. Even better, I think I should be able to reuse the same code verbatim in the CBT package framework we use in work, to replace the clunky new window popups entirely! |
|||
| Comments: 0 (Post your comments) | |||
| Anti wikiloss! | |||
| Posted at: Wed, 16 Sep 2009 10:27:07 by The Watcher | |||
|
One of the most famous Holy Wars in the computer world is the eternal Pulling Of Beards that is Emacs v Vi, a debate that has raged for decades and will probably continue until the last atoms smear themselves into the entropy death of the universe. Both sides have their points, but I'm firmly in the Emacs camp. Back in the Old Times, I used to use GoldED on the Amiga (which has since become 'CubicIDE' apparently, I'm shocked they're even still going), and when I moved to the linux and windows worlds I spent a fair amount of time using GoldED in WinUAE because I just couldn't find another text editor I liked. Eventually, the process became too clumbersome, and I found myself picking up emacs and its idiosyncrasies. All of this is just prologue, really. The important part of it is that I am very used to emacs' keyboard incantations now, so things like "I want to cut this region of text" is far more synonymous with 'ctrl+w' than with the 'ctrl+x' most people associate with Cut. On its own, this is also not a problem. Until you realise that seamonkey (my browser of choice, given that Opera still has Issues for me) binds ctrl+w to 'Close current tab or window', and then things get nasty. I have this habit, when editing text in text areas, of unconsciously using emacsism: selecting a piece of text to cut only to hit the close window key because my brain is in the wrong editor mode is... infuriating. To make matters worse, seamonkey does not have any remotely sane method of remapping controls (as far as I can tell, it requires hacking chrome files, but I've never been able to get it to work). This gets even worse when I accidentally do it while working in the course development wiki for work, and end up wiping 15 minutes of editing by pressing the wrong key shortcut. Yesterday, after racking up something like 3 or 4 hours of lost work because of that mistake, I finally snapped and started to look at ways to add a window close confirm to mediawiki. It turns out it's actually remarkably simple to do, at least in recent browsers. In the end, all it took was editing two files. Here, in case anyone is interested, is how to do it. First, some javascript is needed to handle the close warning. This can't go in MediaWiki:Common.js otherwise it would completely mess up navigating through the wiki, it pretty much requires editing the MediaWiki files. At the bottom of skins/common/edit.js add the following lines:
This creates a variable used as a flag to determine whether the user needs to confirm window close or not, and then registers an anonymous function as the callback for the onbeforeunload event for the window. This will prompt the user to confirm the window close if the confirm flag is true. With that in place, the user will be prompted to confirm closing the window every time they attempt to exit an edit page in the wiki, unfortunately they will be prompted even if they use the Save or Preview. To get around that, a few lines need to be added to includes/EditPage.php. This is slightly trickier, as it means inserting code in the midst of existing code. The easiest thing to do is look for
and then, in each of the '$temp = array(' blocks in that function, add the following line:
So, for example:
Has the onclick line added so that it becomes:
Now, the user will be prompted whenever they attempt to close, cancel, or navigate away from an edit page, but not when they hit Save Page, Preview, or Changes. I'm vaguely tempted to submit this as a patch to MediaWiki and see what happens, as it's already saved my arse twice... |
|||
| Comments: 0 (Post your comments) | |||
| Cleaning up properly | |||
| Posted at: Sat, 12 Sep 2009 17:04:02 by The Watcher | |||
|
So, I have another web application in the early throes of development. As ever, I decided to reuse chunks of my hard-working perl module based web framework to implement it, only this time I was forced to look long and hard at what I was doing. One thing I hadn't fully realised until I looked at things carefully was just how much commonality there was between my web apps. For example, http://www.starforge.co.uk/ and http://myst.starforge.co.uk/ share very large amounts of code: the starforge site totals 5955 lines of code, ORB comes out at 6769 loc, and the two have 3087 lines in common (52% of the starforge site code is reused verbatim in the ORB!) However, to my slight embarrassment, that shared code was actually duplicated in both apps (for example, both the starforge site and the ORB had identical copies of phpBB3.pm, Template.pm, and several other modules) There were a few minor differences between some modules used by the two apps, but with some rewriting and refactoring I have been able to get to the point where I have been able to move the common modules out into a shared location, and I can now safely work on the shared code or the webapp specific code without worrying about fixing a bug in a module in one of them but forgetting to fix the same bug in the other. I can also easily create another webapp using them without having to worry about having the latest versions! On top of that, it also means that I can make them available for anyone who wants them - the tarball containing the source can be found here, while the documentation for the modules (generated by doxygen from the source) can be viewed online here. If you are interested, go look and play around with them, and poke me if you have any questions or suggestions. And now, back to the thing that triggered this in the first place... |
|||
| Comments: 0 (Post your comments) | |||
| Imaging the handler... | |||
| Posted at: Mon, 20 Jul 2009 23:18:49 by The Watcher | |||
|
As I noted in #code yesterday, I think I have an unhealthy obsession with attempting to represent system designs diagramatically. And almost never in 'accepted' standards like UML (which I tend to view as the Unusuable Modeling Language - any modeling system that requires a course to use properly has missed the point, guys) but using some odd system that shows flows of data or objects, and systems that process them, that I've never really been able to fully place properly in any "standard" modeling framework. This is somewhat demonstrated by this refinement to the ImageHandler diagram from a couple of entries back:
This tells me what I need to know to tackle the implementation: it shows me which components of the system need to talk to each other, where things come from and go to, and notes about how to do it thrown in. I rather suspect that it's not really a huge help to any other coder, as there's probably a lot of tacit information I have omitted. But, it works for me, and I'm hardly being held to some Forced Standard. Of course, the diagram will also evolve as I implement things and find better ways to do things1. That, in turn, may open up other directions for development and improvement... But anyway, what it does tell me right now is that, now that I have the code done to implement the Request Queue, Thumbnail Cache, and Image Cache, the next thing I really need to concentrate on is the code to allow the image loader threads to save data into the disc cache: SDL_image does not - for some reason probably related to it not being 'interesting', or something - provide any functions to save as png/jpeg/etc, despite relying libraries that provide those facilities for loading, so I need to put something together to do that before I can start to build the loader threads. 1 some time (when it isn't 23:16) I will Rant on the subject of designs, models, managers, and unrealistic expectations. But not now, because it is 23:16, and I need to be up at 7:00 tomorrow to commute. Blegh. |
|||
| Comments: 0 (Post your comments) | |||
| Recipe system update | |||
| Posted at: Wed, 15 Jul 2009 17:59:20 by The Watcher | |||
|
I've slacked off a bit with the Online Recipe Book system, but I've just finished the summary page (as much as is possible now anyway), and fixed up the pagination controls for the recipe index pages. Big remaining sections are:
That said, the current code status:
|
|||
| Comments: 0 (Post your comments) | |||
