r3365 committed - introducing widget-method as discussed on ui-dev: wrote tests for core...
Revision: 3365
Author: joern.zaefferer
Date: Thu Oct 15 03:05:53 2009
Log: introducing widget-method as discussed on ui-dev: wrote tests for
core, datepicker and dialog, implemented in button, core, datepicker,
dialog and tooltip, no tests yet at all for button and tooltip; button
implementation is somewhat dubious, as it can return multiple elements
http://code.google.com/p/jquery-ui/source/detail?r=3365
Modified:
/branches/dev/tests/unit/core/core.js
/branches/dev/tests/unit/datepicker/datepicker_core.js
/branches/dev/tests/unit/dialog/dialog_core.js
/branches/dev/ui/jquery.ui.button.js
/branches/dev/ui/jquery.ui.core.js
/branches/dev/ui/jquery.ui.datepicker.js
/branches/dev/ui/jquery.ui.dialog.js
/branches/dev/ui/jquery.ui.tooltip.js
=======================================
--- /branches/dev/tests/unit/core/core.js Tue Sep 22 00:54:11 2009
+++ /branches/dev/tests/unit/core/core.js Thu Oct 15 03:05:53 2009
@@ -93,4 +93,23 @@
});
});
+test("widget factory, base widget method", function() {
+ $.widget("test.testwidget", {
+ _init: function() {}
+ });
+ var div = $("<div/>").testwidget()
+ same(div[0], div.testwidget("widget")[0]);
+});
+
+test("widget factory, overriden widget method", function() {
+ var wrapper = $("<div/>");
+ $.widget("test.testwidget2", {
+ _init: function() {},
+ widget: function() {
+ return wrapper;
+ }
+ });
+ same(wrapper[0], $("<div/>").testwidget2().testwidget2("widget")[0]);
+});
+
})(jQuery);
=======================================
--- /branches/dev/tests/unit/datepicker/datepicker_core.js Tue Sep 22
00:54:11 2009
+++ /branches/dev/tests/unit/datepicker/datepicker_core.js Thu Oct 15
03:05:53 2009
@@ -47,6 +47,11 @@
}
});
+test("widget method", function() {
+ var actual = $("#inp").datepicker().datepicker("widget")[0];
+ same($("body > #ui-datepicker-div:last-child")[0], actual);
+});
+
test('baseStructure', function() {
var inp = init('#inp');
inp.focus();
=======================================
--- /branches/dev/tests/unit/dialog/dialog_core.js Tue Sep 22 00:54:11 2009
+++ /branches/dev/tests/unit/dialog/dialog_core.js Thu Oct 15 03:05:53 2009
@@ -147,4 +147,9 @@
el.remove();
});
+test("widget method", function() {
+ var dialog = $("<div/>").appendTo("#main").dialog();
+ same(dialog.parent()[0], dialog.dialog("widget")[0]);
+});
+
})(jQuery);
=======================================
--- /branches/dev/ui/jquery.ui.button.js Thu Oct 1 18:04:49 2009
+++ /branches/dev/ui/jquery.ui.button.js Thu Oct 15 03:05:53 2009
@@ -141,6 +141,10 @@
this.element.add(this.label).show();
this.button.remove();
$.widget.prototype.destroy.call(this);
+ },
+
+ widget: function() {
+ return this.button;
}
});
@@ -185,6 +189,11 @@
this.buttons.remove();
this.labels.add(this.radios).show();
$.widget.prototype.destroy.call(this);
+ },
+
+ widget: function() {
+ // TODO technically correct, but inconsistent
+ return this.radios.next();
}
});
@@ -218,6 +227,11 @@
}
this.buttons.button("destroy").removeClass("ui-corner-left
ui-corner-right");
$.widget.prototype.destroy.call(this);
+ },
+
+ widget: function() {
+ // TODO technically correct, but inconsistent
+ return this.buttons;
}
});
=======================================
--- /branches/dev/ui/jquery.ui.core.js Thu Sep 17 03:39:12 2009
+++ /branches/dev/ui/jquery.ui.core.js Thu Oct 15 03:05:53 2009
@@ -327,6 +327,11 @@
return this;
},
+
+ // override when the widget element is a wrapper or similar
+ widget: function() {
+ return this.element;
+ },
option: function(key, value) {
var options = key,
=======================================
--- /branches/dev/ui/jquery.ui.datepicker.js Thu Sep 17 03:39:12 2009
+++ /branches/dev/ui/jquery.ui.datepicker.js Thu Oct 15 03:05:53 2009
@@ -118,6 +118,11 @@
if (this.debug)
console.log.apply('', arguments);
},
+
+ // TODO rename to "widget" when switching to widget factory
+ _widgetDatepicker: function() {
+ return this.dpDiv;
+ },
/* Override the default settings for all instances of the date picker.
@param settings object - the new settings to use as defaults
(anonymous object)
@@ -1658,7 +1663,7 @@
}
var otherArgs = Array.prototype.slice.call(arguments, 1);
- if (typeof options == 'string' && (options == 'isDisabled' || options
== 'getDate'))
+ if (typeof options == 'string' && (options == 'isDisabled' || options
== 'getDate' || options == 'widget'))
return $.datepicker['_' + options + 'Datepicker'].
apply($.datepicker, [this[0]].concat(otherArgs));
if (options == 'option' && arguments.length == 2 && typeof arguments[1]
== 'string')
=======================================
--- /branches/dev/ui/jquery.ui.dialog.js Wed Sep 30 06:59:05 2009
+++ /branches/dev/ui/jquery.ui.dialog.js Thu Oct 15 03:05:53 2009
@@ -147,6 +147,10 @@
return self;
},
+
+ widget: function() {
+ return this.uiDialog;
+ },
close: function(event) {
var self = this;
=======================================
--- /branches/dev/ui/jquery.ui.tooltip.js Sat Sep 26 04:12:14 2009
+++ /branches/dev/ui/jquery.ui.tooltip.js Thu Oct 15 03:05:53 2009
@@ -35,6 +35,10 @@
$.widget.prototype.destroy.apply(this, arguments);
},
+ widget: function() {
+ return this.tooltip;
+ },
+
show: function(target) {
if (this.options.disabled)
return;