Non DOM Widget Test
by markallgood
HTML
<p id="WidgetToggler">Click me to toggle the widget</p>
<p id="WidgetDemonstrator">Click me to demonstrate the widget</p>
JavaScript
(function ($, undefined) {
$.widget("my.testWidget", {
defaultElement: null,
options: {
guess: 1
},
_create: function () {
},
_setOption: function (key, value) {
switch (key) {
case "guess":
//alert(value);
}
this._super(key, value);
},
toggle: function () {
this._setOption("guess", this.options.guess + 1);
},
say: function () {
return this.options.guess;
},
_destroy: function () {
}
});
})(jQuery);
var testInst = $.my.testWidget();
$("p#WidgetToggler").on("click", function() {
testInst.toggle();
});
$("p#WidgetDemonstrator").on("click", function() {
alert(testInst.say());
});