|
10 | 10 | <script src="../../ui/jquery.ui.position.js"></script>
|
11 | 11 | <link rel="stylesheet" href="../demos.css">
|
12 | 12 | <style>
|
13 |
| - .colorize { |
| 13 | + .custom-colorize { |
14 | 14 | font-size: 25px;
|
15 | 15 | width: 75px;
|
16 | 16 | height: 75px;
|
|
28 | 28 | blue: 0,
|
29 | 29 |
|
30 | 30 | // callbacks
|
| 31 | + change: null, |
31 | 32 | random: null
|
32 | 33 | },
|
33 | 34 |
|
34 | 35 | // the constructor
|
35 | 36 | _create: function() {
|
36 | 37 | this.element
|
37 |
| - // add a class for themeing |
38 |
| - .addClass("colorize") |
| 38 | + // add a class for theming |
| 39 | + .addClass( "custom-colorize" ) |
39 | 40 | // prevent double click to select text
|
40 | 41 | .disableSelection();
|
41 | 42 |
|
42 | 43 | // bind click events to random method
|
43 | 44 | this._bind({
|
44 |
| - // _bind won"t call random when widget is disabled |
| 45 | + // _bind won't call random when widget is disabled |
45 | 46 | click: "random"
|
46 | 47 | });
|
47 | 48 | this._refresh();
|
|
68 | 69 | blue: Math.floor( Math.random() * 256 )
|
69 | 70 | };
|
70 | 71 |
|
71 |
| - // trigger an event, check if it"s canceled |
| 72 | + // trigger an event, check if it's canceled |
72 | 73 | if ( this._trigger( "random", event, colors ) !== false ) {
|
73 | 74 | this.option( colors );
|
74 | 75 | }
|
|
78 | 79 | // revert other modifications here
|
79 | 80 | _destroy: function() {
|
80 | 81 | this.element
|
81 |
| - .removeClass( "colorize" ) |
| 82 | + .removeClass( "custom-colorize" ) |
82 | 83 | .enableSelection()
|
83 | 84 | .css( "background-color", "transparent" );
|
84 | 85 | },
|
85 | 86 |
|
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 |
94 | 88 | // always refresh when changing options
|
95 | 89 | _setOptions: function() {
|
96 |
| - // _super handles keeping the right this-context |
| 90 | + // _super and _superApply handle keeping the right this-context |
97 | 91 | this._superApply( "_setOptions", arguments );
|
98 | 92 | 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 ); |
99 | 102 | }
|
100 | 103 | });
|
101 | 104 |
|
|
131 | 134 | red: 0,
|
132 | 135 | green: 0,
|
133 | 136 | blue: 0
|
134 |
| - } ); |
| 137 | + }); |
135 | 138 | });
|
136 | 139 | });
|
137 | 140 | </script>
|
|
0 commit comments