Hi, Thomas.
Below is my final version of the modified cmItemMouseUp() method. It should
work with any protocol and scripting language.
The method checks the link for the portion right after the JSF tag. If this is
a word followed by "://", it assumes the link is a URL, which is opened in a new
window. Otherwise, if this is a word followed by ":", it assumes the link is a
scripted method. Otherwise, it assumes the link is a JSF action. I think this
is a reasonable and simple approach, but I recommend more testing by others.
Let me know if you have any questions.
I look forward to seeing this or something similar in the next release of
MyFaces.
Thanks.
+ Richard
function cmItemMouseUp (obj, index)
{
var item = _cmItemList[index];
var link = null, target = '_self';
if (item.length > 2)
link = item[2];
if (item.length > 3 && item[3])
target = item[3];
if (link != null)
{
// changes by Richard J. Barbalace
if (link.match(/^\w*:\w*:\/\//) != null ) {
// Link is a URL
link = link.replace(/^\w*:/, ""); // Remove JSF ID
window.open (link, target);
} else if (link.match(/^\w*:\w*:/) != null ) {
// Link is a script method
link = link.replace(/^\w*:/, ""); // Remove JSF ID
window.open (link, '_self');
} else {
// Link is a JSF action
var dummyForm = document.forms['linkDummyForm'];
dummyForm.elements['jscook_action'].value = link;
dummyForm.submit();
}
}
var prefix = obj.cmPrefix;
var thisMenu = cmGetThisMenu (obj, prefix);
var hasChild = (item.length > 5);
if (!hasChild)
{
if (cmIsDefaultItem (item))
{
if (obj.cmIsMain)
obj.className = prefix + 'MainItem';
else
obj.className = prefix + 'MenuItem';
}
cmHideMenu (thisMenu, null, prefix);
}
else
{
if (cmIsDefaultItem (item))
{
if (obj.cmIsMain)
obj.className = prefix + 'MainItemHover';
else
obj.className = prefix + 'MenuItemHover';
}
}
}
> -----Original Message-----
> From: Thomas Spiegl [mailto:[EMAIL PROTECTED]
> Sent: Thursday, November 03, 2005 5:57 PM
> To: MyFaces Development
> Cc: Simon Kitching; [EMAIL PROTECTED]; Barbalace, Richard
> Subject: Re: JavaScript in jsCookMenu component?
>
>
> Can you send me a final verion for cmItemMouseUp? I will patch the
> current version.
>
> Thomas
>
> On 11/2/05, Barbalace, Richard <[EMAIL PROTECTED]> wrote:
> > Simon Kitching [mailto:[EMAIL PROTECTED] writes:
> > > I'd rather see detection of *any* protocol on the front
> of the URL
> > > rather than checking just for "http:". The protocols
> > > "https:", "mail:"
> > > etc are also useful.
> > >
> > > == proposal: ==
> > > The URL *always* has "menu_id:" on the start, so
> presumably the jscript
> > > could just strip this ID off then look for a ":" before
> any occurrence
> > > of "/" or "?". If that is present, then the URL is
> "absolute". And if
> > > that is not present but the URL contains a "/" then it
> isn't an action
> > > so treat that as a local URL.
> >
> > I would have done something similar to that originally, but
> I was not sure how
> > consistent the "menu_id:" string was or if that string
> might change in the
> > future. The string is actually "id0_menu:" in the version
> I am using, at least
> > for the first jsCookMenu element on the page.
> >
> > That proposal sounds almost fine to me. The code needs to
> check for only ":" in
> > the case of scripting languages. For example, one of my actions is
> > "id0_menu:javascript:getHelp();", which contains no "/"
> character. I am not
> > sure what the ideal regular expression would be, but it
> would definitely check
> > for ":", "/", and "?". Perhaps that would be enough; can
> any of those
> > characters be used in a JSF action name?
> >
> > Thanks.
> > + Richard
> >
>