diff options
author | Scott González <scott.gonzalez@gmail.com> | 2008-06-04 19:51:59 +0000 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2008-06-04 19:51:59 +0000 |
commit | 98f42fc80258bd8c9dc4299472889881e4be73fa (patch) | |
tree | a41ace777c18c8786a64a3f9a8085cbdd2b2ca97 /ui | |
parent | f17737b2d4b2fdd8bf474ac62a62176a9bd496bf (diff) | |
download | jquery-ui-98f42fc80258bd8c9dc4299472889881e4be73fa.tar.gz jquery-ui-98f42fc80258bd8c9dc4299472889881e4be73fa.zip |
Core: Exposed the base widget prototype; Adding/removing disabled classes automatically.
Draggable, Droppable, Resizable, Selectable, Sortable: Removed unneeded enable/disable methods.
Dialog: Delegating standard functionality for setData to the widget prototype.
Diffstat (limited to 'ui')
-rw-r--r-- | ui/source/ui.core.js | 51 | ||||
-rw-r--r-- | ui/source/ui.dialog.js | 3 | ||||
-rw-r--r-- | ui/source/ui.draggable.js | 4 | ||||
-rw-r--r-- | ui/source/ui.droppable.js | 8 | ||||
-rw-r--r-- | ui/source/ui.resizable.js | 8 | ||||
-rw-r--r-- | ui/source/ui.selectable.js | 8 | ||||
-rw-r--r-- | ui/source/ui.sortable.js | 8 |
7 files changed, 31 insertions, 59 deletions
diff --git a/ui/source/ui.core.js b/ui/source/ui.core.js index 0ad95ce57..aa3c9f464 100644 --- a/ui/source/ui.core.js +++ b/ui/source/ui.core.js @@ -84,30 +84,10 @@ function getter(namespace, plugin, method) { return ($.inArray(method, methods) != -1); } -var widgetPrototype = { - init: function() {}, - destroy: function() { - this.element.removeData(this.widgetName); - }, - - getData: function(key) { - return this.options[key]; - }, - setData: function(key, value) { - this.options[key] = value; - }, - - enable: function() { - this.setData('disabled', false); - }, - disable: function() { - this.setData('disabled', true); - } -}; - $.widget = function(name, prototype) { var namespace = name.split(".")[0]; name = name.split(".")[1]; + // create plugin method $.fn[name] = function(options) { var isMethodCall = (typeof options == 'string'), @@ -134,6 +114,7 @@ $.widget = function(name, prototype) { var self = this; this.widgetName = name; + this.widgetBaseClass = namespace + '-' + name; this.options = $.extend({}, $[namespace][name].defaults, options); this.element = $(element) @@ -150,7 +131,33 @@ $.widget = function(name, prototype) { }; // add widget prototype - $[namespace][name].prototype = $.extend({}, widgetPrototype, prototype); + $[namespace][name].prototype = $.extend({}, $.widget.prototype, prototype); +}; + +$.widget.prototype = { + init: function() {}, + destroy: function() { + this.element.removeData(this.widgetName); + }, + + getData: function(key) { + return this.options[key]; + }, + setData: function(key, value) { + this.options[key] = value; + + if (key == 'disabled') { + this.element[value ? 'addClass' : 'removeClass']( + this.widgetBaseClass + '-disabled'); + } + }, + + enable: function() { + this.setData('disabled', false); + }, + disable: function() { + this.setData('disabled', true); + } }; diff --git a/ui/source/ui.dialog.js b/ui/source/ui.dialog.js index 4299910b3..be7df473a 100644 --- a/ui/source/ui.dialog.js +++ b/ui/source/ui.dialog.js @@ -171,7 +171,8 @@ $.widget("ui.dialog", { this.uiDialog.width(value); break; } - this.options[key] = value; + + $.widget.prototype.setData.apply(this, arguments); }, position: function(pos) { diff --git a/ui/source/ui.draggable.js b/ui/source/ui.draggable.js index 36f9d1ac3..6e9888d35 100644 --- a/ui/source/ui.draggable.js +++ b/ui/source/ui.draggable.js @@ -30,10 +30,6 @@ $.widget("ui.draggable", $.extend($.ui.mouse, { this.mouseInit(); }, - setData: function(key, value) { - (key == 'disabled' && this.element[(value ? 'add' : 'remove') + 'Class']('ui-draggable-disabled')); - this.options[key] = value; - }, mouseStart: function(e) { var o = this.options; diff --git a/ui/source/ui.droppable.js b/ui/source/ui.droppable.js index f2ef209da..6d98183d0 100644 --- a/ui/source/ui.droppable.js +++ b/ui/source/ui.droppable.js @@ -59,14 +59,6 @@ $.widget("ui.droppable", { .removeData("droppable") .unbind(".droppable"); }, - enable: function() { - this.element.removeClass("ui-droppable-disabled"); - this.options.disabled = false; - }, - disable: function() { - this.element.addClass("ui-droppable-disabled"); - this.options.disabled = true; - }, over: function(e) { var draggable = $.ui.ddmanager.current; diff --git a/ui/source/ui.resizable.js b/ui/source/ui.resizable.js index 0bb7cf4bb..7e9ed4de0 100644 --- a/ui/source/ui.resizable.js +++ b/ui/source/ui.resizable.js @@ -248,14 +248,6 @@ $.widget("ui.resizable", $.extend($.ui.mouse, { _destroy(wrapped); } }, - enable: function() { - this.element.removeClass("ui-resizable-disabled"); - this.options.disabled = false; - }, - disable: function() { - this.element.addClass("ui-resizable-disabled"); - this.options.disabled = true; - }, mouseStart: function(e) { if(this.options.disabled) return false; diff --git a/ui/source/ui.selectable.js b/ui/source/ui.selectable.js index 5e1683ca7..72ff9d1f2 100644 --- a/ui/source/ui.selectable.js +++ b/ui/source/ui.selectable.js @@ -65,14 +65,6 @@ $.widget("ui.selectable", $.extend($.ui.mouse, { .unbind(".selectable"); this.mouseDestroy(); }, - enable: function() { - this.element.removeClass("ui-selectable-disabled"); - this.options.disabled = false; - }, - disable: function() { - this.element.addClass("ui-selectable-disabled"); - this.options.disabled = true; - }, mouseStart: function(e) { var self = this; diff --git a/ui/source/ui.sortable.js b/ui/source/ui.sortable.js index f5867aec5..847a054bf 100644 --- a/ui/source/ui.sortable.js +++ b/ui/source/ui.sortable.js @@ -86,14 +86,6 @@ $.widget("ui.sortable", $.extend($.ui.mouse, { items.each(function() { ret.push($(this).attr(attr || 'id')); }); return ret; }, - enable: function() { - this.element.removeClass("ui-sortable-disabled"); - this.options.disabled = false; - }, - disable: function() { - this.element.addClass("ui-sortable-disabled"); - this.options.disabled = true; - }, /* Be careful with the following core functions */ intersectsWith: function(item) { |