myfaces-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Kitching <skitch...@obsidium.com>
Subject Re: JavaScript in jsCookMenu component?
Date Tue, 08 Nov 2005 21:48:37 GMT
I was doing some thinking about this too. The user may wish to open the 
URL in a new window (as implemented), or in the same window.

The normal jscookmenu provides a "target" value for this. However the 
JSF JSCookMenu tag is now using this to specify which *form* should be 
submitted when the menu item is selected, so this isn't available to 
convey the target window info.

The target window (current window, named window, or new window) 
therefore needs to be encoded somewhere else, probably in the action field.

I was playing around with the idea of having the action field be 
something like this:
   // open absolute URL in same window
   somemenuid:target=self:http://www.yahoo.com

   // open relative URL in new window
   somemenuid:target=new:/context/foo/bar.html

   // execute JSF action
   somemenuid:action:goto_home_page

This is only a half-baked proposal, but I think the requirement 
(specifying what window to open url in) is needed.

Regards,

Simon

Barbalace, Richard wrote:
> 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:thomas.spiegl@gmail.com] 
>> Sent: Thursday, November 03, 2005 5:57 PM
>> To: MyFaces Development
>> Cc: Simon Kitching; rjbarbal@mit.edu; 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 <RBARBALACE@partners.org> wrote:
>>> Simon Kitching [mailto:skitching@obsidium.com] 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
>>>
> 


Mime
View raw message