-
-
Save don-smith/889781 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($){ | |
$.widget("ui.mywidget", { | |
options: { | |
autoOpen: true | |
}, | |
_create: function(){ | |
// by default, consider this thing closed. | |
this._isOpen = false; | |
}, | |
_init: function(){ | |
// call open if this instance should be open by default | |
if( this.options.autoOpen ){ | |
this.open(); | |
} | |
}, | |
open: function(){ | |
this._isOpen = true; | |
// trigger beforeopen event. if beforeopen returns false, | |
// prevent bail out of this method. | |
if( this._trigger("beforeopen") === false ){ | |
return; | |
} | |
// more open related code here | |
// trigger open event | |
this._trigger("open"); | |
// bind with $(...).bind('mywidgetopen', function() { ... | |
return this; | |
}, | |
close: function(){ | |
this._isOpen = false; | |
// trigger close event | |
this._trigger("close"); | |
return this; | |
}, | |
isOpen: function(){ | |
return this._isOpen; | |
}, | |
destroy: function(){ | |
// call the original destroy method since we overwrote it | |
$.Widget.prototype.destroy.call( this ); | |
}, | |
_setOption: function(key, value){ | |
this.options[key] = value; | |
switch(key){ | |
case "something": | |
// perform some additional logic if just setting the new | |
// value in this.options is not enough. | |
break; | |
} | |
} | |
}); | |
$.extend($.ui.mywidget, { | |
// other properties like: version: '@VERSION' | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment