Saturday, August 26, 2006

And people wonder why I prefer passthru....

Well, it seems that you folks were able to break my little piece of script pretty darned thoroughly. The "No Documents Found" bit was entirely my fault. Pulling any old bit of script off of the ol' hard drive and posting it with only minimal testing is not a good idea. It worked in the project I was doing, but that's because I had "pinned" documents so there was always something in the view.

The other breakage, though, I would never have picked up. You see, I never, ever, use Domino WYSIWYG to create headings and so forth. There is no semantic value to anything created with FONT tags, so I always make sure that things like that are done in passthru. And I never use the alignment settings, since it creates markup that you can't override with CSS. (The behaviour here was actually better in R5, since CSS could tell the browser to render a CENTER tag with any alignment you saw fit to use. The DIV with an inline style can only be changed using JavaScript, because inline styles will trump whatever is in the stylesheet.)

The problems with the script are twofold. First, if you create a WYSIWYG heading, Domino generates a DIV around the FONT tag soup it needs to render your semantically useless verbiage (sorry, folks, but unless you use an Hx tag to mark a heading, it ain't a heading). That wouldn't be so bad, except that it will eat the passthru DIV you created around the view by putting the heading's closing /DIV tag after your passthru. Easy to fix, you'd think -- just make sure there's at least one line of not-centred text between the heading DIV and the passthru, right?

Well, that does close the alignment DIV tag before the passthru DIV, but it creates a new problem. Domino may throw in an unclosed P tag, just for fun. Now, I have no problem with Domino rendering a line break with a paragraph. It might not be semantically correct when there is no actual paragraph content, but it's not a biggie, either. What burns my butt is the fact that the tag is never closed. That throws the whole document structure for a loop. The P will not be logically closed until its parent, Domino's FORM tag, is also closed.

There are three ways to try to handle this. The first is to futz around with the form in Designer until you can force Domino to render a BR instead of a P. A BR tag is not a container, so it won't interfere with stepping through the hierarchy in either direction. I'm not quite sure what the magic words are, or what face you have to make while doing it, but it CAN be done. Obviously, it's not particularly reliable, and the next developer to touch the form is going to break it. You can also try closing the P tag yourself, but this will get you no further -- eventually, someone is going to do something that changes the P to a BR. Or worse, they're going to try to get rid of the extra space between the heading and the view, closing off the DIV tag yet again.

The second is to expand the script yet again to cover all of the possible bases, searching every nook and cranny of the DOM until the view table, and only the view table, is finally found. You saw how big the original script was. Scanning the whole DOM tree until you find something that looks like it might be a view will make that little script just a little bit bigger. I'm not afraid of a little scripting (remember the library I keep talking about?), but I do resent having to write that much code to get around something that should never have been a problem in the first place.

The third is to lobby IBM for fixes. No, I don't expect them to add an HTML-prettifying function to the view rendering. In fact, it's just about the last thing I'd want to see, since it would mean that "normal" rendering could never be controlled with CSS -- you'd absolutely need to run some script to change the look of what Domino renders. (Yes, I know I'm running script now, but that's to add stuff that doesn't need to be there.) To my mind, something like that would be far worse than the current state of affairs. What I would like to see is a fix that gets Domino out of my way. If I start some passthru on a new line, and that whole line is marked as passthru, I want it to appear in the HTML source exactly where I put it, not inside a tag that Domino needs to render the previous line. In this case, if I wanted the viewPanel DIV to begin inside the heading alignment DIV, I should have to put in in the centre-aligned part of the text. Things like the document selection JavaScript should be moved completely out of the way -- the <head> sounds like a nice place to put that, doesn't it?. And since response-only columns are the last usable column in a response document row in a view, wouldn't it make a lot more sense to colspan the host cell all the way to the end (as this script does)?

No, folks, I am not whining about Domino's overall HTML rendering. While it can be improved somewhat (and Mark Vincenzes and team are working on it for Domino Next), it is very nearly impossible to create semantically-correct markup from purely visual formatting in a reliable way. A human being with good vision looking at the page can intuit the meaning of the text based on its formatting, but a machine can only do so much. What if your headings are smaller than the body text (a common-enough thing in trendy print publications)? There are some things we need to do ourselves if we want the end result to be meaningful and accessible. But there are a few little bugs that need to be squashed. They might not get the fixes into the current code streams (6.5.x & 7.x), but we can try to make sure that they are gone for Domino Next (no fixed number has been announced yet, but it has been stated that the number will be somewhere between 7.9 and 8.1).

In any case, the script as it now stands has been through the wringer. It'll find the view table if it's there and at least comes somewhere after the viewPanel DIV tag, as long as you don't put another table between the view and the div tag. If there's a "No Documents Found", it fails gracefully -- again, as long as you don't put an H2 tag into the middle of the actual viewPanel DIV AND use a centred, justified, or right-aligned WYSIWYG heading right above the passthru. (I'm only looking for the H2, since I can't predict the language of the message.) I've done everything I can to mangle the $$ViewTemplate and the view, and it seems to be bulletproof. Well, at least until one of you folks tries to use it, that is -- somebody's going to have done something I never would have though of trying, and that will probably result in Domino rendering the table cells outside of the table tag or something. Can you ever really win at this game?

2 comments:

Anonymous said...

Another small tweak ;) if I may.

Right now, the view "refreshes" itself within the first moment of loading, first showing the ugly view and then the pretty one, when the init() runs.

I think this can be fixed by putting
style="display:none"
in the tablePanel tag and then adding
panel.style.display="block";
right at the end of the prettyView() function, just before the last curly bracket.

Adi

Ralph Kolarik said...

Hey Stan, man sounds like live has not been the best lately. Hope you can get on your feet again. i had lost track of you, so was looking you up in notes land, did a google and found this. Anyway, i just had a java question, but i think it's really not worth it if your still feeling bad. Anyway, take care and hope it all works out. Stay in touch send me some jokes or whatever and i'll pass you some too. Take care!