[IMP] website snippet: add onfocus, onblur, onclone and onremove on snippet options; fix banner id
bzr revid: chm@openerp.com-20140314113510-dqj70i85z41q5j0k
This commit is contained in:
parent
aa412d99ec
commit
51a0bb001b
|
@ -419,7 +419,7 @@
|
|||
$target.data("overlay").remove();
|
||||
$target.removeData("overlay");
|
||||
}
|
||||
$target.find("[data-snippet-id]").each(function () {
|
||||
$target.find(website.snippet.globalSelector).each(function () {
|
||||
var $snippet = $(this);
|
||||
$snippet.removeData("snippet-editor");
|
||||
if ($snippet.data("overlay")) {
|
||||
|
@ -676,6 +676,30 @@
|
|||
// start is call just after the init
|
||||
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
|
||||
|
@ -806,23 +830,36 @@
|
|||
});
|
||||
|
||||
website.snippet.options.slider = website.snippet.Option.extend({
|
||||
unique_id: function () {
|
||||
var id = 0;
|
||||
$(".carousel").each(function () {
|
||||
var cid = 1 + parseInt($(this).attr("id").replace(/[^0123456789]/g, ''),10);
|
||||
if (id < cid) id = cid;
|
||||
});
|
||||
return "myCarousel" + id;
|
||||
},
|
||||
drop_and_build_snippet: function() {
|
||||
var id = $(".carousel").length;
|
||||
this.id = "myCarousel" + id;
|
||||
this.id = this.unique_id();
|
||||
this.$target.attr("id", this.id);
|
||||
this.$target.find(".carousel-control").attr("href", "#myCarousel" + id);
|
||||
this.$target.find("[data-target]").attr("data-target", "#myCarousel" + id);
|
||||
this.$target.find("[data-slide]").attr("href", "#" + this.id);
|
||||
this.$target.find("[data-slide-to]").attr("data-target", "#" + this.id);
|
||||
|
||||
this.rebind_event();
|
||||
},
|
||||
on_clone: function ($clone) {
|
||||
var id = this.unique_id();
|
||||
$clone.attr("id", id);
|
||||
$clone.find("[data-slide]").attr("href", "#" + id);
|
||||
$clone.find("[data-slide-to]").attr("data-target", "#" + id);
|
||||
},
|
||||
// rebind event to active carousel on edit mode
|
||||
rebind_event: function () {
|
||||
var self = this;
|
||||
this.$target.find('.carousel-indicators [data-target]').off('click').on('click', function () {
|
||||
this.$target.find('.carousel-indicators [data-slide-to]').off('click').on('click', function () {
|
||||
self.$target.carousel(+$(this).data('slide-to')); });
|
||||
|
||||
this.$target.attr('contentEditable', 'false');
|
||||
this.$target.find('.oe_structure, .content>.row').attr('contentEditable', 'true');
|
||||
this.$target.find('.oe_structure, .content>.row, [data-slide]').attr('contentEditable', 'true');
|
||||
},
|
||||
clean_for_save: function () {
|
||||
this._super();
|
||||
|
@ -1187,25 +1224,22 @@
|
|||
this._super();
|
||||
},
|
||||
hide_remove_button: function() {
|
||||
this.$overlay.find('.oe_snippet_remove').toggleClass("hidden",
|
||||
!this.$target.siblings().length && this.$target.parents("[data-snippet-id]:first").find("[data-snippet-id='colmd']").length > 1);
|
||||
this.$overlay.find('.oe_snippet_remove').toggleClass("hidden", !this.$target.siblings().length);
|
||||
},
|
||||
onFocus : function () {
|
||||
this._super();
|
||||
this.hide_remove_button();
|
||||
},
|
||||
on_clone: function () {
|
||||
var $clone = this.$target.clone(false);
|
||||
on_clone: function ($clone) {
|
||||
var _class = $clone.attr("class").replace(/\s*(col-lg-offset-|col-md-offset-)([0-9-]+)/g, '');
|
||||
$clone.attr("class", _class);
|
||||
this.$target.after($clone);
|
||||
this.hide_remove_button();
|
||||
return false;
|
||||
},
|
||||
on_remove: function () {
|
||||
if (!this.$target.siblings().length) {
|
||||
var $parent = this.$target.parents("[data-snippet-id]:first");
|
||||
if($parent.find("[data-snippet-id='colmd']").length > 1) {
|
||||
var $parent = this.$target.parents(".row:first");
|
||||
if($parent.find("[class*='col-md']").length > 1) {
|
||||
return false;
|
||||
} else {
|
||||
if (!$parent.data("snippet-editor")) {
|
||||
|
@ -1455,7 +1489,7 @@
|
|||
get_parent_block: function () {
|
||||
var self = this;
|
||||
var $button = this.$overlay.find('.oe_snippet_parent');
|
||||
var $parent = this.$target.parents("[data-snippet-id]:first");
|
||||
var $parent = this.$target.parents(website.snippet.globalSelector).first();
|
||||
if ($parent.length) {
|
||||
$button.removeClass("hidden");
|
||||
$button.off("click").on('click', function (event) {
|
||||
|
@ -1483,12 +1517,18 @@
|
|||
on_clone: function () {
|
||||
var $clone = this.$target.clone(false);
|
||||
this.$target.after($clone);
|
||||
for (var i in this.styles){
|
||||
this.styles[i].on_clone($clone);
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
on_remove: function () {
|
||||
this.onBlur();
|
||||
var index = _.indexOf(this.BuildingBlock.snippets, this.$target.get(0));
|
||||
for (var i in this.styles){
|
||||
this.styles[i].on_remove();
|
||||
}
|
||||
delete this.BuildingBlock.snippets[index];
|
||||
this.$target.remove();
|
||||
this.$overlay.remove();
|
||||
|
@ -1511,12 +1551,18 @@
|
|||
*/
|
||||
onFocus : function () {
|
||||
this.$overlay.addClass('oe_active');
|
||||
for (var i in this.styles){
|
||||
this.styles[i].onFocus();
|
||||
}
|
||||
},
|
||||
|
||||
/* onFocus
|
||||
* This method is called when the user click outside the snippet in the dom, after a focus
|
||||
*/
|
||||
onBlur : function () {
|
||||
for (var i in this.styles){
|
||||
this.styles[i].onBlur();
|
||||
}
|
||||
this.$overlay.removeClass('oe_active');
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue