AJAX outliners work better now

darcs
slava 2006-06-26 07:07:57 +00:00
parent cfdb6aef7b
commit 7176754832
3 changed files with 37 additions and 12 deletions

View File

@ -20,10 +20,9 @@ global [
"callback" [ callback-responder ] add-simple-responder
! Javascript source used by ajax libraries
"javascript" [
"resources" [
[
"contrib/httpd/javascript/" resource-path
"doc-root" set
"" resource-path "doc-root" set
file-responder
] with-scope
] add-simple-responder

View File

@ -18,9 +18,9 @@ IN: html
: style-css, ( flag -- )
dup
{ italic bold-italic } member?
"font-style: " % "italic" "normal" ? % ";" %
"font-style: " % "italic" "normal" ? % "; " %
{ bold bold-italic } member?
"font-weight: " % "bold" "normal" ? % ";" % ;
"font-weight: " % "bold" "normal" ? % "; " % ;
: size-css, ( size -- )
"font-size: " % # "pt; " % ;
@ -148,7 +148,7 @@ M: html-stream stream-format ( str style stream -- )
: make-outliner-quot
[
<div "padding-left:20px;" =style div>
<div "padding-left: 20px; " =style div>
with-html-stream
</div>
] curry ;
@ -156,7 +156,7 @@ M: html-stream stream-format ( str style stream -- )
: html-outliner ( caption contents -- )
"+ " get-random-id dup >r
rot make-outliner-quot updating-anchor call
<span r> =id span> </span> ;
<span r> =id "display: none; " =style span> </span> ;
: outliner-tag ( style quot -- )
outline pick hash [ html-outliner ] [ call ] if* ;
@ -172,12 +172,27 @@ M: html-stream with-nested-stream ( quot style stream -- )
] outliner-tag
] with-stream* ;
: border-spacing-css,
"padding: " % first2 max 2 /i # "px; " % ;
: table-style ( style -- str )
[
H{
{ table-border [ border-css, ] }
{ table-gap [ border-spacing-css, ] }
} hash-apply
] "" make ;
: table-attrs ( style -- )
table-style " border-collapse: collapse;" append =style ;
M: html-stream with-stream-table ( grid quot style stream -- )
[
<table> rot [
<table dup table-attrs table> rot [
<tr> [
<td "top" =valign td>
pick pick stdio get with-nested-stream </td>
<td "top" =valign over table-style =style td>
pick H{ } swap with-nesting
</td>
] each </tr>
] each 2drop </table>
] with-stream* ;

View File

@ -11,7 +11,8 @@ strings ;
: include-prototype-js ( -- )
#! Write out the HTML script tag to include the prototype
#! javascript library.
<script "text/javascript" =type "/responder/javascript/prototype.js" =src script>
<script "text/javascript" =type "/responder/resources/contrib/httpd/javascript/prototype.js"
=src script>
</script> ;
: updating-javascript ( id quot -- string )
@ -20,9 +21,19 @@ strings ;
t register-html-callback swap
[ "new Ajax.Updater(\"" % % "\",\"" % % "\", { method: \"get\" });" % ] "" make ;
: toggle-javascript ( string id -- string )
[
"if(Element.visible(\"" % dup % "\"))" %
"Element.hide(\"" % dup % "\");" %
"else {" %
swap %
" Element.show(\"" % % "\"); }" %
] "" make ;
: updating-anchor ( text id quot -- )
#! Write the HTML for an anchor that when clicked will
#! call the given quotation on the server. The output generated
#! from that quotation will replace the DOM element on the page with
#! the given id. The 'text' is the anchor text.
<a updating-javascript =onclick a> write </a> ;
over >r updating-javascript r> toggle-javascript
<a =onclick a> write </a> ;