summaryrefslogtreecommitdiff
path: root/www/external
diff options
context:
space:
mode:
authorArjun Roychowdhury <pliablepixels@gmail.com>2015-11-08 16:22:38 -0500
committerArjun Roychowdhury <pliablepixels@gmail.com>2015-11-08 16:22:38 -0500
commita2dee7794f8991aad06e97334b8119cbd87526fc (patch)
tree630c275e6aecd52321970f750b4e0940b2dedd26 /www/external
parent770bb8b52481cdcae26464a5112746e775b861c2 (diff)
save canvas to disk fixes for desktop mode
Former-commit-id: 3bef567e1c93ad274e456d32700b66ae4d12095d
Diffstat (limited to 'www/external')
-rw-r--r--www/external/FileSaver.min.js2
-rw-r--r--www/external/canvas-toBlob.js124
2 files changed, 126 insertions, 0 deletions
diff --git a/www/external/FileSaver.min.js b/www/external/FileSaver.min.js
new file mode 100644
index 00000000..8bbbf769
--- /dev/null
+++ b/www/external/FileSaver.min.js
@@ -0,0 +1,2 @@
+/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
+var saveAs=saveAs||function(e){"use strict";if(typeof navigator!=="undefined"&&/MSIE [1-9]\./.test(navigator.userAgent)){return}var t=e.document,n=function(){return e.URL||e.webkitURL||e},r=t.createElementNS("http://www.w3.org/1999/xhtml","a"),i="download"in r,o=function(e){var t=new MouseEvent("click");e.dispatchEvent(t)},a=/Version\/[\d\.]+.*Safari/.test(navigator.userAgent),f=e.webkitRequestFileSystem,u=e.requestFileSystem||f||e.mozRequestFileSystem,s=function(t){(e.setImmediate||e.setTimeout)(function(){throw t},0)},c="application/octet-stream",d=0,l=500,w=function(t){var r=function(){if(typeof t==="string"){n().revokeObjectURL(t)}else{t.remove()}};if(e.chrome){r()}else{setTimeout(r,l)}},p=function(e,t,n){t=[].concat(t);var r=t.length;while(r--){var i=e["on"+t[r]];if(typeof i==="function"){try{i.call(e,n||e)}catch(o){s(o)}}}},v=function(e){if(/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)){return new Blob(["\ufeff",e],{type:e.type})}return e},y=function(t,s,l){if(!l){t=v(t)}var y=this,m=t.type,S=false,h,R,O=function(){p(y,"writestart progress write writeend".split(" "))},g=function(){if(R&&a&&typeof FileReader!=="undefined"){var r=new FileReader;r.onloadend=function(){var e=r.result;R.location.href="data:attachment/file"+e.slice(e.search(/[,;]/));y.readyState=y.DONE;O()};r.readAsDataURL(t);y.readyState=y.INIT;return}if(S||!h){h=n().createObjectURL(t)}if(R){R.location.href=h}else{var i=e.open(h,"_blank");if(i==undefined&&a){e.location.href=h}}y.readyState=y.DONE;O();w(h)},b=function(e){return function(){if(y.readyState!==y.DONE){return e.apply(this,arguments)}}},E={create:true,exclusive:false},N;y.readyState=y.INIT;if(!s){s="download"}if(i){h=n().createObjectURL(t);r.href=h;r.download=s;setTimeout(function(){o(r);O();w(h);y.readyState=y.DONE});return}if(e.chrome&&m&&m!==c){N=t.slice||t.webkitSlice;t=N.call(t,0,t.size,c);S=true}if(f&&s!=="download"){s+=".download"}if(m===c||f){R=e}if(!u){g();return}d+=t.size;u(e.TEMPORARY,d,b(function(e){e.root.getDirectory("saved",E,b(function(e){var n=function(){e.getFile(s,E,b(function(e){e.createWriter(b(function(n){n.onwriteend=function(t){R.location.href=e.toURL();y.readyState=y.DONE;p(y,"writeend",t);w(e)};n.onerror=function(){var e=n.error;if(e.code!==e.ABORT_ERR){g()}};"writestart progress write abort".split(" ").forEach(function(e){n["on"+e]=y["on"+e]});n.write(t);y.abort=function(){n.abort();y.readyState=y.DONE};y.readyState=y.WRITING}),g)}),g)};e.getFile(s,{create:false},b(function(e){e.remove();n()}),b(function(e){if(e.code===e.NOT_FOUND_ERR){n()}else{g()}}))}),g)}),g)},m=y.prototype,S=function(e,t,n){return new y(e,t,n)};if(typeof navigator!=="undefined"&&navigator.msSaveOrOpenBlob){return function(e,t,n){if(!n){e=v(e)}return navigator.msSaveOrOpenBlob(e,t||"download")}}m.abort=function(){var e=this;e.readyState=e.DONE;p(e,"abort")};m.readyState=m.INIT=0;m.WRITING=1;m.DONE=2;m.error=m.onwritestart=m.onprogress=m.onwrite=m.onabort=m.onerror=m.onwriteend=null;return S}(typeof self!=="undefined"&&self||typeof window!=="undefined"&&window||this.content);if(typeof module!=="undefined"&&module.exports){module.exports.saveAs=saveAs}else if(typeof define!=="undefined"&&define!==null&&define.amd!=null){define([],function(){return saveAs})} \ No newline at end of file
diff --git a/www/external/canvas-toBlob.js b/www/external/canvas-toBlob.js
new file mode 100644
index 00000000..6d895a78
--- /dev/null
+++ b/www/external/canvas-toBlob.js
@@ -0,0 +1,124 @@
+/* canvas-toBlob.js
+ * A canvas.toBlob() implementation.
+ * 2013-12-27
+ *
+ * By Eli Grey, http://eligrey.com and Devin Samarin, https://github.com/eboyjr
+ * License: MIT
+ * See https://github.com/eligrey/canvas-toBlob.js/blob/master/LICENSE.md
+ */
+
+/*global self */
+/*jslint bitwise: true, regexp: true, confusion: true, es5: true, vars: true, white: true,
+ plusplus: true */
+
+/*! @source http://purl.eligrey.com/github/canvas-toBlob.js/blob/master/canvas-toBlob.js */
+
+(function(view) {
+"use strict";
+var
+ Uint8Array = view.Uint8Array
+ , HTMLCanvasElement = view.HTMLCanvasElement
+ , canvas_proto = HTMLCanvasElement && HTMLCanvasElement.prototype
+ , is_base64_regex = /\s*;\s*base64\s*(?:;|$)/i
+ , to_data_url = "toDataURL"
+ , base64_ranks
+ , decode_base64 = function(base64) {
+ var
+ len = base64.length
+ , buffer = new Uint8Array(len / 4 * 3 | 0)
+ , i = 0
+ , outptr = 0
+ , last = [0, 0]
+ , state = 0
+ , save = 0
+ , rank
+ , code
+ , undef
+ ;
+ while (len--) {
+ code = base64.charCodeAt(i++);
+ rank = base64_ranks[code-43];
+ if (rank !== 255 && rank !== undef) {
+ last[1] = last[0];
+ last[0] = code;
+ save = (save << 6) | rank;
+ state++;
+ if (state === 4) {
+ buffer[outptr++] = save >>> 16;
+ if (last[1] !== 61 /* padding character */) {
+ buffer[outptr++] = save >>> 8;
+ }
+ if (last[0] !== 61 /* padding character */) {
+ buffer[outptr++] = save;
+ }
+ state = 0;
+ }
+ }
+ }
+ // 2/3 chance there's going to be some null bytes at the end, but that
+ // doesn't really matter with most image formats.
+ // If it somehow matters for you, truncate the buffer up outptr.
+ return buffer;
+ }
+;
+if (Uint8Array) {
+ base64_ranks = new Uint8Array([
+ 62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1
+ , -1, -1, 0, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
+ , 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
+ , -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35
+ , 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
+ ]);
+}
+if (HTMLCanvasElement && !canvas_proto.toBlob) {
+ canvas_proto.toBlob = function(callback, type /*, ...args*/) {
+ if (!type) {
+ type = "image/png";
+ } if (this.mozGetAsFile) {
+ callback(this.mozGetAsFile("canvas", type));
+ return;
+ } if (this.msToBlob && /^\s*image\/png\s*(?:$|;)/i.test(type)) {
+ callback(this.msToBlob());
+ return;
+ }
+
+ var
+ args = Array.prototype.slice.call(arguments, 1)
+ , dataURI = this[to_data_url].apply(this, args)
+ , header_end = dataURI.indexOf(",")
+ , data = dataURI.substring(header_end + 1)
+ , is_base64 = is_base64_regex.test(dataURI.substring(0, header_end))
+ , blob
+ ;
+ if (Blob.fake) {
+ // no reason to decode a data: URI that's just going to become a data URI again
+ blob = new Blob
+ if (is_base64) {
+ blob.encoding = "base64";
+ } else {
+ blob.encoding = "URI";
+ }
+ blob.data = data;
+ blob.size = data.length;
+ } else if (Uint8Array) {
+ if (is_base64) {
+ blob = new Blob([decode_base64(data)], {type: type});
+ } else {
+ blob = new Blob([decodeURIComponent(data)], {type: type});
+ }
+ }
+ callback(blob);
+ };
+
+ if (canvas_proto.toDataURLHD) {
+ canvas_proto.toBlobHD = function() {
+ to_data_url = "toDataURLHD";
+ var blob = this.toBlob();
+ to_data_url = "toDataURL";
+ return blob;
+ }
+ } else {
+ canvas_proto.toBlobHD = canvas_proto.toBlob;
+ }
+}
+}(typeof self !== "undefined" && self || typeof window !== "undefined" && window || this.content || this));