' +
- '
' +
- content["username"] + '
');
- }
- } else {
- _this.cursorContainer.find("." + content["username"]).remove();
- }
- } else if (tool === "undo") {
- _this.undoWhiteboard(username);
- }
- });
+ if (_this.tool == "text" && _this.latestActiveTextBoxId) {
+ _this.sendFunction({ "t": "setTextboxFontSize", "d": [_this.latestActiveTextBoxId, thickness] });
+ _this.setTextboxFontSize(_this.latestActiveTextBoxId, thickness);
+ }
+ },
+ addImgToCanvasByUrl: function (url) {
+ var _this = this;
+ var wasTextTool = false;
+ if (_this.tool === "text") {
+ wasTextTool = true;
+ _this.setTool("mouse"); //Set to mouse tool while dropping to prevent errors
+ }
+ _this.imgDragActive = true;
+ _this.mouseOverlay.css({ "cursor": "default" });
+ var imgDiv = $('' +
+ '
' +
+ decodeURIComponent(atob(content["username"])) + '
');
+ }
+ } else {
+ _this.cursorContainer.find("." + content["username"]).remove();
+ }
+ } else if (tool === "undo") {
+ _this.undoWhiteboard(username);
+ }
+ });
- if (isNewData && ["line", "pen", "rect", "circle", "eraser", "addImgBG", "recSelect", "eraseRec", "addTextBox", "setTextboxText", "removeTextbox", "setTextboxPosition", "setTextboxFontSize", "setTextboxFontColor"].includes(tool)) {
- content["drawId"] = content["drawId"] ? content["drawId"] : _this.drawId;
- content["username"] = content["username"] ? content["username"] : _this.settings.username;
- _this.drawBuffer.push(content);
- }
- },
- userLeftWhiteboard(username) {
- this.cursorContainer.find("." + username).remove();
- },
- refreshUserBadges() {
- this.cursorContainer.find(".userbadge").remove();
- },
- getImageDataBase64() {
- _this = this;
- var width = this.mouseOverlay.width();
- var height = this.mouseOverlay.height();
- var copyCanvas = document.createElement('canvas');
- copyCanvas.width = width;
- copyCanvas.height = height;
- var ctx = copyCanvas.getContext("2d");
+ if (isNewData && ["line", "pen", "rect", "circle", "eraser", "addImgBG", "recSelect", "eraseRec", "addTextBox", "setTextboxText", "removeTextbox", "setTextboxPosition", "setTextboxFontSize", "setTextboxFontColor"].includes(tool)) {
+ content["drawId"] = content["drawId"] ? content["drawId"] : _this.drawId;
+ content["username"] = content["username"] ? content["username"] : _this.settings.username;
+ _this.drawBuffer.push(content);
+ }
+ },
+ userLeftWhiteboard(username) {
+ this.cursorContainer.find("." + username).remove();
+ },
+ refreshUserBadges() {
+ this.cursorContainer.find(".userbadge").remove();
+ },
+ getImageDataBase64() {
+ _this = this;
+ var width = this.mouseOverlay.width();
+ var height = this.mouseOverlay.height();
+ var copyCanvas = document.createElement('canvas');
+ copyCanvas.width = width;
+ copyCanvas.height = height;
+ var ctx = copyCanvas.getContext("2d");
- $.each(_this.imgContainer.find("img"), function () { //Draw Backgroundimages to the export canvas
- var width = $(this).width();
- var height = $(this).height();
- var p = $(this).position();
- var left = Math.round(p.left * 100) / 100;
- var top = Math.round(p.top * 100) / 100;
- ctx.drawImage(this, left, top, width, height);
- });
+ $.each(_this.imgContainer.find("img"), function () { //Draw Backgroundimages to the export canvas
+ var width = $(this).width();
+ var height = $(this).height();
+ var p = $(this).position();
+ var left = Math.round(p.left * 100) / 100;
+ var top = Math.round(p.top * 100) / 100;
+ ctx.drawImage(this, left, top, width, height);
+ });
- var destCtx = copyCanvas.getContext('2d'); //Draw the maincanvas to the exportcanvas
- destCtx.drawImage(this.canvas, 0, 0);
+ var destCtx = copyCanvas.getContext('2d'); //Draw the maincanvas to the exportcanvas
+ destCtx.drawImage(this.canvas, 0, 0);
- $.each($(".textBox"), function () { //Draw the text on top
- var textContainer = $(this)
- var textEl = $(this).find(".textContent");
- var text = textEl.text();
- var fontSize = textEl.css('font-size');
- var fontColor = textEl.css('color');
- var p = textContainer.position();
- var left = Math.round(p.left * 100) / 100;
- var top = Math.round(p.top * 100) / 100;
- top += 25; //Fix top position
- ctx.font = fontSize + " monospace";
- ctx.fillStyle = fontColor;
- ctx.fillText(text, left, top);
- });
+ $.each($(".textBox"), function () { //Draw the text on top
+ var textContainer = $(this)
+ var textEl = $(this).find(".textContent");
+ var text = textEl.text();
+ var fontSize = textEl.css('font-size');
+ var fontColor = textEl.css('color');
+ var p = textContainer.position();
+ var left = Math.round(p.left * 100) / 100;
+ var top = Math.round(p.top * 100) / 100;
+ top += 25; //Fix top position
+ ctx.font = fontSize + " Monospace";
+ ctx.fillStyle = fontColor;
+ ctx.fillText(text, left, top);
+ });
- var url = copyCanvas.toDataURL();
- return url;
- },
- getImageDataJson() {
- var sendObj = [];
- for (var i = 0; i < this.drawBuffer.length; i++) {
- sendObj.push(JSON.parse(JSON.stringify(this.drawBuffer[i])));
- delete sendObj[i]["username"];
- delete sendObj[i]["wid"];
- delete sendObj[i]["drawId"];
- }
- return JSON.stringify(sendObj);
- },
- loadData: function (content) {
- var _this = this;
- _this.loadDataInSteps(content, true, function (stepData) {
- if (stepData["username"] == _this.settings.username && _this.drawId < stepData["drawId"]) {
- _this.drawId = stepData["drawId"] + 1;
- }
- });
- },
- loadDataInSteps(content, isNewData, callAfterEveryStep) {
- var _this = this;
- function lData(index) {
- for (var i = index; i < content.length; i++) {
- if (content[i]["t"] === "addImgBG" && content[i]["draw"] == "1") {
- _this.handleEventsAndData(content[i], isNewData, function () {
- callAfterEveryStep(content[i], i);
- lData(i + 1);
- });
- break;
- } else {
- _this.handleEventsAndData(content[i], isNewData);
- callAfterEveryStep(content[i], i);
- }
- }
- }
- lData(0);
- },
- loadJsonData(content, doneCallback) {
- var _this = this;
- _this.loadDataInSteps(content, false, function (stepData, index) {
- _this.sendFunction(stepData);
- if (index >= content.length - 1) { //Done with all data
- _this.drawId++;
- if (doneCallback) {
- doneCallback();
- }
- }
- });
- },
- sendFunction: function (content) { //Sends every draw to server
- var _this = this;
- content["wid"] = _this.settings.whiteboardId;
- content["username"] = _this.settings.username;
- content["drawId"] = _this.drawId;
+ var url = copyCanvas.toDataURL();
+ return url;
+ },
+ getImageDataJson() {
+ var sendObj = [];
+ for (var i = 0; i < this.drawBuffer.length; i++) {
+ sendObj.push(JSON.parse(JSON.stringify(this.drawBuffer[i])));
+ delete sendObj[i]["username"];
+ delete sendObj[i]["wid"];
+ delete sendObj[i]["drawId"];
+ }
+ return JSON.stringify(sendObj);
+ },
+ loadData: function (content) {
+ var _this = this;
+ _this.loadDataInSteps(content, true, function (stepData) {
+ if (stepData["username"] == _this.settings.username && _this.drawId < stepData["drawId"]) {
+ _this.drawId = stepData["drawId"] + 1;
+ }
+ });
+ },
+ loadDataInSteps(content, isNewData, callAfterEveryStep) {
+ var _this = this;
- var tool = content["t"];
- if (_this.settings.sendFunction) {
- _this.settings.sendFunction(content);
- }
- if (["line", "pen", "rect", "circle", "eraser", "addImgBG", "recSelect", "eraseRec", "addTextBox", "setTextboxText", "removeTextbox", "setTextboxPosition", "setTextboxFontSize", "setTextboxFontColor"].includes(tool)) {
- _this.drawBuffer.push(content);
- }
- },
- refreshCursorAppearance() { //Set cursor depending on current active tool
- var _this = this;
- if (_this.tool === "pen" || _this.tool === "eraser") {
- _this.mouseOverlay.css({ "cursor": "none" });
- } else if (_this.tool === "mouse") {
- this.mouseOverlay.css({ "cursor": "default" });
- } else { //Line, Rec, Circle, Cutting
- _this.mouseOverlay.css({ "cursor": "crosshair" });
- }
- }
+ function lData(index) {
+ for (var i = index; i < content.length; i++) {
+ if (content[i]["t"] === "addImgBG" && content[i]["draw"] == "1") {
+ _this.handleEventsAndData(content[i], isNewData, function () {
+ callAfterEveryStep(content[i], i);
+ lData(i + 1);
+ });
+ break;
+ } else {
+ _this.handleEventsAndData(content[i], isNewData);
+ callAfterEveryStep(content[i], i);
+ }
+ }
+ }
+ lData(0);
+ },
+ loadJsonData(content, doneCallback) {
+ var _this = this;
+ _this.loadDataInSteps(content, false, function (stepData, index) {
+ _this.sendFunction(stepData);
+ if (index >= content.length - 1) { //Done with all data
+ _this.drawId++;
+ if (doneCallback) {
+ doneCallback();
+ }
+ }
+ });
+ },
+ sendFunction: function (content) { //Sends every draw to server
+ var _this = this;
+ content["wid"] = _this.settings.whiteboardId;
+ content["username"] = _this.settings.username;
+ content["drawId"] = _this.drawId;
+
+ var tool = content["t"];
+ if (_this.settings.sendFunction) {
+ _this.settings.sendFunction(content);
+ }
+ if (["line", "pen", "rect", "circle", "eraser", "addImgBG", "recSelect", "eraseRec", "addTextBox", "setTextboxText", "removeTextbox", "setTextboxPosition", "setTextboxFontSize", "setTextboxFontColor"].includes(tool)) {
+ _this.drawBuffer.push(content);
+ }
+ },
+ refreshCursorAppearance() { //Set cursor depending on current active tool
+ var _this = this;
+ if (_this.tool === "pen" || _this.tool === "eraser") {
+ _this.mouseOverlay.css({ "cursor": "none" });
+ } else if (_this.tool === "mouse") {
+ this.mouseOverlay.css({ "cursor": "default" });
+ } else { //Line, Rec, Circle, Cutting
+ _this.mouseOverlay.css({ "cursor": "crosshair" });
+ }
+ }
}
\ No newline at end of file
diff --git a/s_whiteboard.js b/s_whiteboard.js
index 980d3f5..a0b09aa 100644
--- a/s_whiteboard.js
+++ b/s_whiteboard.js
@@ -2,42 +2,43 @@
var savedBoards = {};
module.exports = {
- handleEventsAndData : function(content) {
- var tool = content["t"]; //Tool witch is used
- var wid = content["wid"]; //whiteboard ID
- var username = content["username"];
- if(tool==="clear") { //Clear the whiteboard
- delete savedBoards[wid];
- } else if(tool==="undo") { //Undo an action
- if(savedBoards[wid]) {
- for(var i=savedBoards[wid].length-1;i>=0;i--){
- if(savedBoards[wid][i]["username"]==username) {
- var drawId = savedBoards[wid][i]["drawId"];
- for(var i=savedBoards[wid].length-1;i>=0;i--){
- if(savedBoards[wid][i]["drawId"]==drawId && savedBoards[wid][i]["username"]==username) {
- savedBoards[wid].splice(i, 1);
- }
- }
- break;
- }
- }
- }
- } else if(["line", "pen", "rect", "circle", "eraser", "addImgBG", "recSelect", "eraseRec", "addTextBox", "setTextboxText", "removeTextbox", "setTextboxPosition", "setTextboxFontSize", "setTextboxFontColor"].includes(tool)) { //Save all this actions
- if(!savedBoards[wid]) {
- savedBoards[wid] = [];
- }
- delete content["wid"]; //Delete id from content so we don't store it twice
- if(tool==="setTextboxText") {
- for(var i=savedBoards[wid].length-1;i>=0;i--){ //Remove old textbox tex -> dont store it twice
- if(savedBoards[wid][i]["t"]==="setTextboxText" && savedBoards[wid][i]["d"][0]===content["d"][0]) {
- savedBoards[wid].splice(i,1);
- }
- }
- }
- savedBoards[wid].push(content);
- }
- },
- loadStoredData : function(wid) { //Load saved whiteboard
- return savedBoards[wid] ? savedBoards[wid] : [];
- }
+ handleEventsAndData: function (content) {
+ var tool = content["t"]; //Tool witch is used
+ var wid = content["wid"]; //whiteboard ID
+ var username = content["username"];
+ if (tool === "clear") { //Clear the whiteboard
+ delete savedBoards[wid];
+ } else if (tool === "undo") { //Undo an action
+ if (savedBoards[wid]) {
+ for (var i = savedBoards[wid].length - 1; i >= 0; i--) {
+ if (savedBoards[wid][i]["username"] == username) {
+ var drawId = savedBoards[wid][i]["drawId"];
+ for (var i = savedBoards[wid].length - 1; i >= 0; i--) {
+ if (savedBoards[wid][i]["drawId"] == drawId && savedBoards[wid][i]["username"] == username) {
+ savedBoards[wid].splice(i, 1);
+ }
+ }
+ break;
+ }
+ }
+ }
+ } else if (["line", "pen", "rect", "circle", "eraser", "addImgBG", "recSelect", "eraseRec", "addTextBox", "setTextboxText", "removeTextbox", "setTextboxPosition", "setTextboxFontSize", "setTextboxFontColor"].includes(tool)) { //Save all this actions
+ if (!savedBoards[wid]) {
+ savedBoards[wid] = [];
+ }
+ delete content["wid"]; //Delete id from content so we don't store it twice
+ if (tool === "setTextboxText") {
+ for (var i = savedBoards[wid].length - 1; i >= 0; i--) { //Remove old textbox tex -> dont store it twice
+ if (savedBoards[wid][i]["t"] === "setTextboxText" && savedBoards[wid][i]["d"][0] === content["d"][0]) {
+ savedBoards[wid].splice(i, 1);
+ }
+ }
+ }
+ console.log(content)
+ savedBoards[wid].push(content);
+ }
+ },
+ loadStoredData: function (wid) { //Load saved whiteboard
+ return savedBoards[wid] ? savedBoards[wid] : [];
+ }
}
\ No newline at end of file