Created
February 24, 2015 00:18
-
-
Save devdays/0a5e4df6a6a46ea3c97b to your computer and use it in GitHub Desktop.
Calling a Trigger
This file contains 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
<script> | |
var theClicker = $("#myClicker").clicker({ | |
isUpdated: function (event, data) { | |
console.log("isOneHundredOne"); | |
alert("Is " + data.myValue); | |
} | |
}); | |
theClicker.clicker({ newValue: 101 }); | |
</script> |
This file contains 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
setting [newValue]: 101 | |
update:101 | |
calling isUpdated | |
isOneHundredOne | |
isUpdated has been called |
This file contains 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("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