[Seaside] liveAction using existing method

William E Harford seaside at harford.org
Thu Jun 30 05:58:04 CEST 2005


Thanks John 

I took a look at LiveWeb (very nifty) and found the solution I was
looking for (I ripped you off John :-) ). 

I added the following to the javaScript function processRequestChange()
in  WAStandardScripts liveUpdate...

var startOfData = request.responseText.indexOf("<script");
while (startOfData != -1) {
    var startOfData = request.responseText.indexOf(">", startOfData) +
1;
    var endOfData = request.responseText.indexOf("<\/script>",
startOfData);
				
    eval(request.responseText.substring(startOfData, endOfData));
    startOfData = request.responseText.indexOf("<script", endOfData);
}

So now if I put  "h script: 'alert(''Annoying model dialog'');'." in any
liveAction block it works as expected. 

There could be a potential bug in the above. I am not sure Seaside would
allow it or even if it's valid html but if "<script" appears in an
attribute value the above would fail. I am not sure that < is allowed in
attribute values but I do know that it works as expected.

If no one objects (hehe) I would like to see this or something like it
added to future releases of Seaside.

I don't know how you all usually except these sort of things but I have
seen plenty of "fileOut"s posted so I attached a .st


Thanks 
Will

On Wed, 2005-06-29 at 22:06 -0400, John Pierce wrote:
> Hi WIlliam,
> 
> I believe modern browsers do no automatically execute scripts injected
> into the browser page using the DOM. You would have to run an eval on
> these new scripts to get them to execute. In the LiveWeb add-on for
> Seaside I handled this exact issue. Let me know if you need any other
> advice.
> 
> Regards,
> 
> John
> 
> On 6/29/05, William E Harford <seaside at harford.org> wrote:
>         anchorWithAction:liveAction:text: overrides the onClick
>         callback of the
>         calling anchor.
>         
>         Is there anyway to execute more JavaScript for the onClick
>         callback of
>         the anchor after the liveAction is done?
>         
>         I tried using  h script: 'alert(''IEEEEEE!!'');'. within the
>         liveAction 
>         block but sadly that JavaScript does appear in the live action
>         page but
>         is never executed.
>         
>         On a side note ...
>         This Listserv and the people on it is simply amazing. I have
>         not seen
>         this sort of helpfulness, thoughtful discussion, genuine
>         interest , and 
>         kindness (particularly from the lead developers) in a
>         discussion group
>         in many years. I thought the days of these sort of groups were
>         gone. I
>         guess I have been subscribed to the wrong Listservs.
>         
>         Thanks Will 
>         --
>         William E Harford <seaside at harford.org>
>         
>         _______________________________________________
>         Seaside mailing list
>         Seaside at lists.squeakfoundation.org
>         http://lists.squeakfoundation.org/listinfo/seaside
> 
> 
> 
> -- 
> It's easy to have a complicated idea. It's very very hard to have a
> simple idea. -- Carver Mead 
> _______________________________________________
> Seaside mailing list
> Seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/listinfo/seaside
-------------- next part --------------
'From Squeak3.8 of ''5 May 2005'' [latest update: #6665] on 29 June 2005 at 11:36:47 pm'!
!WAStandardScripts methodsFor: 'as yet unclassified ' stamp: 'wh 6/29/2005 23:29'!
liveUpdate
	^ 'function liveUpdaterUri(uri)
{
    return liveUpdater(function() { return uri; });
}
function addParameter(uri, key, value)
{
	var separator = "?";
	if(uri.indexOf("?") >= 0)
	    separator = "&";
	return uri + separator + key + "=" + escape(value);
}
function liveUpdater(uriFunc)
{
    var request = false;
    var regex = /<(\w+).*?id="(\w+)".*?>((.|\n)*)<\/\1>/;
    
    if (window.XMLHttpRequest) {
       	request = new XMLHttpRequest();
    }
    
    function update()
    {
       if(request && request.readyState < 4)
            request.abort();
            
        if(!!window.XMLHttpRequest)
            request = new ActiveXObject("Microsoft.XMLHTTP");
        
        request.onreadystatechange = processRequestChange;
        request.open("GET", addParameter(uriFunc(), "timestamp", (new Date()).getTime().toString()));
        request.send(null);
        return false;
    }
    
 function processRequestChange()
   {
       if(request.readyState == 4)
       {
           var results = regex.exec(request.responseText);
           if(results) {
               document.getElementById(results[2]).innerHTML = results[3];
           } else {
                 var bodyRegex = /<body>(.*)?<\/body>/;
                 var body = bodyRegex.exec(request.responseText);
                 if ( body ) {
                     document.body.innerHTML = body[1];
                 } else {
                     document.body.innerHTML = request.responseText;
                 }
		   }
			
		   var startOfData = request.responseText.indexOf("<script");
		   while (startOfData !!= -1) {
                 var startOfData = request.responseText.indexOf(">", startOfData) + 1;
                 var endOfData = request.responseText.indexOf("<\/script>", startOfData);
				
                 eval(request.responseText.substring(startOfData, endOfData));
		       startOfData = request.responseText.indexOf("<script", endOfData);
              }
           
       }
   }
    return update;
}
function liveSelect(id, uri)
{
	function constructUri()
	{
		return addParameter(uri, "s", document.getElementById(id).selectedIndex.toString());
	}
	
	return liveUpdater(constructUri); 
}
function liveSearch(id, uri)
{
    function constructUri()
    {
        return addParameter(uri, "s", document.getElementById(id).value);
    }
    
    var updater = liveUpdater(constructUri);
    var last = "";
    var timeout = false;
   
    function update()
    {
       if (last !!= document.getElementById(id).value)
            updater();
    }
        
    function start() {
	   if (timeout)
	       window.clearTimeout(timeout);
	   
    	   timeout = window.setTimeout(update, 300);
    }
	
	if (navigator.userAgent.indexOf("Safari") > 0)
		document.getElementById(id).addEventListener("keydown",start,false);
    else if (navigator.product == "Gecko")
		document.getElementById(id).addEventListener("keypress",start,false);
    else
		document.getElementById(id).attachEvent("onkeydown",start);
}
function timedUpdate(uriFunc, milliSeconds)
{
	var updater = liveUpdaterUri(uriFunc);
	updater();
	var again = "timedUpdate(\""+uriFunc+"\","+milliSeconds+")";
	setTimeout(again, milliSeconds);
}
'! !


More information about the Seaside mailing list