-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathionic-img-cache.min.js
1 lines (1 loc) · 3.39 KB
/
ionic-img-cache.min.js
1
!function(e){"use strict";function c(e,c,n){ImgCache.options.skipURIencoding=!0,ImgCache.options.debug=c.debug,ImgCache.options.headers=c.headers,ImgCache.options.localCacheFolder=c.folder,ImgCache.options.chromeQuota=1024*c.quota*1024,ImgCache.options.cacheClearSize=c.cacheClearSize,e.ready(function(){ImgCache.init(function(){c.debug&&n.info("ionicImgCache initialized")},function(){c.debug&&n.error("Failed to init ionicImgCache.")})})}function n(c){function n(){var n=c.defer();return ImgCache.ready?n.resolve():e.addEventListener("ImgCacheReady",function(){n.resolve()},!1),n.promise}return{add:function(e){var t=c.defer();return n().then(function(){ImgCache.cacheFile(e,function(){ImgCache.isCached(e,function(e,c){t.resolve(e)},t.reject)},t.reject)}).catch(t.reject),t.promise},get:function(e){var t=c.defer();return n().then(function(){ImgCache.isCached(e,function(e,c){c?t.resolve(e):t.reject()},t.reject)}).catch(t.reject),t.promise},remove:function(e){var t=c.defer();return n().then(function(){ImgCache.isCached(e,function(c,n){ImgCache.removeFile(e,function(){t.resolve()},t.reject)},t.reject)}).catch(t.reject),t.promise},checkCacheStatus:function(e){var t=c.defer();return n().then(function(){ImgCache.isCached(e,function(c,n){n?t.resolve(c):ImgCache.cacheFile(e,function(){ImgCache.isCached(e,function(e,c){t.resolve(e)},t.reject)},t.reject)},t.reject)}).catch(t.reject),t.promise},checkBgCacheStatus:function(e){var t=c.defer();return n().then(function(){ImgCache.isBackgroundCached(e,function(c,n){n?t.resolve(c):ImgCache.cacheBackground(e,function(){ImgCache.isBackgroundCached(e,function(e,c){t.resolve(e)},t.reject)},t.reject)},t.reject)}).catch(t.reject),t.promise},clearCache:function(){var e=c.defer();return n().then(function(){ImgCache.clearCache(e.resolve,e.reject)}).catch(e.reject),e.promise},getCacheSize:function(){var e=c.defer();return n().then(function(){e.resolve(ImgCache.getCurrentSize())}).catch(e.reject),e.promise}}}function t(e){return{restrict:"A",priority:98,link:function(c,n,t){t.$observe("ngSrc",function(c){e.checkCacheStatus(c).then(function(){ImgCache.useCachedFile(n)})})}}}function i(e){this.$onInit=function(){this.alt||(this.alt=""),this.checkSrc()},this.$onChanges=function(e){e&&e.imgSrc&&!e.imgSrc.isFirstChange()&&this.checkSrc()},this.checkSrc=function(){this.imgSrc?this.src=e.checkCacheStatus(this.imgSrc):this.src=""}}function r(e){return{restrict:"A",link:function(c,n,t){e.checkBgCacheStatus(n).then(function(){ImgCache.useCachedBackground(n)}),t.$observe("ngStyle",function(){e.checkBgCacheStatus(n).then(function(){ImgCache.useCachedBackground(n)})})}}}c.$inject=["$ionicPlatform","ionicImgCache","$log"],n.$inject=["$q"],t.$inject=["ionImgCacheSrv"],r.$inject=["ionImgCacheSrv"],i.$inject=["ionImgCacheSrv"],angular.module("ionicImgCache",["ionic"]).run(c).provider("ionicImgCache",function(){var e=!1,c={},n=50,t="ionic-img-cache",i=0;this.debug=function(c){e=!!c},this.headers=function(e){c=e},this.quota=function(e){n=isFinite(e)?e:50},this.folder=function(e){t=""+e},this.cacheClearSize=function(e){i=isFinite(e)?e:0},this.$get=function(){return{debug:e,quota:n,headers:c,folder:t,cacheClearSize:i}}}).factory("ionImgCacheSrv",n).directive("ionImgCache",t).directive("ionImgCacheBg",r),"component"in angular&&angular.module("ionicImgCache").component("ionImgCacheComponent",{bindings:{imgSrc:"<",alt:"<"},template:'<img ng-src="{{ $ctrl.src }}" alt="{{ $ctrl.alt }}" />',controller:i})}(document);