Skip to content

Instantly share code, notes, and snippets.

@devdays
Created February 24, 2015 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save devdays/0a5e4df6a6a46ea3c97b to your computer and use it in GitHub Desktop.
Save devdays/0a5e4df6a6a46ea3c97b to your computer and use it in GitHub Desktop.
Calling a Trigger
<script>
var theClicker = $("#myClicker").clicker({
isUpdated: function (event, data) {
console.log("isOneHundredOne");
alert("Is " + data.myValue);
}
});
theClicker.clicker({ newValue: 101 });
</script>
setting [newValue]: 101
update:101
calling isUpdated
isOneHundredOne
isUpdated has been called
(function ($) {
$.widget("custom.clicker", {
// Default options.
options: {
newValue: 0
},
_create: function () {
this.element.text("The starting value is " + this.options.newValue);
},
_setOption: function (key, value) {
console.log("setting [" + key + "]: " + value);
this.options[key] = value;
this._update();
},
_update: function () {
console.log("update:" + this.options.newValue);
this.element.text("The updated value is " + this.options.newValue);
if (this.options.newValue == 101) {
console.log("calling isUpdated");
this._trigger("isUpdated", null, { myValue: this.options.newValue });
console.log("isUpdated has been called");
}
}
});
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment