Skip to content

Commit 7cd3d0a

Browse files
committed
Widget demo: Coding standards, fixed some broken code, added more comments.
1 parent 0e9f87f commit 7cd3d0a

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

demos/widget/default.html

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<script src="../../ui/jquery.ui.position.js"></script>
1111
<link rel="stylesheet" href="../demos.css">
1212
<style>
13-
.colorize {
13+
.custom-colorize {
1414
font-size: 25px;
1515
width: 75px;
1616
height: 75px;
@@ -28,20 +28,21 @@
2828
blue: 0,
2929

3030
// callbacks
31+
change: null,
3132
random: null
3233
},
3334

3435
// the constructor
3536
_create: function() {
3637
this.element
37-
// add a class for themeing
38-
.addClass("colorize")
38+
// add a class for theming
39+
.addClass( "custom-colorize" )
3940
// prevent double click to select text
4041
.disableSelection();
4142

4243
// bind click events to random method
4344
this._bind({
44-
// _bind won"t call random when widget is disabled
45+
// _bind won't call random when widget is disabled
4546
click: "random"
4647
});
4748
this._refresh();
@@ -68,7 +69,7 @@
6869
blue: Math.floor( Math.random() * 256 )
6970
};
7071

71-
// trigger an event, check if it"s canceled
72+
// trigger an event, check if it's canceled
7273
if ( this._trigger( "random", event, colors ) !== false ) {
7374
this.option( colors );
7475
}
@@ -78,24 +79,26 @@
7879
// revert other modifications here
7980
_destroy: function() {
8081
this.element
81-
.removeClass( "colorize" )
82+
.removeClass( "custom-colorize" )
8283
.enableSelection()
8384
.css( "background-color", "transparent" );
8485
},
8586

86-
_setOption: function( key, value ) {
87-
// prevent invalid color values
88-
if ( /red|green|blue/.test(key) && value < 0 || value > 255 ) {
89-
return;
90-
}
91-
this._super( "_setOptions", options );
92-
},
93-
87+
// _setOptions is called with a hash of all options that are changing
9488
// always refresh when changing options
9589
_setOptions: function() {
96-
// _super handles keeping the right this-context
90+
// _super and _superApply handle keeping the right this-context
9791
this._superApply( "_setOptions", arguments );
9892
this._refresh();
93+
},
94+
95+
// _setOption is called for each individual option that is changing
96+
_setOption: function( key, value ) {
97+
// prevent invalid color values
98+
if ( /red|green|blue/.test(key) && (value < 0 || value > 255) ) {
99+
return;
100+
}
101+
this._super( "_setOption", key, value );
99102
}
100103
});
101104

@@ -131,7 +134,7 @@
131134
red: 0,
132135
green: 0,
133136
blue: 0
134-
} );
137+
});
135138
});
136139
});
137140
</script>

0 commit comments

Comments
 (0)