Skip to content

Instantly share code, notes, and snippets.

View devdays's full-sized avatar

Bruce D Kyle devdays

View GitHub Profile
@devdays
devdays / click-handler.js
Created February 24, 2015 22:52
Handling clicks in jQuery UI Widget
_create: function () {
...
this._on(this.elTitle, {
click: "_titleClick" // Note: function name must be passed as a string!
});
},
_titleClick: function (event) {
console.log(this); // 'this' is now the widget instance.
},
@devdays
devdays / destroyTheWidget.js
Created February 24, 2015 00:22
Destroy the Widget
(function ($) {
$.widget("custom.clicker", {
// the rest of the clicker is omitted
destroy: function () {
this.element.text("");
// Call the base destroy function.
$.Widget.prototype.destroy.call(this);
@devdays
devdays / CallingTheTrigger.html
Created February 24, 2015 00:18
Calling a Trigger
<script>
var theClicker = $("#myClicker").clicker({
isUpdated: function (event, data) {
console.log("isOneHundredOne");
alert("Is " + data.myValue);
}
});
theClicker.clicker({ newValue: 101 });
</script>
@devdays
devdays / callingWidgetWithSetOptions
Created February 23, 2015 23:10
Setting options
myClicker.clicker( { currentValue: 100 } );
newCurrentValue = myClicker.clicker("currentValue");
alert(newCurrentValue);
@devdays
devdays / addMethod.js
Created February 23, 2015 21:16
Calling the Add Method
(function ($) {
$.widget("custom.clicker", {
// Default options.
options: {
startingValue: 0,
_currentValue : 0
},
// _create and other methods to access properties ommitted ..
@devdays
devdays / callingGettersAndSetters.html
Created February 23, 2015 21:10
Getting the startingValue, getting or setting the currentValue in a jQuery UI Widget
<script>
// initializing the startingValue
var myClicker = $("#myClicker").clicker({ startingValue: 4 });
// getting the startingValue
alert(myClicker.clicker("startingValue"));
// setting the currentValue
myClicker.clicker("currentValue", 7);
// getting the currentValue
@devdays
devdays / jquerywidget-clicker-0.0.1.js
Created February 23, 2015 19:35
jQuery widget create with default options values
(function ($) {
$.widget("custom.clicker", {
// Default options.
options: {
startingValue: 0
},
_create: function () {
var startingValue = this.options.startingValue;
@devdays
devdays / jquerywidget-clicker-0.0.1.js
Created February 23, 2015 19:32
jQuery Widget _create
(function ($) {
$.widget("custom.clicker", {
_create: function () {
var startingValue = this.options.startingValue;
this.element.text("The starting value is " + startingValue);
}
});
}(jQuery));
@devdays
devdays / passingOptionValues.js
Created February 23, 2015 19:29
Passing option values to the widget
$("#myClicker").clicker( {
startingValue: 4
});
@devdays
devdays / clickewidget.html
Last active August 29, 2015 14:15
Page to host clicker widget
<!DOCTYPE html>
<html>
<head>
<title>Clicker</title>
</head>
<body>
<div id="myClicker">
</div>
<script src="Scripts/jquery-2.1.3.js"></script>