diff --git a/src/js/main.js b/src/js/main.js index 6d5bbb2..c653693 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -117,15 +117,21 @@ function showBasicAlert(html, newOptions) { ); alertHtml.find(".htmlcontent").append(html); $("body").append(alertHtml); - alertHtml.find(".okbtn").click(function () { - if (options.onOkClick) { - options.onOkClick(); - } - alertHtml.remove(); - }); - alertHtml.find(".closeAlert").click(function () { - alertHtml.remove(); - }); + alertHtml + .find(".okbtn") + .off("click") + .click(function () { + if (options.onOkClick) { + options.onOkClick(); + } + alertHtml.remove(); + }); + alertHtml + .find(".closeAlert") + .off("click") + .click(function () { + alertHtml.remove(); + }); if (options.hideAfter) { setTimeout(function () { @@ -236,272 +242,309 @@ function initWhiteboard() { }); // whiteboard clear button - $("#whiteboardTrashBtn").click(function () { - $("#whiteboardTrashBtnConfirm").show().focus(); - $(this).css({ visibility: "hidden" }); - }); + $("#whiteboardTrashBtn") + .off("click") + .click(function () { + $("#whiteboardTrashBtnConfirm").show().focus(); + $(this).css({ visibility: "hidden" }); + }); $("#whiteboardTrashBtnConfirm").mouseout(function () { $(this).hide(); $("#whiteboardTrashBtn").css({ visibility: "inherit" }); }); - $("#whiteboardTrashBtnConfirm").click(function () { - $(this).hide(); - $("#whiteboardTrashBtn").css({ visibility: "inherit" }); - whiteboard.clearWhiteboard(); - }); + $("#whiteboardTrashBtnConfirm") + .off("click") + .click(function () { + $(this).hide(); + $("#whiteboardTrashBtn").css({ visibility: "inherit" }); + whiteboard.clearWhiteboard(); + }); // undo button - $("#whiteboardUndoBtn").click(function () { - whiteboard.undoWhiteboardClick(); - }); + $("#whiteboardUndoBtn") + .off("click") + .click(function () { + whiteboard.undoWhiteboardClick(); + }); // redo button - $("#whiteboardRedoBtn").click(function () { - whiteboard.redoWhiteboardClick(); - }); + $("#whiteboardRedoBtn") + .off("click") + .click(function () { + whiteboard.redoWhiteboardClick(); + }); // view only - $("#whiteboardLockBtn").click(() => { - ReadOnlyService.deactivateReadOnlyMode(); - }); - $("#whiteboardUnlockBtn").click(() => { - ReadOnlyService.activateReadOnlyMode(); - }); + $("#whiteboardLockBtn") + .off("click") + .click(() => { + ReadOnlyService.deactivateReadOnlyMode(); + }); + $("#whiteboardUnlockBtn") + .off("click") + .click(() => { + ReadOnlyService.activateReadOnlyMode(); + }); $("#whiteboardUnlockBtn").hide(); $("#whiteboardLockBtn").show(); // switch tool - $(".whiteboard-tool").click(function () { - $(".whiteboard-tool").removeClass("active"); - $(this).addClass("active"); - var activeTool = $(this).attr("tool"); - whiteboard.setTool(activeTool); - if (activeTool == "mouse" || activeTool == "recSelect") { - $(".activeToolIcon").empty(); - } else { - $(".activeToolIcon").html($(this).html()); //Set Active icon the same as the button icon - } - }); + $(".whiteboard-tool") + .off("click") + .click(function () { + $(".whiteboard-tool").removeClass("active"); + $(this).addClass("active"); + var activeTool = $(this).attr("tool"); + whiteboard.setTool(activeTool); + if (activeTool == "mouse" || activeTool == "recSelect") { + $(".activeToolIcon").empty(); + } else { + $(".activeToolIcon").html($(this).html()); //Set Active icon the same as the button icon + } + }); // upload image button - $("#addImgToCanvasBtn").click(function () { - if (ReadOnlyService.readOnlyActive) return; - showBasicAlert("Please drag the image into the browser."); - }); + $("#addImgToCanvasBtn") + .off("click") + .click(function () { + if (ReadOnlyService.readOnlyActive) return; + showBasicAlert("Please drag the image into the browser."); + }); // save image as imgae - $("#saveAsImageBtn").click(function () { - whiteboard.getImageDataBase64( - { - imageFormat: ConfigService.imageDownloadFormat, - drawBackgroundGrid: ConfigService.drawBackgroundGrid, - }, - function (imgData) { - var w = window.open("about:blank"); //Firefox will not allow downloads without extra window - setTimeout(function () { - //FireFox seems to require a setTimeout for this to work. - var a = document.createElement("a"); - a.href = imgData; - a.download = "whiteboard." + ConfigService.imageDownloadFormat; - w.document.body.appendChild(a); - a.click(); - w.document.body.removeChild(a); - setTimeout(function () { - w.close(); - }, 100); - }, 0); - } - ); - }); - - // save image to json containing steps - $("#saveAsJSONBtn").click(function () { - var imgData = whiteboard.getImageDataJson(); - - var w = window.open("about:blank"); //Firefox will not allow downloads without extra window - setTimeout(function () { - //FireFox seems to require a setTimeout for this to work. - var a = document.createElement("a"); - a.href = window.URL.createObjectURL(new Blob([imgData], { type: "text/json" })); - a.download = "whiteboard.json"; - w.document.body.appendChild(a); - a.click(); - w.document.body.removeChild(a); - setTimeout(function () { - w.close(); - }, 100); - }, 0); - }); - - $("#uploadWebDavBtn").click(function () { - if ($(".webdavUploadBtn").length > 0) { - return; - } - - var webdavserver = localStorage.getItem("webdavserver") || ""; - var webdavpath = localStorage.getItem("webdavpath") || "/"; - var webdavusername = localStorage.getItem("webdavusername") || ""; - var webdavpassword = localStorage.getItem("webdavpassword") || ""; - var webDavHtml = $( - "
" + - "" + - "" + - "" + - '' + - "" + - "" + - "" + - "" + - '' + - '' + - "" + - "" + - "" + - '' + - '' + - "" + - "" + - "" + - '' + - '' + - "" + - "" + - '' + - "" + - "" + - "" + - '' + - "" + - "
Server URL:
Path:path always have to start & end with "/"
Username:
Password:
Note: You have to generate and use app credentials if you have 2 Factor Auth activated on your dav/nextcloud server!
" + - "
" - ); - webDavHtml.find(".webdavUploadBtn").click(function () { - var webdavserver = webDavHtml.find(".webdavserver").val(); - localStorage.setItem("webdavserver", webdavserver); - var webdavpath = webDavHtml.find(".webdavpath").val(); - localStorage.setItem("webdavpath", webdavpath); - var webdavusername = webDavHtml.find(".webdavusername").val(); - localStorage.setItem("webdavusername", webdavusername); - var webdavpassword = webDavHtml.find(".webdavpassword").val(); - localStorage.setItem("webdavpassword", webdavpassword); + $("#saveAsImageBtn") + .off("click") + .click(function () { whiteboard.getImageDataBase64( { imageFormat: ConfigService.imageDownloadFormat, drawBackgroundGrid: ConfigService.drawBackgroundGrid, }, - function (base64data) { - var webdavaccess = { - webdavserver: webdavserver, - webdavpath: webdavpath, - webdavusername: webdavusername, - webdavpassword: webdavpassword, - }; - webDavHtml.find(".loadingWebdavText").show(); - webDavHtml.find(".webdavUploadBtn").hide(); - saveWhiteboardToWebdav(base64data, webdavaccess, function (err) { - if (err) { - webDavHtml.find(".loadingWebdavText").hide(); - webDavHtml.find(".webdavUploadBtn").show(); - } else { - webDavHtml.parents(".basicalert").remove(); - } - }); + function (imgData) { + var w = window.open("about:blank"); //Firefox will not allow downloads without extra window + setTimeout(function () { + //FireFox seems to require a setTimeout for this to work. + var a = document.createElement("a"); + a.href = imgData; + a.download = "whiteboard." + ConfigService.imageDownloadFormat; + w.document.body.appendChild(a); + a.click(); + w.document.body.removeChild(a); + setTimeout(function () { + w.close(); + }, 100); + }, 0); } ); }); - showBasicAlert(webDavHtml, { - header: "Save to Webdav", - okBtnText: "cancel", - headercolor: "#0082c9", + + // save image to json containing steps + $("#saveAsJSONBtn") + .off("click") + .click(function () { + var imgData = whiteboard.getImageDataJson(); + + var w = window.open("about:blank"); //Firefox will not allow downloads without extra window + setTimeout(function () { + //FireFox seems to require a setTimeout for this to work. + var a = document.createElement("a"); + a.href = window.URL.createObjectURL(new Blob([imgData], { type: "text/json" })); + a.download = "whiteboard.json"; + w.document.body.appendChild(a); + a.click(); + w.document.body.removeChild(a); + setTimeout(function () { + w.close(); + }, 100); + }, 0); }); - // render newly added icons - dom.i2svg(); - }); - // upload json containing steps - $("#uploadJsonBtn").click(function () { - $("#myFile").click(); - }); - - $("#shareWhiteboardBtn").click(() => { - function urlToClipboard(whiteboardId = null) { - const { protocol, host, pathname, search } = window.location; - const basePath = `${protocol}//${host}${pathname}`; - const getParams = new URLSearchParams(search); - - // Clear ursername from get parameters - getParams.delete("username"); - - if (whiteboardId) { - // override whiteboardId value in URL - getParams.set("whiteboardid", whiteboardId); + $("#uploadWebDavBtn") + .off("click") + .click(function () { + if ($(".webdavUploadBtn").length > 0) { + return; } - const url = `${basePath}?${getParams.toString()}`; - $("