Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
tower1229 committed Jul 9, 2018
1 parent 8eb34a0 commit 6a03b7d
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions sdk/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,13 @@ define(function(require, exports, module) {
var cacheImg = function(element, callback) {
var placeholderPic = seajs.root + '/res/img/placeholder.jpg';
var remoteEle;
var setImg = function(ele, url){
if (ele.tagName.toLowerCase() === 'img') {
ele.setAttribute('src', url);
} else {
ele.style.backgroundImage = "url(" + url + ")";
}
};
if ($(element)[0].getAttribute('data-remote')) {
remoteEle = $(element);
} else {
Expand All @@ -383,23 +390,23 @@ define(function(require, exports, module) {
app.ready(function() {
var cacheCount = 0;
$.each(remoteEle, function(i, ele) {
var remote = ele.getAttribute('data-remote') || placeholderPic;
api.imageCache({
url: remote,
policy: "cache_else_network"
}, function(ret, err) {
var url = ret.url;
if (ele.tagName.toLowerCase() === 'img') {
ele.setAttribute('src', url);
} else {
ele.style.backgroundImage = "url(" + url + ")";
}
ele.removeAttribute('data-remote');
cacheCount++;
if (cacheCount === remoteEle.length) {
typeof callback === 'function' && callback();
}
});
var remote = ele.getAttribute('data-remote');
if(remote){
api.imageCache({
url: remote,
policy: "cache_else_network"
}, function(ret, err) {
var url = ret.url;
setImg(ele, url);
ele.removeAttribute('data-remote');
cacheCount++;
if (cacheCount === remoteEle.length) {
typeof callback === 'function' && callback();
}
});
}else{
setImg(ele, placeholderPic);
}
});
});
return remoteEle;
Expand Down

0 comments on commit 6a03b7d

Please sign in to comment.