diff options
Diffstat (limited to 'addons/web_editor/static/src/js/snippets.animation.js')
| -rw-r--r-- | addons/web_editor/static/src/js/snippets.animation.js | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/addons/web_editor/static/src/js/snippets.animation.js b/addons/web_editor/static/src/js/snippets.animation.js new file mode 100644 index 00000000000..b3fccc5584a --- /dev/null +++ b/addons/web_editor/static/src/js/snippets.animation.js @@ -0,0 +1,82 @@ +odoo.define('web_editor.snippets.animation', function (require) { +'use strict'; + +var Class = require('web.Class'); +var base = require('web_editor.base'); + +var registry = []; +var ready = []; + +var Animation = Class.extend({ + selector: false, + $: function () { + return this.$el.find.apply(this.$el, arguments); + }, + init: function (dom, editable_mode) { + this.$el = this.$target = $(dom); + this.start(editable_mode); + }, + /* + * start + * This method is called after init + */ + start: function (editable_mode) { + }, + /* + * stop + * This method is called to stop the animation (e.g.: when rte is launch) + */ + stop: function () { + }, +}); + +var start = function (editable_mode, $target) { + for (var k in registry) { + var Animation = registry[k]; + var selector = ""; + if (Animation.prototype.selector) { + if (selector != "") selector += ", " + selector += Animation.prototype.selector; + } + if ($target) { + if ($target.is(selector)) selector = $target; + else continue; + } + + $(selector).each(function() { + var $snipped_id = $(this); + if ( !$snipped_id.parents("#oe_snippets").length && + !$snipped_id.parent("body").length && + !$snipped_id.data("snippet-view")) { + ready.push($snipped_id); + $snipped_id.data("snippet-view", new Animation($snipped_id, editable_mode)); + } else if ($snipped_id.data("snippet-view")) { + $snipped_id.data("snippet-view").start(editable_mode); + } + }); + } +}; + +var stop = function () { + $(ready).each(function() { + var $snipped_id = $(this); + if ($snipped_id.data("snippet-view")) { + $snipped_id.data("snippet-view").stop(); + } + }); +}; + +base.ready(function () { + setTimeout(function () { + start(); + },0); +}); + +return { + 'Class': Class, + 'registry': registry, + 'start': start, + 'stop': stop +}; + +});
\ No newline at end of file |
