aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2009-04-15 02:33:28 +0000
committerScott González <scott.gonzalez@gmail.com>2009-04-15 02:33:28 +0000
commit1195854aaad61308e7f5339eed54f92284d7666e (patch)
tree5991992a73f910d897967559332a15bd774816d8 /ui
parent3c7b61299333d1ec3f4d4d773b1ec4296129a98e (diff)
downloadjquery-ui-1195854aaad61308e7f5339eed54f92284d7666e.tar.gz
jquery-ui-1195854aaad61308e7f5339eed54f92284d7666e.zip
Merged in widget-factory branch and added tests. Fixes #4411 - Widget factory should auto detect getters.
Diffstat (limited to 'ui')
-rw-r--r--ui/ui.accordion.js5
-rw-r--r--ui/ui.core.js62
-rw-r--r--ui/ui.dialog.js14
-rw-r--r--ui/ui.draggable.js2
-rw-r--r--ui/ui.droppable.js2
-rw-r--r--ui/ui.progressbar.js1
-rw-r--r--ui/ui.resizable.js1
-rw-r--r--ui/ui.selectable.js2
-rw-r--r--ui/ui.slider.js2
-rw-r--r--ui/ui.sortable.js7
-rw-r--r--ui/ui.tabs.js16
11 files changed, 67 insertions, 47 deletions
diff --git a/ui/ui.accordion.js b/ui/ui.accordion.js
index 0a625e5d3..c7e55f5c8 100644
--- a/ui/ui.accordion.js
+++ b/ui/ui.accordion.js
@@ -125,6 +125,8 @@ $.widget("ui.accordion", {
if (o.autoHeight || o.fillHeight) {
contents.css("height", "");
}
+
+ return this;
},
_setData: function(key, value) {
@@ -195,12 +197,15 @@ $.widget("ui.accordion", {
}).height(maxHeight);
}
+ return this;
},
activate: function(index) {
// call clickHandler with custom event
var active = this._findActive(index)[0];
this._clickHandler({ target: active }, active);
+
+ return this;
},
_findActive: function(selector) {
diff --git a/ui/ui.core.js b/ui/ui.core.js
index d95ec747b..27b12681d 100644
--- a/ui/ui.core.js
+++ b/ui/ui.core.js
@@ -203,19 +203,6 @@ $.extend($.expr[':'], {
// $.widget is a factory to create jQuery plugins
// taking some boilerplate code out of the plugin code
-function getter(namespace, plugin, method, args) {
- function getMethods(type) {
- var methods = $[namespace][plugin][type] || [];
- return (typeof methods == 'string' ? methods.split(/,?\s+/) : methods);
- }
-
- var methods = getMethods('getter');
- if (args.length == 1 && typeof args[0] == 'string') {
- methods = methods.concat(getMethods('getterSetter'));
- }
- return ($.inArray(method, methods) != -1);
-}
-
$.widget = function(name, prototype) {
var namespace = name.split(".")[0],
fullName;
@@ -230,32 +217,31 @@ $.widget = function(name, prototype) {
// create plugin method
$.fn[name] = function(options) {
var isMethodCall = (typeof options == 'string'),
- args = Array.prototype.slice.call(arguments, 1);
+ args = Array.prototype.slice.call(arguments, 1),
+ returnValue = this;
// prevent calls to internal methods
if (isMethodCall && options.substring(0, 1) == '_') {
- return this;
- }
-
- // handle getter methods
- if (isMethodCall && getter(namespace, name, options, args)) {
- var instance = $.data(this[0], name);
- return (instance ? instance[options].apply(instance, args)
- : undefined);
+ return returnValue;
}
- // handle initialization and non-getter methods
- return this.each(function() {
- var instance = $.data(this, name);
-
- // constructor
- (!instance && !isMethodCall &&
- $.data(this, name, new $[namespace][name](this, options))._init());
+ (isMethodCall
+ ? this.each(function() {
+ var instance = $.data(this, name),
+ methodValue = (instance && $.isFunction(instance[options])
+ ? instance[options].apply(instance, args)
+ : instance);
+ if (methodValue !== instance) {
+ returnValue = methodValue;
+ return false;
+ }
+ })
+ : this.each(function() {
+ ($.data(this, name) ||
+ $.data(this, name, new $[namespace][name](this, options))._init());
+ }));
- // method call
- (instance && isMethodCall && $.isFunction(instance[options]) &&
- instance[options].apply(instance, args));
- });
+ return returnValue;
};
// create widget constructor
@@ -292,10 +278,6 @@ $.widget = function(name, prototype) {
// add widget prototype
$[namespace][name].prototype = $.extend({}, $.widget.prototype, prototype);
-
- // TODO: merge getter and getterSetter properties from widget prototype
- // and plugin prototype
- $[namespace][name].getterSetter = 'option';
};
$.widget.prototype = {
@@ -304,6 +286,8 @@ $.widget.prototype = {
this.element.removeData(this.widgetName)
.removeClass(this.widgetBaseClass + '-disabled' + ' ' + this.namespace + '-state-disabled')
.removeAttr('aria-disabled');
+
+ return this;
},
option: function(key, value) {
@@ -321,6 +305,8 @@ $.widget.prototype = {
$.each(options, function(key, value) {
self._setData(key, value);
});
+
+ return self;
},
_getData: function(key) {
return this.options[key];
@@ -339,9 +325,11 @@ $.widget.prototype = {
enable: function() {
this._setData('disabled', false);
+ return this;
},
disable: function() {
this._setData('disabled', true);
+ return this;
},
_trigger: function(type, event, data) {
diff --git a/ui/ui.dialog.js b/ui/ui.dialog.js
index d8b348c9b..18bdfa6bb 100644
--- a/ui/ui.dialog.js
+++ b/ui/ui.dialog.js
@@ -137,7 +137,6 @@ $.widget("ui.dialog", {
(options.bgiframe && $.fn.bgiframe && uiDialog.bgiframe());
(options.autoOpen && this.open());
-
},
destroy: function() {
@@ -151,6 +150,8 @@ $.widget("ui.dialog", {
this.uiDialog.remove();
(this.originalTitle && this.element.attr('title', this.originalTitle));
+
+ return this;
},
close: function(event) {
@@ -172,7 +173,7 @@ $.widget("ui.dialog", {
$.ui.dialog.overlay.resize();
self._isOpen = false;
-
+
// adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
if (self.options.modal) {
var maxZ = 0;
@@ -183,6 +184,8 @@ $.widget("ui.dialog", {
});
$.ui.dialog.maxZ = maxZ;
}
+
+ return self;
},
isOpen: function() {
@@ -192,7 +195,6 @@ $.widget("ui.dialog", {
// the force parameter allows us to move modal dialogs to their correct
// position on open
moveToTop: function(force, event) {
-
if ((this.options.modal && !force)
|| (!this.options.stack && !this.options.modal)) {
return this._trigger('focus', event);
@@ -209,6 +211,8 @@ $.widget("ui.dialog", {
this.uiDialog.css('z-index', ++$.ui.dialog.maxZ);
this.element.attr(saveScroll);
this._trigger('focus', event);
+
+ return this;
},
open: function() {
@@ -256,6 +260,8 @@ $.widget("ui.dialog", {
this._trigger('open');
this._isOpen = true;
+
+ return this;
},
_createButtons: function(buttons) {
@@ -519,8 +525,6 @@ $.extend($.ui.dialog, {
zIndex: 1000
},
- getter: 'isOpen',
-
uuid: 0,
maxZ: 0,
diff --git a/ui/ui.draggable.js b/ui/ui.draggable.js
index c408ae8b0..4a11d3a61 100644
--- a/ui/ui.draggable.js
+++ b/ui/ui.draggable.js
@@ -35,6 +35,8 @@ $.widget("ui.draggable", $.extend({}, $.ui.mouse, {
+ " ui-draggable-dragging"
+ " ui-draggable-disabled");
this._mouseDestroy();
+
+ return this;
},
_mouseCapture: function(event) {
diff --git a/ui/ui.droppable.js b/ui/ui.droppable.js
index e4c187c26..ee9172780 100644
--- a/ui/ui.droppable.js
+++ b/ui/ui.droppable.js
@@ -45,6 +45,8 @@ $.widget("ui.droppable", {
.removeClass("ui-droppable ui-droppable-disabled")
.removeData("droppable")
.unbind(".droppable");
+
+ return this;
},
_setData: function(key, value) {
diff --git a/ui/ui.progressbar.js b/ui/ui.progressbar.js
index e72b31e5d..6988f8dff 100644
--- a/ui/ui.progressbar.js
+++ b/ui/ui.progressbar.js
@@ -52,6 +52,7 @@ $.widget("ui.progressbar", {
$.widget.prototype.destroy.apply(this, arguments);
+ return this;
},
value: function(newValue) {
diff --git a/ui/ui.resizable.js b/ui/ui.resizable.js
index fef9e4b36..6e5691aea 100644
--- a/ui/ui.resizable.js
+++ b/ui/ui.resizable.js
@@ -199,6 +199,7 @@ $.widget("ui.resizable", $.extend({}, $.ui.mouse, {
this.originalElement.css('resize', this.originalResizeStyle);
_destroy(this.originalElement);
+ return this;
},
_mouseCapture: function(event) {
diff --git a/ui/ui.selectable.js b/ui/ui.selectable.js
index 49cdd805f..93d0c8ca8 100644
--- a/ui/ui.selectable.js
+++ b/ui/ui.selectable.js
@@ -59,6 +59,8 @@ $.widget("ui.selectable", $.extend({}, $.ui.mouse, {
.removeData("selectable")
.unbind(".selectable");
this._mouseDestroy();
+
+ return this;
},
_mouseStart: function(event) {
diff --git a/ui/ui.slider.js b/ui/ui.slider.js
index 2eee4f2d8..2f5ac1e7b 100644
--- a/ui/ui.slider.js
+++ b/ui/ui.slider.js
@@ -192,6 +192,7 @@ $.widget("ui.slider", $.extend({}, $.ui.mouse, {
this._mouseDestroy();
+ return this;
},
_mouseCapture: function(event) {
@@ -536,7 +537,6 @@ $.widget("ui.slider", $.extend({}, $.ui.mouse, {
}));
$.extend($.ui.slider, {
- getter: "value values",
version: "@VERSION",
eventPrefix: "slide",
defaults: {
diff --git a/ui/ui.sortable.js b/ui/ui.sortable.js
index 01f41cd33..76cce9aa6 100644
--- a/ui/ui.sortable.js
+++ b/ui/ui.sortable.js
@@ -42,6 +42,8 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
for ( var i = this.items.length - 1; i >= 0; i-- )
this.items[i].item.removeData("sortable-item");
+
+ return this;
},
_mouseCapture: function(event, overrideHandle) {
@@ -354,7 +356,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
$(this.domPosition.parent).prepend(this.currentItem);
}
- return true;
+ return this;
},
@@ -460,6 +462,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
refresh: function(event) {
this._refreshItems(event);
this.refreshPositions();
+ return this;
},
_connectWith: function() {
@@ -595,6 +598,7 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
};
}
+ return this;
},
_createPlaceholder: function(that) {
@@ -984,7 +988,6 @@ $.widget("ui.sortable", $.extend({}, $.ui.mouse, {
}));
$.extend($.ui.sortable, {
- getter: "serialize toArray",
version: "@VERSION",
eventPrefix: "sort",
defaults: {
diff --git a/ui/ui.tabs.js b/ui/ui.tabs.js
index 1a52ce3ee..c09ce038d 100644
--- a/ui/ui.tabs.js
+++ b/ui/ui.tabs.js
@@ -434,6 +434,8 @@ $.widget("ui.tabs", {
if (o.cookie) {
this._cookie(null, o.cookie);
}
+
+ return this;
},
add: function(url, label, index) {
@@ -480,6 +482,7 @@ $.widget("ui.tabs", {
// callback
this._trigger('add', null, this._ui(this.anchors[index], this.panels[index]));
+ return this;
},
remove: function(index) {
@@ -499,6 +502,7 @@ $.widget("ui.tabs", {
// callback
this._trigger('remove', null, this._ui($li.find('a')[0], $panel[0]));
+ return this;
},
enable: function(index) {
@@ -512,6 +516,7 @@ $.widget("ui.tabs", {
// callback
this._trigger('enable', null, this._ui(this.anchors[index], this.panels[index]));
+ return this;
},
disable: function(index) {
@@ -525,6 +530,8 @@ $.widget("ui.tabs", {
// callback
this._trigger('disable', null, this._ui(this.anchors[index], this.panels[index]));
}
+
+ return this;
},
select: function(index) {
@@ -539,6 +546,7 @@ $.widget("ui.tabs", {
}
this.anchors.eq(index).trigger(this.options.event + '.tabs');
+ return this;
},
load: function(index) {
@@ -583,6 +591,8 @@ $.widget("ui.tabs", {
self.element.dequeue("tabs");
}
}));
+
+ return this;
},
abort: function() {
@@ -598,11 +608,12 @@ $.widget("ui.tabs", {
// take care of tab labels
this._cleanup();
-
+ return this;
},
url: function(index, url) {
this.anchors.eq(index).removeData('cache.tabs').data('load.tabs', url);
+ return this;
},
length: function() {
@@ -613,7 +624,6 @@ $.widget("ui.tabs", {
$.extend($.ui.tabs, {
version: '@VERSION',
- getter: 'length',
defaults: {
ajaxOptions: null,
cache: false,
@@ -679,6 +689,8 @@ $.extend($.ui.tabs.prototype, {
delete this._rotate;
delete this._unrotate;
}
+
+ return this;
}
});