Running the hello widget
So, we end up with a widget like so:
// Create the namespace
var pax = pax || {};
pax.widget = pax.widget || {};
pax.widget.hello = pax.widget.hello || {};
// "Controller" method
pax.widget.hello.init = function( target, args ) {
var model = pax.widget.hello.model( target, args );
pax.widget.init( {
target: target,
model: model,
template: pax.widget.hello.template()
} ).render(); // This renders the widget
};
// "View" method
pax.widget.hello.template = function() {
return "Hello [:= name :]";
};
// "Model" method
pax.widget.hello.model = function( target, args ) {
return pax.defaultArgs( {
name: 'world' // Default the name to 'world', if none is specified
}, args );
};
var pax = pax || {};
pax.widget = pax.widget || {};
pax.widget.hello = pax.widget.hello || {};
// "Controller" method
pax.widget.hello.init = function( target, args ) {
var model = pax.widget.hello.model( target, args );
pax.widget.init( {
target: target,
model: model,
template: pax.widget.hello.template()
} ).render(); // This renders the widget
};
// "View" method
pax.widget.hello.template = function() {
return "Hello [:= name :]";
};
// "Model" method
pax.widget.hello.model = function( target, args ) {
return pax.defaultArgs( {
name: 'world' // Default the name to 'world', if none is specified
}, args );
};
HTML:
<div id='widget_introduction_example1'></div>
pax.widget.hello.init( pax.$('widget_introduction_example1') );
HTML:
<div id='widget_introduction_example2'></div>
pax.widget.hello.init( pax.$('widget_introduction_example2'), {
name: 'Bartholemew'
} );
name: 'Bartholemew'
} );




