HighDots Forums  

Re: Need Help Trying to merge 2 Function and CSS to work

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: Need Help Trying to merge 2 Function and CSS to work in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Michael Winter
 
Posts: n/a

Default Re: Need Help Trying to merge 2 Function and CSS to work - 04-16-2004 , 10:45 PM






On Wed, 14 Apr 2004 10:00:59 -0700, EasyRider41
<tconley (AT) semprautilities (DOT) com> wrote:

Quote:
I am trying to merge to scripting samples I for on a source code web
site and having limited luck. Then first one is called Zebra Tables
witch colors alternate rows of a table to look beter. The second is a
rule code that highlights the row you are currently moused over. Both
are making use of CSS style sheet to do all of their formating.
My problem is that the rollover is changing the text color but not the
color of the row background as the example does in the original code
which is what I am looking for out of this. Anyone have any ideas???

Link to the Samples are here:
http://www.alistapart.com/articles/zebratables/
http://www.alistapart.com/articles/tableruler/
Their "ruler" example is flaky on Opera, and both scripts could have been
written better, so I started from scratch. You can see an example here:

<URL:http://www.mlwinter.pwp.blueyonder.co.uk/clj/easyrider/table.html>

As you'll no doubt notice, there's redundancy in the two main functions,
but I'll let you sort that out. I also added a fall-back that will allow
the "ruler" effect to work when JavaScript is disabled[1]: you'll want to
make sure that the colours specified in the "table.ruler tr:hover"
declaration and the initialiseTableRuler() function are in sync.

[snipped code]

I suggest you validate your HTML before you attempt to script documents,
especially when DOM methods and modification of the document structure is
involved. Invalid documents might not behave as you expect.

<URL:http://validator.w3.org/>

Hope that helps,
Mike


[1] IE doesn't support the :hover pseudo-class on any element other than
A, so it will rely on JavaScript to provide the ruler effect.

--
Michael Winter
M.Winter (AT) blueyonder (DOT) co.invalid (replace ".invalid" with ".uk" to reply)


Reply With Quote
  #2  
Old   
Yann-Erwan Perio
 
Posts: n/a

Default Re: Need Help Trying to merge 2 Function and CSS to work - 04-17-2004 , 05:30 AM






Michael Winter wrote:

A very clear and enjoyable script.

FWIW, here are some suggestions/questions:
- in the CSS declarations, I don't think that you need to use "table
td"-like selectors, "td" only would do; AFAICS you're trying to address
invalid-HTML cases, where we'd have TD elements anywhere - but then
you're telling the OP to fix invalid HTML. Fixing HTML should be enough:-)

- "if( b = tB[ i ]) {" is a bit strange, since you're iterating in the
tBodies collection, the tBody has to exist; have you come across any
implementation in which this wasn't the case?

- "r[ j ].onmouseover = function() {" is declaring a different function
at each iteration; you could declare the function once and then use
reference. Moreover, on a technical note, functions expressions declared
this way could hardly be joined because of scope issues, so if you still
want to declare functions in a loop I'd advise using the Function
Constructor instead, in which case it's easier for implementations to
create joined objects (although not compulsory - a single function, then
references remains the best method).


Regards,
Yep.


Reply With Quote
  #3  
Old   
Michael Winter
 
Posts: n/a

Default Re: Need Help Trying to merge 2 Function and CSS to work - 04-17-2004 , 08:03 AM



On Sat, 17 Apr 2004 11:30:41 +0200, Yann-Erwan Perio
<y-e.perio (AT) em-lyon (DOT) com> wrote:

Quote:
Michael Winter wrote:

URL:http://www.mlwinter.pwp.blueyonder.c...der/table.html

A very clear and enjoyable script.
I actually uploaded the page prematurely. I've uploaded the version that
should have been posted originally (few changes, so there's no point
looking at it again).

Quote:
FWIW, here are some suggestions/questions:
Always welcome.

Quote:
- in the CSS declarations, I don't think that you need to use "table
td"-like selectors, "td" only would do; AFAICS you're trying to address
invalid-HTML cases, where we'd have TD elements anywhere - but then
you're telling the OP to fix invalid HTML. Fixing HTML should be
enough:-)
Can't say why I did that. The only place where "table" needs to be
included in the selector is with "table.ruler td:hover", to make sure that
non-ruler-enabled tables don't use the effect.

Quote:
- "if( b = tB[ i ]) {" is a bit strange, since you're iterating in the
tBodies collection, the tBody has to exist; have you come across any
implementation in which this wasn't the case?
That's out of habit: test everything. It shouldn't be needed.

Quote:
- "r[ j ].onmouseover = function() {" is declaring a different function
at each iteration; you could declare the function once and then use
reference. Moreover, on a technical note, functions expressions declared
this way could hardly be joined because of scope issues, so if you still
want to declare functions in a loop I'd advise using the Function
Constructor instead, in which case it's easier for implementations to
create joined objects (although not compulsory - a single function, then
references remains the best method).
I realised that myself after I uploaded the page. I made the changes to
the local version, but forgot to upload it again. It uses two functions
and assigns references to the handlers.

Mike

--
Michael Winter
M.Winter (AT) blueyonder (DOT) co.invalid (replace ".invalid" with ".uk" to reply)


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.