Commit 67b06eb2 authored by Duhoux Pierre-Louis's avatar Duhoux Pierre-Louis

Display bookmark popup from content script

parent 8c546016
......@@ -541,7 +541,16 @@
"content_nav_showbar": {
"message": "Display AMR ToolBar",
"description": "Tooltip to show AMR bar when icon clicked and bar hidden"
},
"content_nav_click_bm": {
"message": "Click here to bookmark this chapter",
"description": "Tooltip on button to bookmark a chapter"
},
"content_nav_note_bm": {
"message": "Note : $1",
"description": "Text to display the note for a bookmark. $1 is the note"
},
"bookmark_popup_title": {
"message": "Bookmark",
"description": "Title of the bookmark popup"
......
import store from '../store';
class HandleBookmarks {
handle(message, sender) {
switch (message.action) {
// hide navigation bar --> keeps its state
case "getBookmarkNote":
return Promise.resolve({}); //TODO
let noteBM = this.getBookmark(message);
return Promise.resolve({
isBooked: noteBM.booked,
note: noteBM.note,
scanSrc: noteBM.scanSrc
});
case "deleteBookmark": //TODO
return Promise.resolve({});
case "addUpdateBookmark": //TODO
this.addBookmark(message);
return Promise.resolve({});
case "createContextMenu": //TODO
return Promise.resolve({});
}
}
/**
* Find a bookmark from store
* @param {*} obj
*/
findBookmark(obj) {
return store.state.bookmarks.all.find(
bm =>
obj.mirror === bm.mirror &&
obj.url === bm.url &&
obj.chapUrl === bm.chapUrl &&
obj.type === bm.type &&
(obj.type === "chapter" ||
(obj.scanUrl === bm.scanUrl || encodeURI(obj.scanUrl) === bm.scanUrl)
)
)
}
/**
* Retrieve a stored bookmark
* @param {*} obj
*/
getBookmark(obj) {
let bm = this.findBookmark(obj);
if (bm !== undefined) {
if (obj.type === "chapter") {
return {
booked : true,
note : bm.note
}
} else {
return {
booked : true,
note : bm.note,
scanSrc : obj.scanUrl
}
}
}
return {
booked : false,
note : ""
}
}
/**
* Adds a bookmark in store
* @param {*} obj
*/
addBookmark(obj) {
let bm = this.findBookmark(obj);
if (bm === undefined) {
// adds a new bookmark
store.dispatch("createBookmark", {
mirror : obj.mirror,
url : obj.url,
chapUrl : obj.chapUrl,
type : obj.type,
name : obj.name,
chapName : obj.chapName,
scanUrl : obj.scanUrl,
scanName : obj.scanName,
note : obj.note
})
} else {
// update bookmark note
store.dispatch("updateBookmarkNote", obj.note);
}
}
}
export default (new HandleBookmarks)
\ No newline at end of file
......@@ -14,7 +14,10 @@ const contentScripts = [
'/content/back.js'
];
/** CSS to inject in pages containing mangas */
const contentCss = ['/content/content.css'];
const contentCss = [
'/content/content.css',
'/lib/jquery.modal.min.css'
];
class HandleManga {
handle(message, sender) {
......
......@@ -222,7 +222,7 @@ a.buttonAMR:active {
vertical-align:middle!important;
}
.buttonAMR.progress{
margin-button: auto !important;
margin: auto !important;
}
#AMRBarIn select, .amrbarlayout select {
vertical-align:middle!important;
......@@ -273,3 +273,7 @@ a.buttonAMR:active {
padding:0!important;
margin:0!important;
}
.jquery-modal.blocker {
z-index: 10000001;
}
\ No newline at end of file
......@@ -166,6 +166,70 @@ class Navigation {
return divContent;
}
/**
* Action for the button to add a bookmark
*/
async add_bookmark_button () {
var obj = {
action: "addUpdateBookmark",
mirror: $("#bookmarkData").data("mirror"),
url: $("#bookmarkData").data("url"),
chapUrl: $("#bookmarkData").data("chapUrl"),
type: $("#bookmarkData").data("type"),
name: $("#bookmarkData").data("name"),
chapName: $("#bookmarkData").data("chapName"),
note: $("#noteAMR").val()
};
if ($("#bookmarkData").data("type") !== "chapter") {
obj.scanUrl = $("#bookmarkData").data("scanUrl");
obj.scanName = $("#bookmarkData").data("scanName");
var imgScan = $(".spanForImg img[src='" + obj.scanUrl + "']");
imgScan.css("border-color", "#999999");
if ($("#noteAMR").val() !== "") {
imgScan.attr("title", "Note : " + $("#noteAMR").val());
}
imgScan.data("note", $("#noteAMR").val());
imgScan.data("booked", true);
} else {
$("#bookmarkData").data("note", $("#noteAMR").val());
if ($("#noteAMR").val() !== "") {
$(".bookAMR").attr("title", "Note : " + $("#noteAMR").val());
}
$(".bookAMR").attr("src", browser.extension.getURL("icons/bookmarkred.png"));
$("#bookmarkData").data("chapbooked", true);
}
await browser.runtime.sendMessage(obj);
$.modal.close();
}
/**
* Action for the button to delete current bookmark
*/
async delete_bookmark_button () {
var obj = {
action: "deleteBookmark",
mirror: $("#bookmarkData").data("mirror"),
url: $("#bookmarkData").data("url"),
chapUrl: $("#bookmarkData").data("chapUrl"),
type: $("#bookmarkData").data("type")
};
if ($("#bookmarkData").data("type") !== "chapter") {
obj.scanUrl = $("#bookmarkData").data("scanUrl");
var imgScan = $(".spanForImg img[src='" + obj.scanUrl + "']");
imgScan.css("border-color", "white");
imgScan.removeAttr("title");
imgScan.removeData("booked");
} else {
$(".bookAMR").removeAttr("title");
$(".bookAMR").attr("src", browser.extension.getURL("icons/bookmark.png"));
$("#bookmarkData").removeData("chapbooked");
}
await browser.runtime.sendMessage(obj);
$.modal.close();
}
/**
*
* @param {*} where
......@@ -178,12 +242,10 @@ class Navigation {
$("<div id='descEltAMR'></div>").appendTo(div);
$("<table><tr><td style='vertical-align:top'><b>" + i18n("bookmark_popup_note") + ":</b></td><td><textarea id='noteAMR' cols='50' rows='5' /></td></tr></table>").appendTo(div);
//TODO !!
//btn.click(add_bookmark_button);
btn.click(this.add_bookmark_button);
let btndel = $("<a id='delBtnAMR' class='buttonAMR'>" + i18n("bookmark_popup_delete") + "</a>");
//TODO !!
//btndel.click(delete_bookmark_button);
btndel.click(this.delete_bookmark_button);
btndel.appendTo(div);
btn.appendTo(div);
......@@ -205,7 +267,7 @@ class Navigation {
action: "mangaInfos",
url: pageData.currentMangaURL
});
where.each((index, w) => {
where.each(async (index, w) => {
let selectIns;
let $w = $(w);
......@@ -249,16 +311,9 @@ class Navigation {
} else {
$("#delBtnAMR").hide();
}
$("#bookmarkPop").modal({
focus: false,
onShow: navigation.showDialog,
zIndex: 10000000
});
navigation.showDialog();
});
if (index === 0) {
//TODO !! careful there is an await but no async as it is an anonymous function wrapped by jQuery --> externalize to function
/*
let objBM = {
action: "getBookmarkNote",
mirror: mirrorImpl.get().mirrorName,
......@@ -269,13 +324,13 @@ class Navigation {
let result = await browser.runtime.sendMessage(objBM);
if (!result.isBooked) {
$("#bookmarkData").data("note", "");
$(".bookAMR").attr("title", "Click here to bookmark this chapter");
$(".bookAMR").attr("title", i18n("content_nav_click_bm"));
} else {
$("#bookmarkData").data("note", result.note);
if (result.note !== "") $(".bookAMR").attr("title", "Note : " + result.note);
if (result.note !== "") $(".bookAMR").attr("title", i18n("content_nav_note_bm", result.note));
$("#bookmarkData").data("chapbooked", true);
$(".bookAMR").attr("src", browser.extension.getURL("icons/bookmarkred.png"));
}*/
}
}
let isRead = (mangaInfos === null ? false : (mangaInfos.read == 1));
......@@ -403,8 +458,10 @@ class Navigation {
}
}
//TODO
showDialog(dialog) {
/**
* Show bookmarks dialog
*/
showDialog() {
let textDesc;
if ($("#bookmarkData").data("type") == "chapter") {
textDesc = i18n("bookmark_chapter_text",
......@@ -419,6 +476,7 @@ class Navigation {
$("#bookmarkData").data("mirror"));
}
$("#bookmarkPop #descEltAMR").text(textDesc);
$("#bookmarkPop").modal();
}
}
export default (new Navigation) // singleton
\ No newline at end of file
......@@ -40,6 +40,15 @@ const actions = {
commit('createBookmark', bm);
await storedb.storeBookmark(bm);
},
/**
* Updates the note on a bookmark
* @param {*} param0
* @param {*} bm bookmark with new note
*/
async updateBookmarkNote({ commit }, bm) {
commit('updateBookmarkNote', bm);
await storedb.storeBookmark(bm);
},
/**
* Delete a bookmark in the store
* @param {*} param0
......@@ -78,10 +87,21 @@ const mutations = {
*/
createBookmark(state, bm) {
if (!bm.key) {
bm.key = utils.mangaKey(bm.url)
bm.key = utils.mangaKey(bm.chapUrl) + bm.scanUrl ? "_" + utils.mangaKey(bm.scanUrl) : ""
}
state.all.push(bm)
},
/**
* Updates the note on a bookmark
* @param {*} state
* @param {*} bm bookmark with new note
*/
async updateBookmarkNote(state, bm) {
let bmn = state.all.find(bookmark => bookmark.key === key)
if (bmn !== undefined) {
bmn.note = bm.note
}
},
/**
* Delete a bookmark
* @param {*} state
......
......@@ -90,6 +90,7 @@ const config = {
{from: '_locales/**/*', to: '.'},
{from: '../node_modules/jquery/dist/jquery.min.js', to: 'lib/jquery.min.js'},
{from: '../node_modules/jquery-modal/jquery.modal.min.js', to: 'lib/jquery.modal.min.js'},
{from: '../node_modules/jquery-modal/jquery.modal.min.css', to: 'lib/jquery.modal.min.css'},
{from: '../node_modules/jquery.scrollto/jquery.scrollTo.min.js', to: 'lib/jquery.scrollTo.min.js'}
]),
new WebpackShellPlugin({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment