mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
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.
This commit is contained in:
parent
f17737b2d4
commit
98f42fc802
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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) {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user