Skip to content

Instantly share code, notes, and snippets.

@ghinch
Created August 14, 2010 00:25
Show Gist options
  • Save ghinch/523772 to your computer and use it in GitHub Desktop.
Save ghinch/523772 to your computer and use it in GitHub Desktop.
YUI().use('widget-base', 'widget-stdmod', 'base-build', function (Y) {
var headerContent = '<a href="#" id="someButton">Click me</a>';
var myWidget = Y.Base.create('my-widget', Y.Widget, [Y.WidgetStdMod], {
_headerButton : null, // ref to btn
renderUI : function () {
this.setStdModContent(Y.WidgetStdMod.HEADER, headerContent, Y.WidgetStdMod.REPLACE);
var header = this.getStdModNode(Y.WidgetStdMod.HEADER);
this._headerButton = header.one('#someButton'); // Returns null
},
bindUI : function () {
if (this._headerButton) { // Fails, it doesn't exist
this._headerButton.on('click', function (e) {
e.preventDefault();
});
}
},
syncUI : function () {
var header = this.getStdModNode(Y.WidgetStdMod.HEADER);
this._headerButton = header.one('#someButton'); // Here we can get it, but bind has already come and gone
}
});
var myInstance = new myWidget();
myInstance.render();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment