|
14 | 14 | (function($) {
|
15 | 15 |
|
16 | 16 | $.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 | + |
17 | 25 | _create: function() {
|
18 | 26 | this.element.addClass("ui-panel ui-widget ui-helper-reset");
|
19 | 27 |
|
20 | 28 | var self = this;
|
21 | 29 | 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 | + }) |
23 | 36 | .bind("mouseleave.panel", function() { $(this).removeClass('ui-state-hover'); })
|
24 | 37 | .bind("focus.panel", function() { $(this).addClass('ui-state-focus'); })
|
25 | 38 | .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(); |
27 | 47 |
|
28 | 48 | this.headers
|
29 | 49 | .next()
|
30 | 50 | .addClass("ui-panel-content ui-helper-reset ui-widget-content ui-corner-bottom")
|
31 | 51 | .hide();
|
32 | 52 | },
|
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"); |
35 | 78 | },
|
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); |
38 | 83 | header.next().toggleClass("ui-panel-content-active").slideToggle("fast");
|
39 | 84 | }
|
40 | 85 | });
|
|
0 commit comments