_.each(this.getChildren(), function(el) {
el.destroy();
});
- if(this.$el) {
- this.$el.remove();
+ if(this.$element) {
+ this.$element.remove();
}
instance.web.PropertiesMixin.destroy.call(this);
},
appendTo: function(target) {
var self = this;
return this.__widgetRenderAndInsert(function(t) {
- self.$el.appendTo(t);
+ self.$element.appendTo(t);
}, target);
},
/**
prependTo: function(target) {
var self = this;
return this.__widgetRenderAndInsert(function(t) {
- self.$el.prependTo(t);
+ self.$element.prependTo(t);
}, target);
},
/**
insertAfter: function(target) {
var self = this;
return this.__widgetRenderAndInsert(function(t) {
- self.$el.insertAfter(t);
+ self.$element.insertAfter(t);
}, target);
},
/**
insertBefore: function(target) {
var self = this;
return this.__widgetRenderAndInsert(function(t) {
- self.$el.insertBefore(t);
+ self.$element.insertBefore(t);
}, target);
},
/**
*/
replace: function(target) {
return this.__widgetRenderAndInsert(_.bind(function(t) {
- this.$el.replaceAll(t);
+ this.$element.replaceAll(t);
}, this), target);
},
__widgetRenderAndInsert: function(insertion, target) {
* @returns {*} this
*/
replaceElement: function ($el) {
- var $oldel = this.$el;
+ var $oldel = this.$element;
this.setElement($el);
- if ($oldel && !$oldel.is(this.$el)) {
- $oldel.replaceWith(this.$el);
+ if ($oldel && !$oldel.is(this.$element)) {
+ $oldel.replaceWith(this.$element);
}
return this;
},
* @return {*} this
*/
setElement: function (element) {
- if (this.$el) {
+ if (this.$element) {
this.undelegateEvents();
}
- this.$element = this.$el = (element instanceof $) ? element : $(element);
- this.el = this.$el[0];
+ this.$element = (element instanceof $) ? element : $(element);
+ this.el = this.$element[0];
this.delegateEvents();
event += '.widget_events';
if (!selector) {
- this.$el.on(event, method);
+ this.$element.on(event, method);
} else {
- this.$el.on(event, selector, method);
+ this.$element.on(event, selector, method);
}
}
},
undelegateEvents: function () {
- this.$el.off('.widget_events');
+ this.$element.off('.widget_events');
},
/**
- * Shortcut for ``this.$el.find(selector)``
+ * Shortcut for ``this.$element.find(selector)``
*
* @param {String} selector CSS selector, rooted in $el
* @returns {jQuery} selector match
*/
$: function(selector) {
- return this.$el.find(selector);
+ return this.$element.find(selector);
},
/**
* Informs the action manager to do an action. This supposes that
test('no template, default', function () {
var w = new (instance.web.Widget.extend({ }));
- ok(!w.$el, "should not initially have a root element");
+ ok(!w.$element, "should not initially have a root element");
w.renderElement();
- ok(w.$el, "should have generated a root element");
- strictEqual(w.$element, w.$el, "should provide $element alias");
- ok(w.$el.is(w.el), "should provide raw DOM alias");
+ ok(w.$element, "should have generated a root element");
+ strictEqual(w.$element, w.$element, "should provide $element alias");
+ ok(w.$element.is(w.el), "should provide raw DOM alias");
equal(w.el.nodeName, 'DIV', "should have generated the default element");
equal(w.el.attributes.length, 0, "should not have generated any attribute");
- ok(_.isEmpty(w.$el.html(), "should not have generated any content"));
+ ok(_.isEmpty(w.$element.html(), "should not have generated any content"));
});
test('no template, custom tag', function () {
var w = new (instance.web.Widget.extend({
w.renderElement();
equal(w.el.attributes.length, 1, "should have one attribute");
- equal(w.$el.attr('id'), 'foo', "should have generated the id attribute");
+ equal(w.$element.attr('id'), 'foo', "should have generated the id attribute");
equal(w.el.id, 'foo', "should also be available via property");
});
test('no template, @className', function () {
w.renderElement();
equal(w.el.className, 'oe_some_class', "should have the right property");
- equal(w.$el.attr('class'), 'oe_some_class', "should have the right attribute");
+ equal(w.$element.attr('class'), 'oe_some_class', "should have the right attribute");
});
test('no template, bunch of attributes', function () {
var w = new (instance.web.Widget.extend({
equal(w.el.attributes.length, 5, "should have all the specified attributes");
equal(w.el.id, 'some_id');
- equal(w.$el.attr('id'), 'some_id');
+ equal(w.$element.attr('id'), 'some_id');
equal(w.el.className, 'some_class');
- equal(w.$el.attr('class'), 'some_class');
+ equal(w.$element.attr('class'), 'some_class');
- equal(w.$el.attr('data-foo'), 'data attribute');
- equal(w.$el.data('foo'), 'data attribute');
+ equal(w.$element.attr('data-foo'), 'data attribute');
+ equal(w.$element.data('foo'), 'data attribute');
- equal(w.$el.attr('clark'), 'gable');
- equal(w.$el.attr('spoiler'), 'snape kills dumbledore');
+ equal(w.$element.attr('clark'), 'gable');
+ equal(w.$element.attr('spoiler'), 'snape kills dumbledore');
});
test('template', function () {
w.renderElement();
equal(w.el.nodeName, 'OL');
- equal(w.$el.children().length, 5);
+ equal(w.$element.children().length, 5);
equal(w.el.textContent, '01234');
});
}));
w.renderElement();
- ok(w.$('li:eq(3)').is(w.$el.find('li:eq(3)')),
+ ok(w.$('li:eq(3)').is(w.$element.find('li:eq(3)')),
"should do the same thing as calling find on the widget root");
});
}));
w.renderElement();
- w.$el.click();
+ w.$element.click();
w.$('li:eq(3)').click();
w.$('input:last').val('foo').change();
events: { 'click li': function () { clicked = true; } }
}));
w.renderElement();
- w.$el.on('click', 'li', function () { newclicked = true });
+ w.$element.on('click', 'li', function () { newclicked = true });
w.$('li').click();
ok(clicked, "should trigger bound events");
.always(start)
.done(function () {
equal($fix.find('p').text(), '42', "DOM fixture should contain initial value");
- equal(w.$el.text(), '42', "should set initial value");
+ equal(w.$element.text(), '42', "should set initial value");
w.value = 36;
w.renderElement();
equal($fix.find('p').text(), '36', "DOM fixture should use new value");
- equal(w.$el.text(), '36', "should set new value");
+ equal(w.$element.text(), '36', "should set new value");
});
});
});