1 | 2 | 3

11 - 14   [14]

Mozilla COL Alignment via DOM Scripting

Relates to CSS Design and DOM Scripting, Firefox and Co

One of the Mozilla rendering engine's few annoyances is its apparent disregard for the alignment attributes of col and colgroup elements within HTML tables. One might argue this is justified since alignment is a presentational attribute that should be defined with CSS. However, table alignment can be crucial to the visual display of data in a usable format and this should not be dependant on CSS - perhaps one reason why table alignment persists in the XHTML 1.1 Table Module.

Putting this presentation/structure debate aside, a workaround is required if alignment rules are to be defined by column in Mozilla browsers. One solution is to turn to CSS and define adjacent sibling selector rules (or direct adjacent combinators in CSS3 syntax) for table cells as demonstrated in these CSS snippets. However this will only work if the number of columns and columnar alignment is predefined.

The scenario I found myself in earlier today, working on the latest version of my PHP powered CMS, had column alignment and quantity determined on a content module basis with considerable variation. So it was once again time to call on the DOM, and to create those adjacent sibling selector rules dynamically.


function synchronizeColumns(table) {
  var inline = create('style');
  inline.setAttribute('type', 'text/css');
  var rule = "tbody th", 
      rules = "", 
      span, halign, valign, i, temp;
  (function(elem){
   temp = "";
   span = elem.getAttribute('span');     
   halign = elem.getAttribute('align');     
   valign = elem.getAttribute('valign');          
   if (halign != null) {
     temp += "text-align:" + halign + ";";  
   }
   if (valign != null) {
     temp += "vertical-align:" + valign + ";"; 
   }
   i = (span != null) ? span : 1;
   do {
     if (temp.length > 0) {
       rules += rule + "{" + temp + "}\n";
     }
     rule += "+td";      
   } while (–i > 0);
  }).Iterate(table.get('col')());
  inline.appendChild(create(rules,Node.TEXT_NODE));   
  get('head')(0).appendChild(inline);  
}

