From fa1336490f582dcd6c85dafb11f7a3c841826749 Mon Sep 17 00:00:00 2001 From: fishineyuan <382184760@qq.com> Date: Fri, 4 Mar 2016 19:32:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=B9res.type=3D"css"?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81=E4=BB=A5=E5=8A=A0=E8=BD=BD=E5=BC=82?= =?UTF-8?q?=E6=AD=A5=E6=A8=A1=E5=9D=97=E4=B8=AD=E7=9A=84css=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mod.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/mod.js b/mod.js index ec15755..a7a9ccf 100644 --- a/mod.js +++ b/mod.js @@ -80,9 +80,21 @@ var define; url = res.url || res.uri || id; } - createScript(url, onerror && function () { - onerror(id); - }); + if (res.type === 'css') { + require.loadCss({ + url: url, + onload: function() { + define(id, 'css'); + }, + onerror: function() { + onerror && onerror(id); + } + }); + } else { + createScript(url, onerror && function () { + onerror(id); + }); + } }; define = function (id, factory) { @@ -237,9 +249,12 @@ var define; sty.innerHTML = cfg.content; } head.appendChild(sty); + cfg.onload && cfg.onload(); } else if (cfg.url) { var link = document.createElement('link'); + cfg.onload && (link.onload = cfg.onload); + cfg.onerror && (link.onerror = cfg.onerror); link.href = cfg.url; link.rel = 'stylesheet'; link.type = 'text/css';