-
Notifications
You must be signed in to change notification settings - Fork 10
/
imagenie.min.js
1 lines (1 loc) · 2.03 KB
/
imagenie.min.js
1
!function(){function e(e){var n={};return n.getImageBase64String=function(n,t){var i=e.defer(),a=document.createElement("CANVAS"),r=a.getContext("2d"),o=new Image;return o.crossOrigin="Anonymous",o.onload=function(){var e;a.height=o.height,a.width=o.width,r.drawImage(o,0,0),e=a.toDataURL(t),a=null,i.resolve(e)},o.onerror=function(){i.reject(n)},o.src=n,i.promise},n.isUndefined=function(e){return"undefined"==typeof e},n.isEmpty=function(e){return this.isUndefined(e)||""===e||null===e},n.getImageSrc=function(e){return this.isEmpty(e.imagenie)?this.isEmpty(e.ngSrc)?this.isEmpty(e.src)?(console.warn("Image Src Undefined"),null):e.src:e.ngSrc:e.imagenie},n.setImageToElement=function(e,n){"IMG"===e[0].nodeName?e.attr("src",n):e.css("background-image","url("+n+")")},n.isUriAbsolute=function(e){var n=new RegExp("^(?:[a-z]+:)?//","i");return n.test(e)},n}function n(e,n,t){return{restrict:"A",link:function(i,a,r){r.$observe("imagenie",function(){var i=e.getImageSrc(r),o={};try{o=n.instance(t.name)}catch(c){if(ionic.Platform.isIOS()){var s=angular.extend(t,{driver:"webSQLStorage"});o=n.createInstance(s)}else o=n.createInstance(t)}e.isUriAbsolute(i)&&(r.ngSrc="",o.getItem(encodeURIComponent(i)).then(function(n){if(e.isEmpty(n)){var t=angular.element("<img />");t.bind("load",function(){e.getImageBase64String(i).then(function(n){o.setItem(encodeURIComponent(i),n),e.setImageToElement(a,n)},function(n){e.setImageToElement(a,i)})}),t.attr("src",i)}else e.setImageToElement(a,n)},function(){var n=angular.element("<img />");n.bind("load",function(){e.getImageBase64String(i).then(function(n){o.setItem(encodeURIComponent(i),n),e.setImageToElement(a,n)},function(n){e.setImageToElement(a,i)})}),n.attr("src",i)}))})}}}angular.module("imagenie",["LocalForageModule"]).constant("IMAGENIE_LOCAL_FORAGE_CONFIG",{name:"imagenie_db",storeName:"image",description:"The database to hold base 64 versions of all your images so they are available offline"}).factory("ImagenieUtil",["$q",e]).directive("imagenie",["ImagenieUtil","$localForage","IMAGENIE_LOCAL_FORAGE_CONFIG",n])}();