From b60ae57c71e9e18f8a6243ac54231239cf93f5d7 Mon Sep 17 00:00:00 2001 From: Manuel Mujica Date: Thu, 22 Jun 2017 11:50:24 -0600 Subject: [PATCH 1/3] Add slim build support --- css.js | 4 ++-- slim.js | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 slim.js diff --git a/css.js b/css.js index 26b637c..34ff605 100644 --- a/css.js +++ b/css.js @@ -118,8 +118,7 @@ CSSModule.prototype = { // * Zombie headless browser // Weak inference targets Android < 4.4 and // a fallback for IE 8 and beneath - if( "isApplicationInstalled" in navigator || - !link.addEventListener) { + if("isApplicationInstalled" in navigator || !link.addEventListener) { // fallback, polling styleSheets onloadCss(link, loadCB); } else if(navigator.noUI){ @@ -282,3 +281,4 @@ exports.getHead = getHead; exports.locateScheme = true; exports.buildType = "css"; exports.includeInBuild = true; +exports.pluginBuilder = "steal-css/slim"; diff --git a/slim.js b/slim.js new file mode 100644 index 0000000..8d9f96c --- /dev/null +++ b/slim.js @@ -0,0 +1,67 @@ +/* naive version of the css plugin for the slim loader */ +module.exports = function(moduleId, config) { + return new CssModule(config.paths[config.bundles[moduleId]]).injectLink(); +}; + +function CssModule(address) { + this.address = address; +} + +// timeout in seconds +CssModule.waitTimeout = 60; + +CssModule.prototype.linkExists = function() { + var styleSheets = document.styleSheets; + + for (var i = 0; i < styleSheets.length; ++i) { + if (this.address === styleSheets[i].href) { + return true; + } + } + + return false; +}; + +CssModule.prototype.injectLink = function() { + if (this._loadPromise) { + return this._loadPromise; + } + + if (this.linkExists()) { + this._loadPromise = Promise.resolve(""); + return this._loadPromise; + } + + // inspired by https://github.com/filamentgroup/loadCSS + var link = (this.link = document.createElement("link")); + link.type = "text/css"; + link.rel = "stylesheet"; + link.href = this.address; + + // wait until the css file is loaded + this._loadPromise = new Promise(function(resolve, reject) { + var timeout = setTimeout(function() { + reject("Unable to load CSS"); + }, CssModule.waitTimeout * 1000); + + var linkEventCallback = function(event) { + clearTimeout(timeout); + + link.removeEventListener("load", linkEventCallback); + link.removeEventListener("error", linkEventCallback); + + if (event && event.type === "error") { + reject("Unable to load CSS"); + } else { + resolve(""); + } + }; + + link.addEventListener("load", linkEventCallback); + link.addEventListener("error", linkEventCallback); + + document.head.appendChild(link); + }); + + return this._loadPromise; +}; From c0872790114321e172c21fb587a10cedf0da91bd Mon Sep 17 00:00:00 2001 From: Manuel Mujica Date: Tue, 27 Jun 2017 17:00:14 -0600 Subject: [PATCH 2/3] 1.3.0-pre.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cd91a7c..d294f0c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "steal-css", - "version": "1.2.5", + "version": "1.3.0-pre.0", "description": "CSS plugin for StealJS", "main": "css.js", "scripts": { From 9df7f5514f90d1b31099c43b3bf5cb2bcbec46ff Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Mon, 21 Aug 2017 11:31:25 -0400 Subject: [PATCH 3/3] Use patch version so tests will pass --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d294f0c..c56759c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "steal-css", - "version": "1.3.0-pre.0", + "version": "1.2.6", "description": "CSS plugin for StealJS", "main": "css.js", "scripts": {