Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 27 additions & 10 deletions ionic-cache-src.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
ctx.drawImage(img, 0, 0);
return canvas.toDataURL();
}

// For the Default Progress Circle
//****************************************************************************************************//
var default_circle_style = {
Expand Down Expand Up @@ -168,10 +168,27 @@
})
.factory('cacheSrcStorage', function($localStorage) {
var c = {};
c.getCacheDir = function() {
if (window.device)
if (window.cordova.file) {
switch (device.platform) {
case 'iOS':
return $window.cordova.file.documentsDirectory;
case 'Android':
return $window.cordova.file.dataDirectory;
case 'windows':
return $window.cordova.file.dataDirectory;
}
} else
throw new Error("window.cordova.file is not defined! Maybe you should install cordova-plugin-file first!");
else
throw new Error("window.device is not defined! Maybe you should install cordova-plugin-device first!");
return '';
};
c._cache = $localStorage.cache_src || {};
c.get = function(url) {
if (needDownload(url)) {
var cache_url = c._cache[url] && (getCacheDir() + c._cache[url]);
var cache_url = c._cache[url] && (c.getCacheDir() + c._cache[url]);
return cache_url || url;
}
return undefined;
Expand All @@ -198,7 +215,7 @@
'onFinish': '=?',
'onError': '=?',
'onStart': '=?',
//
//
'uiOnStart': '=?',
'uiOnProgress': '=?',
'uiOnFinish': '=?'
Expand Down Expand Up @@ -230,7 +247,7 @@
scope.uiOnStart = ensureFunction(scope.uiOnStart, angular.noop);




function addSrcWithoutFinish(result) {
if (scope.srcIs == 'background') {
Expand Down Expand Up @@ -261,8 +278,8 @@
else
throw new Error("window.device is not defined! Maybe you should install cordova-plugin-device first!");
return '';
};
};

var cache = $localStorage.cache_src = $localStorage.cache_src || {};
var create_time = $localStorage.cache_src_create_time = $localStorage.cache_src_create_time || {};
function scopeOnError(fileName,uiData) {
Expand All @@ -271,7 +288,7 @@
console.log('Error Occurs: ' + E.exception + "\nCode:" + E.code + "\nSrc:" + E.source);
if(uiData)
scope.uiOnFinish(scope, element, $compile, uiData);
addSrcWithoutFinish(E.source);
addSrcWithoutFinish(E.source);
// var b64 = getBase64Image(getElement(element));
// if(b64.length > 200)
// $cordovaFile
Expand All @@ -280,9 +297,9 @@
// cache[attrs.cacheSrc] = fileName;
// if (scope.expire !== Infinity) {
// create_time[attrs.cacheSrc] = Date.now();
// }
// }
// addSrc(getCacheDir() + fileName);
// },scope.onError);
// },scope.onError);
} else {
scope.onError(E);
}
Expand Down Expand Up @@ -375,7 +392,7 @@
});
});
} else {
// in browser
// in browser
attrs.$observe('cacheSrc', function() {
if (attrs.cacheSrc) {
if (needDownload(attrs.cacheSrc)) {
Expand Down