Skip to content

Commit f15ce35

Browse files
committed
Use ES6 promise in css plugin
1 parent 168a395 commit f15ce35

File tree

8 files changed

+29
-25
lines changed

8 files changed

+29
-25
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Then install dependencies with bower (or manually from github if you prefer to):
3535
$ cd requirejs-dplugins
3636
$ bower install
3737

38+
Of course, to use the jQuery plugin you will need to install jquery in your app via `bower install jquery` or
39+
via a script tag (ex: `<script src="https://code.jquery.com/jquery-2.1.1.min.js">`).
3840

3941
## css
4042
This plugin will load and wait for a css file. CSS loaded with this plugin can be overwritten by

bower.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
"version": "0.4.2",
44
"description": "AMD plugins for RequireJS",
55
"dependencies": {
6-
"jquery": ">=2.1",
76
"lie": ">=2.8",
87
"requirejs": "2.1.x"
98
},
10-
"devDependencies": {},
9+
"devDependencies": {
10+
"jquery": ">=2.1"
11+
},
1112
"keywords": [
1213
"requirejs",
1314
"amd",

css.js

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030

3131
define([
3232
"./has",
33-
"./jquery!deferred",
33+
"./Promise!",
3434
"module"
35-
], function (has, $, module) {
35+
], function (has, Promise, module) {
3636
"use strict";
3737

3838
has.add("event-link-onload-api", function (global) {
@@ -49,30 +49,29 @@ define([
4949
* @private
5050
*/
5151
var listenOnLoad = function (link) {
52-
var def = new $.Deferred(),
53-
loadHandler = has("event-link-onload-api") ?
54-
function () {
55-
// We're using "readystatechange" because IE happily support both
56-
link.onreadystatechange = link.onload = function () {
57-
if (!link.readyState || link.readyState === "complete") {
58-
link.onreadystatechange = link.onload = null;
59-
def.resolve();
60-
}
61-
};
62-
} :
63-
function () {
52+
return new Promise(function (resolve) {
53+
if (has("event-link-onload-api")) {
54+
// We're using "readystatechange" because IE happily support both
55+
link.onreadystatechange = link.onload = function () {
56+
if (!link.readyState || link.readyState === "complete") {
57+
link.onreadystatechange = link.onload = null;
58+
resolve();
59+
}
60+
};
61+
} else {
62+
var poll = function () {
6463
// watches a stylesheet for loading signs.
6564
var sheet = link.sheet || link.styleSheet,
6665
styleSheets = document.styleSheets;
6766
if (sheet && Array.prototype.lastIndexOf.call(styleSheets, sheet) !== -1) {
68-
def.resolve();
67+
resolve();
6968
} else {
70-
setTimeout(loadHandler, 25);
69+
setTimeout(poll, 25);
7170
}
7271
};
73-
74-
loadHandler();
75-
return def.promise();
72+
poll();
73+
}
74+
});
7675
};
7776

7877
var loadCss = {

docs/jquery.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ library via a `<script>` tag, in which case it just returns a pointer to the alr
1111

1212
It's useful to avoid loading jQuery twice.
1313

14-
When using this plugin, you can use the provided jquery (installed as a `requirejs-dplugins` bower dependency)
15-
or use your own version, either via `bower install jquery` or via
14+
When using this plugin, you must manually include jquery into your app via `bower install jquery` or via
1615
a script tag (ex: `<script src="https://code.jquery.com/jquery-2.1.1.min.js">`).
1716

1817
## Example

tests/functional/jqueryApp/Gruntfile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = function (grunt) {
1717

1818
paths: {
1919
jquery: "bower_components/jquery",
20+
lie: "bower_components/lie",
2021
"requirejs-dplugins": "../../.."
2122
},
2223

tests/functional/jqueryApp/bower.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.1.0",
44
"description": "Test application using jquery! plugin",
55
"dependencies": {
6+
"lie": ">=2.8",
67
"jquery": ">=2.1",
78
"requirejs": "2.1.x"
89
}

tests/intern.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,5 @@ define({
9595
functionalSuites: ["requirejs-dplugins/tests/functional/all"],
9696

9797
// A regular expression matching URLs to files that should not be included in code coverage analysis
98-
excludeInstrumentation: /(?:requirejs|jquery|tests|node_modules)(?:\/|\\)/
98+
excludeInstrumentation: /(?:requirejs|lie|jquery|tests|node_modules)(?:\/|\\)/
9999
});

tests/unit/css.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ define([
1111
// to be able to access requirejs-dplugins sibling directories.
1212
// The last /requirejs-dplugins is here to allow to use css! directly instead of
1313
// requirejs-dplugins/css!
14-
baseUrl: "../../../requirejs-dplugins"
14+
baseUrl: "../../../requirejs-dplugins",
15+
paths: {lie: "../lie"}
1516
});
1617

1718
function getStyles() {

0 commit comments

Comments
 (0)