The rules are declared inline (to override any default alignment rules that may be set for columns, by appending a new style node to the head element. Then it is just a case of iterating through each col element in the table, extracting the corresponding align and valign attributes and building the corresponding rule. The span attribute must also be taken into consideration to ensure the correct attribute values are assigned across each column as this document fragment demonstrates:


<colgroup>
<col align="left" width="50" />
<col span="3" align="center" width="2*" />
<col width="3*" />
<col span="2" align="right" width="1*" />
</colgroup>

So, the do..while loop takes care of appending the correct number of adjacent sibling selectors.

The function described above only loops through col elements which met my requirements. Including colgroup elements is a little more complex since the content model can contain col child nodes or be empty. Since the problem only applies to Mozilla, this would be a perfect opportunity to utilise the supported TreeWalker interface from the DOM2 Traversal and Range specification. For example:


var nodes = document.createTreeWalker(
  table,
  NodeFilter.SHOW_ELEMENT, 
  {
    acceptNode : function(n) {
    return (n.tagName == "COL" || 
            (n.tagName == "COLGROUP" && 
             n.childNodes.length == 0)
           ) ?
      NodeFilter.FILTER_ACCEPT :  
      NodeFilter.FILTER_SKIP;
    }  
  },
  false);

The returned node list will contain all col and colgroup empty elements. This assumes that a colgroup element does not define the alignment for any child nodes - to account for this the acceptNode method would need to be extended further.

Posted on Nov 08, 2004 at 20:20:29. [Comments for Mozilla COL Alignment via DOM Scripting- 2]

Seeking Firewall Advice

Relates to Security

I am looking for a good reliable firewall tool to run on my Windows 98 system. The story so far…

Once and for all I kissed goodbye to Norton Internet Security last weekend. The registration period had expired and I decided it was time to try something new. Two hours of registry trawling later, 200MB of storage reclaimed, and with vastly improved performance I was content in the knowledge my system was clean. Next step was to install my chosen alternative, BitDefender Pro. I have recommended this AV tool to a number of clients and read nothing but good reviews for it.

Initial tests went well and my system was powering along, until the blue screen of death reared its ugly head! A quick browse of the BitDefender site, and hidden away in the FAQ I discovered that BitDefender Version 8 had been reported to be causing a system freeze on rare occassions with Windows 98. (I was going to link to this item, but the bug has now been changed to a different issue!?). I contacted the support team, who were very responsive, and provided some system reports to help track down the bug. But, while I have been waiting for further feedback, the software has become more and more unstable exhibiting every bug that had been fixed in Patch 7.2.11 for the previous version! I am a little jaded that these lingering bugs on Windows 98 were not made more apparant on the website resulting in a considerable waste of my time. However, I would still recommend this AV software to a user of more recent Windows versions and hope that eventually the bugs will be fixed.

In the meantime, I now plan to uninstall BitDefender before it tears my system apart, and have decided to look solely for a firewall tool as replacement for the time being. I have had a look at all the following:

All of them seem to have positive and negative reviews around the web. So, I am seeking advice from anyone who might have a recommendation or experience using any of these or an alternative. Obviously advice from Windows 98 would be beneficial, but my logs only show 15% of visits using this platform. So, if you have stumbled across this entry, I would appreciate your opinions regardless. Cheers.

Posted on Nov 05, 2004 at 22:31:25. [Comments for Seeking Firewall Advice- 2]

All New ZX Spectrum

Relates to Basic and Nostalgia

I can once again say I own a speccy! The colourful front panel of the ZX Spectrum 48K with its noticeable rainbow logo In fact it is the first ZX Spectrum 48K I have ever owned. By the time I convinced my parents we needed to upgrade our ZX81 first time round (i was pre teen then!), the ZX Spectrum Plus was on the market. So the rare opportunity I had to caress those colourful rubber keys was on visits to my Grandad who had become quite pre-occupied with writing BASIC software for every game and quiz show he could think of. Sadly his early versions of Countdown, Trivial Pursuit and a precursor to the key thumping Daley Thompson's Decathlon called Greasy Poles never made it into the software houses, but they used to keep me and my brother very entertained on family trips.

Well my grandad's old computer has now been passed on to me, along with an entire shelf worth of Spectrum programming books, several megabytes worth of hard drive in the form of several box loads of cassettes, and, notebooks containing all his code snippets and full program listings - full being about 2 pages in some instances! At first the keyboard failed to respond, but a quick dive under the hood, and a little sticky tape later, I was tapping away at those auto-complete Sinclair BASIC programming keys. It is amazing to think that this machine, at only 22 years old, had a mighty 48KB of system RAM, a standard cassette deck as a hard drive, 8 colours and just plugged into the television aerial.

To quote the cover of a BASIC programming book from 1983

The incredible ZX Spectrum presents its user with virtually unlimited scope. It allows versatile use of colour, offers high and low resolution graphics and also adds sound. The result can mean some very effective and exciting programs from BASIC - if you just know how! The Art of Programming the ZX Spectrum by M. James

Indeed! By the time I had reached my teens, and with Manic Miner and Jet Set Willy under my belt, I was insisting that it was time to once again upgrade to the Commodore. Bring on Wizball…!

It may not be very productive for me to while my hours away plugging code onto my television screen, but the occasional minute can always be excused as a brush up on BASIC!? If this entry has made you nostalgic, read up on the early 1980s history of computers.

Posted on Nov 05, 2004 at 22:20:44. [Comments for All New ZX Spectrum- 0]

Device-Independent Tool Tips

Relates to Accessibility and CSS Design, DOM Scripting

I have updated the Accessible DHTML Tool Tips experiment to handle both mouse events and keyboard events. It is not perfect, but the use of unobtrusive Javascript and device-independent event handling is a step in the right direction.

Posted on Nov 05, 2004 at 22:19:54. [Comments for Device-Independent Tool Tips- 0]

Breadcrumbs Trail

[ Home ] -> TW Blog -> Archives for November 2004
Site Map

The Severn Solutions website achieves the following standards:

[ XHTML 1.0 ] [ CSS 2 ] [ WAI AA ] [ Bobby AA ]

Page compiled in 0.026 seconds