Skip to content

Commit abc6a86

Browse files
fix(cards): imagesUrl when module is loaded asychronously
1 parent b4b86f1 commit abc6a86

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

README.md

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,12 @@ Install with [npm](http://blog.npmjs.org/post/85484771375/how-to-install-npm)
2121

2222
### Browser
2323

24-
Include the package from your project
25-
26-
````html
27-
<link rel="stylesheet" type="text/css" href="./node_modules/cardsJS/dist/cards.min.css" />
28-
<script src="./node_modules/cardsJS/dist/cards.min.js" type="text/javascript"></script>
29-
````
30-
31-
or from the [unpkg CDN](https://unpkg.com)
24+
Include the package from the [unpkg CDN](https://unpkg.com)
3225

3326
````html
3427
<link rel="stylesheet" type="text/css" href="https://unpkg.com/cardsJS/dist/cards.min.css" />
35-
<script src="https://unpkg.com/cardsJS/dist/cards.min.js" type="text/javascript"></script>
28+
29+
<script src="https://unpkg.com/cardsJS/dist/cards.min.js" type="text/javascript"></script>
3630
````
3731

3832
## Cards

cards.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/*jslint vars: true, plusplus: true, -W003 */
22
/*globals window, document, define, exports, module, require */
3+
4+
var cardsScript = document.currentScript;
35

46
(function (root, factory) {
57
'use strict';
@@ -302,9 +304,8 @@
302304
});
303305

304306
// Default imagesUrl to a subfolder of the script source.
305-
var mySource = document.currentScript.src;
306-
if (mySource) {
307-
var path = mySource.substring(0, mySource.lastIndexOf('/')) + '/cards/';
307+
if (cardsScript && cardsScript.src) {
308+
var path = cardsScript.src.substring(0, cardsScript.src.lastIndexOf('/')) + '/cards/';
308309
module.options.imagesUrl = path;
309310
}
310311

0 commit comments

Comments
 (0)