2013-08-29 10:29:56 +00:00
|
|
|
(function () {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var website = openerp.website;
|
2013-10-29 16:11:28 +00:00
|
|
|
website.add_template_file('/website/static/src/xml/website.snippets.xml');
|
2013-09-06 15:04:08 +00:00
|
|
|
|
2013-08-29 10:29:56 +00:00
|
|
|
website.EditorBar.include({
|
2013-09-18 08:33:24 +00:00
|
|
|
start: function () {
|
|
|
|
var self = this;
|
2013-09-20 15:21:40 +00:00
|
|
|
$("[data-oe-model]").on('click', function (event) {
|
2013-09-18 08:33:24 +00:00
|
|
|
var $this = $(event.srcElement);
|
2013-10-01 14:38:17 +00:00
|
|
|
var tag = $this[0].tagName.toLowerCase();
|
2013-09-18 08:33:24 +00:00
|
|
|
if (!(tag === 'a' || tag === "button") && !$this.parents("a, button").length) {
|
|
|
|
self.$('[data-action="edit"]').parent().effect('bounce', {distance: 18, times: 5}, 250);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return this._super();
|
|
|
|
},
|
2013-09-06 15:04:08 +00:00
|
|
|
edit: function () {
|
2013-11-07 09:42:56 +00:00
|
|
|
var self = this;
|
2013-09-18 08:33:24 +00:00
|
|
|
$("body").off('click');
|
2013-10-04 10:41:33 +00:00
|
|
|
window.snippets = this.snippets = new website.snippet.BuildingBlock(this);
|
|
|
|
this.snippets.appendTo(this.$el);
|
2013-11-07 09:42:56 +00:00
|
|
|
|
2013-11-08 14:38:48 +00:00
|
|
|
this.on('rte:ready', this, function () {
|
2013-11-07 09:42:56 +00:00
|
|
|
self.snippets.$button.removeClass("hidden");
|
2013-11-08 14:38:48 +00:00
|
|
|
self.trigger('rte:snippets_ready');
|
2013-11-07 09:42:56 +00:00
|
|
|
});
|
|
|
|
|
2013-09-11 12:56:32 +00:00
|
|
|
return this._super.apply(this, arguments);
|
2013-09-09 13:28:00 +00:00
|
|
|
},
|
2013-09-12 11:51:30 +00:00
|
|
|
save: function () {
|
2013-09-23 09:51:22 +00:00
|
|
|
this.snippets.make_active(false);
|
2013-10-19 20:59:31 +00:00
|
|
|
|
2013-10-24 14:10:24 +00:00
|
|
|
// FIXME: call clean_for_save on all snippets of the page, not only modified ones
|
|
|
|
// important for banner of parallax that changes data automatically.
|
2013-10-15 15:43:51 +00:00
|
|
|
this.snippets.clean_for_save();
|
2013-09-16 11:28:34 +00:00
|
|
|
remove_added_snippet_id();
|
2013-09-12 11:51:30 +00:00
|
|
|
this._super();
|
|
|
|
},
|
2013-08-29 10:29:56 +00:00
|
|
|
});
|
|
|
|
|
2013-09-16 11:28:34 +00:00
|
|
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
hack_to_add_snippet_id();
|
|
|
|
$("[data-snippet-id]").each(function() {
|
|
|
|
var $snipped_id = $(this);
|
|
|
|
if (typeof $snipped_id.data("snippet-view") === 'undefined' &&
|
|
|
|
website.snippet.animationRegistry[$snipped_id.data("snippet-id")]) {
|
|
|
|
$snipped_id.data("snippet-view", new website.snippet.animationRegistry[$snipped_id.data("snippet-id")]($snipped_id));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2013-08-29 10:29:56 +00:00
|
|
|
/* ----- SNIPPET SELECTOR ---- */
|
2013-11-08 14:38:48 +00:00
|
|
|
|
2013-09-06 15:04:08 +00:00
|
|
|
website.snippet = {};
|
2013-10-16 12:37:08 +00:00
|
|
|
var observer = new website.Observer(function (mutations) {
|
|
|
|
if (!_(mutations).find(function (m) {
|
|
|
|
return m.type === 'childList' && m.addedNodes.length > 0;
|
|
|
|
})) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
hack_to_add_snippet_id()
|
|
|
|
});
|
2013-09-16 11:28:34 +00:00
|
|
|
|
2013-09-09 13:28:00 +00:00
|
|
|
// puts $el at the same absolute position as $target
|
2013-09-12 17:06:52 +00:00
|
|
|
function hack_to_add_snippet_id () {
|
|
|
|
_.each(website.snippet.selector, function (val) {
|
|
|
|
$(val[0]).each(function() {
|
2013-09-16 11:28:34 +00:00
|
|
|
if (!$(this).is("[data-snippet-id]") && $(this).parents("[data-oe-model]").length) {
|
2013-09-12 17:06:52 +00:00
|
|
|
$(this).attr("data-snippet-id", val[1]);
|
2013-09-16 11:28:34 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function remove_added_snippet_id () {
|
|
|
|
_.each(website.snippet.selector, function (val) {
|
|
|
|
$(val[0]).each(function() {
|
2013-09-17 11:00:43 +00:00
|
|
|
if ($(this).data("snippet-id") === val[1]) {
|
2013-09-16 11:28:34 +00:00
|
|
|
$(this).removeAttr("data-snippet-id");
|
|
|
|
}
|
2013-09-12 17:06:52 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
website.snippet.selector = [];
|
2013-09-06 15:04:08 +00:00
|
|
|
website.snippet.BuildingBlock = openerp.Widget.extend({
|
2013-08-29 10:29:56 +00:00
|
|
|
template: 'website.snippets',
|
2013-09-12 11:51:30 +00:00
|
|
|
activeSnippets: [],
|
2013-09-09 13:28:00 +00:00
|
|
|
init: function (parent) {
|
|
|
|
this.parent = parent;
|
2013-08-29 10:29:56 +00:00
|
|
|
this._super.apply(this, arguments);
|
2013-09-21 09:51:16 +00:00
|
|
|
if(!$('#oe_manipulators').length){
|
|
|
|
$("<div id='oe_manipulators'></div>").appendTo('body');
|
|
|
|
}
|
2013-09-11 12:56:32 +00:00
|
|
|
this.$active_snipped_id = false;
|
2013-09-12 17:06:52 +00:00
|
|
|
hack_to_add_snippet_id();
|
2013-10-15 15:43:51 +00:00
|
|
|
this.snippets = [];
|
2013-10-16 12:37:08 +00:00
|
|
|
|
|
|
|
observer.observe(document.body, {
|
|
|
|
childList: true,
|
|
|
|
subtree: true,
|
|
|
|
});
|
2013-08-29 10:29:56 +00:00
|
|
|
},
|
2013-10-04 10:41:33 +00:00
|
|
|
dom_filter: function (dom, sibling) {
|
2013-09-17 07:48:47 +00:00
|
|
|
if (typeof dom === "string") {
|
2013-09-20 15:21:40 +00:00
|
|
|
var include = "[data-oe-model]";
|
2013-09-17 07:48:47 +00:00
|
|
|
var sdom = dom.split(',');
|
|
|
|
dom = "";
|
|
|
|
_.each(sdom, function (val) {
|
|
|
|
val = val.replace(/^\s+|\s+$/g, '');
|
2013-10-04 10:41:33 +00:00
|
|
|
dom += include + " " + val + ", ";
|
|
|
|
if (!sibling) {
|
|
|
|
val = val.split(" ");
|
|
|
|
dom += val.shift() + include + val.join(" ") + ", ";
|
|
|
|
}
|
2013-09-17 07:48:47 +00:00
|
|
|
});
|
|
|
|
dom = dom.replace(/,\s*$/g, '');
|
|
|
|
return $(dom);
|
|
|
|
} else {
|
2013-10-04 10:41:33 +00:00
|
|
|
return (!sibling && $(dom).is("[data-oe-model]")) || $(dom).parents("[data-oe-model]").length ? $(dom) : $("");
|
2013-09-17 07:48:47 +00:00
|
|
|
}
|
2013-09-16 12:29:42 +00:00
|
|
|
},
|
2013-08-29 10:29:56 +00:00
|
|
|
start: function() {
|
|
|
|
var self = this;
|
|
|
|
|
2013-11-07 09:42:56 +00:00
|
|
|
this.$button = $(openerp.qweb.render('website.snippets_button'))
|
|
|
|
.prependTo(this.parent.$("#website-top-edit ul"))
|
|
|
|
.find("button");
|
2013-09-19 10:20:14 +00:00
|
|
|
|
2013-11-07 09:42:56 +00:00
|
|
|
this.$button.click(function () {
|
2013-09-23 09:51:22 +00:00
|
|
|
self.make_active(false);
|
|
|
|
self.$el.toggleClass("hidden");
|
|
|
|
});
|
2013-09-19 10:20:14 +00:00
|
|
|
|
|
|
|
this.fetch_snippet_templates();
|
|
|
|
|
|
|
|
this.bind_snippet_click_editor();
|
|
|
|
|
|
|
|
this.$el.addClass("hidden");
|
2013-09-19 13:50:01 +00:00
|
|
|
|
|
|
|
this.$modal = $(openerp.qweb.render('website.snippets_modal'));
|
|
|
|
this.$modal.appendTo("body");
|
2013-09-19 10:20:14 +00:00
|
|
|
},
|
|
|
|
fetch_snippet_templates: function () {
|
|
|
|
var self = this;
|
2013-09-19 12:32:06 +00:00
|
|
|
this.style_templates = {};
|
2013-09-19 10:20:14 +00:00
|
|
|
|
2013-10-04 10:41:33 +00:00
|
|
|
openerp.jsonRpc("/website/snippets", 'call', {})
|
|
|
|
.then(function (html) {
|
|
|
|
var $html = $(html);
|
|
|
|
|
|
|
|
var $styles = $html.find("#snippet_styles");
|
|
|
|
$styles.find("> [data-snippet-id]").each(function () {
|
|
|
|
var $style = $(this);
|
|
|
|
var snipped_id = $style.data('snippet-id');
|
|
|
|
self.style_templates[snipped_id] = {
|
|
|
|
'snipped-id' : snipped_id,
|
|
|
|
'selector': $style.data('selector'),
|
|
|
|
'class': $style.find(".oe_snippet_class").text(),
|
|
|
|
'label': $style.find(".oe_snippet_label").text()
|
|
|
|
};
|
|
|
|
});
|
|
|
|
$styles.remove();
|
2013-09-18 15:48:31 +00:00
|
|
|
|
2013-10-04 10:41:33 +00:00
|
|
|
self.$snippets = $html.find(".tab-content > div > div").addClass("oe_snippet");
|
|
|
|
self.$el.append($html);
|
2013-09-18 15:48:31 +00:00
|
|
|
|
2013-10-04 10:41:33 +00:00
|
|
|
self.make_snippet_draggable(self.$snippets);
|
|
|
|
});
|
2013-09-16 11:28:34 +00:00
|
|
|
},
|
|
|
|
cover_target: function ($el, $target){
|
2013-09-17 11:00:43 +00:00
|
|
|
var pos = $target.offset();
|
|
|
|
var mt = parseInt($target.css("margin-top") || 0);
|
|
|
|
var mb = parseInt($target.css("margin-bottom") || 0);
|
2013-09-16 11:28:34 +00:00
|
|
|
$el.css({
|
|
|
|
'position': 'absolute',
|
2013-09-17 13:31:44 +00:00
|
|
|
'width': $target.outerWidth(),
|
2013-09-17 11:00:43 +00:00
|
|
|
'height': $target.outerHeight() + mt + mb,
|
|
|
|
'top': pos.top - mt,
|
2013-09-17 13:31:44 +00:00
|
|
|
'left': pos.left
|
2013-09-16 11:28:34 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
show: function () {
|
2013-09-18 15:48:31 +00:00
|
|
|
this.$el.removeClass("hidden");
|
2013-09-16 11:28:34 +00:00
|
|
|
},
|
|
|
|
hide: function () {
|
2013-09-18 15:48:31 +00:00
|
|
|
this.$el.addClass("hidden");
|
2013-09-11 12:56:32 +00:00
|
|
|
},
|
2013-09-09 13:28:00 +00:00
|
|
|
|
2013-09-11 12:56:32 +00:00
|
|
|
bind_snippet_click_editor: function () {
|
|
|
|
var self = this;
|
|
|
|
var snipped_event_flag = false;
|
2013-10-03 14:34:29 +00:00
|
|
|
$("body").on('click', "[data-oe-model] [data-snippet-id], [data-oe-model][data-snippet-id]", function (event) {
|
2013-09-21 09:51:16 +00:00
|
|
|
if (snipped_event_flag) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
snipped_event_flag = true;
|
|
|
|
setTimeout(function () {snipped_event_flag = false;}, 0);
|
|
|
|
var $target = $(event.currentTarget);
|
|
|
|
if (self.$active_snipped_id && self.$active_snipped_id.is($target)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-09-11 12:56:32 +00:00
|
|
|
self.make_active($target);
|
2013-09-21 09:51:16 +00:00
|
|
|
});
|
2013-10-22 15:11:44 +00:00
|
|
|
$("[data-oe-model]").on('click', function () {
|
2013-09-21 09:51:16 +00:00
|
|
|
if (!snipped_event_flag && self.$active_snipped_id && !self.$active_snipped_id.parents("[data-snippet-id]:first")) {
|
|
|
|
self.make_active(false);
|
|
|
|
}
|
|
|
|
});
|
2013-09-11 12:56:32 +00:00
|
|
|
},
|
|
|
|
snippet_blur: function ($snipped_id) {
|
|
|
|
if ($snipped_id) {
|
|
|
|
if ($snipped_id.data("snippet-editor")) {
|
|
|
|
$snipped_id.data("snippet-editor").onBlur();
|
|
|
|
}
|
|
|
|
if ($snipped_id.data("snippet-view")) {
|
|
|
|
$snipped_id.data("snippet-view").onBlurEdit();
|
|
|
|
}
|
|
|
|
}
|
2013-08-29 10:29:56 +00:00
|
|
|
},
|
2013-09-11 12:56:32 +00:00
|
|
|
snippet_focus: function ($snipped_id) {
|
|
|
|
if ($snipped_id) {
|
|
|
|
if ($snipped_id.data("snippet-view")) {
|
|
|
|
$snipped_id.data("snippet-view").onFocusEdit();
|
|
|
|
}
|
|
|
|
if ($snipped_id.data("snippet-editor")) {
|
|
|
|
$snipped_id.data("snippet-editor").onFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2013-10-15 15:43:51 +00:00
|
|
|
clean_for_save: function () {
|
|
|
|
for (var k in this.snippets) {
|
2013-10-22 15:11:44 +00:00
|
|
|
if (!this.snippets.hasOwnProperty(k)) { continue; }
|
2013-10-16 07:36:30 +00:00
|
|
|
var editor = $(this.snippets[k]).data("snippet-editor");
|
|
|
|
if (editor) {
|
|
|
|
editor.clean_for_save();
|
|
|
|
}
|
2013-10-15 15:43:51 +00:00
|
|
|
}
|
|
|
|
},
|
2013-09-11 12:56:32 +00:00
|
|
|
make_active: function ($snipped_id) {
|
|
|
|
if ($snipped_id && this.$active_snipped_id && this.$active_snipped_id.get(0) === $snipped_id.get(0)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this.$active_snipped_id) {
|
|
|
|
this.snippet_blur(this.$active_snipped_id);
|
2013-11-06 16:39:27 +00:00
|
|
|
this.$active_snipped_id = false;
|
2013-09-11 12:56:32 +00:00
|
|
|
}
|
|
|
|
if ($snipped_id) {
|
2013-10-15 15:43:51 +00:00
|
|
|
if(_.indexOf(this.snippets, $snipped_id.get(0)) === -1) {
|
|
|
|
this.snippets.push($snipped_id.get(0));
|
|
|
|
}
|
2013-09-11 12:56:32 +00:00
|
|
|
this.$active_snipped_id = $snipped_id;
|
|
|
|
this.create_overlay(this.$active_snipped_id);
|
|
|
|
this.snippet_focus($snipped_id);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
create_overlay: function ($snipped_id) {
|
|
|
|
if (typeof $snipped_id.data("snippet-editor") === 'undefined') {
|
2013-10-04 10:41:33 +00:00
|
|
|
var $targets = this.activate_overlay_zones($snipped_id);
|
|
|
|
if (!$targets.length) return;
|
2013-09-16 11:28:34 +00:00
|
|
|
var editor = website.snippet.editorRegistry[$snipped_id.data("snippet-id")] || website.snippet.editorRegistry.resize;
|
2013-09-11 12:56:32 +00:00
|
|
|
$snipped_id.data("snippet-editor", new editor(this, $snipped_id));
|
|
|
|
}
|
2013-09-16 11:28:34 +00:00
|
|
|
this.cover_target($snipped_id.data('overlay'), $snipped_id);
|
2013-09-11 12:56:32 +00:00
|
|
|
},
|
|
|
|
|
2013-08-29 10:29:56 +00:00
|
|
|
path_eval: function(path){
|
|
|
|
var obj = window;
|
|
|
|
path = path.split('.');
|
|
|
|
do{
|
|
|
|
obj = obj[path.shift()];
|
|
|
|
}while(path.length && obj);
|
|
|
|
return obj;
|
|
|
|
},
|
|
|
|
|
2013-09-06 15:04:08 +00:00
|
|
|
// activate drag and drop for the snippets in the snippet toolbar
|
2013-10-04 10:41:33 +00:00
|
|
|
make_snippet_draggable: function($snippets){
|
2013-08-29 10:29:56 +00:00
|
|
|
var self = this;
|
2013-10-04 10:41:33 +00:00
|
|
|
var $tumb = $snippets.find(".oe_snippet_thumbnail:first");
|
|
|
|
var left = $tumb.outerWidth()/2;
|
|
|
|
var top = $tumb.outerHeight()/2;
|
2013-10-07 11:36:20 +00:00
|
|
|
var $toInsert, dropped, $snippet, action, snipped_id;
|
2013-08-29 10:29:56 +00:00
|
|
|
|
2013-10-04 10:41:33 +00:00
|
|
|
$snippets.draggable({
|
2013-09-19 13:57:16 +00:00
|
|
|
greedy: true,
|
2013-08-29 10:29:56 +00:00
|
|
|
helper: 'clone',
|
|
|
|
zIndex: '1000',
|
|
|
|
appendTo: 'body',
|
2013-09-13 09:35:18 +00:00
|
|
|
cursor: "move",
|
2013-09-18 15:54:40 +00:00
|
|
|
handle: ".oe_snippet_thumbnail",
|
|
|
|
cursorAt: {
|
2013-10-04 10:41:33 +00:00
|
|
|
'left': left,
|
|
|
|
'top': top
|
2013-09-18 15:54:40 +00:00
|
|
|
},
|
2013-08-29 10:29:56 +00:00
|
|
|
start: function(){
|
2013-09-20 09:19:17 +00:00
|
|
|
self.hide();
|
2013-09-19 13:50:01 +00:00
|
|
|
dropped = false;
|
2013-10-04 10:41:33 +00:00
|
|
|
$snippet = $(this);
|
2013-10-07 11:36:20 +00:00
|
|
|
snipped_id = $snippet.data('snippet-id');
|
|
|
|
action = $snippet.find('.oe_snippet_body').size() ? 'insert' : 'mutate';
|
2013-08-29 10:29:56 +00:00
|
|
|
if( action === 'insert'){
|
2013-09-16 12:32:57 +00:00
|
|
|
if (!$snippet.data('selector-siblings') && !$snippet.data('selector-children') && !$snippet.data('selector-vertical-children')) {
|
2013-09-16 08:57:55 +00:00
|
|
|
console.debug($snippet.data("snippet-id") + " have oe_snippet_body class and have not for insert action"+
|
2013-09-16 12:32:57 +00:00
|
|
|
"data-selector-siblings, data-selector-children or data-selector-vertical-children tag for mutate action");
|
2013-09-16 08:57:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2013-08-29 10:29:56 +00:00
|
|
|
self.activate_insertion_zones({
|
2013-09-06 15:04:08 +00:00
|
|
|
siblings: $snippet.data('selector-siblings'),
|
2013-09-16 12:32:57 +00:00
|
|
|
children: $snippet.data('selector-children'),
|
|
|
|
vertical_children: $snippet.data('selector-vertical-children')
|
2013-08-29 10:29:56 +00:00
|
|
|
});
|
2013-09-11 12:56:32 +00:00
|
|
|
|
2013-09-17 07:18:06 +00:00
|
|
|
$toInsert = $snippet.find('.oe_snippet_body').clone();
|
|
|
|
$toInsert.removeClass('oe_snippet_body');
|
|
|
|
$toInsert.attr('data-snippet-id', snipped_id);
|
|
|
|
|
2013-09-16 08:57:55 +00:00
|
|
|
} else if( action === 'mutate' ){
|
|
|
|
if (!$snippet.data('selector')) {
|
|
|
|
console.debug($snippet.data("snippet-id") + " have not oe_snippet_body class and have not data-selector tag");
|
|
|
|
return;
|
|
|
|
}
|
2013-09-11 12:56:32 +00:00
|
|
|
var $targets = self.activate_overlay_zones($snippet.data('selector'));
|
|
|
|
$targets.each(function(){
|
|
|
|
var $clone = $(this).data('overlay').clone();
|
|
|
|
$clone.addClass("oe_drop_zone").data('target', $(this));
|
|
|
|
$(this).data('overlay').after($clone);
|
|
|
|
});
|
|
|
|
|
2013-08-29 10:29:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$('.oe_drop_zone').droppable({
|
|
|
|
over: function(){
|
2013-09-17 07:18:06 +00:00
|
|
|
if( action === 'insert'){
|
2013-09-20 09:19:17 +00:00
|
|
|
dropped = true;
|
2013-10-17 14:19:59 +00:00
|
|
|
$(this).first().after($toInsert);
|
2013-09-17 07:18:06 +00:00
|
|
|
}
|
2013-08-29 10:29:56 +00:00
|
|
|
},
|
|
|
|
out: function(){
|
2013-09-17 07:18:06 +00:00
|
|
|
if( action === 'insert'){
|
2013-09-20 09:19:17 +00:00
|
|
|
dropped = false;
|
2013-09-17 07:18:06 +00:00
|
|
|
$toInsert.detach();
|
|
|
|
}
|
2013-08-29 10:29:56 +00:00
|
|
|
},
|
|
|
|
drop: function(){
|
2013-09-19 13:50:01 +00:00
|
|
|
dropped = true;
|
2013-08-29 10:29:56 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
2013-10-12 08:44:52 +00:00
|
|
|
stop: function(ev, ui){
|
2013-10-21 15:01:24 +00:00
|
|
|
if (action === 'insert' && ! dropped) {
|
2013-10-22 15:11:44 +00:00
|
|
|
var $el = $('.oe_drop_zone').nearest({x: ui.position.left, y: ui.position.top}).first();
|
|
|
|
if ($el) {
|
|
|
|
$el.after($toInsert);
|
2013-10-21 15:01:24 +00:00
|
|
|
dropped = true;
|
|
|
|
}
|
|
|
|
}
|
2013-10-17 14:19:59 +00:00
|
|
|
|
2013-09-11 12:56:32 +00:00
|
|
|
$('.oe_drop_zone').droppable('destroy').remove();
|
2013-10-07 11:36:20 +00:00
|
|
|
if (dropped) {
|
|
|
|
var $target = false;
|
|
|
|
if(action === 'insert'){
|
|
|
|
$target = $toInsert;
|
|
|
|
|
|
|
|
if (website.snippet.animationRegistry[snipped_id]) {
|
|
|
|
new website.snippet.animationRegistry[snipped_id]($target);
|
|
|
|
}
|
|
|
|
|
|
|
|
self.create_overlay($target);
|
2013-11-06 13:39:17 +00:00
|
|
|
$target.data("snippet-editor").drop_and_build_snippet($target);
|
2013-10-07 11:36:20 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
$target = $(this).data('target');
|
|
|
|
|
|
|
|
self.create_overlay($target);
|
|
|
|
if (website.snippet.editorRegistry[snipped_id]) {
|
|
|
|
var snippet = new website.snippet.editorRegistry[snipped_id](self, $target);
|
2013-11-06 13:39:17 +00:00
|
|
|
snippet.drop_and_build_snippet($target);
|
2013-10-07 11:36:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
setTimeout(function () {self.make_active($target);},0);
|
|
|
|
} else {
|
|
|
|
$toInsert.remove();
|
|
|
|
if (self.$modal.find('input:not(:checked)').length) {
|
|
|
|
self.$modal.modal('toggle');
|
|
|
|
}
|
2013-09-19 13:50:01 +00:00
|
|
|
}
|
2013-08-29 10:29:56 +00:00
|
|
|
},
|
|
|
|
});
|
2013-09-06 15:04:08 +00:00
|
|
|
},
|
2013-08-29 10:29:56 +00:00
|
|
|
|
2013-09-06 15:04:08 +00:00
|
|
|
// return the original snippet in the editor bar from a snippet id (string)
|
|
|
|
get_snippet_from_id: function(id){
|
|
|
|
return $('.oe_snippet').filter(function(){
|
|
|
|
return $(this).data('snippet-id') === id;
|
|
|
|
}).first();
|
2013-08-29 10:29:56 +00:00
|
|
|
},
|
2013-09-06 15:04:08 +00:00
|
|
|
|
2013-08-29 10:29:56 +00:00
|
|
|
// Create element insertion drop zones. two css selectors can be provided
|
2013-09-16 12:32:57 +00:00
|
|
|
// selector.children -> will insert drop zones as direct child of the selected elements
|
2013-08-29 10:29:56 +00:00
|
|
|
// in case the selected elements have children themselves, dropzones will be interleaved
|
|
|
|
// with them.
|
|
|
|
// selector.siblings -> will insert drop zones after and before selected elements
|
|
|
|
activate_insertion_zones: function(selector){
|
|
|
|
var self = this;
|
2013-09-16 12:32:57 +00:00
|
|
|
var child_selector = selector.children;
|
2013-09-16 12:29:42 +00:00
|
|
|
var sibling_selector = selector.siblings;
|
2013-09-16 12:32:57 +00:00
|
|
|
var vertical_child_selector = selector.vertical_children;
|
2013-09-13 10:19:11 +00:00
|
|
|
|
2013-10-17 14:19:59 +00:00
|
|
|
var zone_template = "<div class='oe_drop_zone oe_insert'></div>";
|
2013-08-29 10:29:56 +00:00
|
|
|
|
|
|
|
if(child_selector){
|
2013-09-16 12:29:42 +00:00
|
|
|
self.dom_filter(child_selector).each(function (){
|
2013-09-13 10:19:11 +00:00
|
|
|
var $zone = $(this);
|
|
|
|
$zone.find('> *:not(.oe_drop_zone):visible').after(zone_template);
|
|
|
|
$zone.prepend(zone_template);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if(vertical_child_selector){
|
2013-09-16 12:29:42 +00:00
|
|
|
self.dom_filter(vertical_child_selector).each(function (){
|
2013-09-13 10:19:11 +00:00
|
|
|
var $zone = $(this);
|
2013-09-20 10:30:35 +00:00
|
|
|
var $template = $(zone_template).addClass("oe_vertical");
|
2013-09-20 10:26:00 +00:00
|
|
|
var nb = 0;
|
2013-09-20 13:01:22 +00:00
|
|
|
var $lastinsert = false;
|
|
|
|
var left = 0;
|
|
|
|
var temp_left = 0;
|
2013-09-20 10:26:00 +00:00
|
|
|
$zone.find('> *:not(.oe_drop_zone):visible').each(function () {
|
2013-09-20 10:30:35 +00:00
|
|
|
var $col = $(this);
|
2013-10-17 14:19:59 +00:00
|
|
|
$template.css('height', ($col.outerHeight() + parseInt($col.css("margin-top")) + parseInt($col.css("margin-bottom")))+'px');
|
2013-09-20 13:01:22 +00:00
|
|
|
$lastinsert = $template.clone();
|
|
|
|
$(this).after($lastinsert);
|
|
|
|
|
|
|
|
temp_left = $col.position().left;
|
|
|
|
if (left === temp_left) {
|
|
|
|
$col.prev(".oe_drop_zone.oe_vertical").remove();
|
|
|
|
$col.before($template.clone().css("clear", "left"));
|
|
|
|
}
|
|
|
|
else if (!nb) {
|
|
|
|
$col.before($template.clone());
|
2013-09-20 10:26:00 +00:00
|
|
|
}
|
2013-09-20 13:01:22 +00:00
|
|
|
left = temp_left;
|
2013-09-20 10:26:00 +00:00
|
|
|
nb ++;
|
|
|
|
});
|
|
|
|
if (!nb) {
|
2013-09-20 10:30:35 +00:00
|
|
|
$zone.prepend($template.css('height', $zone.outerHeight()+'px'));
|
2013-09-20 10:26:00 +00:00
|
|
|
}
|
2013-09-13 10:19:11 +00:00
|
|
|
});
|
2013-08-29 10:29:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(sibling_selector){
|
2013-10-04 10:41:33 +00:00
|
|
|
self.dom_filter(sibling_selector, true).each(function (){
|
2013-09-13 10:19:11 +00:00
|
|
|
var $zone = $(this);
|
|
|
|
if($zone.prev('.oe_drop_zone:visible').length === 0){
|
|
|
|
$zone.before(zone_template);
|
2013-08-29 10:29:56 +00:00
|
|
|
}
|
2013-09-13 10:19:11 +00:00
|
|
|
if($zone.next('.oe_drop_zone:visible').length === 0){
|
|
|
|
$zone.after(zone_template);
|
2013-08-29 10:29:56 +00:00
|
|
|
}
|
2013-09-13 10:19:11 +00:00
|
|
|
});
|
2013-08-29 10:29:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var count;
|
|
|
|
do {
|
|
|
|
count = 0;
|
2013-09-20 13:01:22 +00:00
|
|
|
// var $zones = $('.oe_drop_zone + .oe_drop_zone'); // no two consecutive zones
|
|
|
|
// count += $zones.length;
|
|
|
|
// $zones.remove();
|
2013-08-29 10:29:56 +00:00
|
|
|
|
2013-10-22 15:11:44 +00:00
|
|
|
$zones = $('.oe_drop_zone > .oe_drop_zone:not(.oe_vertical)').remove(); // no recursive zones
|
2013-08-29 10:29:56 +00:00
|
|
|
count += $zones.length;
|
|
|
|
$zones.remove();
|
2013-09-13 10:19:11 +00:00
|
|
|
} while (count > 0);
|
2013-08-29 10:29:56 +00:00
|
|
|
|
|
|
|
// Cleaning up zones placed between floating or inline elements. We do not like these kind of zones.
|
2013-09-13 10:19:11 +00:00
|
|
|
var $zones = $('.oe_drop_zone:not(.oe_vertical)');
|
|
|
|
$zones.each(function (){
|
|
|
|
var zone = $(this);
|
2013-08-29 10:29:56 +00:00
|
|
|
var prev = zone.prev();
|
|
|
|
var next = zone.next();
|
2013-10-22 15:11:44 +00:00
|
|
|
var float_prev = prev.css('float') || 'none';
|
|
|
|
var float_next = next.css('float') || 'none';
|
|
|
|
var disp_prev = prev.css('display') || null;
|
|
|
|
var disp_next = next.css('display') || null;
|
2013-08-29 10:29:56 +00:00
|
|
|
if( (float_prev === 'left' || float_prev === 'right')
|
|
|
|
&& (float_next === 'left' || float_next === 'right') ){
|
|
|
|
zone.remove();
|
|
|
|
}else if( !( disp_prev === null
|
|
|
|
|| disp_next === null
|
|
|
|
|| disp_prev === 'block'
|
|
|
|
|| disp_next === 'block' )){
|
|
|
|
zone.remove();
|
|
|
|
}
|
2013-09-13 10:19:11 +00:00
|
|
|
});
|
2013-08-29 10:29:56 +00:00
|
|
|
},
|
|
|
|
|
2013-09-06 15:04:08 +00:00
|
|
|
// generate drop zones covering the elements selected by the selector
|
2013-09-11 12:56:32 +00:00
|
|
|
// we generate overlay drop zones only to get an idea of where the snippet are, the drop
|
2013-08-29 10:29:56 +00:00
|
|
|
activate_overlay_zones: function(selector){
|
2013-09-16 12:29:42 +00:00
|
|
|
var $targets = this.dom_filter(selector || '[data-snippet-id]');
|
2013-09-16 11:28:34 +00:00
|
|
|
var self = this;
|
2013-10-04 10:41:33 +00:00
|
|
|
|
|
|
|
if (typeof selector !== 'string' && !$targets.length) {
|
|
|
|
console.debug( "A good node must have a [data-oe-model] attribute or must have at least one parent with [data-oe-model] attribute.");
|
|
|
|
console.debug( "Wrong node(s): ", selector);
|
|
|
|
}
|
2013-11-08 14:38:48 +00:00
|
|
|
|
2013-08-29 10:29:56 +00:00
|
|
|
function is_visible($el){
|
|
|
|
return $el.css('display') != 'none'
|
|
|
|
&& $el.css('opacity') != '0'
|
|
|
|
&& $el.css('visibility') != 'hidden';
|
|
|
|
}
|
|
|
|
|
|
|
|
// filter out invisible elements
|
|
|
|
$targets = $targets.filter(function(){ return is_visible($(this)); });
|
|
|
|
|
|
|
|
// filter out elements with invisible parents
|
|
|
|
$targets = $targets.filter(function(){
|
|
|
|
var parents = $(this).parents().filter(function(){ return !is_visible($(this)); });
|
|
|
|
return parents.length === 0;
|
|
|
|
});
|
2013-11-08 14:38:48 +00:00
|
|
|
|
2013-09-11 12:56:32 +00:00
|
|
|
$targets.each(function () {
|
|
|
|
var $target = $(this);
|
|
|
|
if (!$target.data('overlay')) {
|
2013-09-12 14:53:02 +00:00
|
|
|
var $zone = $(openerp.qweb.render('website.snippet_overlay'));
|
2013-09-11 12:56:32 +00:00
|
|
|
$zone.appendTo('#oe_manipulators');
|
|
|
|
$zone.data('target',$target);
|
|
|
|
$target.data('overlay',$zone);
|
|
|
|
|
|
|
|
$target.on("DOMNodeInserted DOMNodeRemoved DOMSubtreeModified", function () {
|
2013-09-16 11:28:34 +00:00
|
|
|
self.cover_target($zone, $target);
|
|
|
|
});
|
|
|
|
$('body').on("resize", function () {
|
|
|
|
self.cover_target($zone, $target);
|
2013-09-11 12:56:32 +00:00
|
|
|
});
|
|
|
|
}
|
2013-09-16 11:28:34 +00:00
|
|
|
self.cover_target($target.data('overlay'), $target);
|
2013-09-06 15:04:08 +00:00
|
|
|
});
|
2013-09-11 12:56:32 +00:00
|
|
|
return $targets;
|
2013-09-16 11:28:34 +00:00
|
|
|
}
|
2013-08-29 10:29:56 +00:00
|
|
|
});
|
2013-09-06 15:04:08 +00:00
|
|
|
|
|
|
|
|
2013-09-09 13:28:00 +00:00
|
|
|
website.snippet.animationRegistry = {};
|
|
|
|
website.snippet.Animation = openerp.Class.extend({
|
2013-09-06 15:04:08 +00:00
|
|
|
$: function () {
|
|
|
|
return this.$el.find.apply(this.$el, arguments);
|
|
|
|
},
|
|
|
|
init: function (dom) {
|
2013-09-12 17:06:52 +00:00
|
|
|
this.$el = this.$target = $(dom);
|
2013-09-16 09:17:01 +00:00
|
|
|
this.start();
|
|
|
|
},
|
|
|
|
/*
|
|
|
|
* start
|
|
|
|
* This method is called after init
|
|
|
|
*/
|
|
|
|
start: function () {
|
2013-09-06 15:04:08 +00:00
|
|
|
},
|
|
|
|
/* onFocusEdit
|
2013-11-08 14:38:48 +00:00
|
|
|
* if they are an editor for this data-snippet-id
|
2013-09-06 15:04:08 +00:00
|
|
|
* Called before onFocus of snippet editor
|
|
|
|
*/
|
|
|
|
onFocusEdit : function () {},
|
|
|
|
|
|
|
|
/* onBlurEdit
|
2013-11-08 14:38:48 +00:00
|
|
|
* if they are an editor for this data-snippet-id
|
2013-09-06 15:04:08 +00:00
|
|
|
* Called after onBlur of snippet editor
|
|
|
|
*/
|
|
|
|
onBlurEdit : function () {},
|
|
|
|
});
|
|
|
|
|
|
|
|
website.snippet.editorRegistry = {};
|
2013-09-10 10:21:40 +00:00
|
|
|
website.snippet.Editor = openerp.Class.extend({
|
2013-09-06 15:04:08 +00:00
|
|
|
init: function (parent, dom) {
|
|
|
|
this.parent = parent;
|
2013-09-11 12:56:32 +00:00
|
|
|
this.$target = $(dom);
|
|
|
|
this.$overlay = this.$target.data('overlay');
|
2013-09-17 11:52:35 +00:00
|
|
|
this.snippet_id = this.$target.data("snippet-id");
|
2013-09-10 10:21:40 +00:00
|
|
|
this._readXMLData();
|
2013-09-19 12:32:06 +00:00
|
|
|
this.load_style_options();
|
2013-09-19 12:58:54 +00:00
|
|
|
this.get_parent_block();
|
2013-09-06 15:04:08 +00:00
|
|
|
this.start();
|
|
|
|
},
|
|
|
|
|
2013-09-10 10:21:40 +00:00
|
|
|
/*
|
|
|
|
* _readXMLData
|
|
|
|
* Read data XML and set value into:
|
|
|
|
* this.$el :
|
|
|
|
* all xml data
|
2013-09-11 12:56:32 +00:00
|
|
|
* this.$overlay :
|
|
|
|
* Dom hover the $target who content options
|
2013-09-10 10:21:40 +00:00
|
|
|
* this.$editor :
|
2013-09-11 12:56:32 +00:00
|
|
|
* content of .oe_snippet_options
|
|
|
|
* Displayed into the overlay options on focus
|
2013-09-10 10:21:40 +00:00
|
|
|
*/
|
|
|
|
_readXMLData: function() {
|
2013-11-04 10:29:14 +00:00
|
|
|
var self = this;
|
|
|
|
this.$el = this.parent.$snippets.filter(function () { return $(this).data("snippet-id") == self.snippet_id; }).clone();
|
2013-09-17 11:52:35 +00:00
|
|
|
this.$editor = this.$el.find(".oe_snippet_options");
|
|
|
|
var $options = this.$overlay.find(".oe_overlay_options");
|
|
|
|
this.$editor.prependTo($options.find(".oe_options ul"));
|
2013-09-20 08:49:52 +00:00
|
|
|
if ($options.find(".oe_options ul li").length) {
|
|
|
|
$options.find(".oe_options").removeClass("hidden");
|
2013-09-19 12:32:06 +00:00
|
|
|
}
|
2013-09-06 15:04:08 +00:00
|
|
|
},
|
|
|
|
|
2013-09-13 09:35:18 +00:00
|
|
|
|
|
|
|
// activate drag and drop for the snippets in the snippet toolbar
|
|
|
|
_drag_and_drop: function(){
|
|
|
|
var self = this;
|
2013-09-23 09:51:22 +00:00
|
|
|
this.dropped = false;
|
2013-09-13 09:35:18 +00:00
|
|
|
this.$overlay.draggable({
|
2013-09-13 11:44:56 +00:00
|
|
|
greedy: true,
|
2013-09-13 09:35:18 +00:00
|
|
|
appendTo: 'body',
|
|
|
|
cursor: "move",
|
2013-09-19 10:20:14 +00:00
|
|
|
handle: ".oe_snippet_move",
|
|
|
|
cursorAt: {
|
|
|
|
left: 18,
|
|
|
|
top: 14
|
|
|
|
},
|
2013-09-17 11:52:35 +00:00
|
|
|
helper: function() {
|
2013-09-20 10:08:21 +00:00
|
|
|
var $clone = $(this).clone().css({width: "24px", height: "24px", border: 0});
|
2013-09-23 09:51:22 +00:00
|
|
|
$clone.find(".oe_overlay_options >:not(:contains(.oe_snippet_move)), .oe_handle").remove();
|
2013-09-19 10:20:14 +00:00
|
|
|
$clone.find(":not(.glyphicon)").css({position: 'absolute', top: 0, left: 0});
|
2013-09-23 09:51:22 +00:00
|
|
|
$clone.appendTo("body").removeClass("hidden");
|
|
|
|
return $clone;
|
2013-09-17 11:52:35 +00:00
|
|
|
},
|
2013-09-23 09:51:22 +00:00
|
|
|
start: _.bind(self._drag_and_drop_start, self),
|
|
|
|
stop: _.bind(self._drag_and_drop_stop, self)
|
|
|
|
});
|
|
|
|
},
|
|
|
|
_drag_and_drop_after_insert_dropzone: function (){},
|
2013-10-17 14:19:59 +00:00
|
|
|
_drag_and_drop_active_drop_zone: function ($zones){
|
2013-09-23 09:51:22 +00:00
|
|
|
var self = this;
|
2013-10-17 14:19:59 +00:00
|
|
|
$zones.droppable({
|
2013-09-23 09:51:22 +00:00
|
|
|
over: function(){
|
2013-10-17 14:19:59 +00:00
|
|
|
$(".oe_drop_zone.hide").removeClass("hide");
|
|
|
|
$(this).addClass("hide").first().after(self.$target);
|
2013-09-23 09:51:22 +00:00
|
|
|
self.dropped = true;
|
2013-09-13 09:35:18 +00:00
|
|
|
},
|
2013-09-23 09:51:22 +00:00
|
|
|
out: function(){
|
2013-10-17 14:19:59 +00:00
|
|
|
$(this).removeClass("hide");
|
2013-09-23 09:51:22 +00:00
|
|
|
self.$target.detach();
|
|
|
|
self.dropped = false;
|
2013-09-13 09:35:18 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
2013-09-23 09:51:22 +00:00
|
|
|
_drag_and_drop_start: function (){
|
|
|
|
var self = this;
|
|
|
|
self.parent.hide();
|
|
|
|
self.parent.editor_busy = true;
|
|
|
|
self.size = {
|
|
|
|
width: self.$target.width(),
|
|
|
|
height: self.$target.height()
|
|
|
|
};
|
|
|
|
self.$target.after("<div class='oe_drop_clone' style='display: none;'/>");
|
|
|
|
self.$target.detach();
|
|
|
|
self.$overlay.addClass("hidden");
|
|
|
|
|
|
|
|
self.parent.activate_insertion_zones({
|
|
|
|
siblings: self.$el ? self.$el.data('selector-siblings') : false,
|
|
|
|
children: self.$el ? self.$el.data('selector-children') : false,
|
|
|
|
vertical_children: self.$el ? self.$el.data('selector-vertical-children') : false,
|
|
|
|
});
|
|
|
|
|
|
|
|
$("body").addClass('move-important');
|
2013-11-08 14:38:48 +00:00
|
|
|
|
2013-09-23 09:51:22 +00:00
|
|
|
self._drag_and_drop_after_insert_dropzone();
|
2013-10-17 14:19:59 +00:00
|
|
|
self._drag_and_drop_active_drop_zone($('.oe_drop_zone'));
|
2013-09-23 09:51:22 +00:00
|
|
|
},
|
|
|
|
_drag_and_drop_stop: function (){
|
|
|
|
var self = this;
|
|
|
|
if (!self.dropped) {
|
|
|
|
$(".oe_drop_clone").after(self.$target);
|
|
|
|
}
|
|
|
|
self.$overlay.removeClass("hidden");
|
|
|
|
$("body").removeClass('move-important');
|
|
|
|
$('.oe_drop_zone').droppable('destroy').remove();
|
|
|
|
$(".oe_drop_clone, .oe_drop_to_remove").remove();
|
|
|
|
self.parent.editor_busy = false;
|
|
|
|
self.get_parent_block();
|
|
|
|
setTimeout(function () {self.parent.create_overlay(self.$target);},0);
|
|
|
|
},
|
2013-09-13 09:35:18 +00:00
|
|
|
|
2013-09-16 12:13:19 +00:00
|
|
|
_clone: function () {
|
|
|
|
var self = this;
|
2013-09-19 10:20:14 +00:00
|
|
|
this.$overlay.on('click', '.oe_snippet_clone', function () {
|
2013-09-16 12:13:19 +00:00
|
|
|
var $clone = self.$target.clone(false);
|
|
|
|
self.$target.after($clone);
|
2013-10-01 14:19:30 +00:00
|
|
|
return false;
|
2013-09-16 12:13:19 +00:00
|
|
|
});
|
|
|
|
},
|
2013-09-13 09:35:18 +00:00
|
|
|
|
2013-09-19 12:32:06 +00:00
|
|
|
load_style_options: function () {
|
|
|
|
var self = this;
|
2013-09-20 08:49:52 +00:00
|
|
|
var $styles = this.$overlay.find('.oe_options');
|
2013-09-27 12:41:16 +00:00
|
|
|
var $ul = $styles.find('ul:first');
|
2013-10-22 15:11:44 +00:00
|
|
|
_.each(this.parent.style_templates, function (val) {
|
2013-09-19 12:32:06 +00:00
|
|
|
if (!self.parent.dom_filter(val.selector).is(self.$target)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-09-20 08:49:52 +00:00
|
|
|
var $li = $("<li class='oe_style'/>").data(val);
|
2013-09-19 12:34:11 +00:00
|
|
|
$li.append($('<a/>').text(val.label));
|
2013-09-19 12:32:06 +00:00
|
|
|
$ul.append($li);
|
|
|
|
if (self.$target.hasClass( "oe_snippet_" + $li.data("snipped-id") )) {
|
|
|
|
$li.addClass("active");
|
|
|
|
}
|
2013-09-20 08:49:52 +00:00
|
|
|
$styles.removeClass("hidden");
|
2013-09-19 12:32:06 +00:00
|
|
|
});
|
2013-09-20 08:49:52 +00:00
|
|
|
$styles.on('click', 'li.oe_style a', _.bind(this.change_style, this));
|
2013-09-19 12:32:06 +00:00
|
|
|
},
|
|
|
|
change_style: function (event) {
|
|
|
|
var $li = $(event.currentTarget).parent();
|
|
|
|
var snipped_id = $li.data("snipped-id");
|
|
|
|
var active = $li.hasClass("active");
|
|
|
|
|
|
|
|
if (website.snippet.editorRegistry[snipped_id]) {
|
|
|
|
var snippet = new website.snippet.editorRegistry[snipped_id](this, this.$target);
|
2013-11-06 13:39:17 +00:00
|
|
|
snippet.drop_and_build_snippet(this.$target);
|
2013-09-19 12:32:06 +00:00
|
|
|
}
|
|
|
|
var _class = "oe_snippet_" + snipped_id + " " + ($li.data("class") || "");
|
|
|
|
if (active) {
|
|
|
|
this.$target.removeClass(_class);
|
|
|
|
} else {
|
|
|
|
this.$target.addClass(_class);
|
|
|
|
}
|
|
|
|
$li.toggleClass("active");
|
|
|
|
},
|
|
|
|
|
2013-09-19 12:58:54 +00:00
|
|
|
get_parent_block: function () {
|
|
|
|
var self = this;
|
|
|
|
var $button = this.$overlay.find('.oe_snippet_parent');
|
|
|
|
var $parent = this.$target.parents("[data-snippet-id]:first");
|
|
|
|
if ($parent.length) {
|
2013-09-20 08:49:52 +00:00
|
|
|
$button.removeClass("hidden");
|
2013-09-19 12:58:54 +00:00
|
|
|
$button.off("click").on('click', function (event) {
|
|
|
|
event.preventDefault();
|
|
|
|
setTimeout(function () {
|
|
|
|
self.parent.make_active($parent);
|
|
|
|
}, 0);
|
|
|
|
});
|
|
|
|
} else {
|
2013-09-20 08:49:52 +00:00
|
|
|
$button.addClass("hidden");
|
2013-09-19 12:58:54 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2013-09-10 10:21:40 +00:00
|
|
|
/*
|
2013-09-11 12:56:32 +00:00
|
|
|
* start
|
|
|
|
* This method is called after init and _readXMLData
|
2013-09-10 10:21:40 +00:00
|
|
|
*/
|
2013-09-11 12:56:32 +00:00
|
|
|
start: function () {
|
2013-09-12 17:06:52 +00:00
|
|
|
var self = this;
|
2013-09-19 10:20:14 +00:00
|
|
|
this.$overlay.on('click', '.oe_snippet_remove', function () {
|
2013-09-12 17:06:52 +00:00
|
|
|
self.onBlur();
|
2013-10-16 07:36:30 +00:00
|
|
|
var index = _.indexOf(self.parent.snippets, self.$target.get(0));
|
|
|
|
delete self.parent.snippets[index];
|
2013-09-12 17:06:52 +00:00
|
|
|
self.$target.remove();
|
2013-11-06 16:39:27 +00:00
|
|
|
self.$overlay.remove();
|
2013-09-12 17:06:52 +00:00
|
|
|
return false;
|
|
|
|
});
|
2013-09-13 09:35:18 +00:00
|
|
|
this._drag_and_drop();
|
2013-09-16 12:13:19 +00:00
|
|
|
this._clone();
|
2013-09-10 10:21:40 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/*
|
2013-11-06 13:39:17 +00:00
|
|
|
* drop_and_build_snippet
|
2013-10-22 15:11:44 +00:00
|
|
|
* This method is called just after that a thumbnail is drag and dropped into a drop zone
|
2013-09-10 10:21:40 +00:00
|
|
|
* (after the insertion of this.$body, if this.$body exists)
|
|
|
|
*/
|
2013-11-06 13:39:17 +00:00
|
|
|
drop_and_build_snippet: function ($target) {
|
2013-09-09 15:32:51 +00:00
|
|
|
},
|
|
|
|
|
2013-09-06 15:04:08 +00:00
|
|
|
/* onFocus
|
2013-09-10 10:21:40 +00:00
|
|
|
* This method is called when the user click inside the snippet in the dom
|
2013-09-06 15:04:08 +00:00
|
|
|
*/
|
|
|
|
onFocus : function () {
|
2013-11-06 16:39:27 +00:00
|
|
|
this.$overlay.addClass('oe_active').effect('bounce', {distance: 18, times: 5}, 250);
|
2013-09-06 15:04:08 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/* onFocus
|
2013-10-22 15:11:44 +00:00
|
|
|
* This method is called when the user click outside the snippet in the dom, after a focus
|
2013-09-06 15:04:08 +00:00
|
|
|
*/
|
|
|
|
onBlur : function () {
|
2013-09-11 12:56:32 +00:00
|
|
|
this.$overlay.removeClass('oe_active');
|
2013-09-30 15:32:50 +00:00
|
|
|
},
|
|
|
|
|
2013-10-15 15:43:51 +00:00
|
|
|
/* clean_for_save
|
|
|
|
* function called just before save vue
|
|
|
|
*/
|
|
|
|
clean_for_save: function () {
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2013-09-30 15:32:50 +00:00
|
|
|
change_background: function (bg, ul_options) {
|
|
|
|
var self = this;
|
2013-10-07 11:36:20 +00:00
|
|
|
this.set_options_background(bg, ul_options);
|
2013-09-30 15:32:50 +00:00
|
|
|
var $ul = this.$editor.find(ul_options);
|
2013-10-16 06:52:57 +00:00
|
|
|
var bg_value = (typeof bg === 'string' ? this.$target.find(bg) : $(bg)).css("background-image").replace(/url\(['"]*|['"]*\)/g, "");
|
2013-09-30 15:32:50 +00:00
|
|
|
|
2013-10-22 15:11:44 +00:00
|
|
|
// bind event on options
|
2013-09-30 15:32:50 +00:00
|
|
|
var $li = $ul.find("li");
|
|
|
|
$li.on('click', function (event) {
|
|
|
|
if ($(this).data("value")) {
|
|
|
|
$li.removeClass("active");
|
|
|
|
$(this).addClass("active");
|
|
|
|
self.$editor.find('input').val("");
|
|
|
|
} else {
|
2013-10-01 12:03:35 +00:00
|
|
|
var editor = new website.editor.ImageDialog();
|
|
|
|
editor.on('start', self, function (o) {o.url = bg_value;});
|
|
|
|
editor.on('save', self, function (o) {
|
2013-10-03 08:40:11 +00:00
|
|
|
var $bg = typeof bg === 'string' ? self.$target.find(bg) : $(bg);
|
2013-10-02 07:12:39 +00:00
|
|
|
$bg.css("background-image", "url(" + o.url + ")");
|
2013-10-01 12:03:35 +00:00
|
|
|
});
|
|
|
|
editor.appendTo($('body'));
|
2013-09-30 15:32:50 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.on('mouseover', function (event) {
|
|
|
|
if ($(this).data("value")) {
|
|
|
|
var src = $(this).data("value");
|
2013-10-03 08:40:11 +00:00
|
|
|
var $bg = typeof bg === 'string' ? self.$target.find(bg) : $(bg);
|
2013-10-02 07:12:39 +00:00
|
|
|
$bg.css("background-image", "url(" + src + ")");
|
2013-09-30 15:32:50 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.on('mouseout', function (event) {
|
|
|
|
var src = $ul.find('li.active').data("value");
|
2013-10-03 08:40:11 +00:00
|
|
|
var $bg = typeof bg === 'string' ? self.$target.find(bg) : $(bg);
|
2013-10-02 07:12:39 +00:00
|
|
|
$bg.css("background-image", "url(" + src + ")");
|
2013-09-30 15:32:50 +00:00
|
|
|
});
|
2013-09-06 15:04:08 +00:00
|
|
|
},
|
2013-10-07 11:36:20 +00:00
|
|
|
|
|
|
|
set_options_background: function (bg, ul_options) {
|
|
|
|
var $ul = this.$editor.find(ul_options);
|
|
|
|
var bg_value = (typeof bg === 'string' ? this.$target.find(bg) : $(bg)).css("background-image").replace(/url\(['"]*|['"]*\)/g, "");
|
|
|
|
|
|
|
|
// select in ul options
|
|
|
|
$ul.find("li").removeClass("active");
|
2013-10-15 15:43:51 +00:00
|
|
|
var selected = $ul.find('[data-value="' + bg_value + '"], [data-value="' + bg_value.replace(/.*:\/\/[^\/]+/, '') + '"]');
|
2013-10-07 11:36:20 +00:00
|
|
|
selected.addClass('active');
|
|
|
|
if (!selected.length) {
|
|
|
|
$ul.find('.oe_custom_bg b').html(bg_value);
|
|
|
|
}
|
|
|
|
},
|
2013-09-06 15:04:08 +00:00
|
|
|
});
|
|
|
|
|
2013-09-06 16:00:06 +00:00
|
|
|
|
2013-09-12 11:51:30 +00:00
|
|
|
website.snippet.editorRegistry.resize = website.snippet.Editor.extend({
|
2013-09-11 12:56:32 +00:00
|
|
|
start: function () {
|
2013-09-09 13:28:00 +00:00
|
|
|
var self = this;
|
2013-09-11 12:56:32 +00:00
|
|
|
this._super();
|
2013-09-12 11:51:30 +00:00
|
|
|
var $box = $(openerp.qweb.render("website.snippets.resize"));
|
2013-09-11 12:56:32 +00:00
|
|
|
|
|
|
|
var resize_values = this.getSize();
|
|
|
|
if (!resize_values.n) $box.find(".oe_handle.n").remove();
|
|
|
|
if (!resize_values.s) $box.find(".oe_handle.s").remove();
|
|
|
|
if (!resize_values.e) $box.find(".oe_handle.e").remove();
|
|
|
|
if (!resize_values.w) $box.find(".oe_handle.w").remove();
|
2013-11-08 14:38:48 +00:00
|
|
|
|
2013-09-11 12:56:32 +00:00
|
|
|
this.$overlay.append($box.find(".oe_handles").html());
|
|
|
|
|
|
|
|
this.$overlay.find(".oe_handle").on('mousedown', function (event){
|
2013-09-09 13:28:00 +00:00
|
|
|
event.preventDefault();
|
2013-09-06 15:04:08 +00:00
|
|
|
|
2013-09-09 13:28:00 +00:00
|
|
|
var $handle = $(this);
|
|
|
|
|
2013-09-11 12:56:32 +00:00
|
|
|
var resize_values = self.getSize();
|
|
|
|
var compass = false;
|
|
|
|
var XY = false;
|
|
|
|
if ($handle.hasClass('n')) {
|
|
|
|
compass = 'n';
|
|
|
|
XY = 'Y';
|
|
|
|
}
|
|
|
|
else if ($handle.hasClass('s')) {
|
|
|
|
compass = 's';
|
|
|
|
XY = 'Y';
|
|
|
|
}
|
|
|
|
else if ($handle.hasClass('e')) {
|
|
|
|
compass = 'e';
|
|
|
|
XY = 'X';
|
|
|
|
}
|
|
|
|
else if ($handle.hasClass('w')) {
|
|
|
|
compass = 'w';
|
|
|
|
XY = 'X';
|
|
|
|
}
|
2013-09-09 13:28:00 +00:00
|
|
|
|
2013-09-11 12:56:32 +00:00
|
|
|
var resize = resize_values[compass];
|
|
|
|
if (!resize) return;
|
2013-09-09 13:28:00 +00:00
|
|
|
|
2013-09-12 11:51:30 +00:00
|
|
|
var current = resize[2] || 0;
|
2013-09-11 12:56:32 +00:00
|
|
|
_.each(resize[0], function (val, key) {
|
|
|
|
if (self.$target.hasClass(val)) {
|
2013-09-12 15:17:18 +00:00
|
|
|
current = key;
|
2013-09-11 12:56:32 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
self.parent.editor_busy = true;
|
|
|
|
|
|
|
|
var xy = event['page'+XY];
|
2013-09-12 11:51:30 +00:00
|
|
|
var begin = current;
|
|
|
|
var beginClass = self.$target.attr("class");
|
2013-09-20 13:01:22 +00:00
|
|
|
var regClass = new RegExp("\\s*" + resize[0][begin].replace(/[-]*[0-9]+/, '[-]*[0-9]+'), 'g');
|
2013-09-11 12:56:32 +00:00
|
|
|
|
|
|
|
var cursor = $handle.css("cursor")+'-important';
|
2013-10-22 15:11:44 +00:00
|
|
|
var $body = $(document.body);
|
|
|
|
$body.addClass(cursor);
|
2013-09-09 13:28:00 +00:00
|
|
|
|
|
|
|
var body_mousemove = function (event){
|
|
|
|
event.preventDefault();
|
2013-09-12 11:51:30 +00:00
|
|
|
var dd = event['page'+XY] - xy + resize[1][begin];
|
2013-09-11 12:56:32 +00:00
|
|
|
var next = current+1 === resize[1].length ? current : (current+1);
|
|
|
|
var prev = current ? (current-1) : 0;
|
|
|
|
|
|
|
|
var change = false;
|
|
|
|
if (dd > (2*resize[1][next] + resize[1][current])/3) {
|
2013-10-01 14:19:30 +00:00
|
|
|
self.$target.attr("class", (self.$target.attr("class")||'').replace(regClass, ''));
|
2013-09-12 11:51:30 +00:00
|
|
|
self.$target.addClass(resize[0][next]);
|
2013-09-11 12:56:32 +00:00
|
|
|
current = next;
|
|
|
|
change = true;
|
2013-09-09 13:28:00 +00:00
|
|
|
}
|
2013-09-11 12:56:32 +00:00
|
|
|
if (prev != current && dd < (2*resize[1][prev] + resize[1][current])/3) {
|
2013-10-01 14:19:30 +00:00
|
|
|
self.$target.attr("class", (self.$target.attr("class")||'').replace(regClass, ''));
|
2013-09-12 11:51:30 +00:00
|
|
|
self.$target.addClass(resize[0][prev]);
|
2013-09-11 12:56:32 +00:00
|
|
|
current = prev;
|
|
|
|
change = true;
|
2013-09-09 13:28:00 +00:00
|
|
|
}
|
2013-09-11 12:56:32 +00:00
|
|
|
|
|
|
|
if (change) {
|
2013-09-12 11:51:30 +00:00
|
|
|
self.on_resize(compass, beginClass, current);
|
2013-09-16 11:28:34 +00:00
|
|
|
self.parent.cover_target(self.$overlay, self.$target);
|
2013-09-09 13:28:00 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var body_mouseup = function(){
|
2013-10-22 15:11:44 +00:00
|
|
|
$body.unbind('mousemove', body_mousemove);
|
|
|
|
$body.unbind('mouseup', body_mouseup);
|
|
|
|
$body.removeClass(cursor);
|
2013-09-11 12:56:32 +00:00
|
|
|
self.parent.editor_busy = false;
|
2013-09-09 13:28:00 +00:00
|
|
|
};
|
2013-10-22 15:11:44 +00:00
|
|
|
$body.mousemove(body_mousemove);
|
|
|
|
$body.mouseup(body_mouseup);
|
2013-09-09 13:28:00 +00:00
|
|
|
});
|
|
|
|
},
|
2013-09-11 12:56:32 +00:00
|
|
|
getSize: function () {
|
|
|
|
var grid = [0,4,8,16,32,48,64,92,128];
|
2013-09-12 11:51:30 +00:00
|
|
|
this.grid = {
|
2013-09-17 11:00:43 +00:00
|
|
|
n: [_.map(grid, function (v) {return 'mt'+v;}), grid],
|
|
|
|
s: [_.map(grid, function (v) {return 'mb'+v;}), grid]
|
2013-09-11 12:56:32 +00:00
|
|
|
};
|
2013-09-12 11:51:30 +00:00
|
|
|
return this.grid;
|
|
|
|
},
|
|
|
|
|
|
|
|
/* on_resize
|
|
|
|
* called when the box is resizing and the class change, before the cover_target
|
|
|
|
* @compass: resize direction : 'n', 's', 'e', 'w'
|
|
|
|
* @beginClass: attributes class at the begin
|
|
|
|
* @current: curent increment in this.grid
|
|
|
|
*/
|
|
|
|
on_resize: function (compass, beginClass, current) {
|
|
|
|
|
2013-09-11 12:56:32 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-09-12 11:51:30 +00:00
|
|
|
website.snippet.editorRegistry.colmd = website.snippet.editorRegistry.resize.extend({
|
2013-09-11 12:56:32 +00:00
|
|
|
getSize: function () {
|
2013-09-12 11:51:30 +00:00
|
|
|
this.grid = this._super();
|
2013-09-11 12:56:32 +00:00
|
|
|
var width = this.$target.parents(".row:first").first().outerWidth();
|
2013-09-12 11:51:30 +00:00
|
|
|
|
2013-09-12 15:17:18 +00:00
|
|
|
var grid = [1,2,3,4,5,6,7,8,9,10,11,12];
|
2013-09-12 11:51:30 +00:00
|
|
|
this.grid.e = [_.map(grid, function (v) {return 'col-md-'+v;}), _.map(grid, function (v) {return width/12*v;})];
|
|
|
|
|
|
|
|
var grid = [-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10,11];
|
2013-09-17 13:31:44 +00:00
|
|
|
this.grid.w = [_.map(grid, function (v) {return 'col-md-offset-'+v;}), _.map(grid, function (v) {return width/12*v;}), 12];
|
2013-09-12 11:51:30 +00:00
|
|
|
|
|
|
|
return this.grid;
|
|
|
|
},
|
2013-09-23 09:51:22 +00:00
|
|
|
|
|
|
|
_drag_and_drop_after_insert_dropzone: function(){
|
|
|
|
var self = this;
|
2013-10-21 15:39:18 +00:00
|
|
|
var $zones = $(".row:has(> .oe_drop_zone)").each(function () {
|
|
|
|
var $row = $(this);
|
|
|
|
var width = $row.innerWidth();
|
|
|
|
var pos = 0;
|
|
|
|
while (width > pos + self.size.width) {
|
|
|
|
var $last = $row.find("> .oe_drop_zone:last");
|
|
|
|
$last.each(function () {
|
|
|
|
pos = $(this).position().left;
|
|
|
|
});
|
|
|
|
if (width > pos + self.size.width) {
|
|
|
|
$row.append("<div class='col-md-1 oe_drop_to_remove'/>");
|
|
|
|
var $add_drop = $last.clone();
|
|
|
|
$row.append($add_drop);
|
|
|
|
self._drag_and_drop_active_drop_zone($add_drop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2013-09-23 09:51:22 +00:00
|
|
|
},
|
|
|
|
_drag_and_drop_start: function () {
|
|
|
|
this._super();
|
|
|
|
this.$target.attr("class",this.$target.attr("class").replace(/\s*(col-lg-offset-|col-md-offset-)([0-9-]+)/g, ''));
|
|
|
|
},
|
|
|
|
_drag_and_drop_stop: function () {
|
|
|
|
this.$target.addClass("col-md-offset-" + this.$target.prevAll(".oe_drop_to_remove").length);
|
|
|
|
this._super();
|
|
|
|
},
|
|
|
|
|
2013-09-12 11:51:30 +00:00
|
|
|
on_resize: function (compass, beginClass, current) {
|
2013-09-12 15:17:18 +00:00
|
|
|
if (compass !== 'w')
|
2013-09-12 11:51:30 +00:00
|
|
|
return;
|
|
|
|
|
2013-10-22 15:11:44 +00:00
|
|
|
// don't change the right border position when we change the offset (replace col size)
|
2013-09-12 15:17:18 +00:00
|
|
|
var beginCol = Number(beginClass.match(/col-md-([0-9]+)|$/)[1] || 0);
|
2013-09-17 13:31:44 +00:00
|
|
|
var beginOffset = Number(beginClass.match(/col-md-offset-([0-9-]+)|$/)[1] || beginClass.match(/col-lg-offset-([0-9-]+)|$/)[1] || 0);
|
|
|
|
var offset = Number(this.grid.w[0][current].match(/col-md-offset-([0-9-]+)|$/)[1] || 0);
|
2013-09-20 14:49:22 +00:00
|
|
|
if (offset < 0) {
|
|
|
|
offset = 0;
|
|
|
|
}
|
|
|
|
var colSize = beginCol - (offset - beginOffset);
|
|
|
|
if (colSize <= 0) {
|
|
|
|
colSize = 1;
|
|
|
|
offset = beginOffset + beginCol - 1;
|
|
|
|
}
|
2013-09-17 13:31:44 +00:00
|
|
|
this.$target.attr("class",this.$target.attr("class").replace(/\s*(col-lg-offset-|col-md-offset-|col-md-)([0-9-]+)/g, ''));
|
2013-09-12 11:51:30 +00:00
|
|
|
|
2013-09-12 15:17:18 +00:00
|
|
|
this.$target.addClass('col-md-' + (colSize > 12 ? 12 : colSize));
|
|
|
|
if (offset > 0) {
|
2013-09-17 13:31:44 +00:00
|
|
|
this.$target.addClass('col-md-offset-' + offset);
|
2013-09-12 11:51:30 +00:00
|
|
|
}
|
2013-09-09 14:49:40 +00:00
|
|
|
},
|
2013-09-09 13:28:00 +00:00
|
|
|
});
|
|
|
|
|
2013-10-15 15:43:51 +00:00
|
|
|
website.snippet.animationRegistry.carousel = website.snippet.Animation.extend({
|
|
|
|
start: function () {
|
2013-10-20 09:19:18 +00:00
|
|
|
this.$target.carousel({interval: false});
|
2013-10-15 15:43:51 +00:00
|
|
|
},
|
|
|
|
});
|
2013-09-12 11:51:30 +00:00
|
|
|
website.snippet.editorRegistry.carousel = website.snippet.editorRegistry.resize.extend({
|
2013-11-06 13:39:17 +00:00
|
|
|
drop_and_build_snippet: function() {
|
2013-10-07 11:36:20 +00:00
|
|
|
var id = 0;
|
|
|
|
$("body .carousel").each(function () {
|
|
|
|
var _id = +$(this).attr("id").replace(/^myCarousel/, '');
|
|
|
|
if (id <= _id) {
|
|
|
|
id = _id + 1;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.$target.attr("id", "myCarousel" + id);
|
|
|
|
this.$target.find(".carousel-control").attr("href", "#myCarousel" + id);
|
|
|
|
this.$target.find("[data-target='#myCarousel']").attr("data-target", "#myCarousel" + id);
|
2013-10-30 10:30:48 +00:00
|
|
|
|
2013-10-07 11:36:20 +00:00
|
|
|
this.rebind_event();
|
|
|
|
},
|
|
|
|
onFocus: function () {
|
|
|
|
this._super();
|
|
|
|
this.$target.carousel('pause');
|
|
|
|
},
|
|
|
|
onBlur: function () {
|
|
|
|
this._super();
|
|
|
|
this.$target.carousel('cycle');
|
2013-09-09 15:32:51 +00:00
|
|
|
},
|
2013-10-15 15:43:51 +00:00
|
|
|
clean_for_save: function () {
|
|
|
|
this._super();
|
2013-10-16 07:02:37 +00:00
|
|
|
this.$target.find(".item").removeClass("next prev left right");
|
2013-10-15 15:43:51 +00:00
|
|
|
if(!this.$target.find(".item.active").length) {
|
|
|
|
this.$target.find(".item:first").addClass("active");
|
|
|
|
}
|
2013-10-30 10:30:48 +00:00
|
|
|
this.$target.removeAttr('contentEditable')
|
|
|
|
.find('.content, .carousel-image img')
|
|
|
|
.removeAttr('contentEditable');
|
2013-10-15 15:43:51 +00:00
|
|
|
},
|
2013-09-06 15:04:08 +00:00
|
|
|
start : function () {
|
2013-09-11 13:37:25 +00:00
|
|
|
this._super();
|
2013-09-06 15:04:08 +00:00
|
|
|
|
2013-10-07 11:36:20 +00:00
|
|
|
this.id = this.$target.attr("id");
|
|
|
|
|
|
|
|
this.$inner = this.$target.find('.carousel-inner');
|
|
|
|
this.$indicators = this.$target.find('.carousel-indicators');
|
|
|
|
|
2013-09-23 12:15:03 +00:00
|
|
|
this.$editor.find(".js_add").on('click', _.bind(this.on_add, this));
|
|
|
|
this.$editor.find(".js_remove").on('click', _.bind(this.on_remove, this));
|
2013-09-13 11:44:56 +00:00
|
|
|
|
2013-09-30 15:32:50 +00:00
|
|
|
this.change_background(".item.active", 'ul[name="carousel-background"]');
|
2013-09-17 11:00:43 +00:00
|
|
|
this.change_style();
|
|
|
|
this.change_size();
|
2013-10-07 11:36:20 +00:00
|
|
|
this.set_options_style();
|
|
|
|
this.$target.carousel();
|
|
|
|
|
|
|
|
var self = this;
|
|
|
|
this.$target.on('slide.bs.carousel', function () {
|
|
|
|
self.set_options_style();
|
|
|
|
self.set_options_background(".item.active", 'ul[name="carousel-background"]');
|
|
|
|
self.$target.carousel();
|
2013-10-15 09:50:58 +00:00
|
|
|
});
|
|
|
|
|
2013-10-07 11:36:20 +00:00
|
|
|
this.rebind_event();
|
|
|
|
},
|
|
|
|
// rebind event to active carousel on edit mode
|
|
|
|
rebind_event: function () {
|
|
|
|
var self = this;
|
2013-10-15 15:43:51 +00:00
|
|
|
this.$target.off('click').on('click', '.carousel-control', function () {
|
2013-10-07 11:36:20 +00:00
|
|
|
self.$target.carousel($(this).data('slide')); });
|
2013-10-15 15:43:51 +00:00
|
|
|
this.$target.off('click').on('click', '.carousel-indicators [data-target]', function () {
|
2013-10-07 11:36:20 +00:00
|
|
|
self.$target.carousel(+$(this).data('slide-to')); });
|
2013-11-06 15:21:26 +00:00
|
|
|
|
|
|
|
this.$target.attr('contentEditable', 'false')
|
|
|
|
.find('.content, .carousel-image img')
|
|
|
|
.attr('contentEditable', 'true');
|
2013-09-17 11:00:43 +00:00
|
|
|
},
|
|
|
|
on_add: function (e) {
|
|
|
|
e.preventDefault();
|
2013-10-07 11:36:20 +00:00
|
|
|
var cycle = this.$inner.find('.item').length;
|
|
|
|
var $active = this.$inner.find('.item.active');
|
|
|
|
var index = $active.index();
|
|
|
|
this.$target.find('.carousel-control, .carousel-indicators').removeClass("hidden");
|
|
|
|
this.$indicators.append('<li data-target="#' + this.id + '" data-slide-to="' + cycle + '"></li>');
|
2013-11-08 14:38:48 +00:00
|
|
|
|
2013-10-15 14:56:54 +00:00
|
|
|
var $clone = this.$el.find(".item.active").clone();
|
|
|
|
var bg = this.$editor.find('ul[name="carousel-background"] li:not([data-value="'+ $active.css("background-image").replace(/.*:\/\/[^\/]+|\)$/g, '') +'"]):first').data("value");
|
|
|
|
$clone.css("background-image", "url('"+ bg +"')");
|
|
|
|
$clone.removeClass('active').insertAfter($active);
|
2013-10-07 11:36:20 +00:00
|
|
|
this.$target.carousel().carousel(++index);
|
2013-10-15 15:43:51 +00:00
|
|
|
this.rebind_event();
|
2013-09-17 11:00:43 +00:00
|
|
|
},
|
|
|
|
on_remove: function (e) {
|
|
|
|
e.preventDefault();
|
2013-10-07 11:36:20 +00:00
|
|
|
var self = this;
|
|
|
|
var new_index = 0;
|
|
|
|
var cycle = this.$inner.find('.item').length - 1;
|
|
|
|
var index = this.$inner.find('.item.active').index();
|
|
|
|
if (cycle > 0) {
|
|
|
|
this.$inner.find('.item.active').fadeOut(1000, function () {
|
|
|
|
$(this).remove();
|
|
|
|
self.$indicators.find('[data-target]:last').remove();
|
|
|
|
self.$indicators.find("[data-slide-to]").removeClass("active");
|
|
|
|
self.$indicators.find("[data-slide-to='" + new_index + "']").addClass("active");
|
|
|
|
});
|
|
|
|
setTimeout(function () {
|
|
|
|
new_index = index % cycle;
|
2013-10-15 15:43:51 +00:00
|
|
|
self.$target.carousel().carousel( new_index + 1 );
|
|
|
|
self.rebind_event();
|
2013-10-07 11:36:20 +00:00
|
|
|
}, 500);
|
|
|
|
} else {
|
|
|
|
this.$target.find('.carousel-control, .carousel-indicators').addClass("hidden");
|
2013-09-23 12:33:59 +00:00
|
|
|
}
|
2013-09-17 11:00:43 +00:00
|
|
|
},
|
2013-09-23 12:15:03 +00:00
|
|
|
set_options_style: function () {
|
2013-09-06 16:00:06 +00:00
|
|
|
var style = false;
|
2013-10-07 11:36:20 +00:00
|
|
|
var $el = this.$inner.find('.item.active');
|
2013-09-23 12:15:03 +00:00
|
|
|
var $ul = this.$editor.find('ul[name="carousel-style"]');
|
|
|
|
|
2013-09-23 10:56:04 +00:00
|
|
|
if ($el.hasClass('text_only'))
|
2013-09-15 15:25:22 +00:00
|
|
|
style = 'text_only';
|
2013-09-23 10:56:04 +00:00
|
|
|
if ($el.hasClass('image_text'))
|
2013-09-15 15:25:22 +00:00
|
|
|
style = 'image_text';
|
2013-09-23 10:56:04 +00:00
|
|
|
if ($el.hasClass('text_image'))
|
2013-09-15 15:25:22 +00:00
|
|
|
style = 'text_image';
|
|
|
|
|
2013-09-23 12:15:03 +00:00
|
|
|
$ul.find('[data-value="' + style + '"]').addClass('active');
|
|
|
|
},
|
|
|
|
change_style: function () {
|
|
|
|
var self = this;
|
2013-09-23 10:56:04 +00:00
|
|
|
var $ul = this.$editor.find('ul[name="carousel-style"]');
|
|
|
|
var $li = $ul.find("li");
|
2013-09-06 15:04:08 +00:00
|
|
|
|
2013-09-23 10:56:04 +00:00
|
|
|
$li.on('click', function (event) {
|
|
|
|
$li.removeClass("active");
|
|
|
|
$(this).addClass("active");
|
|
|
|
})
|
|
|
|
.on('mouseover', function (event) {
|
2013-10-07 11:36:20 +00:00
|
|
|
var $el = self.$inner.find('.item.active');
|
2013-09-23 10:56:04 +00:00
|
|
|
$el.removeClass('image_text text_image text_only');
|
|
|
|
$el.addClass($(event.currentTarget).data("value"));
|
|
|
|
})
|
|
|
|
.on('mouseout', function (event) {
|
2013-10-07 11:36:20 +00:00
|
|
|
var $el = self.$inner.find('.item.active');
|
2013-09-23 10:56:04 +00:00
|
|
|
$el.removeClass('image_text text_image text_only');
|
|
|
|
$el.addClass($ul.find('li.active').data("value"));
|
|
|
|
});
|
2013-09-06 16:00:06 +00:00
|
|
|
},
|
2013-09-17 11:00:43 +00:00
|
|
|
change_size: function () {
|
2013-09-23 10:56:04 +00:00
|
|
|
var $el = this.$target;
|
2013-09-17 11:00:43 +00:00
|
|
|
|
2013-09-23 10:56:04 +00:00
|
|
|
var size = 'oe_big';
|
2013-09-17 11:00:43 +00:00
|
|
|
if (this.$target.hasClass('oe_small'))
|
2013-09-23 10:56:04 +00:00
|
|
|
size = 'oe_small';
|
2013-09-18 08:04:40 +00:00
|
|
|
else if (this.$target.hasClass('oe_medium'))
|
2013-09-23 10:56:04 +00:00
|
|
|
size = 'oe_medium';
|
2013-09-17 11:00:43 +00:00
|
|
|
|
2013-09-23 10:56:04 +00:00
|
|
|
var $ul = this.$editor.find('ul[name="carousel-size"]');
|
|
|
|
var $li = $ul.find("li");
|
2013-09-17 11:00:43 +00:00
|
|
|
|
2013-09-23 10:56:04 +00:00
|
|
|
$ul.find('[data-value="' + size + '"]').addClass('active');
|
|
|
|
|
|
|
|
$li.on('click', function (event) {
|
|
|
|
$li.removeClass("active");
|
|
|
|
$(this).addClass("active");
|
|
|
|
})
|
|
|
|
.on('mouseover', function (event) {
|
|
|
|
$el.removeClass('oe_big oe_small oe_medium');
|
|
|
|
$el.addClass($(event.currentTarget).data("value"));
|
|
|
|
})
|
|
|
|
.on('mouseout', function (event) {
|
|
|
|
$el.removeClass('oe_big oe_small oe_medium');
|
|
|
|
$el.addClass($ul.find('li.active').data("value"));
|
|
|
|
});
|
2013-09-17 11:00:43 +00:00
|
|
|
}
|
2013-09-06 15:04:08 +00:00
|
|
|
});
|
|
|
|
|
2013-09-27 12:41:16 +00:00
|
|
|
website.snippet.editorRegistry.parallax = website.snippet.editorRegistry.resize.extend({
|
|
|
|
start : function () {
|
|
|
|
this._super();
|
2013-10-19 20:59:31 +00:00
|
|
|
this.change_background($('.parallax', this.$target), 'ul[name="parallax-background"]');
|
2013-10-18 14:53:13 +00:00
|
|
|
this.scroll();
|
2013-10-18 09:31:35 +00:00
|
|
|
this.change_size();
|
2013-09-27 12:41:16 +00:00
|
|
|
},
|
2013-10-18 14:53:13 +00:00
|
|
|
scroll: function(){
|
|
|
|
var $ul = this.$editor.find('ul[name="parallax-scroll"]');
|
|
|
|
var $li = $ul.find("li");
|
2013-10-19 20:59:31 +00:00
|
|
|
var $parallax = this.$target.find('.parallax');
|
|
|
|
var speed = $parallax.data('stellar-background-ratio') || 0.5 ;
|
2013-11-08 14:38:48 +00:00
|
|
|
|
2013-10-18 14:53:13 +00:00
|
|
|
$ul.find('[data-value="' + speed + '"]').addClass('active');
|
|
|
|
$li.on('click', function (event) {
|
|
|
|
$li.removeClass("active");
|
|
|
|
$(this).addClass("active");
|
2013-10-22 15:11:44 +00:00
|
|
|
var speed = $(this).data('value');
|
2013-10-19 20:59:31 +00:00
|
|
|
$parallax.attr('data-stellar-background-ratio', speed);
|
2013-10-18 14:53:13 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
},
|
2013-10-19 20:59:31 +00:00
|
|
|
clean_for_save: function () {
|
|
|
|
this._super();
|
|
|
|
this.$target.find(".parallax").css("background-position", '');
|
|
|
|
},
|
2013-10-18 09:31:35 +00:00
|
|
|
change_size: function () {
|
|
|
|
var self = this;
|
2013-10-19 20:59:31 +00:00
|
|
|
var $el = $('.oe_big,.oe_medium,.oe_small', this.$target);
|
2013-10-18 09:31:35 +00:00
|
|
|
|
|
|
|
var size = 'oe_big';
|
2013-10-19 20:59:31 +00:00
|
|
|
if ($el.hasClass('oe_small'))
|
2013-10-18 09:31:35 +00:00
|
|
|
size = 'oe_small';
|
2013-10-19 20:59:31 +00:00
|
|
|
else if ($el.hasClass('oe_medium'))
|
2013-10-18 09:31:35 +00:00
|
|
|
size = 'oe_medium';
|
|
|
|
var $ul = this.$editor.find('ul[name="parallax-size"]');
|
|
|
|
var $li = $ul.find("li");
|
|
|
|
|
|
|
|
$ul.find('[data-value="' + size + '"]').addClass('active');
|
|
|
|
|
|
|
|
$li.on('click', function (event) {
|
|
|
|
$li.removeClass("active");
|
|
|
|
$(this).addClass("active");
|
|
|
|
})
|
|
|
|
.on('mouseover', function (event) {
|
|
|
|
$el.removeClass('oe_big oe_small oe_medium');
|
|
|
|
$el.addClass($(event.currentTarget).data("value"));
|
|
|
|
})
|
|
|
|
.on('mouseout', function (event) {
|
|
|
|
$el.removeClass('oe_big oe_small oe_medium');
|
|
|
|
$el.addClass($ul.find('li.active').data("value"));
|
|
|
|
});
|
|
|
|
}
|
2013-09-27 12:41:16 +00:00
|
|
|
});
|
2013-10-19 20:59:31 +00:00
|
|
|
website.snippet.animationRegistry.parallax = website.snippet.Animation.extend({
|
|
|
|
start: function () {
|
|
|
|
$.stellar({ horizontalScrolling: false, verticalOffset: 0 });
|
2013-09-27 12:41:16 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2013-09-24 08:24:23 +00:00
|
|
|
/*
|
|
|
|
* data-snippet-id automatically setted
|
|
|
|
* Don't need to add data-snippet-id="..." into the views
|
|
|
|
*/
|
|
|
|
|
|
|
|
website.snippet.selector.push([".row > div[class*='col-md-']", 'colmd']);
|
2013-09-17 11:00:43 +00:00
|
|
|
website.snippet.selector.push(['hr', 'hr']);
|
|
|
|
|
2013-09-14 22:13:01 +00:00
|
|
|
})();
|