Skip to content

Instantly share code, notes, and snippets.

@ToddG
Created July 4, 2011 20:46
Show Gist options
  • Save ToddG/1063919 to your computer and use it in GitHub Desktop.
Save ToddG/1063919 to your computer and use it in GitHub Desktop.
logging text from server to client
%% -*- mode: nitrogen -*-
-module (rtext2).
-compile(export_all).
-include_lib("nitrogen_core/include/wf.hrl").
-include_lib("nitrogen_core/include/google_chart.hrl").
-include("records.hrl").
main() -> #template { file="./site/templates/raphael.html" }.
title() -> "Todd's <b>Raphael Text Log</b> Page".
body() ->
Panel = #panel { style="margin: 50px 100px;", body=[
#span { text="Raphael Log Test Below" },
#panel { id=holder, body=[
#p { id=logtext, text="-"}
%%#hidden { id=hiddentext }
]},
#textbox { id=transfer, text="initial text", show_if=true }
]},
wf:wire(transfer, #event { type=onchange, actions=#script { script="
setRText(obj('transfer').text);
"}}),
wf:comet(fun() -> bg_update(transfer, 1, 5000) end),
wf:wire(#script { script="
var setRText=function(text){
console.log('setting text');
var hldr = obj('holder');
var R = Raphael(hldr, 640, 480);
var attr = {font: '50px Helvetica, Arial', opacity: 0.5};
txt[0] = R.text(320, 240, text).attr(attr).attr({fill: 'hsb(0, .5, 1)'});
};" }),
Panel.
event(_) -> ok.
bg_update(ControlID, Count, Delay) ->
timer:sleep(Delay),
wf:update(ControlID, wf:to_list(Count)),
wf:flush(),
%%?PRINT(wf:wf("count=" ++ Count)),
bg_update(ControlID, Count + 1, Delay).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment