Skip to content

Instantly share code, notes, and snippets.

@treyruncie
Created October 12, 2012 19:56
Show Gist options
  • Save treyruncie/3881159 to your computer and use it in GitHub Desktop.
Save treyruncie/3881159 to your computer and use it in GitHub Desktop.
yui3 widget pattern
YUI.add('mymodule', function (Y) {
Y.Mymodule = Y.Base.create('mymodule', Y.Widget, [], {
initializer: function (config) {
console.log('initializer');
},
renderUI: function (){
console.log('renderUI');
},
bindUI: function (){
console.log('bindUI');
this.after('fooChange', this._bindAfterFooChange);
},
syncUI: function (){
console.log('syncUI');
if(this.get('bar')){
this.get('boundingBox').set('text','bar is set to true so some text should go in the boundingBox');
}
this.set('foo', true);
},
_bindAfterFooChange: function (e){
console.log('prevVal = '+e.prevVal);
console.log('newVal = '+e.newVal);
}
}, {
ATTRS: {
foo: {
value: true
},
bar: {
value: false
}
}
});
}, '0.1', { requires: ['base','widget'] });
//implementation code
YUI().use('mymodule', function (Y) {
var module = new Y.Mymodule({boundingBox: '#mynode', bar: true});
module.render();
});​
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment