Do not show plus button if toolbox is empty (#439)

This commit is contained in:
Murod Khaydarov 2018-08-30 16:38:52 +03:00 committed by GitHub
parent bd09c150bf
commit f2f8bc0851
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 8 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,6 +1,6 @@
{
"name": "codex.editor",
"version": "2.0.6",
"version": "2.0.7",
"description": "Codex Editor. Native JS, based on API and Open Source",
"main": "build/codex-editor.js",
"scripts": {

View file

@ -35,6 +35,12 @@ export default class Toolbox extends Module {
* @type {number}
*/
this.activeButtonIndex = -1;
/**
* How many tools displayed in Toolbox
* @type {number}
*/
this.displayedToolsCount = 0;
}
/**
@ -126,6 +132,9 @@ export default class Toolbox extends Module {
if (toolSettings && toolSettings[this.Editor.Tools.apiSettings.SHORTCUT]) {
this.enableShortcut(tool, toolName, toolSettings[this.Editor.Tools.apiSettings.SHORTCUT]);
}
/** Increment Tools count */
this.displayedToolsCount++;
}
/**
@ -195,6 +204,10 @@ export default class Toolbox extends Module {
* Open Toolbox with Tools
*/
open() {
if (this.isEmpty) {
return;
}
this.nodes.toolbox.classList.add(Toolbox.CSS.toolboxOpened);
this.opened = true;
}
@ -300,4 +313,12 @@ export default class Toolbox extends Module {
return childNodes[this.activeButtonIndex].title;
}
/**
* Returns True if Toolbox is Empty and nothing to show
* @return {boolean}
*/
get isEmpty() {
return this.displayedToolsCount === 0;
}
}

View file

@ -227,7 +227,12 @@ export default class Toolbar extends Module {
get plusButton() {
return {
hide: () => this.nodes.plusButton.classList.add(Toolbar.CSS.plusButtonHidden),
show: () => this.nodes.plusButton.classList.remove(Toolbar.CSS.plusButtonHidden)
show: () => {
if (this.Editor.Toolbox.isEmpty) {
return;
}
this.nodes.plusButton.classList.remove(Toolbar.CSS.plusButtonHidden);
}
};
}