From ba55fcf1d0ae9d7c53a8d43f3e0a081a5fdf0472 Mon Sep 17 00:00:00 2001
From: "chm@openerp.com" <>
Date: Mon, 24 Mar 2014 14:01:19 +0100
Subject: [IMP] website: Building block / Snippet Editor Add documentation and
clean framework The building blocks appear in the edit bar website. These
prebuilt html block allowing the designer to easily generate content on a
page (drag and drop). Options allow snippets to add customizations party html
code according to their selector (jQuery) and javascript object.
bzr revid: chm@openerp.com-20140324130119-xbnejtayna8haykk
---
.../static/src/js/website.snippets.editor.js | 234 +++++++++++++++------
1 file changed, 165 insertions(+), 69 deletions(-)
(limited to 'addons/website/static/src/js/website.snippets.editor.js')
diff --git a/addons/website/static/src/js/website.snippets.editor.js b/addons/website/static/src/js/website.snippets.editor.js
index 1eee1fee65b..5af0b8ed0d4 100644
--- a/addons/website/static/src/js/website.snippets.editor.js
+++ b/addons/website/static/src/js/website.snippets.editor.js
@@ -1,6 +1,134 @@
(function () {
'use strict';
+/* Building block / Snippet Editor
+
+ The building blocks appear in the edit bar website. These prebuilt html block
+ allowing the designer to easily generate content on a page (drag and drop).
+ Options allow snippets to add customizations party html code according to their
+ selector (jQuery) and javascript object.
+
+ How to create content?
+
+ Designers can add their own html block in the "snippets" (/website/views/snippets.xml).
+ The block must be added in one of four menus (structure, content, feature or effect).
+ Structure:
+
+
+

+
...Block Name...
+
+
+ ...
+
+
+
+
+ How to create options?
+
+ Designers can add their own html block in the "snippet_options" (/website/views/snippets.xml).
+ Structure:
+
+
+ data-selector="..."
+ data-selector-siblings="..."
+ data-selector-children="..."
+ data-selector-vertical-children='...'>
+ ...
+
...
+ ...
+
+
+
+ How to create a javascript object for an options?
+
+ openerp.website.snippet.options["...option-id..."] = website.snippet.Option.extend({
+ // start is called when the user click into a block or when the user drop a block
+ // into the page (just after the init method).
+ // start is usually used to bind event.
+ //
+ // this.$target: block html inserted inside the page
+ // this.$el: html li list of this options
+ // this.$overlay: html editor overlay who content resize bar, customize menu...
+ start: function () {},
+
+
+ // onFocus is called when the user click inside the block inserted in page
+ // and when the user drop on block into the page
+ onFocus : function () {},
+
+
+ // onBlur is called when the user click outside the block inserted in page, if
+ // the block is focused
+ onBlur : function () {},
+
+
+ // on_clone is called when the snippet is duplicate
+ // @variables: $clone is allready inserted is the page
+ on_clone: function ($clone) {},
+
+
+ // on_remove is called when the snippet is removed (dom is removing after this tigger)
+ on_remove: function () {},
+
+
+ // drop_and_build_snippet is called just after that a thumbnail is drag and dropped
+ // into a drop zone. The content is already inserted in the page.
+ drop_and_build_snippet: function () {},
+
+ // select is called when a user select an item in the li list of options
+ // By default, if the li item have a data-value attribute, the data-vlue it's apply
+ // like a class to the html block (this.$target)
+ // @variables: next_previous = {$next, $prev}
+ // $next = next item selected or false
+ // $prev = previous item selected or false
+ select: function (event, next_previous) {}
+
+ // preview is called when a user is on mouse over or mouse out of an item
+ // variables: next_previous = {$next, $prev}
+ // $next = next item selected or false
+ // $prev = previous item selected or false
+ preview: function (event, next_previous) {}
+
+ // clean_for_save
+ // clean_for_save is called just before to save the vue
+ // Sometime it's important to remove or add some datas (contentEditable, added
+ // classes to a running animation...)
+ clean_for_save: function () {}
+ });
+
+
+ // 'snippet-dropped' is triggered on '#oe_snippets' whith $target as attribute when a snippet is dropped
+ // 'snippet-activated' is triggered on '#oe_snippets' (and on snippet) when a snippet is activated
+
+*/
+
+
var website = openerp.website;
website.add_template_file('/website/static/src/xml/website.snippets.xml');
@@ -56,9 +184,6 @@
}
});
- // 'snippet-dropped' is triggered on '#oe_snippets' whith $target as attribute when a snippet is dropped
- // 'snippet-activated' is triggered on '#oe_snippets' (and on snippet) when a snippet is activated
-
if (!website.snippet) website.snippet = {};
website.snippet.templateOptions = {};
website.snippet.globalSelector = "";
@@ -401,14 +526,14 @@
// drop_and_build_snippet
self.create_overlay($target);
if ($target.data("snippet-editor")) {
- $target.data("snippet-editor").drop_and_build_snippet($target);
+ $target.data("snippet-editor").drop_and_build_snippet();
}
for (var k in website.snippet.templateOptions) {
$target.find(website.snippet.templateOptions[k].selector).each(function () {
var $snippet = $(this);
self.create_overlay($snippet);
if ($snippet.data("snippet-editor")) {
- $snippet.data("snippet-editor").drop_and_build_snippet($snippet);
+ $snippet.data("snippet-editor").drop_and_build_snippet();
}
});
}
@@ -665,101 +790,72 @@
self.set_active();
self.$target.trigger("snippet-style-change", [self, np]);
},0);
- this.select(event, {'$next': $next, '$prev': $prev});
+ this.select({'$next': $next, '$prev': $prev});
} else {
setTimeout(function () {
self.$target.trigger("snippet-style-preview", [self, np]);
},0);
- this.preview(event, np);
+ this.preview(np);
}
},
- // start is call just after the init
+ /* set_active
+ * select and set item active or not (add highlight item and his parents)
+ * called before start
+ */
+ set_active: function () {
+ var self = this;
+ this.$el.find('li').removeClass("active");
+ var $active = this.$el.find('li[data-value]')
+ .filter(function () {
+ var $li = $(this);
+ return ($li.data('value') && self.$target.hasClass($li.data('value')));
+ })
+ .first()
+ .addClass("active");
+ this.$el.find('li:has(li[data-value].active)').addClass("active");
+ },
+
start: function () {
},
- /* onFocus
- * This method is called when the user click inside the snippet in the dom
- */
+
onFocus : function () {
},
- /* onFocus
- * This method is called when the user click outside the snippet in the dom, after a focus
- */
onBlur : function () {
},
- /* on_clone
- * This method is called when the snippet is cloned ($clone is allready inserted)
- */
on_clone: function ($clone) {
},
- /* on_remove
- * This method is called when the snippet is removed (dom is removing after this call)
- */
on_remove: function () {
},
- /*
- * drop_and_build_snippet
- * This method is called just after that a thumbnail is drag and dropped into a drop zone
- * (after the insertion of this.$body, if this.$body exists)
- */
- drop_and_build_snippet: function ($target) {
- },
- /* select
- * called when a user select an item
- * li must have data-value attribute
- * variables: np = {$next, $prev}
- * $next is false if they are no next item selected
- * $prev is false if they are no previous item selected
- */
- select: function (event, np) {
+ drop_and_build_snippet: function () {
+ },
+
+ select: function (np) {
var self = this;
// add or remove html class
- if (np.$prev) {
+ if (np.$prev && this.required) {
this.$target.removeClass(np.$prev.data('value' || ""));
}
if (np.$next) {
this.$target.addClass(np.$next.data('value') || "");
}
},
- /* preview
- * called when a user is on mouse over or mouse out of an item
- * variables: np = {$next, $prev}
- * $next is false if they are no next item selected
- * $prev is false if they are no previous item selected
- */
- preview: function (event, np) {
+
+ preview: function (np) {
var self = this;
// add or remove html class
- if (np.$prev) {
+ if (np.$prev && this.required) {
this.$target.removeClass(np.$prev.data('value') || "");
}
if (np.$next) {
this.$target.addClass(np.$next.data('value') || "");
}
},
- /* set_active
- * select and set item active or not (add highlight item and his parents)
- * called before start
- */
- set_active: function () {
- var self = this;
- this.$el.find('li').removeClass("active");
- var $active = this.$el.find('li[data-value]')
- .filter(function () {
- var $li = $(this);
- return ($li.data('value') && self.$target.hasClass($li.data('value')));
- })
- .first()
- .addClass("active");
- this.$el.find('li:has(li[data-value].active)').addClass("active");
- },
- /* clean_for_save
- * function called just before save vue
- */
+
clean_for_save: function () {
}
});
@@ -776,9 +872,9 @@
var src = this._get_bg();
this.$el.find("li[data-value].active.oe_custom_bg").data("src", src);
},
- select: function(event, np) {
+ select: function(np) {
var self = this;
- this._super(event, np);
+ this._super(np);
if (np.$next) {
if (np.$next.hasClass("oe_custom_bg")) {
var editor = new website.editor.ImageDialog();
@@ -803,8 +899,8 @@
this.$target.removeClass(np.$prev.data("value"));
}
},
- preview: function (event, np) {
- this._super(event, np);
+ preview: function (np) {
+ this._super(np);
if (np.$next) {
this._set_bg(np.$next.data("src"));
}
@@ -1539,9 +1635,9 @@
* This method is called just after that a thumbnail is drag and dropped into a drop zone
* (after the insertion of this.$body, if this.$body exists)
*/
- drop_and_build_snippet: function ($target) {
+ drop_and_build_snippet: function () {
for (var i in this.styles){
- this.styles[i].drop_and_build_snippet($target);
+ this.styles[i].drop_and_build_snippet();
}
},
--
cgit v1.2.3
From 449ca3ab1804559315b7f68f349d250a78f200c5 Mon Sep 17 00:00:00 2001
From: "chm@openerp.com" <>
Date: Mon, 24 Mar 2014 14:50:13 +0100
Subject: [IMP] website snippet: add example in documentation
bzr revid: chm@openerp.com-20140324135013-1fr3kznkw29wvca2
---
addons/website/static/src/js/website.snippets.editor.js | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
(limited to 'addons/website/static/src/js/website.snippets.editor.js')
diff --git a/addons/website/static/src/js/website.snippets.editor.js b/addons/website/static/src/js/website.snippets.editor.js
index 5af0b8ed0d4..51e49e166b6 100644
--- a/addons/website/static/src/js/website.snippets.editor.js
+++ b/addons/website/static/src/js/website.snippets.editor.js
@@ -5,7 +5,7 @@
The building blocks appear in the edit bar website. These prebuilt html block
allowing the designer to easily generate content on a page (drag and drop).
- Options allow snippets to add customizations party html code according to their
+ Options allow snippets to add customizations part html code according to their
selector (jQuery) and javascript object.
How to create content?
@@ -35,8 +35,10 @@
data-selector="..."
+ Apply options on all The part of html who
+ match with this jQuery selector.
+ E.g.: If the selector is div, all div will be selected
+ and can be highlighted and assigned an editor. -->
data-selector-siblings="..."
@@ -49,7 +51,7 @@
displayed vertically -->
...
...
--
cgit v1.2.3