Built motion from commit 99feb03.|0.0.140
[motion.git] / public / bower_components / angular-file-saver / angular-file-saver.bundle.js
1 (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2 /* Blob.js
3  * A Blob implementation.
4  * 2014-07-24
5  *
6  * By Eli Grey, http://eligrey.com
7  * By Devin Samarin, https://github.com/dsamarin
8  * License: X11/MIT
9  *   See https://github.com/eligrey/Blob.js/blob/master/LICENSE.md
10  */
11
12 /*global self, unescape */
13 /*jslint bitwise: true, regexp: true, confusion: true, es5: true, vars: true, white: true,
14   plusplus: true */
15
16 /*! @source http://purl.eligrey.com/github/Blob.js/blob/master/Blob.js */
17
18 (function (view) {
19         "use strict";
20
21         view.URL = view.URL || view.webkitURL;
22
23         if (view.Blob && view.URL) {
24                 try {
25                         new Blob;
26                         return;
27                 } catch (e) {}
28         }
29
30         // Internally we use a BlobBuilder implementation to base Blob off of
31         // in order to support older browsers that only have BlobBuilder
32         var BlobBuilder = view.BlobBuilder || view.WebKitBlobBuilder || view.MozBlobBuilder || (function(view) {
33                 var
34                           get_class = function(object) {
35                                 return Object.prototype.toString.call(object).match(/^\[object\s(.*)\]$/)[1];
36                         }
37                         , FakeBlobBuilder = function BlobBuilder() {
38                                 this.data = [];
39                         }
40                         , FakeBlob = function Blob(data, type, encoding) {
41                                 this.data = data;
42                                 this.size = data.length;
43                                 this.type = type;
44                                 this.encoding = encoding;
45                         }
46                         , FBB_proto = FakeBlobBuilder.prototype
47                         , FB_proto = FakeBlob.prototype
48                         , FileReaderSync = view.FileReaderSync
49                         , FileException = function(type) {
50                                 this.code = this[this.name = type];
51                         }
52                         , file_ex_codes = (
53                                   "NOT_FOUND_ERR SECURITY_ERR ABORT_ERR NOT_READABLE_ERR ENCODING_ERR "
54                                 + "NO_MODIFICATION_ALLOWED_ERR INVALID_STATE_ERR SYNTAX_ERR"
55                         ).split(" ")
56                         , file_ex_code = file_ex_codes.length
57                         , real_URL = view.URL || view.webkitURL || view
58                         , real_create_object_URL = real_URL.createObjectURL
59                         , real_revoke_object_URL = real_URL.revokeObjectURL
60                         , URL = real_URL
61                         , btoa = view.btoa
62                         , atob = view.atob
63
64                         , ArrayBuffer = view.ArrayBuffer
65                         , Uint8Array = view.Uint8Array
66
67                         , origin = /^[\w-]+:\/*\[?[\w\.:-]+\]?(?::[0-9]+)?/
68                 ;
69                 FakeBlob.fake = FB_proto.fake = true;
70                 while (file_ex_code--) {
71                         FileException.prototype[file_ex_codes[file_ex_code]] = file_ex_code + 1;
72                 }
73                 // Polyfill URL
74                 if (!real_URL.createObjectURL) {
75                         URL = view.URL = function(uri) {
76                                 var
77                                           uri_info = document.createElementNS("http://www.w3.org/1999/xhtml", "a")
78                                         , uri_origin
79                                 ;
80                                 uri_info.href = uri;
81                                 if (!("origin" in uri_info)) {
82                                         if (uri_info.protocol.toLowerCase() === "data:") {
83                                                 uri_info.origin = null;
84                                         } else {
85                                                 uri_origin = uri.match(origin);
86                                                 uri_info.origin = uri_origin && uri_origin[1];
87                                         }
88                                 }
89                                 return uri_info;
90                         };
91                 }
92                 URL.createObjectURL = function(blob) {
93                         var
94                                   type = blob.type
95                                 , data_URI_header
96                         ;
97                         if (type === null) {
98                                 type = "application/octet-stream";
99                         }
100                         if (blob instanceof FakeBlob) {
101                                 data_URI_header = "data:" + type;
102                                 if (blob.encoding === "base64") {
103                                         return data_URI_header + ";base64," + blob.data;
104                                 } else if (blob.encoding === "URI") {
105                                         return data_URI_header + "," + decodeURIComponent(blob.data);
106                                 } if (btoa) {
107                                         return data_URI_header + ";base64," + btoa(blob.data);
108                                 } else {
109                                         return data_URI_header + "," + encodeURIComponent(blob.data);
110                                 }
111                         } else if (real_create_object_URL) {
112                                 return real_create_object_URL.call(real_URL, blob);
113                         }
114                 };
115                 URL.revokeObjectURL = function(object_URL) {
116                         if (object_URL.substring(0, 5) !== "data:" && real_revoke_object_URL) {
117                                 real_revoke_object_URL.call(real_URL, object_URL);
118                         }
119                 };
120                 FBB_proto.append = function(data/*, endings*/) {
121                         var bb = this.data;
122                         // decode data to a binary string
123                         if (Uint8Array && (data instanceof ArrayBuffer || data instanceof Uint8Array)) {
124                                 var
125                                           str = ""
126                                         , buf = new Uint8Array(data)
127                                         , i = 0
128                                         , buf_len = buf.length
129                                 ;
130                                 for (; i < buf_len; i++) {
131                                         str += String.fromCharCode(buf[i]);
132                                 }
133                                 bb.push(str);
134                         } else if (get_class(data) === "Blob" || get_class(data) === "File") {
135                                 if (FileReaderSync) {
136                                         var fr = new FileReaderSync;
137                                         bb.push(fr.readAsBinaryString(data));
138                                 } else {
139                                         // async FileReader won't work as BlobBuilder is sync
140                                         throw new FileException("NOT_READABLE_ERR");
141                                 }
142                         } else if (data instanceof FakeBlob) {
143                                 if (data.encoding === "base64" && atob) {
144                                         bb.push(atob(data.data));
145                                 } else if (data.encoding === "URI") {
146                                         bb.push(decodeURIComponent(data.data));
147                                 } else if (data.encoding === "raw") {
148                                         bb.push(data.data);
149                                 }
150                         } else {
151                                 if (typeof data !== "string") {
152                                         data += ""; // convert unsupported types to strings
153                                 }
154                                 // decode UTF-16 to binary string
155                                 bb.push(unescape(encodeURIComponent(data)));
156                         }
157                 };
158                 FBB_proto.getBlob = function(type) {
159                         if (!arguments.length) {
160                                 type = null;
161                         }
162                         return new FakeBlob(this.data.join(""), type, "raw");
163                 };
164                 FBB_proto.toString = function() {
165                         return "[object BlobBuilder]";
166                 };
167                 FB_proto.slice = function(start, end, type) {
168                         var args = arguments.length;
169                         if (args < 3) {
170                                 type = null;
171                         }
172                         return new FakeBlob(
173                                   this.data.slice(start, args > 1 ? end : this.data.length)
174                                 , type
175                                 , this.encoding
176                         );
177                 };
178                 FB_proto.toString = function() {
179                         return "[object Blob]";
180                 };
181                 FB_proto.close = function() {
182                         this.size = 0;
183                         delete this.data;
184                 };
185                 return FakeBlobBuilder;
186         }(view));
187
188         view.Blob = function(blobParts, options) {
189                 var type = options ? (options.type || "") : "";
190                 var builder = new BlobBuilder();
191                 if (blobParts) {
192                         for (var i = 0, len = blobParts.length; i < len; i++) {
193                                 if (Uint8Array && blobParts[i] instanceof Uint8Array) {
194                                         builder.append(blobParts[i].buffer);
195                                 }
196                                 else {
197                                         builder.append(blobParts[i]);
198                                 }
199                         }
200                 }
201                 var blob = builder.getBlob(type);
202                 if (!blob.slice && blob.webkitSlice) {
203                         blob.slice = blob.webkitSlice;
204                 }
205                 return blob;
206         };
207
208         var getPrototypeOf = Object.getPrototypeOf || function(object) {
209                 return object.__proto__;
210         };
211         view.Blob.prototype = getPrototypeOf(new view.Blob());
212 }(typeof self !== "undefined" && self || typeof window !== "undefined" && window || this.content || this));
213
214 },{}],2:[function(require,module,exports){
215 /* FileSaver.js
216  * A saveAs() FileSaver implementation.
217  * 1.1.20151003
218  *
219  * By Eli Grey, http://eligrey.com
220  * License: MIT
221  *   See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
222  */
223
224 /*global self */
225 /*jslint bitwise: true, indent: 4, laxbreak: true, laxcomma: true, smarttabs: true, plusplus: true */
226
227 /*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
228
229 var saveAs = saveAs || (function(view) {
230         "use strict";
231         // IE <10 is explicitly unsupported
232         if (typeof navigator !== "undefined" && /MSIE [1-9]\./.test(navigator.userAgent)) {
233                 return;
234         }
235         var
236                   doc = view.document
237                   // only get URL when necessary in case Blob.js hasn't overridden it yet
238                 , get_URL = function() {
239                         return view.URL || view.webkitURL || view;
240                 }
241                 , save_link = doc.createElementNS("http://www.w3.org/1999/xhtml", "a")
242                 , can_use_save_link = "download" in save_link
243                 , click = function(node) {
244                         var event = new MouseEvent("click");
245                         node.dispatchEvent(event);
246                 }
247                 , is_safari = /Version\/[\d\.]+.*Safari/.test(navigator.userAgent)
248                 , webkit_req_fs = view.webkitRequestFileSystem
249                 , req_fs = view.requestFileSystem || webkit_req_fs || view.mozRequestFileSystem
250                 , throw_outside = function(ex) {
251                         (view.setImmediate || view.setTimeout)(function() {
252                                 throw ex;
253                         }, 0);
254                 }
255                 , force_saveable_type = "application/octet-stream"
256                 , fs_min_size = 0
257                 // See https://code.google.com/p/chromium/issues/detail?id=375297#c7 and
258                 // https://github.com/eligrey/FileSaver.js/commit/485930a#commitcomment-8768047
259                 // for the reasoning behind the timeout and revocation flow
260                 , arbitrary_revoke_timeout = 500 // in ms
261                 , revoke = function(file) {
262                         var revoker = function() {
263                                 if (typeof file === "string") { // file is an object URL
264                                         get_URL().revokeObjectURL(file);
265                                 } else { // file is a File
266                                         file.remove();
267                                 }
268                         };
269                         if (view.chrome) {
270                                 revoker();
271                         } else {
272                                 setTimeout(revoker, arbitrary_revoke_timeout);
273                         }
274                 }
275                 , dispatch = function(filesaver, event_types, event) {
276                         event_types = [].concat(event_types);
277                         var i = event_types.length;
278                         while (i--) {
279                                 var listener = filesaver["on" + event_types[i]];
280                                 if (typeof listener === "function") {
281                                         try {
282                                                 listener.call(filesaver, event || filesaver);
283                                         } catch (ex) {
284                                                 throw_outside(ex);
285                                         }
286                                 }
287                         }
288                 }
289                 , auto_bom = function(blob) {
290                         // prepend BOM for UTF-8 XML and text/* types (including HTML)
291                         if (/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(blob.type)) {
292                                 return new Blob(["\ufeff", blob], {type: blob.type});
293                         }
294                         return blob;
295                 }
296                 , FileSaver = function(blob, name, no_auto_bom) {
297                         if (!no_auto_bom) {
298                                 blob = auto_bom(blob);
299                         }
300                         // First try a.download, then web filesystem, then object URLs
301                         var
302                                   filesaver = this
303                                 , type = blob.type
304                                 , blob_changed = false
305                                 , object_url
306                                 , target_view
307                                 , dispatch_all = function() {
308                                         dispatch(filesaver, "writestart progress write writeend".split(" "));
309                                 }
310                                 // on any filesys errors revert to saving with object URLs
311                                 , fs_error = function() {
312                                         if (target_view && is_safari && typeof FileReader !== "undefined") {
313                                                 // Safari doesn't allow downloading of blob urls
314                                                 var reader = new FileReader();
315                                                 reader.onloadend = function() {
316                                                         var base64Data = reader.result;
317                                                         target_view.location.href = "data:attachment/file" + base64Data.slice(base64Data.search(/[,;]/));
318                                                         filesaver.readyState = filesaver.DONE;
319                                                         dispatch_all();
320                                                 };
321                                                 reader.readAsDataURL(blob);
322                                                 filesaver.readyState = filesaver.INIT;
323                                                 return;
324                                         }
325                                         // don't create more object URLs than needed
326                                         if (blob_changed || !object_url) {
327                                                 object_url = get_URL().createObjectURL(blob);
328                                         }
329                                         if (target_view) {
330                                                 target_view.location.href = object_url;
331                                         } else {
332                                                 var new_tab = view.open(object_url, "_blank");
333                                                 if (new_tab == undefined && is_safari) {
334                                                         //Apple do not allow window.open, see http://bit.ly/1kZffRI
335                                                         view.location.href = object_url
336                                                 }
337                                         }
338                                         filesaver.readyState = filesaver.DONE;
339                                         dispatch_all();
340                                         revoke(object_url);
341                                 }
342                                 , abortable = function(func) {
343                                         return function() {
344                                                 if (filesaver.readyState !== filesaver.DONE) {
345                                                         return func.apply(this, arguments);
346                                                 }
347                                         };
348                                 }
349                                 , create_if_not_found = {create: true, exclusive: false}
350                                 , slice
351                         ;
352                         filesaver.readyState = filesaver.INIT;
353                         if (!name) {
354                                 name = "download";
355                         }
356                         if (can_use_save_link) {
357                                 object_url = get_URL().createObjectURL(blob);
358                                 setTimeout(function() {
359                                         save_link.href = object_url;
360                                         save_link.download = name;
361                                         click(save_link);
362                                         dispatch_all();
363                                         revoke(object_url);
364                                         filesaver.readyState = filesaver.DONE;
365                                 });
366                                 return;
367                         }
368                         // Object and web filesystem URLs have a problem saving in Google Chrome when
369                         // viewed in a tab, so I force save with application/octet-stream
370                         // http://code.google.com/p/chromium/issues/detail?id=91158
371                         // Update: Google errantly closed 91158, I submitted it again:
372                         // https://code.google.com/p/chromium/issues/detail?id=389642
373                         if (view.chrome && type && type !== force_saveable_type) {
374                                 slice = blob.slice || blob.webkitSlice;
375                                 blob = slice.call(blob, 0, blob.size, force_saveable_type);
376                                 blob_changed = true;
377                         }
378                         // Since I can't be sure that the guessed media type will trigger a download
379                         // in WebKit, I append .download to the filename.
380                         // https://bugs.webkit.org/show_bug.cgi?id=65440
381                         if (webkit_req_fs && name !== "download") {
382                                 name += ".download";
383                         }
384                         if (type === force_saveable_type || webkit_req_fs) {
385                                 target_view = view;
386                         }
387                         if (!req_fs) {
388                                 fs_error();
389                                 return;
390                         }
391                         fs_min_size += blob.size;
392                         req_fs(view.TEMPORARY, fs_min_size, abortable(function(fs) {
393                                 fs.root.getDirectory("saved", create_if_not_found, abortable(function(dir) {
394                                         var save = function() {
395                                                 dir.getFile(name, create_if_not_found, abortable(function(file) {
396                                                         file.createWriter(abortable(function(writer) {
397                                                                 writer.onwriteend = function(event) {
398                                                                         target_view.location.href = file.toURL();
399                                                                         filesaver.readyState = filesaver.DONE;
400                                                                         dispatch(filesaver, "writeend", event);
401                                                                         revoke(file);
402                                                                 };
403                                                                 writer.onerror = function() {
404                                                                         var error = writer.error;
405                                                                         if (error.code !== error.ABORT_ERR) {
406                                                                                 fs_error();
407                                                                         }
408                                                                 };
409                                                                 "writestart progress write abort".split(" ").forEach(function(event) {
410                                                                         writer["on" + event] = filesaver["on" + event];
411                                                                 });
412                                                                 writer.write(blob);
413                                                                 filesaver.abort = function() {
414                                                                         writer.abort();
415                                                                         filesaver.readyState = filesaver.DONE;
416                                                                 };
417                                                                 filesaver.readyState = filesaver.WRITING;
418                                                         }), fs_error);
419                                                 }), fs_error);
420                                         };
421                                         dir.getFile(name, {create: false}, abortable(function(file) {
422                                                 // delete file if it already exists
423                                                 file.remove();
424                                                 save();
425                                         }), abortable(function(ex) {
426                                                 if (ex.code === ex.NOT_FOUND_ERR) {
427                                                         save();
428                                                 } else {
429                                                         fs_error();
430                                                 }
431                                         }));
432                                 }), fs_error);
433                         }), fs_error);
434                 }
435                 , FS_proto = FileSaver.prototype
436                 , saveAs = function(blob, name, no_auto_bom) {
437                         return new FileSaver(blob, name, no_auto_bom);
438                 }
439         ;
440         // IE 10+ (native saveAs)
441         if (typeof navigator !== "undefined" && navigator.msSaveOrOpenBlob) {
442                 return function(blob, name, no_auto_bom) {
443                         if (!no_auto_bom) {
444                                 blob = auto_bom(blob);
445                         }
446                         return navigator.msSaveOrOpenBlob(blob, name || "download");
447                 };
448         }
449
450         FS_proto.abort = function() {
451                 var filesaver = this;
452                 filesaver.readyState = filesaver.DONE;
453                 dispatch(filesaver, "abort");
454         };
455         FS_proto.readyState = FS_proto.INIT = 0;
456         FS_proto.WRITING = 1;
457         FS_proto.DONE = 2;
458
459         FS_proto.error =
460         FS_proto.onwritestart =
461         FS_proto.onprogress =
462         FS_proto.onwrite =
463         FS_proto.onabort =
464         FS_proto.onerror =
465         FS_proto.onwriteend =
466                 null;
467
468         return saveAs;
469 }(
470            typeof self !== "undefined" && self
471         || typeof window !== "undefined" && window
472         || this.content
473 ));
474 // `self` is undefined in Firefox for Android content script context
475 // while `this` is nsIContentFrameMessageManager
476 // with an attribute `content` that corresponds to the window
477
478 if (typeof module !== "undefined" && module.exports) {
479   module.exports.saveAs = saveAs;
480 } else if ((typeof define !== "undefined" && define !== null) && (define.amd != null)) {
481   define([], function() {
482     return saveAs;
483   });
484 }
485
486 },{}],3:[function(require,module,exports){
487 'use strict';
488
489 /*
490 *
491 * A AngularJS module that implements the HTML5 W3C saveAs() in browsers that
492 * do not natively support it
493 *
494 * (c) 2015 Philipp Alferov
495 * License: MIT
496 *
497 */
498
499 angular.module('ngFileSaver', [])
500   .factory('FileSaver', ['Blob', 'SaveAs', 'FileSaverUtils', require('./angular-file-saver.service')])
501   .factory('FileSaverUtils', [require('./utils/utils.service.js')])
502   .factory('Blob', ['$window', require('./dependencies/blob-bundle.service.js')])
503   .factory('SaveAs', [require('./dependencies/file-saver-bundle.service.js')]);
504
505 },{"./angular-file-saver.service":4,"./dependencies/blob-bundle.service.js":5,"./dependencies/file-saver-bundle.service.js":6,"./utils/utils.service.js":7}],4:[function(require,module,exports){
506 'use strict';
507
508 module.exports = function FileSaver(Blob, SaveAs, FileSaverUtils) {
509
510   function save(blob, filename, disableAutoBOM) {
511     try {
512       SaveAs(blob, filename, disableAutoBOM);
513     } catch(err) {
514       FileSaverUtils.handleErrors(err.message);
515     }
516   }
517
518   return {
519
520     /**
521     * saveAs
522     * Immediately starts saving a file, returns undefined.
523     *
524     * @name saveAs
525     * @function
526     * @param {Blob} data A Blob instance
527     * @param {Object} filename Custom filename (extension is optional)
528     * @param {Boolean} disableAutoBOM Disable automatically provided Unicode
529     * text encoding hints
530     *
531     * @return {Undefined}
532     */
533
534     saveAs: function(data, filename, disableAutoBOM) {
535
536       if (!FileSaverUtils.isBlobInstance(data)) {
537         FileSaverUtils.handleErrors('Data argument should be a blob instance');
538       }
539
540       if (!FileSaverUtils.isString(filename)) {
541         FileSaverUtils.handleErrors('Filename argument should be a string');
542       }
543
544       return save(data, filename, disableAutoBOM);
545     }
546   };
547 };
548
549 },{}],5:[function(require,module,exports){
550 'use strict';
551
552 require('Blob.js');
553
554 module.exports = function Blob($window) {
555   return $window.Blob;
556 };
557
558 },{"Blob.js":1}],6:[function(require,module,exports){
559 'use strict';
560
561 module.exports = function SaveAs() {
562   return require('FileSaver.js').saveAs || function() {};
563 };
564
565 },{"FileSaver.js":2}],7:[function(require,module,exports){
566 'use strict';
567
568 module.exports = function FileSaverUtils() {
569   return {
570     handleErrors: function(msg) {
571       throw new Error(msg);
572     },
573     isString: function(obj) {
574       return typeof obj === 'string' || obj instanceof String;
575     },
576     isUndefined: function(obj) {
577       return typeof obj === 'undefined';
578     },
579     isBlobInstance: function(obj) {
580       return obj instanceof Blob;
581     }
582   };
583 };
584
585 },{}]},{},[3]);