@Luis Gonzalez
Hi. I am a newbe also but will take a shot at your issues.
As I see it you have two main problems:
1) Timing - you start manipulating the DOM before it is ready, and
2) Your template HTML does not have a single defining tag.
I re-did your code as follows including a wait for DOM ready
conditions (see jQuery documentation) and a namespace 'app' creating a
closure module for the code. Also, I suggest Agility's verbose
format; atleast initially. It provides better readability while you
"get the hang of it."
Code:
----------------------
<!doctype html>
<html lang="en" >
<head>
<meta charset='utf-8' />
<title>Agility Test</title>
</head>
<body>
<!-- HTML template for 'view' -->
<script id="show" type="text/html">
<div>
<span data-bind="name"></span>
<button id="do" >change name</button>
</div>
</script>
<!-- Application dependent libs. -->
<script src="agility.js"></script>
<!-- Application 'code' module(s). -->
<script>
/*
* jQuery's on DOM ready methods definition - '$(function()
{…});'
* Here, it is proxied to bind our application's namespace,
'app'
*/
$( $.proxy(function ()
{
console.log("DOM is ready for modifications now.");
/*
* 'app' is a namespace for all agility objects and
miscellanea
* required for our application. Example:
*
* $( $.proxy( function () {
* . . . this === 'app' which is our application's
namespace.
* }, (window['app']||(window['app']={})) ));
*
* Now first, localize our namespace as a 'closure' variable
shortcut
* to: window['app'] i.e.
window.app.
*/
var app = this;
this.dude = $$(
{
model : {
name: 'Luis'
},
view : {
format: $("#show").html(),
style : 'span { color:white; background:orange; padding:
5px; }'
},
controller : {
'click button': function() {
this.model.set({name:'Ramona'});
},
'change': function() {
alert('model changed');
}
}
});
$$.document.append(this.dude);
}, (window['app']||(window['app']={})) ));
/* End of DOM ready, namespaced, module closure. */
</script>
</body>
</html>
----------------------
Greg