[IMP] extract 'set element as new widget root and replace old one in DOM' in its own method
also fix OldWidget to use it, as it had not been fixed when #replaceWith was extracted out of setElement bzr revid: xmo@openerp.com-20120725091916-g9t5qmaeeqcceuk1
This commit is contained in:
@@ -706,13 +706,24 @@ instance.web.Widget = instance.web.Class.extend(instance.web.WidgetMixin, {
|
||||
if (this.className) { attrs['class'] = this.className; }
|
||||
$el = $(this.make(this.tagName, attrs));
|
||||
}
|
||||
this.replaceElement($el);
|
||||
},
|
||||
|
||||
/**
|
||||
* Re-sets the widget's root element and replaces the old root element
|
||||
* (if any) by the new one in the DOM.
|
||||
*
|
||||
* @param {HTMLElement | jQuery} $el
|
||||
* @returns {*} this
|
||||
*/
|
||||
replaceElement: function ($el) {
|
||||
var $oldel = this.$el;
|
||||
this.setElement($el);
|
||||
if ($oldel && !$oldel.is(this.$el)) {
|
||||
$oldel.replaceWith(this.$el);
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
/**
|
||||
* Re-sets the widget's root element (el/$el/$element).
|
||||
*
|
||||
@@ -723,7 +734,7 @@ instance.web.Widget = instance.web.Class.extend(instance.web.WidgetMixin, {
|
||||
* element in the DOM
|
||||
*
|
||||
* @param {HTMLElement | jQuery} element new root element for the widget
|
||||
* @return {*}
|
||||
* @return {*} this
|
||||
*/
|
||||
setElement: function (element) {
|
||||
if (this.$el) {
|
||||
|
||||
@@ -26,8 +26,7 @@ instance.web.OldWidget = instance.web.Widget.extend({
|
||||
renderElement: function() {
|
||||
var rendered = this.render();
|
||||
if (rendered) {
|
||||
var $el = $(rendered);
|
||||
this.setElement($el);
|
||||
this.replaceElement($(rendered));
|
||||
}
|
||||
return this;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user