2017-01-10 19:22:40 +01:00
|
|
|
/**
|
|
|
|
* Codex Editor toolbar module
|
|
|
|
*
|
|
|
|
* Contains:
|
|
|
|
* - Inline toolbox
|
|
|
|
* - Toolbox within plus button
|
|
|
|
* - Settings section
|
|
|
|
*
|
|
|
|
* @author Codex Team
|
|
|
|
* @version 1.0
|
|
|
|
*/
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
module.exports = (function (toolbar) {
|
|
|
|
|
2017-02-13 18:54:18 +01:00
|
|
|
let editor = codex.editor;
|
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
toolbar.settings = require('./settings');
|
|
|
|
toolbar.inline = require('./inline');
|
|
|
|
toolbar.toolbox = require('./toolbox');
|
2016-12-07 19:25:31 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Margin between focused node and toolbar
|
|
|
|
*/
|
|
|
|
toolbar.defaultToolbarHeight = 49;
|
|
|
|
|
|
|
|
toolbar.defaultOffset = 34;
|
|
|
|
|
|
|
|
toolbar.opened = false;
|
|
|
|
|
|
|
|
toolbar.current = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @protected
|
|
|
|
*/
|
2017-02-01 18:25:59 +01:00
|
|
|
toolbar.open = function () {
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-02-16 23:15:23 +01:00
|
|
|
if (editor.hideToolbar) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-08-30 03:12:30 +02:00
|
|
|
let toolType = editor.content.currentNode.dataset.tool;
|
|
|
|
|
|
|
|
if (!editor.tools[toolType] || !editor.tools[toolType].makeSettings ) {
|
|
|
|
|
|
|
|
editor.nodes.showSettingsButton.classList.add('hide');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
editor.nodes.showSettingsButton.classList.remove('hide');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
editor.nodes.toolbar.classList.add('opened');
|
2016-12-07 19:25:31 +01:00
|
|
|
this.opened = true;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @protected
|
|
|
|
*/
|
2017-02-01 18:25:59 +01:00
|
|
|
toolbar.close = function () {
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
editor.nodes.toolbar.classList.remove('opened');
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2016-12-25 15:41:57 +01:00
|
|
|
toolbar.opened = false;
|
|
|
|
toolbar.current = null;
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
for (var button in editor.nodes.toolbarButtons) {
|
|
|
|
|
|
|
|
editor.nodes.toolbarButtons[button].classList.remove('selected');
|
|
|
|
|
2016-12-07 19:25:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Close toolbox when toolbar is not displayed */
|
2017-02-01 18:25:59 +01:00
|
|
|
editor.toolbar.toolbox.close();
|
|
|
|
editor.toolbar.settings.close();
|
2016-12-07 19:25:31 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
toolbar.toggle = function () {
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
if ( !this.opened ) {
|
2016-12-07 19:25:31 +01:00
|
|
|
|
|
|
|
this.open();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
toolbar.hidePlusButton = function () {
|
|
|
|
|
|
|
|
editor.nodes.plusButton.classList.add('hide');
|
|
|
|
|
2016-12-07 19:25:31 +01:00
|
|
|
};
|
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
toolbar.showPlusButton = function () {
|
|
|
|
|
|
|
|
editor.nodes.plusButton.classList.remove('hide');
|
|
|
|
|
2016-12-07 19:25:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Moving toolbar to the specified node
|
|
|
|
*/
|
2017-02-01 18:25:59 +01:00
|
|
|
toolbar.move = function () {
|
2016-12-07 19:25:31 +01:00
|
|
|
|
|
|
|
/** Close Toolbox when we move toolbar */
|
2017-02-01 18:25:59 +01:00
|
|
|
editor.toolbar.toolbox.close();
|
|
|
|
|
|
|
|
if (!editor.content.currentNode) {
|
2016-12-07 19:25:31 +01:00
|
|
|
|
|
|
|
return;
|
2017-02-01 18:25:59 +01:00
|
|
|
|
2016-12-07 19:25:31 +01:00
|
|
|
}
|
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
var newYCoordinate = editor.content.currentNode.offsetTop - (editor.toolbar.defaultToolbarHeight / 2) + editor.toolbar.defaultOffset;
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
editor.nodes.toolbar.style.transform = `translate3D(0, ${Math.floor(newYCoordinate)}px, 0)`;
|
2016-12-07 19:25:31 +01:00
|
|
|
|
|
|
|
/** Close trash actions */
|
2017-02-01 18:25:59 +01:00
|
|
|
editor.toolbar.settings.hideRemoveActions();
|
2016-12-07 19:25:31 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
return toolbar;
|
|
|
|
|
2017-08-30 03:12:30 +02:00
|
|
|
})({});
|