Skip to content

Commit aaf11d2

Browse files
committed
Panel: Added icons and disabled options
1 parent df534ee commit aaf11d2

File tree

2 files changed

+74
-7
lines changed

2 files changed

+74
-7
lines changed

tests/visual/panel/panel.html

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,25 @@
1111
<script type="text/javascript" src="../../../ui/jquery.ui.panel.js"></script>
1212
<script type="text/javascript">
1313
$(function() {
14-
$("#panel1").panel();
14+
var panel = $("#panel1").panel();
15+
16+
$("#icons").toggle(function() {
17+
panel.panel("option", "icons", false);
18+
}, function() {
19+
panel.panel("option", "icons", $.ui.panel.prototype.options.icons);
20+
});
21+
22+
$("#disable").toggle(function() {
23+
panel.panel("disable");
24+
}, function() {
25+
panel.panel("enable");
26+
});
27+
28+
$("#destroy").toggle(function() {
29+
panel.panel("destroy");
30+
}, function() {
31+
panel.panel();
32+
});
1533
})
1634
</script>
1735
</head>
@@ -32,5 +50,9 @@ <h3><a href="#">Panel Header 3</a></h3>
3250
</div>
3351
</div>
3452

53+
<button id="icons">Icons</button>
54+
<button id="disable">Disable</button>
55+
<button id="destroy">Destroy</button>
56+
3557
</body>
3658
</html>

ui/jquery.ui.panel.js

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,72 @@
1414
(function($) {
1515

1616
$.widget("ui.panel", {
17+
18+
options: {
19+
icons: {
20+
header: "ui-icon-triangle-1-e",
21+
headerSelected: "ui-icon-triangle-1-s"
22+
}
23+
},
24+
1725
_create: function() {
1826
this.element.addClass("ui-panel ui-widget ui-helper-reset");
1927

2028
var self = this;
2129
this.headers = this.element.find("> li > :first-child,> :not(li):even").addClass("ui-panel-header ui-helper-reset ui-state-default ui-corner-all")
22-
.bind("mouseenter.panel", function() { $(this).addClass('ui-state-hover'); })
30+
.bind("mouseenter.panel", function() {
31+
if (self.options.disabled) {
32+
return;
33+
}
34+
$(this).addClass('ui-state-hover');
35+
})
2336
.bind("mouseleave.panel", function() { $(this).removeClass('ui-state-hover'); })
2437
.bind("focus.panel", function() { $(this).addClass('ui-state-focus'); })
2538
.bind("blur.panel", function() { $(this).removeClass('ui-state-focus'); })
26-
.bind("click.panel", function(e) { self.click($(this), e); return false; });
39+
.bind("click.panel", function(e) {
40+
if (self.options.disabled) {
41+
return;
42+
}
43+
self.click($(this));
44+
return false;
45+
});
46+
this._createIcons();
2747

2848
this.headers
2949
.next()
3050
.addClass("ui-panel-content ui-helper-reset ui-widget-content ui-corner-bottom")
3151
.hide();
3252
},
33-
destroy: function() {
34-
$.widget.prototype.destroy.call(this);
53+
54+
_setOption: function(key, value) {
55+
$.Widget.prototype._setOption.apply(this, arguments);
56+
57+
if (key == "icons") {
58+
this._destroyIcons();
59+
if (value) {
60+
this._createIcons();
61+
}
62+
}
63+
64+
},
65+
66+
_createIcons: function() {
67+
var o = this.options;
68+
if (o.icons) {
69+
$("<span/>").addClass("ui-icon " + o.icons.header).prependTo(this.headers);
70+
this.headers.filter(".ui-state-active").find(".ui-icon").removeClass(o.icons.header).addClass(o.icons.headerSelected);
71+
this.element.addClass("ui-panel-icons");
72+
}
73+
},
74+
75+
_destroyIcons: function() {
76+
this.headers.children(".ui-icon").remove();
77+
this.element.removeClass("ui-panel-icons");
3578
},
36-
click: function(header, event) {
37-
header.toggleClass("ui-state-active ui-corner-top ui-corner-all");
79+
80+
click: function(header) {
81+
header.toggleClass("ui-state-active ui-corner-top ui-corner-all")
82+
.find(".ui-icon").toggleClass(this.options.icons.headerSelected).toggleClass(this.options.icons.header);
3883
header.next().toggleClass("ui-panel-content-active").slideToggle("fast");
3984
}
4085
});

0 commit comments

Comments
 (0)