2017-01-18 16:12:50 +01:00
|
|
|
/**
|
|
|
|
* Toolbar settings
|
|
|
|
*
|
2017-08-30 03:19:02 +02:00
|
|
|
* @version 1.0.5
|
2017-01-18 16:12:50 +01:00
|
|
|
*/
|
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
module.exports = (function (settings) {
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-02-13 18:54:18 +01:00
|
|
|
let editor = codex.editor;
|
|
|
|
|
2016-12-07 19:25:31 +01:00
|
|
|
settings.opened = false;
|
|
|
|
|
|
|
|
settings.setting = null;
|
|
|
|
settings.actions = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Append and open settings
|
|
|
|
*/
|
2017-02-01 18:25:59 +01:00
|
|
|
settings.open = function (toolType) {
|
2016-12-07 19:25:31 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Append settings content
|
|
|
|
* It's stored in tool.settings
|
|
|
|
*/
|
2017-08-30 03:19:02 +02:00
|
|
|
if ( !editor.tools[toolType] || !editor.tools[toolType].makeSettings ) {
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-08-30 03:19:02 +02:00
|
|
|
return;
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-08-30 03:19:02 +02:00
|
|
|
}
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-08-30 03:19:02 +02:00
|
|
|
/**
|
|
|
|
* Draw settings block
|
|
|
|
*/
|
|
|
|
var settingsBlock = editor.tools[toolType].makeSettings();
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-08-30 03:19:02 +02:00
|
|
|
editor.nodes.pluginSettings.appendChild(settingsBlock);
|
2017-02-01 18:25:59 +01:00
|
|
|
|
2016-12-07 19:25:31 +01:00
|
|
|
|
|
|
|
/** Open settings block */
|
2017-02-01 18:25:59 +01:00
|
|
|
editor.nodes.blockSettings.classList.add('opened');
|
2016-12-07 19:25:31 +01:00
|
|
|
this.opened = true;
|
2017-02-01 18:25:59 +01:00
|
|
|
|
2016-12-07 19:25:31 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close and clear settings
|
|
|
|
*/
|
2017-02-01 18:25:59 +01:00
|
|
|
settings.close = function () {
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
editor.nodes.blockSettings.classList.remove('opened');
|
|
|
|
editor.nodes.pluginSettings.innerHTML = '';
|
2016-12-07 19:25:31 +01:00
|
|
|
|
|
|
|
this.opened = false;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {string} toolType - plugin type
|
|
|
|
*/
|
2017-02-01 18:25:59 +01:00
|
|
|
settings.toggle = function ( toolType ) {
|
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(toolType);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Here we will draw buttons and add listeners to components
|
|
|
|
*/
|
2017-02-01 18:25:59 +01:00
|
|
|
settings.makeRemoveBlockButton = function () {
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
var removeBlockWrapper = editor.draw.node('SPAN', 'ce-toolbar__remove-btn', {}),
|
|
|
|
settingButton = editor.draw.node('SPAN', 'ce-toolbar__remove-setting', { innerHTML : '<i class="ce-icon-trash"></i>' }),
|
|
|
|
actionWrapper = editor.draw.node('DIV', 'ce-toolbar__remove-confirmation', {}),
|
|
|
|
confirmAction = editor.draw.node('DIV', 'ce-toolbar__remove-confirm', { textContent : 'Удалить блок' }),
|
|
|
|
cancelAction = editor.draw.node('DIV', 'ce-toolbar__remove-cancel', { textContent : 'Отмена' });
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-02-13 18:54:18 +01:00
|
|
|
editor.listeners.add(settingButton, 'click', editor.toolbar.settings.removeButtonClicked, false);
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-02-13 18:54:18 +01:00
|
|
|
editor.listeners.add(confirmAction, 'click', editor.toolbar.settings.confirmRemovingRequest, false);
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-02-13 18:54:18 +01:00
|
|
|
editor.listeners.add(cancelAction, 'click', editor.toolbar.settings.cancelRemovingRequest, false);
|
2016-12-07 19:25:31 +01:00
|
|
|
|
|
|
|
actionWrapper.appendChild(confirmAction);
|
|
|
|
actionWrapper.appendChild(cancelAction);
|
|
|
|
|
|
|
|
removeBlockWrapper.appendChild(settingButton);
|
|
|
|
removeBlockWrapper.appendChild(actionWrapper);
|
|
|
|
|
|
|
|
/** Save setting */
|
2017-02-01 18:25:59 +01:00
|
|
|
editor.toolbar.settings.setting = settingButton;
|
|
|
|
editor.toolbar.settings.actions = actionWrapper;
|
2016-12-07 19:25:31 +01:00
|
|
|
|
|
|
|
return removeBlockWrapper;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
settings.removeButtonClicked = function () {
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
var action = editor.toolbar.settings.actions;
|
2016-12-07 19:25:31 +01:00
|
|
|
|
|
|
|
if (action.classList.contains('opened')) {
|
2017-02-01 18:25:59 +01:00
|
|
|
|
|
|
|
editor.toolbar.settings.hideRemoveActions();
|
|
|
|
|
2016-12-07 19:25:31 +01:00
|
|
|
} else {
|
2017-02-01 18:25:59 +01:00
|
|
|
|
|
|
|
editor.toolbar.settings.showRemoveActions();
|
|
|
|
|
2016-12-07 19:25:31 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
settings.cancelRemovingRequest = function () {
|
|
|
|
|
|
|
|
editor.toolbar.settings.actions.classList.remove('opened');
|
2016-12-07 19:25:31 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
settings.confirmRemovingRequest = function () {
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
var currentBlock = editor.content.currentNode,
|
2016-12-07 19:25:31 +01:00
|
|
|
firstLevelBlocksCount;
|
|
|
|
|
|
|
|
currentBlock.remove();
|
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
firstLevelBlocksCount = editor.nodes.redactor.childNodes.length;
|
2016-12-07 19:25:31 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If all blocks are removed
|
|
|
|
*/
|
|
|
|
if (firstLevelBlocksCount === 0) {
|
|
|
|
|
|
|
|
/** update currentNode variable */
|
2017-02-01 18:25:59 +01:00
|
|
|
editor.content.currentNode = null;
|
2016-12-07 19:25:31 +01:00
|
|
|
|
|
|
|
/** Inserting new empty initial block */
|
2017-02-01 18:25:59 +01:00
|
|
|
editor.ui.addInitialBlock();
|
|
|
|
|
2016-12-07 19:25:31 +01:00
|
|
|
}
|
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
editor.ui.saveInputs();
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
editor.toolbar.close();
|
2016-12-07 19:25:31 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
settings.showRemoveActions = function () {
|
|
|
|
|
|
|
|
editor.toolbar.settings.actions.classList.add('opened');
|
|
|
|
|
2016-12-07 19:25:31 +01:00
|
|
|
};
|
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
settings.hideRemoveActions = function () {
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
editor.toolbar.settings.actions.classList.remove('opened');
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-02-01 18:25:59 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return settings;
|
2016-12-07 19:25:31 +01:00
|
|
|
|
2017-08-30 03:14:34 +02:00
|
|
|
})({});
|