Skip to content

Commit 51ee3be

Browse files
committed
Widget demo: Add a button to change the color of the widget.
1 parent e2a9b0c commit 51ee3be

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

demos/widget/default.html

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,23 @@
66
<link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
77
<script src="../../jquery-1.5.1.js"></script>
88
<script src="../../ui/jquery.ui.core.js"></script>
9-
<script src="../../ui/jquery.ui.widget.js"></script>
109
<script src="../../ui/jquery.ui.position.js"></script>
10+
<script src="../../ui/jquery.ui.widget.js"></script>
11+
<script src="../../ui/jquery.ui.button.js"></script>
1112
<link rel="stylesheet" href="../demos.css">
1213
<style>
1314
.custom-colorize {
14-
font-size: 25px;
15+
font-size: 20px;
16+
position: relative;
1517
width: 75px;
1618
height: 75px;
1719
}
20+
.custom-colorize-changer {
21+
font-size: 10px;
22+
position: absolute;
23+
right: 0;
24+
bottom: 0;
25+
}
1826
</style>
1927
<script>
2028
$(function() {
@@ -40,8 +48,15 @@
4048
// prevent double click to select text
4149
.disableSelection();
4250

43-
// bind click events to random method
44-
this._bind({
51+
this.changer = $( "<button>", {
52+
text: "change",
53+
className: "custom-colorize-changer"
54+
})
55+
.appendTo( this.element )
56+
.button();
57+
58+
// bind click events on the changer button to the random method
59+
this._bind( this.changer, {
4560
// _bind won't call random when widget is disabled
4661
click: "random"
4762
});
@@ -78,6 +93,9 @@
7893
// events bound via _bind are removed automatically
7994
// revert other modifications here
8095
_destroy: function() {
96+
// remove generated elements
97+
this.changer.remove();
98+
8199
this.element
82100
.removeClass( "custom-colorize" )
83101
.enableSelection()

0 commit comments

Comments
 (0)