[REF] *: convert odoo module by native one

This commit converts all odoo module of this repo by native module.
The goal is to depreciate odoo.define in favor of native module
and then simplify boot.js by removing the regexp that finds
module dependencies.

task id: 3162300

closes odoo/design-themes#652

Signed-off-by: Géry Debongnie <ged@odoo.com>
This commit is contained in:
Michael (mcm)
2023-04-27 07:50:35 +00:00
parent 9cca23373e
commit 7ab07c6ec1
10 changed files with 230 additions and 251 deletions
@@ -1,7 +1,6 @@
odoo.define('theme_common.compatibility_editor', function (require) { /** @odoo-module **/
'use strict';
var sOptions = require('web_editor.snippets.options'); import sOptions from "web_editor.snippets.options";
sOptions.registry.BackgroundImage.include({ sOptions.registry.BackgroundImage.include({
/** /**
@@ -16,4 +15,3 @@ sOptions.registry.BackgroundImage.include({
} }
}, },
}); });
});
+3 -6
View File
@@ -1,8 +1,7 @@
odoo.define('theme_common.preheader', function (require) { /** @odoo-module **/
'use strict';
var publicWidget = require('web.public.widget'); import publicWidget from "web.public.widget";
require('website.content.menu'); import "website.content.menu";
publicWidget.registry.StandardAffixedHeader.include({ publicWidget.registry.StandardAffixedHeader.include({
/** /**
@@ -111,5 +110,3 @@ const BaseDisappearingPreheader = {
publicWidget.registry.DisappearingHeader.include(BaseDisappearingPreheader); publicWidget.registry.DisappearingHeader.include(BaseDisappearingPreheader);
publicWidget.registry.FadeOutHeader.include(BaseDisappearingPreheader); publicWidget.registry.FadeOutHeader.include(BaseDisappearingPreheader);
});
@@ -1,7 +1,6 @@
odoo.define('theme_common.s_animated_boxes_frontend', function (require) { /** @odoo-module **/
'use strict';
var publicWidget = require('web.public.widget'); import publicWidget from "web.public.widget";
/** /**
* This is a fix for some apple devices. * This is a fix for some apple devices.
@@ -12,4 +11,3 @@ var publicWidget = require('web.public.widget');
publicWidget.registry._fixAnimatedBoxesAppleClick = publicWidget.registry._fixAppleCollapse.extend({ publicWidget.registry._fixAnimatedBoxesAppleClick = publicWidget.registry._fixAppleCollapse.extend({
selector: '.s_animated_boxes .item', selector: '.s_animated_boxes .item',
}); });
});
@@ -1,122 +1,120 @@
odoo.define('theme_common.s_css_slider_frontend', function (require) { /** @odoo-module **/
'use strict';
var publicWidget = require('web.public.widget'); import publicWidget from "web.public.widget";
publicWidget.registry.s_css_slider = publicWidget.Widget.extend({ publicWidget.registry.s_css_slider = publicWidget.Widget.extend({
selector: ".s_css_slider", selector: ".s_css_slider",
disabledInEditableMode: false, disabledInEditableMode: false,
start: function () { start: function () {
var self = this; var self = this;
var $container = self.$el; var $container = self.$el;
$container.find(".s_css_slider_pagination").remove(); $container.find(".s_css_slider_pagination").remove();
// create slider pagination // create slider pagination
var sliderPagination = self.createSliderPagination($container); var sliderPagination = self.createSliderPagination($container);
self.bindEvents($container, sliderPagination); self.bindEvents($container, sliderPagination);
$(window).on("resize", function () { $(window).on("resize", function () {
self.resizeImgs($container); self.resizeImgs($container);
}).trigger("resize"); }).trigger("resize");
return this._super.apply(this, arguments); return this._super.apply(this, arguments);
}, },
bindEvents: function ($container, sliderPagination) { bindEvents: function ($container, sliderPagination) {
var self = this, var self = this,
$next_btn = $container.find('.next'), $next_btn = $container.find('.next'),
$prev_btn = $container.find('.prev'); $prev_btn = $container.find('.prev');
$next_btn.on('click.s_css', function (e) { $next_btn.on('click.s_css', function (e) {
self.nextSlide($container, sliderPagination); self.nextSlide($container, sliderPagination);
}); });
$prev_btn.on('click.s_css', function (e) { $prev_btn.on('click.s_css', function (e) {
self.prevSlide($container, sliderPagination); self.prevSlide($container, sliderPagination);
}); });
if ($container.hasClass("autoplay") && this.editableMode !== true) { if ($container.hasClass("autoplay") && this.editableMode !== true) {
var interval; var interval;
var autoplay = function () { var autoplay = function () {
interval = setInterval(function () { interval = setInterval(function () {
if (!$next_btn.hasClass("inactive")) { if (!$next_btn.hasClass("inactive")) {
self.nextSlide($container, sliderPagination); self.nextSlide($container, sliderPagination);
} else {
self.prevSlide($container, sliderPagination, 0);
}
}, 3000);
};
autoplay();
$container.hover(function () { clearInterval(interval); });
$container.mouseleave(function () { autoplay(); });
}
sliderPagination.on('click.s_css', function () {
var selectedDot = $(this);
if (!selectedDot.hasClass('selected')) {
var selectedPosition = selectedDot.index(),
activePosition = $container.find('.slider .selected').index();
if ( activePosition < selectedPosition) {
self.nextSlide($container, sliderPagination, selectedPosition);
} else { } else {
self.prevSlide($container, sliderPagination, selectedPosition); self.prevSlide($container, sliderPagination, 0);
} }
}, 3000);
};
autoplay();
$container.hover(function () { clearInterval(interval); });
$container.mouseleave(function () { autoplay(); });
}
sliderPagination.on('click.s_css', function () {
var selectedDot = $(this);
if (!selectedDot.hasClass('selected')) {
var selectedPosition = selectedDot.index(),
activePosition = $container.find('.slider .selected').index();
if ( activePosition < selectedPosition) {
self.nextSlide($container, sliderPagination, selectedPosition);
} else {
self.prevSlide($container, sliderPagination, selectedPosition);
} }
}); }
}, });
},
resizeImgs: function ($container) { resizeImgs: function ($container) {
var cont_h = $container.height(), var cont_h = $container.height(),
imgs = $container.find(".slide img"); imgs = $container.find(".slide img");
imgs.each(function () { imgs.each(function () {
var $img = $(this), var $img = $(this),
img_h = $img.height(); img_h = $img.height();
if (img_h > cont_h) { if (img_h > cont_h) {
$img.css("width", "100%"); $img.css("width", "100%");
$img.css("margin-top", (cont_h - img_h)/2); $img.css("margin-top", (cont_h - img_h)/2);
} }
}); });
}, },
createSliderPagination: function ($container) { createSliderPagination: function ($container) {
var wrapper = $('<ul class="s_css_slider_pagination"></ul>').insertAfter($container.find('.navigation')); var wrapper = $('<ul class="s_css_slider_pagination"></ul>').insertAfter($container.find('.navigation'));
$container.find('.slider .slide').each(function (index) { $container.find('.slider .slide').each(function (index) {
var dotWrapper = (index === 0) ? $('<li class="selected"></li>') : $('<li></li>'), var dotWrapper = (index === 0) ? $('<li class="selected"></li>') : $('<li></li>'),
dot = $('<a href="#0"></a>').appendTo(dotWrapper); dot = $('<a href="#0"></a>').appendTo(dotWrapper);
dotWrapper.appendTo(wrapper); dotWrapper.appendTo(wrapper);
dot.text(index+1); dot.text(index+1);
}); });
return wrapper.children('li'); return wrapper.children('li');
}, },
nextSlide: function ($container, $pagination, $n) { nextSlide: function ($container, $pagination, $n) {
var self = this, var self = this,
visibleSlide = $container.find('.slider .selected'), visibleSlide = $container.find('.slider .selected'),
navigationDot = $container.find('.s_css_slider_pagination .selected'); navigationDot = $container.find('.s_css_slider_pagination .selected');
if (typeof $n === 'undefined') $n = visibleSlide.index() + 1; if (typeof $n === 'undefined') $n = visibleSlide.index() + 1;
visibleSlide.removeClass('selected'); visibleSlide.removeClass('selected');
$container.find('.slider .slide').eq($n).addClass('selected').prevAll().addClass('move-left'); $container.find('.slider .slide').eq($n).addClass('selected').prevAll().addClass('move-left');
navigationDot.removeClass('selected'); navigationDot.removeClass('selected');
$pagination.eq($n).addClass('selected'); $pagination.eq($n).addClass('selected');
self.updateNavigation($container, $container.find('.slider .slide').eq($n)); self.updateNavigation($container, $container.find('.slider .slide').eq($n));
}, },
prevSlide: function ($container, $pagination, $n) { prevSlide: function ($container, $pagination, $n) {
var self = this, var self = this,
visibleSlide = $container.find('.slider .selected'), visibleSlide = $container.find('.slider .selected'),
navigationDot = $container.find('.s_css_slider_pagination .selected'); navigationDot = $container.find('.s_css_slider_pagination .selected');
if (typeof $n === 'undefined') $n = visibleSlide.index() - 1; if (typeof $n === 'undefined') $n = visibleSlide.index() - 1;
visibleSlide.removeClass('selected'); visibleSlide.removeClass('selected');
$container.find('.slider .slide').eq($n).addClass('selected').removeClass('move-left').nextAll().removeClass('move-left'); $container.find('.slider .slide').eq($n).addClass('selected').removeClass('move-left').nextAll().removeClass('move-left');
navigationDot.removeClass('selected'); navigationDot.removeClass('selected');
$pagination.eq($n).addClass('selected'); $pagination.eq($n).addClass('selected');
self.updateNavigation($container, $container.find('.slider .slide').eq($n)); self.updateNavigation($container, $container.find('.slider .slide').eq($n));
}, },
updateNavigation: function ($container, $active) { updateNavigation: function ($container, $active) {
$container.find('.prev').toggleClass('inactive', $active.is(':first-child')); $container.find('.prev').toggleClass('inactive', $active.is(':first-child'));
$container.find('.next').toggleClass('inactive', $active.is(':last-child')); $container.find('.next').toggleClass('inactive', $active.is(':last-child'));
}, },
});
}); });
@@ -1,8 +1,7 @@
odoo.define('theme_common.s_mini_nav_bar', function (require) { /** @odoo-module **/
'use strict';
const dom = require('web.dom'); import dom from "web.dom";
var publicWidget = require('web.public.widget'); import publicWidget from "web.public.widget";
publicWidget.registry.miniNavbarScroll = publicWidget.Widget.extend({ publicWidget.registry.miniNavbarScroll = publicWidget.Widget.extend({
selector: '.s_mini_nav_bar a[href*="#"]:not([href="#"])', selector: '.s_mini_nav_bar a[href*="#"]:not([href="#"])',
@@ -28,4 +27,3 @@ publicWidget.registry.miniNavbarScroll = publicWidget.Widget.extend({
} }
}, },
}); });
});
@@ -1,132 +1,130 @@
odoo.define("theme_common.s_showcase_slider_frontend", function (require) { /** @odoo-module **/
"use strict";
const dom = require('web.dom'); import dom from "web.dom";
var publicWidget = require('web.public.widget'); import publicWidget from "web.public.widget";
publicWidget.registry.s_showcase_slider = publicWidget.Widget.extend({ publicWidget.registry.s_showcase_slider = publicWidget.Widget.extend({
selector: ".s_showcase_slider", selector: ".s_showcase_slider",
start: function () { start: function () {
_.defer(this.bindEvents.bind(this)); // FIXME delayed to counter a web_editor bug which off all click event _.defer(this.bindEvents.bind(this)); // FIXME delayed to counter a web_editor bug which off all click event
this.createPagination(); this.createPagination();
return this._super.apply(this, arguments); return this._super.apply(this, arguments);
}, },
destroy: function () { destroy: function () {
this._super.apply(this, arguments); this._super.apply(this, arguments);
_.defer(this.unbindEvents.bind(this)); // FIXME delayed to counter a web_editor bug which off all click event _.defer(this.unbindEvents.bind(this)); // FIXME delayed to counter a web_editor bug which off all click event
this.destroyPagination(); this.destroyPagination();
this.$el.removeClass("active");
},
bindEvents: function () {
// Enlarge image on click if not already enlarged
this.$el.on("click.s_showcase_slider", ".s_ss_slider", (function (e) {
if (this.$el.hasClass("active")) return;
this.$el
.addClass("active")
.one("webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend", (function () {
dom.scrollTo(this.el, {
duration: 200,
extraOffset: 70,
});
this.$el.trigger("transitionIsFinished");
}).bind(this));
}).bind(this));
// Close the enlarged image on close icon click
this.$el.on("click.s_showcase_slider", ".s_ss_close", (function (e) {
this.$el.removeClass("active"); this.$el.removeClass("active");
}, }).bind(this));
bindEvents: function () { // Handle click navigation
// Enlarge image on click if not already enlarged this.$el.on("click.s_showcase_slider", ".s_ss_prev", this.prevSlide.bind(this));
this.$el.on("click.s_showcase_slider", ".s_ss_slider", (function (e) { this.$el.on("click.s_showcase_slider", ".s_ss_next", this.nextSlide.bind(this));
if (this.$el.hasClass("active")) return; this.$el.on("click.s_showcase_slider", ".s_ss_slider_pagination > li > a", (function (e) {
e.preventDefault();
var $selectedDot = $(e.currentTarget).parent();
if ($selectedDot.hasClass("selected")) return;
this.changeSlide($selectedDot.index());
}).bind(this));
this.$el // Keyboard slider navigation
.addClass("active") $(document).on("keyup.s_showcase_slider", (function (e) {
.one("webkitTransitionEnd otransitionend oTransitionEnd msTransitionEnd transitionend", (function () { if (!this.$el.hasClass("active")) return;
dom.scrollTo(this.el, {
duration: 200,
extraOffset: 70,
});
this.$el.trigger("transitionIsFinished");
}).bind(this));
}).bind(this));
// Close the enlarged image on close icon click switch (e.which) {
this.$el.on("click.s_showcase_slider", ".s_ss_close", (function (e) { case $.ui.keyCode.LEFT:
this.$el.removeClass("active"); this.prevSlide();
}).bind(this)); break;
case $.ui.keyCode.RIGHT:
// Handle click navigation this.nextSlide();
this.$el.on("click.s_showcase_slider", ".s_ss_prev", this.prevSlide.bind(this)); break;
this.$el.on("click.s_showcase_slider", ".s_ss_next", this.nextSlide.bind(this)); case $.ui.keyCode.ESCAPE:
this.$el.on("click.s_showcase_slider", ".s_ss_slider_pagination > li > a", (function (e) { this.$el.removeClass("active");
e.preventDefault(); break;
var $selectedDot = $(e.currentTarget).parent();
if ($selectedDot.hasClass("selected")) return;
this.changeSlide($selectedDot.index());
}).bind(this));
// Keyboard slider navigation
$(document).on("keyup.s_showcase_slider", (function (e) {
if (!this.$el.hasClass("active")) return;
switch (e.which) {
case $.ui.keyCode.LEFT:
this.prevSlide();
break;
case $.ui.keyCode.RIGHT:
this.nextSlide();
break;
case $.ui.keyCode.ESCAPE:
this.$el.removeClass("active");
break;
}
}).bind(this));
},
unbindEvents: function () {
this.$el.off(".s_showcase_slider");
$(document).off(".s_showcase_slider");
},
createPagination: function () { // FIXME pagination should be saved with editor but keep this for compatibility
this.$el.find(".s_ss_slider_pagination").remove(); // Remove saved-with-editor pagination
this.$pagination = $("<ul/>", {class: "s_ss_slider_pagination"});
this.$pagination.insertAfter(this.$el.find(".s_ss_slider_navigation"));
var nbSlides = this.$el.find(".s_ss_slider").children().length;
for (var i = 0 ; i < nbSlides ; i++) {
this.$pagination.append("<li><a href=\"#\"></a></li>");
} }
}).bind(this));
},
this.$pagination.children().eq(this.getCurrentIndex()).addClass("selected"); unbindEvents: function () {
}, this.$el.off(".s_showcase_slider");
$(document).off(".s_showcase_slider");
},
destroyPagination: function () { createPagination: function () { // FIXME pagination should be saved with editor but keep this for compatibility
if (this.$pagination) { this.$el.find(".s_ss_slider_pagination").remove(); // Remove saved-with-editor pagination
this.$pagination.remove();
this.$pagination = null;
}
},
prevSlide: function () { this.$pagination = $("<ul/>", {class: "s_ss_slider_pagination"});
var nbSlides = this.$el.find(".s_ss_slider").children().length; this.$pagination.insertAfter(this.$el.find(".s_ss_slider_navigation"));
var currentIndex = this.getCurrentIndex();
this.changeSlide(currentIndex > 0 ? (currentIndex - 1) : (nbSlides - 1));
},
nextSlide: function () { var nbSlides = this.$el.find(".s_ss_slider").children().length;
var nbSlides = this.$el.find(".s_ss_slider").children().length; for (var i = 0 ; i < nbSlides ; i++) {
var currentIndex = this.getCurrentIndex(); this.$pagination.append("<li><a href=\"#\"></a></li>");
this.changeSlide((currentIndex + 1) % nbSlides); }
},
getCurrentIndex: function () { this.$pagination.children().eq(this.getCurrentIndex()).addClass("selected");
return this.$el.find(".s_ss_slider > .selected").index(); },
},
changeSlide: function (n) { destroyPagination: function () {
var $slides = this.$el.find(".s_ss_slider > li").removeClass("selected"); if (this.$pagination) {
this.$el.find(".s_ss_slider_pagination > li").removeClass("selected"); this.$pagination.remove();
this.$pagination = null;
}
},
var $slide = $slides.eq(n).addClass("selected"); prevSlide: function () {
$slides.removeClass("move-left"); var nbSlides = this.$el.find(".s_ss_slider").children().length;
$slide.prevAll().addClass("move-left"); var currentIndex = this.getCurrentIndex();
this.changeSlide(currentIndex > 0 ? (currentIndex - 1) : (nbSlides - 1));
},
this.$pagination.children().eq(n).addClass("selected"); nextSlide: function () {
this.updateNavigation(); var nbSlides = this.$el.find(".s_ss_slider").children().length;
}, var currentIndex = this.getCurrentIndex();
this.changeSlide((currentIndex + 1) % nbSlides);
},
updateNavigation: function () { getCurrentIndex: function () {
var $active = this.$el.find(".s_ss_slider > .selected"); return this.$el.find(".s_ss_slider > .selected").index();
this.$el.find(".s_ss_prev").toggleClass("inactive", $active.is(":first-child")); },
this.$el.find(".s_ss_next").toggleClass("inactive", $active.is(":last-child"));
}, changeSlide: function (n) {
}); var $slides = this.$el.find(".s_ss_slider > li").removeClass("selected");
this.$el.find(".s_ss_slider_pagination > li").removeClass("selected");
var $slide = $slides.eq(n).addClass("selected");
$slides.removeClass("move-left");
$slide.prevAll().addClass("move-left");
this.$pagination.children().eq(n).addClass("selected");
this.updateNavigation();
},
updateNavigation: function () {
var $active = this.$el.find(".s_ss_slider > .selected");
this.$el.find(".s_ss_prev").toggleClass("inactive", $active.is(":first-child"));
this.$el.find(".s_ss_next").toggleClass("inactive", $active.is(":last-child"));
},
}); });
+2 -4
View File
@@ -1,7 +1,6 @@
odoo.define("theme_enark.tour.enark", function (require) { /** @odoo-module **/
"use strict";
const wTourUtils = require("website.tour_utils"); import wTourUtils from "website.tour_utils";
const snippets = [ const snippets = [
{ {
@@ -41,4 +40,3 @@ wTourUtils.registerThemeHomepageTour("enark_tour", [
wTourUtils.dragNDrop(snippets[4]), wTourUtils.dragNDrop(snippets[4]),
wTourUtils.dragNDrop(snippets[5]), wTourUtils.dragNDrop(snippets[5]),
]); ]);
});
+2 -4
View File
@@ -1,7 +1,6 @@
odoo.define("theme_graphene.tour.graphene", function (require) { /** @odoo-module **/
"use strict";
const wTourUtils = require("website.tour_utils"); import wTourUtils from "website.tour_utils";
const snippets = [ const snippets = [
{ {
@@ -43,4 +42,3 @@ wTourUtils.registerThemeHomepageTour("graphene_tour", [
wTourUtils.changeBackgroundColor('left'), wTourUtils.changeBackgroundColor('left'),
wTourUtils.selectColorPalette(), wTourUtils.selectColorPalette(),
]); ]);
});
+2 -4
View File
@@ -1,7 +1,6 @@
odoo.define("theme_real_estate.tour.real_estate", function (require) { /** @odoo-module **/
"use strict";
const wTourUtils = require("website.tour_utils"); import wTourUtils from "website.tour_utils";
const snippets = [ const snippets = [
{ {
@@ -65,4 +64,3 @@ wTourUtils.registerThemeHomepageTour("real_estate_tour", [
wTourUtils.dragNDrop(snippets[8]), wTourUtils.dragNDrop(snippets[8]),
wTourUtils.dragNDrop(snippets[9]), wTourUtils.dragNDrop(snippets[9]),
]); ]);
});
+2 -4
View File
@@ -1,7 +1,6 @@
odoo.define("theme_vehicle.tour.vehicle", function (require) { /** @odoo-module **/
"use strict";
const wTourUtils = require("website.tour_utils"); import wTourUtils from "website.tour_utils";
const snippets = [ const snippets = [
{ {
@@ -44,4 +43,3 @@ wTourUtils.registerThemeHomepageTour("vehicle_tour", [
wTourUtils.changeBackgroundColor(), wTourUtils.changeBackgroundColor(),
wTourUtils.selectColorPalette(), wTourUtils.selectColorPalette(),
]); ]);
});