summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/corelib.js
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2012-07-25 11:19:16 +0200
committerXavier Morel <xmo@openerp.com>2012-07-25 11:19:16 +0200
commit9cc2f4fb2553e7c327cbe97e49ab693813500c4b (patch)
tree4125132b2e19758b4c1fc0798579ca01d636cb08 /addons/web/static/src/js/corelib.js
parent0310d5ae73b34ded9c67c3a4b7423afabccd5630 (diff)
[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
Diffstat (limited to 'addons/web/static/src/js/corelib.js')
-rw-r--r--addons/web/static/src/js/corelib.js15
1 files changed, 13 insertions, 2 deletions
diff --git a/addons/web/static/src/js/corelib.js b/addons/web/static/src/js/corelib.js
index 6c7fd539b38..42e549b5ca1 100644
--- a/addons/web/static/src/js/corelib.js
+++ b/addons/web/static/src/js/corelib.js
@@ -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) {