From d76882276d78240dd5a1d42ea8f58dbbafd5de09 Mon Sep 17 00:00:00 2001 From: Gonzalo Ruiz de Villa Date: Mon, 7 Jul 2014 19:56:19 +0200 Subject: [PATCH] fix(callback): callback was called twice when lib was already loaded --- src/script.js | 3 +-- tests/tests.js | 8 ++++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/script.js b/src/script.js index ab0f53c..cb9b585 100644 --- a/src/script.js +++ b/src/script.js @@ -51,8 +51,7 @@ path = !force && path.indexOf('.js') === -1 && !/^https?:\/\//.test(path) && scriptpath ? scriptpath + path + '.js' : path if (scripts[path]) { if (id) ids[id] = 1 - if (scripts[path] == 2) callback() - else return setTimeout(function () { loading(path, true) }, 0) + return (scripts[path] == 2) ? callback() : setTimeout(function () { loading(path, true) }, 0) } scripts[path] = 1 diff --git a/tests/tests.js b/tests/tests.js index 23de0f0..b7078e1 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -133,6 +133,14 @@ script('../node_modules/domready/ready.js', function () { script('double-load', load) }) + test('correctly count loaded scripts', function (done){ + script.path('../vendor/') + script(['patha', 'pathb', 'http://ded.github.com/morpheus/morpheus.js', 'http://ajax.googleapis.com/ajax/libs/angularjs/1.2.19/angular.js'], function () { + ok(typeof angular !== 'undefined', 'loaded angular.js from http') + done(); + }) + }) + }) start() })