mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-02 13:24:20 +01:00
4 lines
1.1 KiB
JavaScript
4 lines
1.1 KiB
JavaScript
/*! angular-base64-upload - v0.0.8 - 2015-04-27
|
|
* https://github.com/adonespitogo/angular-base64-upload
|
|
* Copyright (c) Adones Pitogo <pitogo.adones@gmail.com> 2015; Licensed */
|
|
angular.module("naif.base64",[]).directive("baseSixtyFourInput",["$window",function(a){return{restrict:"A",require:"ngModel",link:function(b,c,d,e){function f(b){for(var c="",d=new Uint8Array(b),e=d.byteLength,f=0;e>f;f++)c+=String.fromCharCode(d[f]);return a.btoa(c)}var g={};b.readerOnload=function(a){var c=f(a.target.result);g.base64=c,b.$apply(function(){e.$setViewValue(angular.copy(g))})};var h=new FileReader;h.onload=b.readerOnload,c.on("change",function(){if(c[0].files.length){var a=c[0].files[0];g.filetype=a.type,g.filename=a.name,g.filesize=a.size,h.readAsArrayBuffer(a)}})}}}]).directive("baseSixtyFourImage",[function(){return{restrict:"A",link:function(a,b,c){function d(a){return"data:"+a.filetype+";base64,"+a.base64}a.$watch(c.baseSixtyFourImage,function(a){a&&a.filetype&&0===a.filetype.indexOf("image")?b.attr("src",d(a)):b.attr("src",c.baseSixtyFourImagePlaceholder)})}}}]); |