|
|
Author |
Thread |
smonkey
Paranoid (IV) Inmate
From: Northumberland, England Insane since: Apr 2003
|
posted 09-08-2003 22:29
Ok I like most people like regular expressions - they are like a rubix puzzle and can do some really cool things
But I am bad at puzzles,
Does anyone know how this could be written simply with a regular expression:
--> will match ':hover' providing there it is not directly preceded by the character 'a' (ie 'a:hover' wont match - 'myDiv:hover' will match).
So far I have got the ever so simple /:hover/ which matches anything with ':hover' in - not quite good enough tho.
D'oh
Thanks,
Jon
|
Emperor
Maniac (V) Mad Scientist with Finglongers
From: Cell 53, East Wing Insane since: Jul 2001
|
posted 09-08-2003 22:36
smonkey: I'm not sure you need a regexp why not start with using getElementByTag and filtering out where the tag is an A and then look for alternatives for this in browsers that don't support getElementByTag?
[edit: Hmmmmm is getElementByTag right? I can't find much info on it and pos. I was thinking of something else?]
___________________
Emps
FAQs: Emperor
|
smonkey
Paranoid (IV) Inmate
From: Northumberland, England Insane since: Apr 2003
|
posted 09-08-2003 23:18
Emps, I respect your superior knowledge, but I don't think I can use the getElementsByTag or whatever method - you see I'm looking find all classes/tags/ids that have :hover states applied but aren't on 'link' elements in an external css file. I am currently scanning the css file on page load and returning all classes/tags/ids that have :hover states - but I only want to find all classes/tags/ids with :hover states if they aren't assigned to 'link' elements.
My reason for doing this is that IE is the only current mainstream browser that doesn't support the :hover rollover method on all elements. IE can only use the :hover rollover method on 'link' elements (hence the checking for the preceding 'a'.
Once I find the classes/tags/ids with :hover states that aren't links I can use javascript to add the corresponding element.style effects to simulate this :hover functionality on all elements.
Basically my aim is to make http://www.pixy.cz/blogg/clanky/csshiermenu/ work in IE without editing the css or the nested list structure - all I'm gonna do is put a javascript in the head of the page and make it work.
I'm slowly getting there, althought any help would be appreciated.
Thanks,
Jon
|
Emperor
Maniac (V) Mad Scientist with Finglongers
From: Cell 53, East Wing Insane since: Jul 2001
|
posted 09-08-2003 23:29
smonkey: Ahhhhhhhhh right I see. That sounds like quite a lot of effort for very little return (over just using DHTML) but I admire the ethos there
I don't think I can be of much help but I'll be keeping an eye on developments
___________________
Emps
FAQs: Emperor
|
smonkey
Paranoid (IV) Inmate
From: Northumberland, England Insane since: Apr 2003
|
posted 09-09-2003 00:10
Yeah, there isn't much return to be honest - basically the javascript will just fix an oversight in IE that I hadn't even noticed until I found those very neat css menus. No doubt in any further versions of IE the :hover pseudo-class will probably be implemented correctly, but I'd like to do it now since I have seen a path to doing it and I just can't resist walking it.
I just think it'd be nice to apply rollover effects to anything from within the css in the native css tongue - w3c have been as kind as to put this in there standards, but crappy ol' M$ have once again decided to do things their way.
Thanks for reading and responding tho - nice to get people's attention once in a while.
|
mobrul
Bipolar (III) Inmate
From: Insane since: Aug 2000
|
posted 09-09-2003 05:18
I played around with this a little...more playing to come in the near future.
In the meantime, why couldn't you simply see if the string contains ':hover', then split the string.
code:
//line by line, walk through the css file
var st = new css line;
//look for any letter, number or underscore \w
//and the + says there must be at least 1 match
//with no maximum number of matches
var reg1 = /[\w]+:hover/g;
//test to see if it evaluates true
if(reg1.test(st)){
//split the string by colons
var x = st.split(/[:]/);
//x is now an array that holds values representing
//each side of the colon
//then see if x(0)=='hover' or 'a'
//then throw them away
var i=0;
for(i=0; i<x.length; i++){
if(x[i] == 'hover'){
}
else if(x[i] == 'a'){
}
else{
//write a new search and replace based precisely on the value of x[i]
}
}
}
//if string doesn't match :hover you don't care
else{
}
That ought to get you close to what you want, yes?
It's a little complicated, but I think it'll work.
[edit]My apologies if you happened to read this between when I originally wrote it and now. I won't go into details, but to say my brain was working at the capacity of a brick.
All better now, I hope.
[/edit]
[This message has been edited by mobrul (edited 09-09-2003).]
|
bitdamaged
Maniac (V) Mad Scientist
From: 100101010011 <-- right about here Insane since: Mar 2000
|
posted 09-09-2003 17:26
you are over thinking this.
You only want to match "a:hover" correct?
then you can do
if (str.indexOf("a:hover") >= 0) ...
In a regex you if you want to allow for spaces and different cases
/a\s*:\s*hover/i
will do it.
Basically you were trying to hard to Not match the other things which was not necessary since you actually want to just match a:hover
.:[ Never resist a perfect moment ]:.
|
mobrul
Bipolar (III) Inmate
From: Insane since: Aug 2000
|
posted 09-09-2003 17:43
bit to the rescue...
thank you
|
smonkey
Paranoid (IV) Inmate
From: Northumberland, England Insane since: Apr 2003
|
posted 09-09-2003 18:22
Sorry Bitty, i'm not sure i do want to match 'a:hover' - I basically want to get all the ':hover' tags that don't have an 'a' infront of them. That make sense? I was hoping one regex could do that, otherwise it's a case of checking once for the ':hover' and then checking those results for the 'a'.
Apologies if I have missed what you suggested, maybe there is a way with what you said.
|
bitdamaged
Maniac (V) Mad Scientist
From: 100101010011 <-- right about here Insane since: Mar 2000
|
posted 09-09-2003 19:08
/[^a]:hover/
.:[ Never resist a perfect moment ]:.
|
Slime
Lunatic (VI) Mad Scientist
From: Massachusetts, USA Insane since: Mar 2000
|
posted 09-09-2003 19:36
You should consider cases like:
lalala:hover (tag name before ":hover" ends in "a" but is more than just an "a")
a.something:hover (something between the "a" and the ":hover")
a:hoverstuff (pseudoclass isn't "hover", it's "hoverstuff")
You might have some luck with a lookbehind assertion, maybe. It's going to be hard to properly determine whether the :hover pseudoclass applies to an anchor tag or not.
|
smonkey
Paranoid (IV) Inmate
From: Northumberland, England Insane since: Apr 2003
|
posted 09-09-2003 19:44
bugger
[This message has been edited by smonkey (edited 09-09-2003).]
|
Kirk
Nervous Wreck (II) Inmate
From: Insane since: Sep 2003
|
posted 09-15-2003 09:29
Those menus suck... you can do the same thing and make it functional in all browsers by making the anchor tags block elements...
|
smonkey
Paranoid (IV) Inmate
From: Northumberland, England Insane since: Apr 2003
|
posted 09-16-2003 20:18
I know visually the meus do look crap, but the principle is an extremely good one.
Kirk I don't really understand what you mean with your suggestion - if you think you can write crossbrowser css pop-up / drop down menus with css using just block level elements then I think maybe you would be disappointed.
Did you actually look at the menus with a browser like mozilla? In IE you'll get the top buttons.
And Slime,
lalala:hover - admitedly a problem
a.something:hover - but my script would be needed here - IE wouldn't do rollover effects with that CSS syntax by default
a:hoverstuff (pseudoclass isn't "hover", it's "hoverstuff") - :hoverstuff isn't a current or future pseudoclass, Now I'm pretty sure in XML you can make your own pseudoclasses, but I don't think the same applies with XHTML/CSS. Therefore I don't see why I would ever encounter a pseudoclass like this.
One final note, I'm not arguing or trying to get at you, I do really appreciate all your advice and help - please don't take any offence at the slightly confrontational tone of this post. I respect that you Slime know much more than I do, and that there is every chance Kirk does too. So I could very well be wrong in my assertations here, and I would appreciate being told if I am since I will need not be wrong next time this subject comes up.
Thanks again guys,
Jon
|
Slime
Lunatic (VI) Mad Scientist
From: Massachusetts, USA Insane since: Mar 2000
|
posted 09-16-2003 22:34
quote: a.something:hover - but my script would be needed here - IE wouldn't do rollover effects with that CSS syntax by default
Are you sure? Although IE has problems with multiple classes applied to an element, I believe that particular case is handled somewhat properly by IE.
quote: hoverstuff isn't a current or future pseudoclass
Neither you nor I know what the future holds =)
Point is, always account for future changes in a language. In this particular case, I don't think it will even be very hard - just check for a word boundary after "hover" by using "hover\b".
|
smonkey
Paranoid (IV) Inmate
From: Northumberland, England Insane since: Apr 2003
|
posted 09-17-2003 02:35
OK Slime,
If I can be arsed I will try out the 'a.whatever:hover' method - I don't think it will highlight a link (or whatever effect specified), I think I have tried applying classes directly to links and from memory I'm pretty sure IE choked.
You are definitely right about the future tho, I was mostly thinking in regards of CSS3 specs but after that who knows? and besides, no one ever knows with microsoft, they'll probably create their own proprietry pseudoclass called ver just to piss the web makers off.
In fact does anyone know if custom pseudoclasses are allowed in xml even? and then what about xhtml? and besides, how would you use them? :hover, :active :before, :first-child - they all have a specific pre-defined 'function', but how would you go about creating one from scratch?
|
Kirk
Nervous Wreck (II) Inmate
From: Insane since: Sep 2003
|
posted 09-17-2003 09:43
The following link is to drop down menu I have written. You can pull it apart if you like...
It works well in both Ie and Mozilla.
www.eviltrip.com/temp/flynav.zip
|
Maskkkk
Paranoid (IV) Inmate
From: Willaimsport, PA, US of A the hole in the Ozone Insane since: Mar 2002
|
posted 09-22-2003 21:38
Heck for that matter if you need a good reference on regular expressions, try this website:
http://wwww.itlab.musc.edu/docs/perl_regexp/
- Biggie
- Face the Present
- AIM: MASKKKK
01001101011000010111001101101011011010110110101101101011
|
Veneficuz
Paranoid (IV) Inmate
From: A graveyard of dreams Insane since: Mar 2001
|
posted 09-22-2003 23:01
Another great place for RegExp information:
:FAQ: Can you help me understand regular expressions?
_________________________
"There are 10 kinds of people; those who know binary, those who don't and those who start counting at zero"
- the Golden Ratio -
|