From d304f9fbb7765be660ac54d47c5ed2cba6719880 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 26 Jul 2012 09:53:59 +0200 Subject: [PATCH] [CHG] rename this. to this. because why make things simple when you can make them fucked up bzr revid: xmo@openerp.com-20120726075359-b0uvuuagrfsf7nhb --- addons/web/static/src/js/corelib.js | 36 +++++++++++++-------------- addons/web/static/test/Widget.js | 38 ++++++++++++++--------------- doc/widget.rst | 4 +-- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/addons/web/static/src/js/corelib.js b/addons/web/static/src/js/corelib.js index 42e549b5ca1..b80543a34d8 100644 --- a/addons/web/static/src/js/corelib.js +++ b/addons/web/static/src/js/corelib.js @@ -523,8 +523,8 @@ instance.web.WidgetMixin = _.extend({},instance.web.CallbackEnabledMixin, { _.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); }, @@ -536,7 +536,7 @@ instance.web.WidgetMixin = _.extend({},instance.web.CallbackEnabledMixin, { appendTo: function(target) { var self = this; return this.__widgetRenderAndInsert(function(t) { - self.$el.appendTo(t); + self.$element.appendTo(t); }, target); }, /** @@ -547,7 +547,7 @@ instance.web.WidgetMixin = _.extend({},instance.web.CallbackEnabledMixin, { prependTo: function(target) { var self = this; return this.__widgetRenderAndInsert(function(t) { - self.$el.prependTo(t); + self.$element.prependTo(t); }, target); }, /** @@ -558,7 +558,7 @@ instance.web.WidgetMixin = _.extend({},instance.web.CallbackEnabledMixin, { insertAfter: function(target) { var self = this; return this.__widgetRenderAndInsert(function(t) { - self.$el.insertAfter(t); + self.$element.insertAfter(t); }, target); }, /** @@ -569,7 +569,7 @@ instance.web.WidgetMixin = _.extend({},instance.web.CallbackEnabledMixin, { insertBefore: function(target) { var self = this; return this.__widgetRenderAndInsert(function(t) { - self.$el.insertBefore(t); + self.$element.insertBefore(t); }, target); }, /** @@ -579,7 +579,7 @@ instance.web.WidgetMixin = _.extend({},instance.web.CallbackEnabledMixin, { */ replace: function(target) { return this.__widgetRenderAndInsert(_.bind(function(t) { - this.$el.replaceAll(t); + this.$element.replaceAll(t); }, this), target); }, __widgetRenderAndInsert: function(insertion, target) { @@ -717,10 +717,10 @@ instance.web.Widget = instance.web.Class.extend(instance.web.WidgetMixin, { * @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; }, @@ -737,12 +737,12 @@ instance.web.Widget = instance.web.Class.extend(instance.web.WidgetMixin, { * @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(); @@ -781,23 +781,23 @@ instance.web.Widget = instance.web.Class.extend(instance.web.WidgetMixin, { 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 diff --git a/addons/web/static/test/Widget.js b/addons/web/static/test/Widget.js index 99bae019ae4..55d9e7e7ad1 100644 --- a/addons/web/static/test/Widget.js +++ b/addons/web/static/test/Widget.js @@ -86,15 +86,15 @@ $(document).ready(function () { 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({ @@ -111,7 +111,7 @@ $(document).ready(function () { 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 () { @@ -121,7 +121,7 @@ $(document).ready(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({ @@ -138,16 +138,16 @@ $(document).ready(function () { 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 () { @@ -157,7 +157,7 @@ $(document).ready(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'); }); @@ -168,7 +168,7 @@ $(document).ready(function () { })); 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"); }); @@ -189,7 +189,7 @@ $(document).ready(function () { })); w.renderElement(); - w.$el.click(); + w.$element.click(); w.$('li:eq(3)').click(); w.$('input:last').val('foo').change(); @@ -204,7 +204,7 @@ $(document).ready(function () { 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"); @@ -227,11 +227,11 @@ $(document).ready(function () { .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"); }); }); }); diff --git a/doc/widget.rst b/doc/widget.rst index b29260c5882..02332382ce9 100644 --- a/doc/widget.rst +++ b/doc/widget.rst @@ -39,14 +39,14 @@ DOM Root A :js:class:`~openerp.web.Widget` is responsible for a section of the page materialized by the DOM root of the widget. The DOM root is available via the :js:attr:`~openerp.web.Widget.el` and -:js:attr:`~openerp.web.Widget.$el` attributes, which are respectively +:js:attr:`~openerp.web.Widget.$element` attributes, which are respectively the raw DOM Element and the jQuery wrapper around the DOM element. .. note:: both attributes are compatible with Backbone's equivalent, there is also the :js:attr:`~openerp.web.Widget.$element` attribute - which aliases to :js:attr:`~openerp.web.Widget.$el` and remains + which aliases to :js:attr:`~openerp.web.Widget.$element` and remains for backwards compatiblity reasons. There are two main ways to define and generate this DOM root: