Extend a widget, with an event handler
Say I want to extend the dialog widget to log to console when the "focus" event is triggered. What is the proper way to do this?
- $.widget("my.loggeddialog", $.ui.dialog, {
- // what?
- });
- $.widget("my.loggeddialog", $.ui.dialog, {
- _create: function() {
- $.ui.dialog.prototype._create.apply(this, arguments);
- this.widget().focus(function() {
- console.log("dialog focus");
- });
- }
- });
But is doesn't work properly - it seems to fire only when I click the surface of the dialog, not inner elements, and not the title bar.
Using jQuery UI 1.8
UPDATE:
OK, I found one way to do this:
- $.widget("my.loggeddialog", $.ui.dialog, {
- _create: function() {
- $.ui.dialog.prototype._create.apply(this, arguments);
- this.element.bind("loggeddialogfocus", function() {
- console.log("dialog focus");
- });
- }
- });
This seems to have the desired effect. Is this the recommended way to do it?