Skip to content

Commit

Permalink
Added real file downloading
Browse files Browse the repository at this point in the history
  • Loading branch information
toonvandenbos committed Jun 7, 2016
1 parent a87804b commit 7dd52db
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
27 changes: 24 additions & 3 deletions build/paparazzimg.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ var paparazzimg = (function(p) {
};

p.download = function(mode, id) {
if(id == undefined) return downloadAll(mode);
return downloadTracker(id, mode);
var a;
if(id == undefined) a = downloadAll(mode);
else a = downloadTracker(id, mode);
for (var i = 0; i < a.length; i++) a[i].download();
};

function registerEvent() {
Expand Down Expand Up @@ -125,6 +127,7 @@ paparazzimg.canvas = function( tracker, mode ) {
this.file = null;
this.canvas = null;
this.ctx = null;
this.link = null;
this.conf = {
colors: {
base: {r: 63, g: 74, b: 78, a: 1},
Expand All @@ -143,7 +146,7 @@ paparazzimg.canvas = function( tracker, mode ) {
this.makeCanvas();
this.drawBase();
this.drawBreaks();
document.body.appendChild(this.canvas);
this.makeDownloadLink();
};

this.makeName = function() {
Expand All @@ -160,6 +163,24 @@ paparazzimg.canvas = function( tracker, mode ) {
this.ctx.lineCap = "round";
};

this.makeDownloadLink = function() {
this.link = document.createElement('a');
this.link.addEventListener('click',(function(self){return function(e){self.event_download(e)}})(this),false);
};

// API

this.download = function() {
this.link.click();
};

// EVENT

this.event_download = function() {
this.link.href = this.canvas.toDataURL();
this.link.download = this.file;
};

// DRAW

this.drawBase = function() {
Expand Down
2 changes: 1 addition & 1 deletion build/paparazzimg.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 20 additions & 1 deletion src/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ paparazzimg.canvas = function( tracker, mode ) {
this.file = null;
this.canvas = null;
this.ctx = null;
this.link = null;
this.conf = {
colors: {
base: {r: 63, g: 74, b: 78, a: 1},
Expand All @@ -22,7 +23,7 @@ paparazzimg.canvas = function( tracker, mode ) {
this.makeCanvas();
this.drawBase();
this.drawBreaks();
document.body.appendChild(this.canvas);
this.makeDownloadLink();
};

this.makeName = function() {
Expand All @@ -39,6 +40,24 @@ paparazzimg.canvas = function( tracker, mode ) {
this.ctx.lineCap = "round";
};

this.makeDownloadLink = function() {
this.link = document.createElement('a');
this.link.addEventListener('click',(function(self){return function(e){self.event_download(e)}})(this),false);
};

// API

this.download = function() {
this.link.click();
};

// EVENT

this.event_download = function() {
this.link.href = this.canvas.toDataURL();
this.link.download = this.file;
};

// DRAW

this.drawBase = function() {
Expand Down
6 changes: 4 additions & 2 deletions src/front.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ var paparazzimg = (function(p) {
};

p.download = function(mode, id) {
if(id == undefined) return downloadAll(mode);
return downloadTracker(id, mode);
var a;
if(id == undefined) a = downloadAll(mode);
else a = downloadTracker(id, mode);
for (var i = 0; i < a.length; i++) a[i].download();
};

function registerEvent() {
Expand Down

0 comments on commit 7dd52db

Please sign in to comment.