Skip to content

Commit

Permalink
delete-scale-config
Browse files Browse the repository at this point in the history
  • Loading branch information
fleurWang committed Nov 16, 2015
1 parent 3525ac6 commit 7d1fd7c
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
6 changes: 6 additions & 0 deletions component_modules/DDFE-imageLoader/0.0.1/component.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "imageLoader",
"version": "0.0.1",
"main": "imageloader.js",
"description": "图片预加载函数"
}
86 changes: 86 additions & 0 deletions component_modules/DDFE-imageLoader/0.0.1/imageloader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
var __id = 0;

function getId() {
return ++__id;
}

function noop() {

}

function loadImage(images, callback, timeout) {
var key, item, count, success, timeoutId, isTimeout;

count = 0;
success = true;
isTimeout = false;

callback = callback || noop;
for (key in images) {
if (!images.hasOwnProperty(key))
continue;
item = images[key];

if (typeof (item) == 'string') {
item = images[key] = {
src: item
};
}

if (!item || !item.src)
continue;

count++;
item.id = '__img_' + key + getId();
item.img = window[item.id] = new Image();

doLoad(item);
}

if (!count) {
callback(success);
} else if (timeout) {
timeoutId = setTimeout(onTimeout, timeout);
}

function doLoad(item) {
var img = item.img,
id = item.id;

item.status = "loading";

img.onload = function () {
success = success && true;
item.status = "loaded";
done();
};
img.onerror = function () {
success = false;
item.status = "error";
done();
};
img.src = item.src;

function done() {
img.onload = img.onerror = null;

try {
delete window[id];
}
catch (e) {

}
if (!--count && !isTimeout) {
clearTimeout(timeoutId);
callback(success);
}
}
}

function onTimeout() {
isTimeout = true;
callback(false);
}
}

module.exports = loadImage;
4 changes: 3 additions & 1 deletion dialog.styl
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@
margin: 24px 0 18px
.icon-tip
background-image: url(i-tip.png?__sprite)
background-size: 45px 45px
background-repeat: no-repeat
.alert
.icon-alert
background-image: url(i-alert.png?__sprite)
background-size: 45px 45px
background-repeat: no-repeat
.floading
.icon-flat
Expand Down Expand Up @@ -105,7 +107,7 @@
float: right
.icon-confirm
background-image: url(i-alert.png?__sprite)
background-position: 23px
background-size: 45px 45px
background-repeat: no-repeat
.d-close
position: absolute
Expand Down

0 comments on commit 7d1fd7c

Please sign in to comment.