From 08335dfdee8b5db74b6a751b263c15296ea48448 Mon Sep 17 00:00:00 2001 From: zombieFox Date: Sat, 18 Apr 2020 10:40:10 +0100 Subject: [PATCH] [refactor] improve group name when left empty --- package-lock.json | 2 +- package.json | 2 +- src/js/bookmarks.js | 23 +++-------------------- src/js/control.js | 4 ++-- src/js/header.js | 4 ++-- src/js/link.js | 30 +++++++++++++++++++++--------- src/js/version.js | 2 +- src/manifest.json | 2 +- 8 files changed, 32 insertions(+), 37 deletions(-) diff --git a/package-lock.json b/package-lock.json index a8aaa44a..4f0d11b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "nightTab", - "version": "5.8.0", + "version": "5.9.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index ae79897d..a8c30695 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nightTab", - "version": "5.8.0", + "version": "5.9.0", "description": "A neutral new tab page accented with a chosen colour. Customise the layout, style, background and bookmarks in nightTab.", "main": "index.js", "scripts": { diff --git a/src/js/bookmarks.js b/src/js/bookmarks.js index d0fa3cc8..76db51db 100644 --- a/src/js/bookmarks.js +++ b/src/js/bookmarks.js @@ -232,31 +232,14 @@ var bookmarks = (function() { mod.all[data.position.destination.group].items.splice(data.position.destination.item, 0, data.link); }, group: function(data) { - var makeName = function() { - var count = get().length + 1; - return "Group " + count; - }; if (data) { if (data.group.name.text == null) { - data.group.name.text = makeName(); - } else if (typeof data.group.name.text == "string") { + data.group.name.text = ""; + }; + if (typeof data.group.name.text == "string") { data.group.name.text = data.group.name.text.trim(); - if (data.group.name.text == "") { - data.group.name.text = makeName(); - }; }; mod.all.splice(data.position.destination, 0, data.group); - } else { - mod.all.push({ - name: { - text: makeName(), - show: true - }, - openAll: { - show: true - }, - items: [] - }); }; } }; diff --git a/src/js/control.js b/src/js/control.js index 7bfe3d08..6d6f226b 100644 --- a/src/js/control.js +++ b/src/js/control.js @@ -20,13 +20,13 @@ var control = (function() { menu.open(); }, }, { - element: ".control-link-add", + element: ".control-add-link", type: "button", func: function() { link.add.item.open(); } }, { - element: ".control-group-add", + element: ".control-add-group", type: "button", func: function() { link.add.group.open(); diff --git a/src/js/header.js b/src/js/header.js index e12d47e1..a74fbac4 100644 --- a/src/js/header.js +++ b/src/js/header.js @@ -383,12 +383,12 @@ var header = (function() { controlAddToggle.appendChild(controlAddToggleText); var formDropdownMenu = helper.node("ul|class:list-unstyled form-dropdown-menu"); var controlGroupAddLi = helper.node("li"); - var controlGroupAdd = helper.node("button|class:button button-block text-left form-dropdown-menu-item control-group-add,tabindex:1"); + var controlGroupAdd = helper.node("button|class:button button-block text-left form-dropdown-menu-item control-add-group,tabindex:1"); var controlGroupAddText = helper.node("span:New Group|class:button-text"); controlGroupAdd.appendChild(controlGroupAddText); controlGroupAddLi.appendChild(controlGroupAdd); var controlLinkAddLi = helper.node("li"); - var controlLinkAdd = helper.node("button|class:button button-block text-left form-dropdown-menu-item control-link-add,tabindex:1"); + var controlLinkAdd = helper.node("button|class:button button-block text-left form-dropdown-menu-item control-add-link,tabindex:1"); var controlLinkAddText = helper.node("span:New Bookmark|class:button-text"); controlLinkAdd.appendChild(controlLinkAddText); controlLinkAddLi.appendChild(controlLinkAdd); diff --git a/src/js/link.js b/src/js/link.js index e5ef5f14..bfa1a4b7 100644 --- a/src/js/link.js +++ b/src/js/link.js @@ -1047,12 +1047,18 @@ var link = (function() { var makeGroupOptions = function() { if (bookmarks.get().length > 0) { bookmarks.get().forEach(function(arrayItem, index) { + var name; + if (arrayItem.name.text == null || arrayItem.name.text == "") { + name = "Unnamed group " + (index + 1); + } else { + name = arrayItem.name.text; + }; var option = helper.makeNode({ tag: "option", - text: arrayItem.name.text, + text: name, attr: [{ key: "value", - value: arrayItem.name.text + value: name }] }); groupExistingGroup.appendChild(option); @@ -1413,7 +1419,7 @@ var link = (function() { groupBody.appendChild(linkEmpty); group.appendChild(groupBody); addButton.addEventListener("click", function(event) { - link.add.item.open(); + add.item.open(); }, false); return group; }, @@ -1424,8 +1430,8 @@ var link = (function() { linkEmpty.appendChild(para); linkEmpty.appendChild(addButton); addButton.addEventListener("click", function(event) { - link.add.item.open(); - link.add.item.selectGroup(groupIndex); + add.item.open(); + add.item.selectGroup(groupIndex); }, false); return linkEmpty; }, @@ -1636,6 +1642,7 @@ var link = (function() { pagelock.unlock(); }, selectGroup: function(groupIndex) { + stagedGroup.init(); stagedLink.position.destination.group = groupIndex; stagedLink.position.destination.item = 0; helper.e(".link-form-select-group").selectedIndex = stagedLink.position.destination.group; @@ -1750,7 +1757,12 @@ var link = (function() { var form = render.group.form({ useStagedGroup: true }); - var heading = "Edit " + stagedGroup.group.name.text; + var heading; + if (stagedGroup.group.name.text == null || stagedGroup.group.name.text == "") { + heading = "Edit unnamed group " + (stagedGroup.position.origin + 1); + } else { + heading = "Edit " + stagedGroup.group.name.text; + }; var successAction = function() { var copyStagedGroup = JSON.parse(JSON.stringify(stagedGroup)); bookmarks.mod.edit.group(copyStagedGroup); @@ -1844,10 +1856,10 @@ var link = (function() { stagedGroup.group = JSON.parse(JSON.stringify(copyStagedGroup.group)); stagedGroup.position = JSON.parse(JSON.stringify(copyStagedGroup.position)); var heading; - if (stagedGroup.group.name.text != null && stagedGroup.group.name.text != "") { - heading = "Remove " + stagedGroup.group.name.text; + if (stagedGroup.group.name.text == null || stagedGroup.group.name.text == "") { + heading = "Remove unnamed group " + (stagedGroup.position.origin + 1); } else { - heading = "Remove unnamed group"; + heading = "Remove " + stagedGroup.group.name.text; }; var successAction = function() { var copyStagedGroup = JSON.parse(JSON.stringify(stagedGroup)); diff --git a/src/js/version.js b/src/js/version.js index 48ccbb6c..92a3b9bd 100644 --- a/src/js/version.js +++ b/src/js/version.js @@ -1,6 +1,6 @@ var version = (function() { - var current = "5.8.0"; + var current = "5.9.0"; var name = "Zonked Tarsier"; diff --git a/src/manifest.json b/src/manifest.json index 9b8f0386..8e97fb01 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -2,7 +2,7 @@ "name": "nightTab", "short_name": "nightTab", "description": "A neutral new tab page accented with a chosen colour. Customise the layout, style, background and bookmarks in nightTab.", - "version": "5.8.0", + "version": "5.9.0", "manifest_version": 2, "chrome_url_overrides": { "newtab": "index.html"