Skip to content
Permalink
Browse files

Widget factory: Changed _create to _init.

Partial fix for #5064 - Widget: make multiple instantiation more useful.
  • Loading branch information...
scottgonzalez committed Jan 15, 2010
1 parent ab153e0 commit 7d96a0d0966d9e680c968db2869900ac624a44ad
@@ -13,7 +13,7 @@
<script type="text/javascript">
(function($) {
$.widget("ui.combobox", {
_init: function() {
_create: function() {
var self = this;
var select = this.element.hide();
var input = $("<input>")
@@ -11,14 +11,14 @@ module('widget factory', {

test('widget creation', function() {
var myPrototype = {
_init: function() {},
_create: function() {},
creationTest: function() {}
};

$.widget('ui.testWidget', myPrototype);
ok($.isFunction($.ui.testWidget), 'constructor was created');
equals('object', typeof $.ui.testWidget.prototype, 'prototype was created');
equals($.ui.testWidget.prototype._init, myPrototype._init, 'init function is copied over');
equals($.ui.testWidget.prototype._create, myPrototype._create, 'create function is copied over');
equals($.ui.testWidget.prototype.creationTest, myPrototype.creationTest, 'random function is copied over');
equals($.ui.testWidget.prototype.option, $.Widget.prototype.option, 'option method copied over from base widget');
});
@@ -30,7 +30,7 @@ test('jQuery usage', function() {

$.widget('ui.testWidget', {
getterSetterVal: 5,
_init: function() {
_create: function() {
ok(shouldInit, 'init called on instantiation');
},
methodWithParams: function(param1, param2) {
@@ -73,7 +73,7 @@ test('direct usage', function() {

$.widget('ui.testWidget', {
getterSetterVal: 5,
_init: function() {
_create: function() {
ok(shouldInit, 'init called on instantiation');
},
methodWithParams: function(param1, param2) {
@@ -113,7 +113,7 @@ test('direct usage', function() {
test('merge multiple option arguments', function() {
expect(1);
$.widget("ui.testWidget", {
_init: function() {
_create: function() {
same(this.options, {
disabled: false,
option1: "value1",
@@ -148,7 +148,7 @@ test('merge multiple option arguments', function() {

test(".widget() - base", function() {
$.widget("ui.testWidget", {
_init: function() {}
_create: function() {}
});
var div = $("<div></div>").testWidget()
same(div[0], div.testWidget("widget")[0]);
@@ -157,7 +157,7 @@ test(".widget() - base", function() {
test(".widget() - overriden", function() {
var wrapper = $("<div></div>");
$.widget("ui.testWidget", {
_init: function() {},
_create: function() {},
widget: function() {
return wrapper;
}
@@ -32,7 +32,7 @@ $.widget("ui.accordion", {
return this.href.toLowerCase() == location.href.toLowerCase();
}
},
_init: function() {
_create: function() {

var o = this.options, self = this;
this.running = 0;
@@ -18,7 +18,7 @@ $.widget("ui.autocomplete", {
minLength: 1,
delay: 300
},
_init: function() {
_create: function() {
var self = this;
this.element
.addClass("ui-autocomplete ui-widget ui-widget-content ui-corner-all")
@@ -296,7 +296,7 @@ $.extend($.ui.autocomplete, {
(function($) {

$.widget("ui.menu", {
_init: function() {
_create: function() {
var self = this;
this.element
.addClass("ui-menu ui-widget ui-widget-content ui-corner-all")
@@ -27,7 +27,7 @@ $.widget("ui.button", {
secondary: null
}
},
_init: function() {
_create: function() {
this._determineButtonType();
this.hasTitle = !!this.buttonElement.attr('title');

@@ -208,7 +208,7 @@ $.widget("ui.button", {
});

$.widget("ui.buttonset", {
_init: function() {
_create: function() {
this.element.addClass("ui-button-set");
this.buttons = this.element.find(':button, :submit, :reset, :checkbox, :radio, a, .ui-button')
.button()
@@ -48,7 +48,7 @@ $.widget("ui.dialog", {
width: 300,
zIndex: 1000
},
_init: function() {
_create: function() {
this.originalTitle = this.element.attr('title');

var self = this,
@@ -41,7 +41,7 @@ $.widget("ui.draggable", $.ui.mouse, {
stack: false,
zIndex: false
},
_init: function() {
_create: function() {

if (this.options.helper == 'original' && !(/^(?:r|a|f)/).test(this.element.css("position")))
this.element[0].style.position = 'relative';
@@ -26,7 +26,7 @@ $.widget("ui.droppable", {
scope: 'default',
tolerance: 'intersect'
},
_init: function() {
_create: function() {

var o = this.options, accept = o.accept;
this.isover = 0; this.isout = 1;
@@ -17,7 +17,7 @@ $.widget("ui.progressbar", {
options: {
value: 0
},
_init: function() {
_create: function() {

this.element
.addClass("ui-progressbar"
@@ -33,7 +33,7 @@ $.widget("ui.resizable", $.ui.mouse, {
minWidth: 10,
zIndex: 1000
},
_init: function() {
_create: function() {

var self = this, o = this.options;
this.element.addClass("ui-resizable");
@@ -22,7 +22,7 @@ $.widget("ui.selectable", $.ui.mouse, {
filter: '*',
tolerance: 'touch'
},
_init: function() {
_create: function() {
var self = this;

this.element.addClass("ui-selectable");
@@ -31,7 +31,7 @@ $.widget("ui.slider", $.ui.mouse, {
value: 0,
values: null
},
_init: function() {
_create: function() {

var self = this, o = this.options;
this._keySliding = false;
@@ -39,7 +39,7 @@ $.widget("ui.sortable", $.ui.mouse, {
tolerance: "intersect",
zIndex: 1000
},
_init: function() {
_create: function() {

var o = this.options;
this.containerCache = {};
@@ -36,7 +36,7 @@ $.widget("ui.tabs", {
spinner: '<em>Loading&#8230;</em>',
tabTemplate: '<li><a href="#{href}"><span>#{label}</span></a></li>'
},
_init: function() {
_create: function() {
this._tabify(true);
},

@@ -39,7 +39,7 @@ $.widget = function(name, base, prototype) {
$[namespace] = $[namespace] || {};
$[namespace][name] = function(options, element) {
// allow instantiation without initializing for simple inheritance
(arguments.length && this._widgetInit(options, element));
(arguments.length && this._createWidget(options, element));
};

var basePrototype = new base();
@@ -99,7 +99,7 @@ $.widget.bridge = function(name, object) {

$.Widget = function(options, element) {
// allow instantiation without initializing for simple inheritance
(arguments.length && this._widgetInit(options, element));
(arguments.length && this._createWidget(options, element));
};

$.Widget.prototype = {
@@ -108,9 +108,9 @@ $.Widget.prototype = {
options: {
disabled: false
},
_widgetInit: function(options, element) {
_createWidget: function(options, element) {
// $.widget.bridge stores the plugin instance, but we do it anyway
// so that it's stored even before the _init function runs
// so that it's stored even before the _create function runs
this.element = $(element).data(this.widgetName, this);
this.options = $.extend(true, {},
this.options,
@@ -119,13 +119,13 @@ $.Widget.prototype = {
$.metadata && $.metadata.get(element)[this.widgetName],
options);

// TODO: use bind's scope option when moving to jQuery 1.4
var self = this;
this.element.bind('remove.' + this.widgetName, function() {
self.destroy();
});

(this._init && this._init(options, element));
(this._create && this._create(options, element));
(this._init && this._init());
},

destroy: function() {

0 comments on commit 7d96a0d

Please sign in to comment.
You can’t perform that action at this time.