Created
November 30, 2011 16:47
-
-
Save mountain/1409763 to your computer and use it in GitHub Desktop.
How to bind events in bean? With qwery and bonzo but without ender
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### | |
csmain.coffee | |
link for this section: | |
http://playground.wahlque.org/tutorials/coffeescript/004-webworkers/ | |
### | |
define [ | |
'underscore', | |
'domReady', | |
'qwery', | |
'bonzo', | |
'bean', | |
'cs!/wahlque/util/url' | |
], (_, domReady, qwery, bonzo, bean, url) -> | |
$ = (selector) -> bonzo(qwery(selector)) | |
q = (selector) -> document.querySelectorAll(selector) | |
domReady( -> | |
ps = url.params() | |
ps['a'] = 5 if not ps['a'] | |
ps['b'] = 10 if not ps['b'] | |
ctx = | |
keys: _.keys(ps) | |
vals: ps | |
list = _.template( | |
"<ul> | |
<form action='/tutorials/coffeescript/004-webworkers/' method='get'> | |
<% _.each(keys, function(key) { %> | |
<li><%= key %>: <input type='text' name='<%= key %>' value='<%= vals[key] %>'></li> | |
<% }); %> | |
<input type='submit' value='Submit' /> | |
</form> | |
</ul>", | |
ctx | |
) | |
$('#params').html(list) | |
worker = new Worker 'worker.js' | |
worker.onmessage = (e) -> | |
data = 'result: ' + e.data | |
$('#result').append("<li>#{data}</li>") | |
true | |
invoke = -> | |
console.info('start of calling from page') | |
worker.postMessage( _.values(ps)) | |
console.info('end of calling from page') | |
true | |
bean.add( | |
$('#btn'), 'click', (-> invoke()), q | |
) | |
true | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Finally I solve it by myself. Just using get() method to fetch out the dom elements.
See https://github.com/Wahlque/tutorials/blob/master/coffeescript/004-webworkers/csmain.coffee#52