Skip to content

Commit

Permalink
[FIX] website, *: restore 'animation' system to the way it worked
Browse files Browse the repository at this point in the history
* website_forum

Following the new editor's merge at #29775,
the website 'animation' system was 'extended' to vaguely use a
'Registry' instance instead of an object. This was however left
undocumented, with a require in the middle of a file, restarting all
animations when used, only used by website_forum... with more code for
no reason at all, ...

This commit restores the system to the way it was before and re-adapts
website_forum:
- No need to check if website_forum is in the DOM as it is already
  checked by the animation system (on top of that... the new code was
  checking the DOM before it was ready...).
- No need of a dynamic add on a registry, this is always done before the
  DOM is ready, so before the animations are started.
- No need to know the root instance in website forum, just use the
  animation as the Wysiwyg instance's parent.

The goal of this commit is also to avoid useless conflicts with
#29442 (that should not have had any
conflict at all as totally independent of the editor task...)

closes #30478
  • Loading branch information
qsm-odoo committed Jan 24, 2019
1 parent 7a2394c commit a00e6f3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 21 deletions.
5 changes: 1 addition & 4 deletions addons/website/static/src/js/content/snippets.animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,7 @@ var Animation = Widget.extend({
/**
* The registry object contains the list of available animations.
*/
var Registry = require('web.Registry');
var registryObject = new Registry();
var registry = registryObject.map;
var registry = {};

registry.slider = Animation.extend({
selector: '.carousel',
Expand Down Expand Up @@ -1110,6 +1108,5 @@ registry.anchorSlide = Animation.extend({
return {
Class: Animation,
registry: registry,
registryObject: registryObject,
};
});
10 changes: 2 additions & 8 deletions addons/website/static/src/js/content/website_root.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ var WebsiteRoot = BodyManager.extend({
init: function () {
this._super.apply(this, arguments);
this.animations = [];
sAnimation.registryObject.onAdd(this._startMissingAnimations.bind(this));
},
/**
* @override
Expand Down Expand Up @@ -142,7 +141,7 @@ var WebsiteRoot = BodyManager.extend({
_startAnimations: function (editableMode, $from) {
var self = this;

this.startInEditableMode = editableMode || false;
editableMode = editableMode || false;
if ($from === undefined) {
$from = this.$('#wrapwrap');
}
Expand All @@ -154,19 +153,14 @@ var WebsiteRoot = BodyManager.extend({
var $target = $from.find(selector).addBack(selector);

var defs = _.map($target, function (el) {
var animation = new Animation(self, self.startInEditableMode);
var animation = new Animation(self, editableMode);
self.animations.push(animation);
return animation.attachTo($(el));
});
return $.when.apply($, defs);
});
return $.when.apply($, defs);
},
_startMissingAnimations: function () {
if (this.animations.length) {
this._startAnimations(this.startInEditableMode);
}
},
/**
* Destroys all animation instances. Especially needed before saving while
* in edition mode for example.
Expand Down
12 changes: 3 additions & 9 deletions addons/website_forum/static/src/js/website_forum.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,13 @@ odoo.define('website_forum.website_forum', function (require) {
var core = require('web.core');
var wContext = require('website.context');
var Wysiwyg = require('web_editor.wysiwyg');
var rootWidget = require('root.widget');
var sAnimations = require('website.content.snippets.animation');
var session = require('web.session');
var qweb = core.qweb;

var _t = core._t;


if (!$('.website_forum').length) {
return $.Deferred().reject("DOM doesn't contain '.website_forum'");
}

sAnimations.registryObject.add('websiteForum', sAnimations.Class.extend({
sAnimations.registry.websiteForum = sAnimations.Class.extend({
selector: '.website_forum',
xmlDependencies: ['/website_forum/static/src/xml/website_forum_share_templates.xml'],
read_events: {
Expand Down Expand Up @@ -155,7 +149,7 @@ sAnimations.registryObject.add('websiteForum', sAnimations.Class.extend({
MediaPlugin: false,
};
}
var wysiwyg = new Wysiwyg(rootWidget, options);
var wysiwyg = new Wysiwyg(self, options);
wysiwyg.attachTo($textarea).then(function () {
// float-left class messes up the post layout OPW 769721
$form.find('.note-editable').find('img.float-left').removeClass('float-left');
Expand Down Expand Up @@ -508,7 +502,7 @@ sAnimations.registryObject.add('websiteForum', sAnimations.Class.extend({
$('.forum_intro').slideUp();
return true;
},
}));
});

sAnimations.registry.websiteForumSpam = sAnimations.Class.extend({
selector: '.o_wforum_moderation_queue',
Expand Down

0 comments on commit a00e6f3

Please sign in to comment.