|
|
|
@ -30,9 +30,12 @@ define(function(require) { |
|
|
|
CommandButtons = require('./model/CommandButtons'), |
|
|
|
CommandButtonsView = require('./view/CommandButtonsView'); |
|
|
|
var tlbPfx, toolbar, commands; |
|
|
|
var mainSelf; |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
customRte: null, |
|
|
|
|
|
|
|
/** |
|
|
|
* Name of the module |
|
|
|
* @type {String} |
|
|
|
@ -46,6 +49,7 @@ define(function(require) { |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
init: function(config) { |
|
|
|
mainSelf = this; |
|
|
|
c = config || {}; |
|
|
|
for (var name in defaults) { |
|
|
|
if (!(name in c)) |
|
|
|
@ -114,10 +118,11 @@ define(function(require) { |
|
|
|
* Triggered when the offset of the editro is changed |
|
|
|
* @private |
|
|
|
*/ |
|
|
|
udpatePosition: function(){ |
|
|
|
udpatePosition: function() { |
|
|
|
var u = 'px'; |
|
|
|
var canvas = c.em.get('Canvas'); |
|
|
|
var pos = canvas.getTargetToElementDim(toolbar.el, this.lastEl, 1); |
|
|
|
//console.log(toolbar.el, this.lastEl, pos);
|
|
|
|
var toolbarStyle = toolbar.el.style; |
|
|
|
toolbarStyle.top = pos.top + u; |
|
|
|
toolbarStyle.left = pos.left + u; |
|
|
|
@ -126,20 +131,31 @@ define(function(require) { |
|
|
|
/** |
|
|
|
* Bind rich text editor to the element |
|
|
|
* @param {View} view |
|
|
|
* @param {Object} rte The instance of already defined RTE |
|
|
|
* @private |
|
|
|
* */ |
|
|
|
attach: function(view){ |
|
|
|
view.$el.wysiwyg({}).focus(); |
|
|
|
attach: function(view, rte) { |
|
|
|
this.lastEl = view.el; |
|
|
|
var customRte = this.customRte; |
|
|
|
|
|
|
|
// If a custom RTE is defined
|
|
|
|
if (customRte) { |
|
|
|
// No RTE instance was provided
|
|
|
|
if(!rte || rte.status == 'destroyed') { |
|
|
|
rte = customRte.enable(view.el, rte); |
|
|
|
} |
|
|
|
} else { |
|
|
|
view.$el.wysiwyg({}).focus(); |
|
|
|
} |
|
|
|
|
|
|
|
this.show(); |
|
|
|
|
|
|
|
if(c.em){ |
|
|
|
this.udpatePosition(); |
|
|
|
//this.udpatePosition();
|
|
|
|
|
|
|
|
if(c.em) { |
|
|
|
setTimeout(this.udpatePosition.bind(this), 0); |
|
|
|
c.em.off('change:canvasOffset', this.udpatePosition, this); |
|
|
|
c.em.on('change:canvasOffset', this.udpatePosition, this); |
|
|
|
|
|
|
|
// Update position on scrolling
|
|
|
|
c.em.off('canvasScroll', this.udpatePosition, this); |
|
|
|
c.em.on('canvasScroll', this.udpatePosition, this); |
|
|
|
@ -147,32 +163,58 @@ define(function(require) { |
|
|
|
|
|
|
|
//Avoid closing edit mode clicking on toolbar
|
|
|
|
toolbar.$el.on('mousedown', this.disableProp); |
|
|
|
return rte; |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Unbind rich text editor from the element |
|
|
|
* @param {View} view |
|
|
|
* @param {Object} rte The instance of already defined RTE |
|
|
|
* @private |
|
|
|
* */ |
|
|
|
detach: function(view){ |
|
|
|
view.$el.wysiwyg('destroy'); |
|
|
|
detach: function(view, rte) { |
|
|
|
var customRte = this.customRte; |
|
|
|
if (customRte) { |
|
|
|
view.model.set('content', view.el.innerHTML); |
|
|
|
customRte.disable(view.el, rte); |
|
|
|
} else { |
|
|
|
view.$el.wysiwyg('destroy'); |
|
|
|
} |
|
|
|
this.hide(); |
|
|
|
toolbar.$el.off('mousedown', this.disableProp); |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Unbind rich text editor from the element |
|
|
|
* @param {View} view |
|
|
|
* @param {Object} rte The instance of already defined RTE |
|
|
|
* @private |
|
|
|
* */ |
|
|
|
focus: function(view, rte) { |
|
|
|
var customRte = this.customRte; |
|
|
|
if (customRte) { |
|
|
|
customRte.focus(view.el, rte); |
|
|
|
} else { |
|
|
|
this.attach(view); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Show the toolbar |
|
|
|
* @private |
|
|
|
* */ |
|
|
|
show: function(){ |
|
|
|
toolbar.el.style.display = "block"; |
|
|
|
show: function() { |
|
|
|
var toolbarStyle = toolbar.el.style; |
|
|
|
toolbarStyle.top = 0; |
|
|
|
toolbarStyle.left = 0; |
|
|
|
toolbarStyle.display = "block"; |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* Hide the toolbar |
|
|
|
* @private |
|
|
|
* */ |
|
|
|
hide: function(){ |
|
|
|
hide: function() { |
|
|
|
toolbar.el.style.display = "none"; |
|
|
|
}, |
|
|
|
|
|
|
|
@ -180,7 +222,7 @@ define(function(require) { |
|
|
|
* Isolate the disable propagation method |
|
|
|
* @private |
|
|
|
* */ |
|
|
|
disableProp: function(e){ |
|
|
|
disableProp: function(e) { |
|
|
|
e.stopPropagation(); |
|
|
|
}, |
|
|
|
|
|
|
|
|