]> gitweb.factorcode.org Git - factor.git/blob - contrib/httpd/prototype-js.factor
Furnace tools overhaul
[factor.git] / contrib / httpd / prototype-js.factor
1 ! Copyright (C) 2006 Chris Double.
2 ! See http://factorcode.org/license.txt for BSD license.
3 !
4 ! Wrapper for the Prototype javascript library.
5 ! For information and license details for protoype 
6 ! see http://prototype.conio.net
7 IN: prototype-js
8 USING: callback-responder html httpd io kernel namespaces
9 strings ;
10
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"
15   =src script>
16   </script> ;
17
18 : updating-javascript ( id quot -- string )
19   #! Return the javascript code to perform the updating
20   #! ajax call.
21   t register-html-callback swap 
22   [ "new Ajax.Updater(\"" % % "\",\"" % % "\", { method: \"get\" });" % ] "" make ;
23
24 : toggle-javascript ( string id -- string )
25     [
26         "if(Element.visible(\"" % dup % "\"))" %
27         "Element.hide(\"" % dup % "\");" %
28         "else {" %
29         swap %
30         " Element.show(\"" % % "\"); }" %
31     ] "" make ;
32
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> ;