' +
'
' +
@@ -322,36 +250,11 @@ var whiteboard = {
});
_this.mouseOverlay.on("mouseout", function (e) {
- if (_this.imgDragActive) {
- return;
- }
- _this.drawFlag = false;
- _this.mouseover = false;
- _this.ctx.globalCompositeOperation = _this.oldGCO;
- if (_this.ownCursor) _this.ownCursor.remove();
- _this.svgContainer.find("line").remove();
- _this.svgContainer.find("rect").remove();
- _this.svgContainer.find("circle").remove();
- _this.sendFunction({ "t": "cursor", "event": "out" });
+ _this.triggerMouseOut();
});
_this.mouseOverlay.on("mouseover", function (e) {
- if (_this.imgDragActive) {
- return;
- }
- if (!_this.mouseover) {
- var color = _this.drawcolor;
- var widthHeight = _this.thickness;
- if (_this.tool === "eraser") {
- color = "#00000000";
- widthHeight = widthHeight * 2;
- }
- if (_this.tool === "eraser" || _this.tool === "pen") {
- _this.ownCursor = $('
');
- _this.cursorContainer.append(_this.ownCursor);
- }
- }
- _this.mouseover = true;
+ _this.triggerMouseOver();
});
//On textcontainer click (Add a new textbox)
@@ -365,27 +268,142 @@ var whiteboard = {
});
function getRoundedAngles(currX, currY) { //For drawing lines at 0,45,90° ....
- var x = currX - startCoords[0];
- var y = currY - startCoords[1];
+ var x = currX - _this.startCoords[0];
+ var y = currY - _this.startCoords[1];
var angle = Math.atan2(x, y) * (180 / Math.PI);
var angle45 = Math.round(angle / 45) * 45;
if (angle45 % 90 == 0) {
- if (Math.abs(currX - startCoords[0]) > Math.abs(currY - startCoords[1])) {
- currY = startCoords[1]
+ if (Math.abs(currX - _this.startCoords[0]) > Math.abs(currY - _this.startCoords[1])) {
+ currY = _this.startCoords[1]
} else {
- currX = startCoords[0]
+ currX = _this.startCoords[0]
}
} else {
- if ((currY - startCoords[1]) * (currX - startCoords[0]) > 0) {
- currX = startCoords[0] + (currY - startCoords[1]);
+ if ((currY - _this.startCoords[1]) * (currX - _this.startCoords[0]) > 0) {
+ currX = _this.startCoords[0] + (currY - _this.startCoords[1]);
} else {
- currX = startCoords[0] - (currY - startCoords[1]);
+ currX = _this.startCoords[0] - (currY - _this.startCoords[1]);
}
}
return { "x": currX, "y": currY };
}
},
- entfKeyAction: function () {
+ triggerMouseMove: function (e) {
+ var _this = this;
+ if (_this.imgDragActive) {
+ return;
+ }
+ var currX = e.currX || (e.offsetX || e.pageX - $(e.target).offset().left);
+ var currY = e.currY || (e.offsetY || e.pageY - $(e.target).offset().top);
+ window.requestAnimationFrame(function () {
+ if ((!currX || !currY) && e.touches && e.touches[0]) {
+ var touche = e.touches[0];
+ currX = touche.clientX - $(_this.mouseOverlay).offset().left;
+ currY = touche.clientY - $(_this.mouseOverlay).offset().top;
+ }
+ _this.latestTouchCoods = [currX, currY];
+
+ if (_this.drawFlag) {
+ if (_this.tool === "pen") {
+ _this.drawPenLine(currX, currY, _this.prevX, _this.prevY, _this.drawcolor, _this.thickness);
+ _this.sendFunction({ "t": _this.tool, "d": [currX, currY, _this.prevX, _this.prevY], "c": _this.drawcolor, "th": _this.thickness });
+ } else if (_this.tool == "eraser") {
+ _this.drawEraserLine(currX, currY, _this.prevX, _this.prevY, _this.thickness);
+ _this.sendFunction({ "t": _this.tool, "d": [currX, currY, _this.prevX, _this.prevY], "th": _this.thickness });
+ }
+ }
+
+ if (_this.tool === "eraser") {
+ var left = currX - _this.thickness;
+ var top = currY - _this.thickness;
+ if (_this.ownCursor) _this.ownCursor.css({ "top": top + "px", "left": left + "px" });
+ } else if (_this.tool === "pen") {
+ var left = currX - _this.thickness / 2;
+ var top = currY - _this.thickness / 2;
+ if (_this.ownCursor) _this.ownCursor.css({ "top": top + "px", "left": left + "px" });
+ } else if (_this.tool === "line") {
+ if (_this.svgLine) {
+ if (_this.pressedKeys.shift) {
+ var angs = getRoundedAngles(currX, currY);
+ currX = angs.x;
+ currY = angs.y;
+ }
+ _this.svgLine.setAttribute('x2', currX);
+ _this.svgLine.setAttribute('y2', currY);
+ }
+ } else if (_this.tool === "rect" || (_this.tool === "recSelect" && _this.drawFlag)) {
+ if (_this.svgRect) {
+ var width = Math.abs(currX - _this.startCoords[0]);
+ var height = Math.abs(currY - _this.startCoords[1]);
+ if (_this.pressedKeys.shift) {
+ height = width;
+ var x = currX < _this.startCoords[0] ? _this.startCoords[0] - width : _this.startCoords[0];
+ var y = currY < _this.startCoords[1] ? _this.startCoords[1] - width : _this.startCoords[1];
+ _this.svgRect.setAttribute('x', x);
+ _this.svgRect.setAttribute('y', y);
+ } else {
+ var x = currX < _this.startCoords[0] ? currX : _this.startCoords[0];
+ var y = currY < _this.startCoords[1] ? currY : _this.startCoords[1];
+ _this.svgRect.setAttribute('x', x);
+ _this.svgRect.setAttribute('y', y);
+ }
+
+ _this.svgRect.setAttribute('width', width);
+ _this.svgRect.setAttribute('height', height);
+ }
+ } else if (_this.tool === "circle") {
+ var a = currX - _this.startCoords[0];
+ var b = currY - _this.startCoords[1];
+ var r = Math.sqrt(a * a + b * b);
+ if (_this.svgCirle) {
+ _this.svgCirle.setAttribute('r', r);
+ }
+ }
+ _this.prevX = currX;
+ _this.prevY = currY;
+ });
+ _this.sendFunction({ "t": "cursor", "event": "move", "d": [currX, currY], "username": _this.settings.username });
+ },
+ triggerMouseOver: function () {
+ var _this = this;
+ if (_this.imgDragActive) {
+ return;
+ }
+ if (!_this.mouseover) {
+ var color = _this.drawcolor;
+ var widthHeight = _this.thickness;
+ if (_this.tool === "eraser") {
+ color = "#00000000";
+ widthHeight = widthHeight * 2;
+ }
+ if (_this.tool === "eraser" || _this.tool === "pen") {
+ _this.ownCursor = $('
');
+ _this.cursorContainer.append(_this.ownCursor);
+ }
+ }
+ _this.mouseover = true;
+ },
+ triggerMouseOut: function () {
+ var _this = this;
+ if (_this.imgDragActive) {
+ return;
+ }
+ _this.drawFlag = false;
+ _this.mouseover = false;
+ _this.ctx.globalCompositeOperation = _this.oldGCO;
+ if (_this.ownCursor) _this.ownCursor.remove();
+ _this.svgContainer.find("line").remove();
+ _this.svgContainer.find("rect").remove();
+ _this.svgContainer.find("circle").remove();
+ _this.sendFunction({ "t": "cursor", "event": "out" });
+ },
+ redrawMouseCursor: function () {
+ var _this = this;
+ _this.triggerMouseOut();
+ _this.triggerMouseOver();
+ _this.triggerMouseMove({ currX: whiteboard.prevX, currY: whiteboard.prevY });
+ },
+ delKeyAction: function () {
var _this = this;
$.each(_this.mouseOverlay.find(".dragOutOverlay"), function () {
var width = $(this).width();
@@ -398,6 +416,7 @@ var whiteboard = {
_this.eraseRec(left, top, width, height);
});
_this.mouseOverlay.find(".xCanvasBtn").click(); //Remove all current drops
+ _this.textContainer.find("#" + _this.latestActiveTextBoxId).find(".removeIcon").click();
},
escKeyAction: function () {
var _this = this;