summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2016-06-16 13:19:15 +0200
committerGéry Debongnie <ged@odoo.com>2016-06-17 13:27:18 +0200
commitd56b35e26e4b578c5f6f434d336edd006d321860 (patch)
tree213d2cad70191c3d6576eb76efa754ade974dcfb /addons/web/static/src
parent611322c36b5dcf73c9f4286a083cd150672d2319 (diff)
[REF] web, *: move QWeb odoo init to web.QWeb
this js module centralizes all odoo initialization
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/boot.js32
-rw-r--r--addons/web/static/src/js/framework/core.js63
-rw-r--r--addons/web/static/src/js/framework/qweb.js48
-rw-r--r--addons/web/static/src/js/framework/translation.js9
4 files changed, 78 insertions, 74 deletions
diff --git a/addons/web/static/src/js/boot.js b/addons/web/static/src/js/boot.js
index 2cc4abe29bb..f070730886d 100644
--- a/addons/web/static/src/js/boot.js
+++ b/addons/web/static/src/js/boot.js
@@ -36,11 +36,7 @@
var job_deps = [];
var job_deferred = [];
- var services = Object.create({
- qweb: new QWeb2.Engine(),
- $: $,
- _: _,
- });
+ var services = Object.create({});
var commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg;
var cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g;
@@ -271,4 +267,30 @@
};
$(log_when_loaded);
+
+ // IE patch
+ //-------------------------------------------------------------------------
+ if (typeof(console) === "undefined") {
+ // Even IE9 only exposes console object if debug window opened
+ window.console = {};
+ ('log error debug info warn assert clear dir dirxml trace group'
+ + ' groupCollapsed groupEnd time timeEnd profile profileEnd count'
+ + ' exception').split(/\s+/).forEach(function(property) {
+ console[property] = _.identity;
+ });
+ }
+
+ /**
+ Some hack to make placeholders work in ie9.
+ */
+ if (!('placeholder' in document.createElement('input'))) {
+ document.addEventListener("DOMNodeInserted",function(event){
+ var nodename = event.target.nodeName.toLowerCase();
+ if ( nodename === "input" || nodename === "textarea" ) {
+ $(event.target).placeholder();
+ }
+ });
+ }
+
+
})();
diff --git a/addons/web/static/src/js/framework/core.js b/addons/web/static/src/js/framework/core.js
index 8f0453151e8..29b461cbe8d 100644
--- a/addons/web/static/src/js/framework/core.js
+++ b/addons/web/static/src/js/framework/core.js
@@ -6,9 +6,7 @@ var mixins = require('web.mixins');
var Registry = require('web.Registry');
var translation = require('web.translation');
-var qweb = require('qweb');
-var _ = require('_');
-var $ = require('$');
+var QWeb = require('web.QWeb');
var debug = $.deparam($.param.querystring()).debug !== undefined;
@@ -37,31 +35,6 @@ _.each('resize,scroll'.split(','), function(evtype) {
});
});
-// IE patch
-//-------------------------------------------------------------------------
-if (typeof(console) === "undefined") {
- // Even IE9 only exposes console object if debug window opened
- window.console = {};
- ('log error debug info warn assert clear dir dirxml trace group'
- + ' groupCollapsed groupEnd time timeEnd profile profileEnd count'
- + ' exception').split(/\s+/).forEach(function(property) {
- console[property] = _.identity;
- });
-}
-
-/**
- Some hack to make placeholders work in ie9.
-*/
-if (!('placeholder' in document.createElement('input'))) {
- document.addEventListener("DOMNodeInserted",function(event){
- var nodename = event.target.nodeName.toLowerCase();
- if ( nodename === "input" || nodename == "textarea" ) {
- $(event.target).placeholder();
- }
- });
-}
-
-
/**
* Lazy translation function, only performs the translation when actually
@@ -74,39 +47,9 @@ if (!('placeholder' in document.createElement('input'))) {
* @param {String} s string to translate
* @returns {Object} lazy translation object
*/
-qweb.debug = debug;
-_.extend(qweb.default_dict, {
- '__debug__': debug,
- 'moment': function(date) { return new moment(date); },
-});
+var qweb = new QWeb(debug);
+
-qweb.default_dict.csrf_token = odoo.csrf_token;
-
-qweb.preprocess_node = function() {
- // Note that 'this' is the Qweb Node
- switch (this.node.nodeType) {
- case Node.TEXT_NODE:
- case Node.CDATA_SECTION_NODE:
- // Text and CDATAs
- var translation = this.node.parentNode.attributes['t-translation'];
- if (translation && translation.value === 'off') {
- return;
- }
- var match = /^(\s*)([\s\S]+?)(\s*)$/.exec(this.node.data);
- if (match) {
- this.node.data = match[1] + _t(match[2]) + match[3];
- }
- break;
- case Node.ELEMENT_NODE:
- // Element
- var attr, attrs = ['label', 'title', 'alt', 'placeholder'];
- while ((attr = attrs.pop())) {
- if (this.attributes[attr]) {
- this.attributes[attr] = _t(this.attributes[attr]);
- }
- }
- }
-};
/** Setup jQuery timeago */
/*
diff --git a/addons/web/static/src/js/framework/qweb.js b/addons/web/static/src/js/framework/qweb.js
new file mode 100644
index 00000000000..b29f0f06d65
--- /dev/null
+++ b/addons/web/static/src/js/framework/qweb.js
@@ -0,0 +1,48 @@
+odoo.define('web.QWeb', function (require) {
+"use strict";
+
+var translation = require('web.translation');
+
+function QWeb(debug) {
+ var qweb = new QWeb2.Engine();
+ qweb.default_dict = {
+ '_' : _,
+ 'JSON': JSON,
+ '_t' : translation._t,
+ '__debug__': debug,
+ 'moment': function(date) { return new moment(date); },
+ 'csrf_token': odoo.csrf_token,
+ };
+ qweb.debug = debug;
+ return qweb;
+}
+
+QWeb.prototype.preprocess_node = function() {
+ // Note that 'this' is the Qweb Node
+ switch (this.node.nodeType) {
+ case Node.TEXT_NODE:
+ case Node.CDATA_SECTION_NODE:
+ // Text and CDATAs
+ var translation = this.node.parentNode.attributes['t-translation'];
+ if (translation && translation.value === 'off') {
+ return;
+ }
+ var match = /^(\s*)([\s\S]+?)(\s*)$/.exec(this.node.data);
+ if (match) {
+ this.node.data = match[1] + _t(match[2]) + match[3];
+ }
+ break;
+ case Node.ELEMENT_NODE:
+ // Element
+ var attr, attrs = ['label', 'title', 'alt', 'placeholder'];
+ while ((attr = attrs.pop())) {
+ if (this.attributes[attr]) {
+ this.attributes[attr] = _t(this.attributes[attr]);
+ }
+ }
+ }
+};
+
+return QWeb;
+
+});
diff --git a/addons/web/static/src/js/framework/translation.js b/addons/web/static/src/js/framework/translation.js
index 69743e9787d..5d747869935 100644
--- a/addons/web/static/src/js/framework/translation.js
+++ b/addons/web/static/src/js/framework/translation.js
@@ -3,8 +3,6 @@ odoo.define('web.translation', function (require) {
"use strict";
var Class = require('web.Class');
-var qweb = require('qweb');
-
var TranslationDataBase = Class.extend(/** @lends instance.TranslationDataBase# */{
init: function() {
@@ -80,12 +78,6 @@ var _lt = function (s) {
return {toString: function () { return _t(s); }};
};
-qweb.default_dict = {
- '_' : _,
- 'JSON': JSON,
- '_t' : _t,
-};
-
return {
_t: _t,
_lt: _lt,
@@ -93,4 +85,3 @@ return {
};
});
-