Jake Churchill

… on Flex, ColdFusion, FarCry, and much more …

  • Home
  • About
  • Projects

20

Mar

IE menu hover fix

Posted by Jake Churchill  Published in Browsers, CSS, Javascript

I run into an issue a lot with fly-out and dropdown menus not always layering on TOP of the subsequent content. I see this most often with Farcry because that is what I use for a lot of sites but I see it elsewhere as well. It can be the most irritating thing in the world to deal with but it CAN be fixed.

In farcry sites, there is a navigation.js or hover.js file that is loaded which provides a nice *hack* for IE6. The purpose of this is that for multi-level navigations, the dropdown/flyout appears when you hover over an LI tag. IE6 only recognizes the seudo element (:hover) on A tags so this javascript file manually adds a class to every LI tag that is a child of a particular element. I.E. if your outer UL has an ID of “menu” this class will be added to all sub-elements.

Here’s what the basic javascript looks like:

hover = function() {
var nav = document.getElementById("menu");
if(nav){
var nodes = nav.getElementsByTagName("li")
for (var i=0; i<nodes.length; i++) {
nodes[i].onmouseover=function() {
this.className+=" hover";
}
nodes[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" hover\\b"), "");
}
}
}
}
if (window.attachEvent) window.attachEvent("onload", hover);

I know, not necessarily that “basic” but all it’s doing is attaching an “onMouseOver” and “onMouseOut” event handler to all LI tags under the element with ID “menu”.

Now, back to the original problem… The dropdown/flyout menus don’t always layer OVER the content in the page. This is thanks to IE rendering all elements with a z-index of 0. Regardless of what you set this to in your CSS (generally z-index of the flyout is higher than the z-index of the page) IE will make it all 0 at the time of loading.

I dealt with this problem for months always hacking my way through a fix depending on the site until it finally dawned on me. I can use this javascript to my advantage because this code runs “onload” (once the page has loaded). Conveniently, this is also after z-indexes have been butchered by IE. So, here is a quick alteration to that javascript that has fixed every problem I’ve run into thusfar:

hover = function() {
var nav = document.getElementById("menu");
nav.style.zIndex = 100;
if(nav){
var nodes = nav.getElementsByTagName("li")
for (var i=0; i<nodes.length; i++) {
nodes[i].onmouseover=function() {
this.className+=" hover";
}
nodes[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" hover\\b"), "");
}
}
}
}
if (window.attachEvent) window.attachEvent("onload", hover);

Notice the line “nav.style.zIndex = 100;”. That’s all it took. Of course, your situation may be much more complex than this and may require more layering of elements. Using this same example you can simply reset z-indexes even if you don’t have a complex menu. Here would be an example of that:

resetZIndexes= function() {
var nav = document.getElementById("menu").style.zIndex = 100;
// other elements would go here
}
if (window.attachEvent) window.attachEvent("onload", resetZIndexes);

I really hope this helps someone avoid the agonizing pain that I had to endure prior to figuring this out.

3 comments

12

Aug

Flex calls to Javascript

Posted by Jake Churchill  Published in Flex, Javascript

Flex is great! Javascript can be great! What if two great things got together?

This is a simple code hint which shows how to call javascript functions from Flex and pass data back and forth:

MXML Button:

<mx:Button
id = "button"
label = "Click Me!"
click = "handleButtonClick(event:MouseEvent)
/>

Flex Function:

private function handleButtonClick(event:MouseEvent):void
{
var functionName:String = "handleButtonClick";
var returnData:String = ExternalInterface.call(f, "You clicked the button!");
}

Javascript Function:

function handleButtonClick(message)
{
alert(message);
}

That’s really all there is to it. the ExternalInterface.call() handles everything for you.

By the way, if you wanted to actually return data from the javascript function, you’d just do a standard return and it’d be available in the returnData variable in Flex:

function handleButtonClick(message)
{
alert(message);
return "success";
}

1 comment

26

Mar

Javascript Popup with graceful fallback

Posted by Jake Churchill  Published in Javascript

I’ve struggled with popups for some time now. I’ve never really found a good way to handle popping up a new window when clicking a link. Sure, there is the target=”_blank” method but I’ve heard that in XHTML1.0 that is not actually valid. That tells me that browsers can still handle this but might not sometime in the future (or it might end up being included in some kind of quirks rendering mode in the future). A standard Javascript popup is another option but is too easily disabled.

This method will actually do both by creating an event handler.


continue reading "Javascript Popup with graceful fallback"

2 comments

31

Jul

CSS close window link

Posted by Jake Churchill  Published in CSS, Javascript

Honestly, I am blogging this to satisfy a coworker (Axel) who thought this was really cool.

You see this kind of thing all the time, a little X on a window that gets open that allows you to close it. Not the X close button on the title bar of the window but a little close link with an x. I’m a bit of a CSS geek so I made this in CSS. Here’s the code:

<a href="Javascript:window.close()" style="text-decoration:none;">close <span style="border:1px solid gray;width:15px;text-align:center;font-size:8pt;cursor:hand;">X</span></a>

Test It!

no comment

12

Jan

Use javascript to embed a flash object

Posted by Jake Churchill  Published in Flash, Javascript

I’m sure everyone’s been browsing the net using Internet Explorer and noticed that annoying “Click to activate the ActiveX Control” thing. This was implemented by Microsoft due to a security flaw but what if you happen to know that what you are embedding is secure?

In this case, use Javascript to embed your flash object. The javascript has to be in a seperate .js file.

Example:

<!-- include .js file -->
<script type="text/javascript" src="/js/writeFlash.js"></script>
.
.
.
<!-- call function -->
<script language="JavaScript" type="text/javascript">
RunFlash(#flashwidth#, #flashheight#, "#flashmovie#");
</script>

And here’s the JavaScript code:

function RunFlash(flashWidth, flashHeight, flashMovie) {
    var oeTags = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
    + 'width='+flashWidth+' height='+flashHeight+' '
    + 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
    + '<param name="movie" value="/files/'+flashMovie+'" /><param name="quality" value="high" /><param name="bgcolor" value="##ffffff" /><param name="wmode" value="transparent">'
    + '<embed src="/files/'+flashMovie+'" quality="high" bgcolor="##ffffff" '
    + 'width="'+flashWidth+'" height="'+flashHeight+'" align="left" wmode="transparent"'
    + 'play="true"'
    + 'loop="false"'
    + 'quality="high"'
    + 'allowScriptAccess="sameDomain"'
    + 'type="application/x-shockwave-flash"'
    + 'pluginspage="http://www.macromedia.com/go/getflashplayer">'
    + '<\/embed>'
    + '<\/object>';
    document.write(oeTags);   // embed the flash movie
}
no comment

Search

Blog Feed

  • Add blog to any reader
  • Comments Rss
July 2009
M T W T F S S
« May    
 12345
6789101112
13141516171819
20212223242526
2728293031  

Subscribe to Blog

Your email:

Subscribe   Unsubscribe

Archives

Categories

  • Browsers (3)
  • CFEclipse (2)
  • ColdFusion (5)
  • CSS (9)
  • Farcry (32)
    • Farcry Examples (2)
    • Farcry Users (1)
  • Flash (1)
  • Flex (14)
  • Javascript (5)
  • Life & Fun (3)
  • Microsoft Office (1)
  • Misc (4)
  • Random Posts (1)
  • SQL (2)

Recent Posts

  • Flex 2 Datagrid not highlighting row (UPDATE)
  • Flex 2 Datagrid not highlighting row
  • Flex Dynamic casting of data
  • Reboot XP PC over Remote Desktop
  • Dynamically instantiate a class

Recent Comments

  • jellyBean on Flex Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Status 200
  • Wouter Meeuwisse on CSS Browser Hacks
  • Jake Churchill on Flex Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Status 200
  • coulix on Flex Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Status 200
  • Jake Churchill on IE menu hover fix

Recent Post

  • Flex 2 Datagrid not highlighting row (UPDATE)
  • Flex 2 Datagrid not highlighting row
  • Flex Dynamic casting of data
  • Reboot XP PC over Remote Desktop
  • Dynamically instantiate a class
  • Flex Custom Preloader without SWF
  • IE menu hover fix
  • Eclipse with plugins
  • Flex Channel.Connect.Failed error NetConnection.Call.Failed: HTTP: Status 200
  • Flex Metadata - Default Property Values

Recent Comments

  • jellyBean in Flex Channel.Connect.Failed error NetConnection.Ca…
  • Wouter Meeuwisse in CSS Browser Hacks
  • Jake Churchill in Flex Channel.Connect.Failed error NetConnection.Ca…
  • coulix in Flex Channel.Connect.Failed error NetConnection.Ca…
  • Jake Churchill in IE menu hover fix
  • nwhysel in IE menu hover fix
  • Jake Churchill » Post Topic &… in Flex 2 Datagrid not highlighting row
  • Jake Churchill in Reboot XP PC over Remote Desktop
  • Jake Churchill in IE6 PNG Transparency Fix
  • oomes in IE6 PNG Transparency Fix
© 2008 Jake Churchill is proudly powered by WordPress
Theme designed by Roam2Rome