Skip to content

Commit

Permalink
Merged and closed #35
Browse files Browse the repository at this point in the history
  • Loading branch information
muaz-khan committed Nov 22, 2017
1 parent 180d557 commit 3b02045
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 62 deletions.
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2017 [Muaz Khan](https://github.com/muaz-khan)

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16 changes: 12 additions & 4 deletions dev/events-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,18 @@ function preventStopEvent(e) {
}

addEvent(canvas, isTouch ? 'touchend touchcancel mouseup' : 'mouseup', function(e) {
if (isTouch) e = e.pageX ? e : e.touches.length ? e.touches[0] : {
pageX: 0,
pageY: 0
};
if (isTouch && (!e || !('pageX' in e))) {
if (e && e.touches && e.touches.length) {
e = e.touches[0];
} else if (e && e.changedTouches && e.changedTouches.length) {
e = e.changedTouches[0];
} else {
e = {
pageX: 0,
pageY: 0
}
}
}

var cache = is;

Expand Down
105 changes: 54 additions & 51 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -351,23 +351,21 @@ <h2><a href="multiple.html">Try multiple designers!</a></h2>
localStorage.setItem('canvas-designer-roomid', this.value);
};

if(localStorage.getItem('canvas-designer-roomid')) {
if (localStorage.getItem('canvas-designer-roomid')) {
document.getElementById('room-id').value = localStorage.getItem('canvas-designer-roomid');
}

document.getElementById('open-room').onclick = function() {
var roomid = document.getElementById('room-id').value;
if(!roomid.length) return alert('Please enter roomid.');
if (!roomid.length) return alert('Please enter roomid.');

this.disabled = true;

connection.open(roomid, onOpenRoom);

this.parentNode.innerHTML = '<a href="#' + roomid + '" target="_blank">Please share this link</a>';
};
</script>

<script>
var designer = new CanvasDesigner();

// you can place widget.html anywhere
Expand All @@ -394,7 +392,7 @@ <h2><a href="multiple.html">Try multiple designers!</a></h2>
quadratic: true,
bezier: true,
marker: true,
zoom: true
zoom: true
});

designer.appendTo(document.getElementById('widget-container'));
Expand All @@ -409,7 +407,7 @@ <h2><a href="multiple.html">Try multiple designers!</a></h2>

var tools = {};
Array.prototype.slice.call(document.getElementById('action-controls').querySelectorAll('input[type=checkbox]')).forEach(function(checkbox2) {
if(checkbox2.checked) {
if (checkbox2.checked) {
tools[checkbox2.id] = true;
}
});
Expand All @@ -421,27 +419,26 @@ <h2><a href="multiple.html">Try multiple designers!</a></h2>
var undoOptions = document.getElementById('undo-options');

document.getElementById('btn-display-undo-popup').onclick = function() {
document.getElementById('light').style.display='block';
document.getElementById('fade').style.display='block';
document.getElementById('light').style.display = 'block';
document.getElementById('fade').style.display = 'block';
};

var txtNumberOfShapesToUndo = document.getElementById('number-of-shapes-to-undo');
txtNumberOfShapesToUndo.onkeyup = function() {
localStorage.setItem('number-of-shapes-to-undo', txtNumberOfShapesToUndo.value);
}

if(localStorage.getItem('number-of-shapes-to-undo')){
if (localStorage.getItem('number-of-shapes-to-undo')) {
txtNumberOfShapesToUndo.value = localStorage.getItem('number-of-shapes-to-undo');
txtNumberOfShapesToUndo.onkeyup();
}

undoOptions.onchange = function() {
txtNumberOfShapesToUndo.parentNode.style.display = 'none';

if(undoOptions.value === 'Specific Range') {
if (undoOptions.value === 'Specific Range') {
//
}
else if(undoOptions.value === 'Last Multiple') {
} else if (undoOptions.value === 'Last Multiple') {
txtNumberOfShapesToUndo.parentNode.style.display = 'block';
}

Expand All @@ -450,27 +447,24 @@ <h2><a href="multiple.html">Try multiple designers!</a></h2>

undoOptions.onclick = undoOptions.onchange;

if(localStorage.getItem('undo-options')) {
if (localStorage.getItem('undo-options')) {
undoOptions.value = localStorage.getItem('undo-options');
undoOptions.onchange();
}

document.getElementById('btn-undo').onclick = function() {
if(undoOptions.value === 'All Shapes') {
if (undoOptions.value === 'All Shapes') {
designer.undo('all');
}
else if(undoOptions.value === 'Specific Range') {
} else if (undoOptions.value === 'Specific Range') {
designer.undo({
specificRange: {
start: -1,
end: -1
}
});
}
else if(undoOptions.value === 'Last Shape') {
} else if (undoOptions.value === 'Last Shape') {
designer.undo(-1);
}
else if(undoOptions.value === 'Last Multiple') {
} else if (undoOptions.value === 'Last Multiple') {
var numberOfLastShapes = txtNumberOfShapesToUndo.value;
numberOfLastShapes = parseInt(numberOfLastShapes || 0) || 0;
designer.undo({
Expand All @@ -482,70 +476,79 @@ <h2><a href="multiple.html">Try multiple designers!</a></h2>
};

function closeUndoPopup() {
document.getElementById('light').style.display='none';
document.getElementById('fade').style.display='none';
document.getElementById('light').style.display = 'none';
document.getElementById('fade').style.display = 'none';

undoOptions.onchange();
}
document.getElementById('btn-close-undo-popup').onclick = closeUndoPopup;

function closeDataURLPopup() {
document.getElementById('dataURL-popup').style.display='none';
document.getElementById('fade').style.display='none';
document.getElementById('dataURL-popup').style.display = 'none';
document.getElementById('fade').style.display = 'none';

dataURLFormat.onchange();
}
document.getElementById('btn-close-dataURL-popup').onclick = closeDataURLPopup;

document.getElementById('export-as-image').onclick = function() {
linkToImage.innerHTML = linkToImage.href = linkToImage.style = '';
linkToImage.innerHTML = linkToImage.href = linkToImage.style = '';

document.getElementById('dataURL-popup').style.display = 'block';
document.getElementById('fade').style.display = 'block';

document.getElementById('dataURL-popup').style.display='block';
document.getElementById('fade').style.display='block';
getDataURL();
};

function getDataURL(callback) {
callback = callback || function() {};
var format = dataURLFormat.value;
designer.toDataURL(format || 'image/png', function(dataURL) {
linkToImage.style = 'margin-left: 10px;display: block;text-align: center;margin-bottom: -50px;';
linkToImage.href = dataURL;
linkToImage.innerHTML = 'Click to Download Image';
linkToImage.download = 'image.' + (format || 'image/png').split('/')[1];

callback(dataURL, format);
});
}

var dataURLFormat = document.getElementById('data-url-format');
var linkToImage = document.getElementById('link-to-image');

dataURLFormat.onchange = function() {
localStorage.setItem('data-url-format', dataURLFormat.value);
getDataURL();
};
dataURLFormat.onclick = dataURLFormat.onchange;

if(localStorage.getItem('data-url-format')) {
if (localStorage.getItem('data-url-format')) {
dataURLFormat.value = localStorage.getItem('data-url-format');
dataURLFormat.onchange();
}

document.getElementById('btn-getDataURL').onclick = function() {
var format = dataURLFormat.value;

designer.toDataURL(format || 'image/png', function(dataURL) {
window.open(dataURL);

linkToImage.style = 'margin-left: 10px;display: block;text-align: center;margin-bottom: -50px;';
linkToImage.href = dataURL;
linkToImage.innerHTML = 'Click to Download Image';
linkToImage.download = 'image.' + (format || 'image/png').split('/')[1];
getDataURL(function(dataURL, format) {
window.open(dataURL);
});

// closeDataURLPopup();
};

document.getElementById('btn-close-comments-popup').onclick = function() {
document.getElementById('comments-popup').style.display='none';
document.getElementById('fade').style.display='none';
document.getElementById('comments-popup').style.display = 'none';
document.getElementById('fade').style.display = 'none';

dataURLFormat.onchange();
dataURLFormat.onchange();
};

function showCommentsPopup(e) {
document.getElementById('comments-popup').style.display='block';
document.getElementById('fade').style.display='block';
document.getElementById('comments-popup').style.display = 'block';
document.getElementById('fade').style.display = 'block';
}
document.getElementById('btn-comments').onclick = showCommentsPopup;
if(location.hash.length && location.hash.indexOf('comment') !== -1) {
showCommentsPopup();
if (location.hash.length && location.hash.indexOf('comment') !== -1) {
showCommentsPopup();
}
</script>

Expand All @@ -569,18 +572,18 @@ <h2><a href="multiple.html">Try multiple designers!</a></h2>
OfferToReceiveVideo: true
};
connection.dontCaptureUserMedia = true;
if(location.hash.replace('#', '').length) {
if (location.hash.replace('#', '').length) {
var roomid = location.hash.replace('#', '');
connection.join(roomid);
}

connection.onUserStatusChanged = function(event) {
var infoBar = document.getElementById('hide-on-datachannel-opened');
if(event.status == 'online') {
if (event.status == 'online') {
infoBar.innerHTML = event.userid + ' is <b>online</b>.';
}

if(event.status == 'offline') {
if (event.status == 'offline') {
infoBar.innerHTML = event.userid + ' is <b>offline</b>.';
}

Expand All @@ -592,7 +595,7 @@ <h2><a href="multiple.html">Try multiple designers!</a></h2>
var infoBar = document.getElementById('hide-on-datachannel-opened');
infoBar.innerHTML = '<b>' + event.userid + '</b> is ready to collaborate with you.';

if(designer.pointsLength <= 0) {
if (designer.pointsLength <= 0) {
// make sure that remote user gets all drawings synced.
setTimeout(function() {
connection.send('plz-sync-points');
Expand All @@ -607,12 +610,12 @@ <h2><a href="multiple.html">Try multiple designers!</a></h2>
};

connection.onmessage = function(event) {
if(event.data === 'plz-sync-points') {
if (event.data === 'plz-sync-points') {
designer.sync();
return;
}

designer.syncData( event.data );
designer.syncData(event.data);
};
</script>

Expand All @@ -633,7 +636,7 @@ <h2><a href="multiple.html">Try multiple designers!</a></h2>
var video = document.querySelector('video');

connection.onstream = function(event) {
if(connection.isInitiator && event.mediaElement) return;
if (connection.isInitiator && event.mediaElement) return;

video.style.display = '';
video.src = URL.createObjectURL(event.stream);
Expand Down
18 changes: 13 additions & 5 deletions widget.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Last time updated: 2017-04-29 1:56:26 PM UTC
// Last time updated: 2017-11-22 11:30:34 AM UTC

// _______________
// Canvas-Designer
Expand Down Expand Up @@ -3297,10 +3297,18 @@
}

addEvent(canvas, isTouch ? 'touchend touchcancel mouseup' : 'mouseup', function(e) {
if (isTouch) e = e.pageX ? e : e.touches.length ? e.touches[0] : {
pageX: 0,
pageY: 0
};
if (isTouch && (!e || !('pageX' in e))) {
if (e && e.touches && e.touches.length) {
e = e.touches[0];
} else if (e && e.changedTouches && e.changedTouches.length) {
e = e.changedTouches[0];
} else {
e = {
pageX: 0,
pageY: 0
}
}
}

var cache = is;

Expand Down
4 changes: 2 additions & 2 deletions widget.min.js

Large diffs are not rendered by default.

0 comments on commit 3b02045

Please sign in to comment.