|
|
|
@ -187,18 +187,25 @@
|
|
|
|
|
};
|
|
|
|
|
$scope.canSave = function() {
|
|
|
|
|
return $scope.dirty && $scope.user && $scope.user.id;
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
$scope.getFilename = function() {
|
|
|
|
|
var name = $scope.keyboard.meta.name.toLowerCase();
|
|
|
|
|
name = name.replace(/[\/\?<>\\:\*\|": \t\x00-\x1f\x80-\x9f\.]+/g,'-'); // control codes, whitespace & invalid filename characters
|
|
|
|
|
name = name.replace(/^(con|prn|aux|nul|com[0-9]|lpt[0-9])$/,''); // reserved windows filenames
|
|
|
|
|
console.log(name);
|
|
|
|
|
return name || "keyboard-layout";
|
|
|
|
|
}
|
|
|
|
|
$scope.downloadSvg = function() {
|
|
|
|
|
var data = $renderKey.fullSVG($scope.keys(), $scope.keyboard.meta);
|
|
|
|
|
var blob = new Blob([data], {type:"image/svg+xml"});
|
|
|
|
|
saveAs(blob, "keyboard-layout.svg");
|
|
|
|
|
saveAs(blob, $scope.getFilename()+".svg");
|
|
|
|
|
};
|
|
|
|
|
$scope.downloadPng = function() {
|
|
|
|
|
html2canvas($("#keyboard-bg"), {
|
|
|
|
|
useCORS: true,
|
|
|
|
|
onrendered: function(canvas) {
|
|
|
|
|
canvas.toBlob(function(blob) {
|
|
|
|
|
saveAs(blob, "keyboard-layout.png");
|
|
|
|
|
saveAs(blob, $scope.getFilename()+".png");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
@ -224,7 +231,7 @@
|
|
|
|
|
onrendered: function(canvas) {
|
|
|
|
|
var thm = getResizedCanvas(canvas,canvas.width,canvas.height,'white'); // not actually resize, just get white background
|
|
|
|
|
thm.toBlob(function(blob) {
|
|
|
|
|
saveAs(blob, "keyboard-layout.jpg");
|
|
|
|
|
saveAs(blob, $scope.getFilename()+".jpg");
|
|
|
|
|
},"image/jpeg");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
@ -239,7 +246,7 @@
|
|
|
|
|
var thmheight = canvas.height * p;
|
|
|
|
|
var thm = getResizedCanvas(canvas,thmwidth,thmheight,'');
|
|
|
|
|
thm.toBlob(function(blob) {
|
|
|
|
|
saveAs(blob, "keyboard-thumb.png");
|
|
|
|
|
saveAs(blob, $scope.getFilename()+"-thumb.png");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
@ -248,7 +255,7 @@
|
|
|
|
|
$scope.downloadJson = function() {
|
|
|
|
|
var data = angular.toJson($serial.serialize($scope.keyboard), true /*pretty*/);
|
|
|
|
|
var blob = new Blob([data], {type:"application/json"});
|
|
|
|
|
saveAs(blob, "keyboard-layout.json");
|
|
|
|
|
saveAs(blob, $scope.getFilename()+".json");
|
|
|
|
|
};
|
|
|
|
|
$scope.uploadJson = function(file, event) {
|
|
|
|
|
if(file && file[0]) {
|
|
|
|
|