From 7d1fd7c4c3be2cec52681bf26eb2cb394cb9e697 Mon Sep 17 00:00:00 2001 From: fleurWang <1159971011@qq.com> Date: Mon, 16 Nov 2015 13:36:50 +0800 Subject: [PATCH] delete-scale-config --- .../DDFE-imageLoader/0.0.1/component.json | 6 ++ .../DDFE-imageLoader/0.0.1/imageloader.js | 86 +++++++++++++++++++ dialog.styl | 4 +- 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 component_modules/DDFE-imageLoader/0.0.1/component.json create mode 100644 component_modules/DDFE-imageLoader/0.0.1/imageloader.js diff --git a/component_modules/DDFE-imageLoader/0.0.1/component.json b/component_modules/DDFE-imageLoader/0.0.1/component.json new file mode 100644 index 0000000..c5e56d6 --- /dev/null +++ b/component_modules/DDFE-imageLoader/0.0.1/component.json @@ -0,0 +1,6 @@ +{ + "name": "imageLoader", + "version": "0.0.1", + "main": "imageloader.js", + "description": "图片预加载函数" +} \ No newline at end of file diff --git a/component_modules/DDFE-imageLoader/0.0.1/imageloader.js b/component_modules/DDFE-imageLoader/0.0.1/imageloader.js new file mode 100644 index 0000000..109974d --- /dev/null +++ b/component_modules/DDFE-imageLoader/0.0.1/imageloader.js @@ -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; diff --git a/dialog.styl b/dialog.styl index f1a6752..d103813 100644 --- a/dialog.styl +++ b/dialog.styl @@ -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 @@ -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