1 ! Copyright (C) 2006 Chris Double.
2 ! See http://factorcode.org/license.txt for BSD license.
4 ! Wrapper for the Prototype javascript library.
5 ! For information and license details for protoype
6 ! see http://prototype.conio.net
8 USING: callback-responder html httpd io kernel namespaces
11 : include-prototype-js ( -- )
12 #! Write out the HTML script tag to include the prototype
13 #! javascript library.
14 <script "text/javascript" =type "/responder/resources/prototype.js"
18 : updating-javascript ( id quot -- string )
19 #! Return the javascript code to perform the updating
21 t register-html-callback swap
22 [ "new Ajax.Updater(\"" % % "\",\"" % % "\", { method: \"get\" });" % ] "" make ;
24 : toggle-javascript ( string id -- string )
26 "if(Element.visible(\"" % dup % "\"))" %
27 "Element.hide(\"" % dup % "\");" %
30 " Element.show(\"" % % "\"); }" %
33 : updating-anchor ( text id quot -- )
34 #! Write the HTML for an anchor that when clicked will
35 #! call the given quotation on the server. The output generated
36 #! from that quotation will replace the DOM element on the page with
37 #! the given id. The 'text' is the anchor text.
38 over >r updating-javascript r> toggle-javascript
39 <a =onclick a> write </a> ;