Script configuration

Kevin Ballard kevin at sb.org
Sun Sep 4 15:53:45 EDT 2005


When poking around in MouseHole I saw that scripts can define a block  
that gets inserted into the page for the script in MouseHole, for use  
in configuring the script. However, there's no good way to actually  
pass the user's chosen configuration back to the script, except for  
mounting a path and using JavaScript XMLHttpRequest to ping that  
path. And that doesn't seem like the best way IMHO.

I was thinking of adding a generic server_config method that took a  
script identifier (which requires giving all scripts identifiers,  
although that might be a good idea to prevent conflicts in my new URL  
rewriting as well) and name=value pairs, and it would pass them back  
to the script (as a hash) to do with however it pleased. And we'd  
also provide a JavaScript method that the configure block can use to  
easily send the config data back to MouseHole via XMLHttpRequest.

Any thoughts?

Oh, and on this subject, the main config for MouseHole has a problem.  
Since it uses a single XMLHttpRequest object for all communication,  
if I click a checkbox twice rapidly, the first toggle never manages  
to get sent to MouseHole, and the current visual state of the  
checkbox is now out of sync with the actual config value (as  
reloading the page will show). I think we need to make a new  
XMLHttpRequest object per message, but we don't want to store them  
forever. I would have done it but I don't know if it's safe to get  
rid of our reference to the request object after handling the result  
text (perhaps it has to clean up the connection?). Yes, JS uses a  
garbage collector, so the object wouldn't disappear immediately, but  
it would as soon as the GC is run. Oh, and by safe I really just mean  
nice and clean - dropping the object wouldn't damage anything, but I  
don't like to keep it from cleaning up the connection. Anybody know  
more about this?

Hrm, I just had a thought. In terms of config, we could actually  
handle sending the config info back to the script ourselves so the  
script just has to output a block of HTML. What we can do is slap a  
Submit button on the end and wrap it all in a form tag and throw an  
onclick on the submit that sends the form data back with  
XMLHttpRequest. Perhaps I should go do that now - we only need a  
single XMLHttpRequest object for this, because it's only triggered  
when clicking the submit button, so the above issue doesn't apply.

-- 
Kevin Ballard
kevin at sb.org
http://www.tildesoft.com
http://kevin.sb.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2378 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/mousehole-scripters/attachments/20050904/f5e4a006/smime.bin


More information about the Mousehole-scripters mailing list