Skip to content

Commit 6c4c2c1

Browse files
committed
show tag editor when adding bookmark
1 parent 7887922 commit 6c4c2c1

File tree

9 files changed

+104
-61
lines changed

9 files changed

+104
-61
lines changed

css/bookmarkManager.css

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
.bookmark-tag-bar {
2+
margin-top: 0.5em;
3+
}
4+
15
.bookmark-editor {
6+
background: transparent !important;
7+
}
8+
.bookmark-editor:not(.simplified) {
29
box-shadow: 0 0 0 1px rgba(0,0,0,0.2);
310
border-radius: 3px;
4-
background: transparent !important;
511
}
6-
.dark-theme .bookmark-editor {
12+
.dark-theme .bookmark-editor:not(.simplified) {
713
box-shadow: 0 0 0 1px rgba(255, 255, 255 ,0.2);
814
}
915

@@ -15,12 +21,12 @@
1521
.bookmark-editor .bookmark-url {
1622
opacity: 0.66;
1723
font-size: 0.95em;
24+
margin-bottom: 0.55em;
1825
}
1926

2027
#searchbar .tag {
2128
display: inline-block;
2229
padding: 0.33em 0.5em;
23-
margin-top: 0.5em;
2430
border-radius: 3px;
2531
background-color: rgba(0, 0, 0, 0.075);
2632
border: 2px transparent solid;
@@ -66,7 +72,6 @@
6672
.tag-edit-area .tag-input {
6773
-webkit-appearance: none;
6874
padding: 0.35em 0.5em;
69-
margin-top: 0.5em;
7075
border-radius: 3px;
7176
background: transparent;
7277
color: inherit;

js/keybindings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ function initialize () {
200200

201201
defineShortcut('addToFavorites', function (e) {
202202
tabBar.getTab(tabs.getSelected()).querySelector('.bookmarks-button').click()
203-
tabBar.enterEditMode(tabs.getSelected()) // we need to show the bookmarks button, which is only visible in edit mode
203+
tabBar.enterEditMode(tabs.getSelected(), null, false) // we need to show the bookmarks button, which is only visible in edit mode
204204
})
205205

206206
// cmd+x should switch to tab x. Cmd+9 should switch to the last tab

js/navbar/bookmarkStar.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
const db = require('util/database.js').db
22
const places = require('places/places.js')
3+
const bookmarkEditor = require('searchbar/bookmarkEditor.js')
4+
const searchbar = require('searchbar/searchbar.js')
5+
const searchbarPlugins = require('searchbar/searchbarPlugins.js')
36

47
const bookmarkStar = {
58
create: function (tabId) {
@@ -17,10 +20,20 @@ const bookmarkStar = {
1720
return star
1821
},
1922
onClick: function (tabId, star) {
23+
searchbarPlugins.clearAll()
24+
2025
star.classList.toggle('fa-star')
2126
star.classList.toggle('fa-star-o')
2227

23-
places.toggleBookmarked(tabId)
28+
places.toggleBookmarked(tabId, function (isBookmarked) {
29+
if (isBookmarked) {
30+
var editorInsertionPoint = document.createElement('div')
31+
searchbarPlugins.getContainer('simpleBookmarkTagInput').appendChild(editorInsertionPoint)
32+
bookmarkEditor.show(tabs.get(tabs.getSelected()).url, editorInsertionPoint, null, {simplified: true})
33+
} else {
34+
searchbar.showResults('')
35+
}
36+
})
2437
},
2538
update: function (tabId, star) {
2639
const currentURL = tabs.get(tabId).url
@@ -45,4 +58,8 @@ const bookmarkStar = {
4558
}
4659
}
4760

61+
searchbarPlugins.register('simpleBookmarkTagInput', {
62+
index: 0
63+
})
64+
4865
module.exports = bookmarkStar

js/navbar/tabBar.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ window.tabBar = {
3838
timeout: 1500
3939
})
4040
},
41-
enterEditMode: function (tabId, editingValue) {
41+
enterEditMode: function (tabId, editingValue, showSearchbar) {
4242
// editingValue: an optional string to show in the searchbar instead of the current URL
4343

4444
webviews.requestPlaceholder('editMode')
@@ -64,10 +64,12 @@ window.tabBar = {
6464

6565
searchbar.show(input)
6666

67-
if (editingValue) {
68-
searchbar.showResults(editingValue, null)
69-
} else {
70-
searchbar.showResults('', null)
67+
if (showSearchbar !== false) {
68+
if (editingValue) {
69+
searchbar.showResults(editingValue, null)
70+
} else {
71+
searchbar.showResults('', null)
72+
}
7173
}
7274

7375
tabBar.editingTab = tabId
@@ -155,11 +157,11 @@ window.tabBar = {
155157

156158
tabEl.appendChild(ec)
157159

158-
var vc = document.createElement('div')
159-
vc.className = 'tab-view-contents'
160+
var viewContents = document.createElement('div')
161+
viewContents.className = 'tab-view-contents'
160162

161-
vc.appendChild(readerView.getButton(data.id))
162-
vc.appendChild(progressBar.create())
163+
viewContents.appendChild(readerView.getButton(data.id))
164+
viewContents.appendChild(progressBar.create())
163165

164166
// icons
165167

@@ -193,17 +195,17 @@ window.tabBar = {
193195
secIcon.hidden = data.secure !== false
194196
iconArea.appendChild(secIcon)
195197

196-
vc.appendChild(iconArea)
198+
viewContents.appendChild(iconArea)
197199

198200
// title
199201

200202
var title = document.createElement('span')
201203
title.className = 'title'
202204
title.textContent = tabTitle
203205

204-
vc.appendChild(title)
206+
viewContents.appendChild(title)
205207

206-
tabEl.appendChild(vc)
208+
tabEl.appendChild(viewContents)
207209

208210
input.addEventListener('keydown', function (e) {
209211
if (e.keyCode === 9 || e.keyCode === 40) { // if the tab or arrow down key was pressed
@@ -253,7 +255,7 @@ window.tabBar = {
253255
})
254256

255257
// click to enter edit mode or switch to a tab
256-
tabEl.addEventListener('click', function (e) {
258+
viewContents.addEventListener('click', function (e) {
257259
if (tabs.getSelected() !== data.id) { // else switch to tab if it isn't focused
258260
browserUI.switchToTab(data.id)
259261
} else { // the tab is focused, edit tab instead

js/places/places.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,29 @@ const places = {
119119
onMessage: function (e) { // assumes this is from a search operation
120120
places.runWorkerCallback(e.data.callbackId, e.data.result)
121121
},
122-
updateItem: function (url, fields) {
122+
updateItem: function (url, fields, callback) {
123+
const callbackId = places.addWorkerCallback(callback)
123124
places.worker.postMessage({
124125
action: 'updatePlace',
125126
pageData: {
126127
url: url,
127128
...fields
128-
}
129+
},
130+
callbackId: callbackId
129131
})
130132
},
131-
toggleBookmarked: function (tabId) { // Toggles whether a URL is bookmarked or not
133+
toggleBookmarked: function (tabId, callback) { // Toggles whether a URL is bookmarked or not
132134
const url = tabs.get(tabId).url
133135

134136
db.places.where('url').equals(url).first(function (item) {
135137
if (item && item.isBookmarked) {
136-
places.updateItem(url, {isBookmarked: false})
138+
places.updateItem(url, {isBookmarked: false}, function () {
139+
callback(false)
140+
})
137141
} else {
138-
places.updateItem(url, {isBookmarked: true})
142+
places.updateItem(url, {isBookmarked: true}, function () {
143+
callback(true)
144+
})
139145
}
140146
})
141147
},

js/places/placesWorker.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ onmessage = function (e) {
179179
} else {
180180
addOrUpdateHistoryCache(item)
181181
}
182+
postMessage({
183+
result: null,
184+
callbackId: callbackId
185+
})
182186
}).catch(function (err) {
183187
console.warn('failed to update history.')
184188
console.warn('page url was: ' + pageData.url)

js/searchbar/bookmarkEditor.js

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,46 +25,52 @@ const bookmarkEditor = {
2525
})
2626
return el
2727
},
28-
render: async function (url) {
28+
render: async function (url, options = {}) {
2929
bookmarkEditor.currentInstance = {};
3030
bookmarkEditor.currentInstance.bookmark = await db.places.where('url').equals(url).first();
3131

3232
var editor = document.createElement('div')
3333
editor.className = 'bookmark-editor searchbar-item'
34+
35+
if (options.simplified) {
36+
editor.className += " simplified"
37+
}
3438

35-
//title input
36-
var title = document.createElement("span")
37-
title.className = "title wide";
38-
title.textContent = bookmarkEditor.currentInstance.bookmark.title;
39-
editor.appendChild(title);
40-
41-
//URL
42-
var URLSpan = document.createElement("div")
43-
URLSpan.className = "bookmark-url";
44-
URLSpan.textContent = bookmarkEditor.currentInstance.bookmark.url;
45-
editor.appendChild(URLSpan);
46-
47-
//save button
48-
var saveButton = document.createElement('button')
49-
saveButton.className = "fa fa-check action-button always-visible";
50-
saveButton.tabIndex = -1
51-
editor.appendChild(saveButton);
52-
saveButton.addEventListener("click", function() {
53-
editor.remove();
54-
bookmarkEditor.currentInstance.onClose(bookmarkEditor.currentInstance.bookmark);
55-
bookmarkEditor.currentInstance = null;
56-
});
57-
58-
//delete button
59-
var delButton = document.createElement('button')
60-
delButton.className = "fa fa-trash action-button always-visible bookmark-delete-button";
61-
delButton.tabIndex = -1
62-
editor.appendChild(delButton);
63-
delButton.addEventListener("click", function() {
64-
editor.remove();
65-
bookmarkEditor.currentInstance.onClose(null);
39+
if (!options.simplified) {
40+
//title input
41+
var title = document.createElement("span")
42+
title.className = "title wide";
43+
title.textContent = bookmarkEditor.currentInstance.bookmark.title;
44+
editor.appendChild(title);
45+
46+
//URL
47+
var URLSpan = document.createElement("div")
48+
URLSpan.className = "bookmark-url";
49+
URLSpan.textContent = bookmarkEditor.currentInstance.bookmark.url;
50+
editor.appendChild(URLSpan);
51+
52+
//save button
53+
var saveButton = document.createElement('button')
54+
saveButton.className = "fa fa-check action-button always-visible";
55+
saveButton.tabIndex = -1
56+
editor.appendChild(saveButton);
57+
saveButton.addEventListener("click", function() {
58+
editor.remove();
59+
bookmarkEditor.currentInstance.onClose(bookmarkEditor.currentInstance.bookmark);
6660
bookmarkEditor.currentInstance = null;
67-
});
61+
});
62+
63+
//delete button
64+
var delButton = document.createElement('button')
65+
delButton.className = "fa fa-trash action-button always-visible bookmark-delete-button";
66+
delButton.tabIndex = -1
67+
editor.appendChild(delButton);
68+
delButton.addEventListener("click", function() {
69+
editor.remove();
70+
bookmarkEditor.currentInstance.onClose(null);
71+
bookmarkEditor.currentInstance = null;
72+
});
73+
}
6874

6975
//tag area
7076
var tagArea = document.createElement('div')
@@ -114,15 +120,17 @@ const bookmarkEditor = {
114120

115121
return editor;
116122
},
117-
show: function (url, replaceItem, onClose) {
123+
show: function (url, replaceItem, onClose, options) {
118124
if (bookmarkEditor.currentInstance) {
119125
if (bookmarkEditor.currentInstance.editor.parentNode) {
120-
bookmarkEditor.currentInstance.onClose(bookmarkEditor.currentInstance.bookmark);
121126
bookmarkEditor.currentInstance.editor.remove();
127+
if (bookmark.currentInstance.onClose) {
128+
bookmarkEditor.currentInstance.onClose(bookmarkEditor.currentInstance.bookmark);
129+
}
122130
}
123131
bookmarkEditor.currentInstance = null;
124132
}
125-
bookmarkEditor.render(url).then(function (editor) {
133+
bookmarkEditor.render(url, options).then(function (editor) {
126134
replaceItem.hidden = true;
127135
replaceItem.parentNode.insertBefore(editor, replaceItem);
128136
bookmarkEditor.currentInstance.editor = editor;

js/searchbar/bookmarkManager.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ function showBookmarks (text, input, event) {
7878
searchbarPlugins.reset('bangs')
7979

8080
var tagBar = document.createElement('div')
81+
tagBar.className = 'bookmark-tag-bar'
8182
container.appendChild(tagBar)
8283

8384
parsedText.tags.forEach(function (tag) {

js/searchbar/searchbarPlugins.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ const searchbarPlugins = {
131131
run: function (text, input, event) {
132132
for (var i = 0; i < plugins.length; i++) {
133133
try {
134-
if ((!plugins[i].trigger || plugins[i].trigger(text))) {
134+
if (plugins[i].showResults && (!plugins[i].trigger || plugins[i].trigger(text))) {
135135
plugins[i].showResults(text, input, event)
136136
} else {
137137
searchbarPlugins.reset(plugins[i].name)

0 commit comments

Comments
 (0)