├── .gitignore
├── .jshintrc
├── .travis.yml
├── MIT-LICENSE.txt
├── README.md
├── bower.json
├── dist
└── jquery.getscripts.min.js
├── gruntfile.js
├── jquery.getscripts.jquery.json
├── package.json
├── source
└── jquery.getscripts.js
└── tests
├── index.html
└── tests.js
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | node_modules
3 | bower_components
4 | *.sublime*
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | // Settings
3 | "passfail" : false, // Stop on first error.
4 | "maxerr" : 100, // Maximum error before stopping.
5 |
6 | // Predefined globals whom JSHint will ignore.
7 | "browser" : true,
8 |
9 | "node" : false,
10 | "rhino" : false,
11 | "couch" : false,
12 | "wsh" : false,
13 |
14 | "jquery" : true,
15 | "prototypejs" : false,
16 | "mootools" : false,
17 | "dojo" : false,
18 |
19 | "predef" : [],
20 |
21 | // Development.
22 | "debug" : false,
23 | "devel" : true,
24 |
25 | // ECMAScript 5.
26 | "strict" : true,
27 | "globalstrict" : false,
28 |
29 | // The Good Parts.
30 | "asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons).
31 | "laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
32 | "bitwise" : true, // Prohibit bitwise operators (&, |, ^, etc.).
33 | "boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
34 | "curly" : true, // Require {} for every new block or scope.
35 | "eqeqeq" : true, // Require triple equals i.e. `===`.
36 | "eqnull" : false, // Tolerate use of `== null`.
37 | "evil" : false, // Tolerate use of `eval`.
38 | "expr" : false, // Tolerate `ExpressionStatement` as Programs.
39 | "forin" : false, // Tolerate `for in` loops without `hasOwnPrototype`.
40 | "immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
41 | "latedef" : true, // Prohipit variable use before definition.
42 | "loopfunc" : false, // Allow functions to be defined within loops.
43 | "noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`.
44 | "regexp" : false, // Prohibit `.` and `[^...]` in regular expressions.
45 | "regexdash" : false, // Tolerate unescaped last dash i.e. `[-...]`.
46 | "scripturl" : true, // Tolerate script-targeted URLs.
47 | "shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
48 | "supernew" : false, // Tolerate `new function () { ... };` and `new Object;`.
49 | "undef" : true, // Require all non-global variables be declared before they are used.
50 |
51 | // Personal styling preferences.
52 | "newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`.
53 | "noempty" : true, // Prohibit use of empty blocks.
54 | "nonew" : true, // Prohibit use of constructors for side-effects.
55 | "nomen" : false, // Prohibit use of initial or trailing underbars in names.
56 | "onevar" : false, // Allow only one `var` statement per function.
57 | "plusplus" : false, // Prohibit use of `++` & `--`.
58 | "sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
59 | "trailing" : true, // Prohibit trailing whitespaces.
60 | "white" : true, // Check against strict whitespace and indentation rules.
61 | "indent" : 2 // Specify indentation spacing
62 | }
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 |
3 | node_js:
4 | - "0.8"
5 |
6 | before_script: npm install -g grunt-cli
7 |
8 | script: grunt test --verbose --force
--------------------------------------------------------------------------------
/MIT-LICENSE.txt:
--------------------------------------------------------------------------------
1 | Copyright 2014 David Hudson
2 | http://davidhudson.me/
3 |
4 | Permission is hereby granted, free of charge, to any person obtaining
5 | a copy of this software and associated documentation files (the
6 | "Software"), to deal in the Software without restriction, including
7 | without limitation the rights to use, copy, modify, merge, publish,
8 | distribute, sublicense, and/or sell copies of the Software, and to
9 | permit persons to whom the Software is furnished to do so, subject to
10 | the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be
13 | included in all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # jQuery.getScripts [](https://travis-ci.org/hudsonfoo/jquery-getscripts)
2 |
3 | Load one or multiple JavaScript files from the server using a GET HTTP request, then execute them..
4 |
5 | ## Installation
6 |
7 | This package is available through Bower. From the command-line, run:
8 |
9 | bower install jquery.getscripts
10 |
11 | Include script *after* the jQuery library (unless you are packaging scripts somehow else):
12 |
13 | ```html
14 |
15 | ```
16 |
17 | **Do not include the script directly from GitHub (http://raw.github.com/...).** The file is being served as text/plain and as such being blocked
18 | in Internet Explorer on Windows 7 for instance (because of the wrong MIME type). Bottom line: GitHub is not a CDN.
19 |
20 | The plugin can also be loaded as AMD or CommonJS module.
21 |
22 | ## Usage
23 |
24 | ```html
25 |
35 | ```
36 |
37 | ## Authors
38 |
39 | [David Hudson](https://github.com/hudsonfoo)
--------------------------------------------------------------------------------
/bower.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jquery.getscripts",
3 | "version": "1.0.1",
4 | "keywords": [
5 | "jquery",
6 | "javascript",
7 | "plugin",
8 | "getscripts",
9 | "getscript"
10 | ],
11 | "licenses": [
12 | {
13 | "type": "MIT",
14 | "url": "https://github.com/hudsonfoo/jquery-getscripts/blob/1.0.0/MIT-LICENSE.txt"
15 | }
16 | ],
17 | "main": "dist/jquery-getscripts.min.js",
18 | "ignore": [
19 | "source",
20 | ".bowerrc",
21 | ".gitignore",
22 | ".jshintignore",
23 | "bower.json",
24 | "gruntfile.js",
25 | "package.json",
26 | "README.md"
27 | ],
28 | "dependencies": {
29 | "jquery": ">=1.5"
30 | }
31 | }
--------------------------------------------------------------------------------
/dist/jquery.getscripts.min.js:
--------------------------------------------------------------------------------
1 | /**
2 | * jQuery.getScripts v1.0.1
3 | * https://github.com/hudsonfoo/jquery-getscripts
4 | *
5 | * Load one or multiple JavaScript files from the server using a GET HTTP request, then execute them..
6 | *
7 | * Copyright 2014 David Hudson
8 | *
9 | * Released Under the Following Licenses
10 | * https://github.com/hudsonfoo/jquery-getscripts/blob/1.0.0/MIT-LICENSE.txt
11 | *
12 | * Date: 2014-03-23T21:35:00
13 | */
14 | !function(a){"use strict";a.getScripts||(a.getScripts=function(b){var c,d,e,f;if(c=a.extend({async:!1,cache:!0},b),"string"==typeof c.urls&&(c.urls=[c.urls]),f=[],d=function(){a.ajax({url:c.urls.shift(),dataType:"script",cache:c.cache,success:function(){f.push(arguments),c.urls.length>0?d():"function"==typeof b.success&&b.success(a.merge([],f))}})},e=function(){f.push(arguments),f.length===c.urls.length&&"function"==typeof b.success&&b.success(a.merge([],f))},c.async===!0)for(var g=0;g v<%= pkg.version %>\n' +
27 | '* <%= pkg.homepage %>\n' +
28 | '*\n' +
29 | '* <%= pkg.description %>\n' +
30 | '*\n' +
31 | '* Copyright <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>\n' +
32 | '*\n' +
33 | '* Released Under the Following Licenses\n' +
34 | '* <%= _.pluck(pkg.licenses, "url").join(", ") %>\n' +
35 | '*\n' +
36 | '* Date: <%= grunt.template.date(Date.now(), "isoDateTime") %>\n' +
37 | '*/\n'
38 | },
39 | all: {
40 | files: {
41 | 'dist/jquery.getscripts.min.js': ['source/jquery.getscripts.js'],
42 | }
43 | }
44 | }
45 | });
46 |
47 | grunt.loadNpmTasks('grunt-contrib-jshint');
48 | grunt.loadNpmTasks('grunt-contrib-uglify');
49 | grunt.loadNpmTasks('grunt-contrib-qunit');
50 |
51 | grunt.registerTask('test', ['jshint', 'qunit']);
52 | grunt.registerTask('dist', ['test', 'uglify']);
53 | grunt.registerTask('default', ['dist']);
54 | };
55 |
--------------------------------------------------------------------------------
/jquery.getscripts.jquery.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jquery.getscripts",
3 | "title": "jQuery.getScripts",
4 | "description": "Load one or multiple JavaScript files from the server using a GET HTTP request, then execute them..",
5 | "version": "1.0.1",
6 | "keywords": [
7 | "jquery",
8 | "javascript",
9 | "plugin",
10 | "getscripts",
11 | "getscript"
12 | ],
13 | "author": {
14 | "name": "David Hudson",
15 | "email": "im@davidhudson.me",
16 | "url": "http://davidhudson.me/"
17 | },
18 | "maintainers": [
19 | {
20 | "name": "David Hudson",
21 | "email": "im@davidhudson.me",
22 | "url": "http://davidhudson.me/"
23 | }
24 | ],
25 | "licenses": [
26 | {
27 | "type": "MIT",
28 | "url": "https://github.com/hudsonfoo/jquery-getscripts/blob/1.0.0/MIT-LICENSE.txt"
29 | }
30 | ],
31 | "bugs": "https://github.com/hudsonfoo/jquery-getscripts/issues",
32 | "homepage": "https://github.com/hudsonfoo/jquery-getscripts",
33 | "docs": "https://github.com/hudsonfoo/jquery-getscripts/blob/1.0.0/README.md",
34 | "download": "https://github.com/hudsonfoo/jquery-getscripts",
35 | "repository": {
36 | "type": "git",
37 | "url": "https://github.com/hudsonfoo/jquery-getscripts"
38 | },
39 | "dependencies": {
40 | "jquery": ">=1.5"
41 | }
42 | }
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "jquery.getscripts",
3 | "title": "jQuery.getScripts",
4 | "description": "Load one or multiple JavaScript files from the server using a GET HTTP request, then execute them..",
5 | "version": "1.0.1",
6 | "keywords": [
7 | "jquery",
8 | "javascript",
9 | "plugin",
10 | "getscripts",
11 | "getscript"
12 | ],
13 | "author": {
14 | "name": "David Hudson",
15 | "email": "im@davidhudson.me",
16 | "url": "http://davidhudson.me/"
17 | },
18 | "maintainers": [
19 | {
20 | "name": "David Hudson",
21 | "email": "im@davidhudson.me",
22 | "url": "http://davidhudson.me/"
23 | }
24 | ],
25 | "licenses": [
26 | {
27 | "type": "MIT",
28 | "url": "https://github.com/hudsonfoo/jquery-getscripts/blob/1.0.0/MIT-LICENSE.txt"
29 | }
30 | ],
31 | "bugs": "https://github.com/hudsonfoo/jquery-getscripts/issues",
32 | "homepage": "https://github.com/hudsonfoo/jquery-getscripts",
33 | "docs": "https://github.com/hudsonfoo/jquery-getscripts",
34 | "download": "https://github.com/hudsonfoo/jquery-getscripts",
35 | "repository": {
36 | "type": "git",
37 | "url": "https://github.com/hudsonfoo/jquery-getscripts"
38 | },
39 | "devDependencies": {
40 | "grunt": "~0.4.1",
41 | "grunt-contrib-jshint": "~0.6.0",
42 | "grunt-contrib-uglify": "~0.2.2",
43 | "grunt-contrib-qunit": "~0.4.0"
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/source/jquery.getscripts.js:
--------------------------------------------------------------------------------
1 | (function ($) {
2 | "use strict";
3 |
4 | if ($.getScripts) { return; }
5 |
6 | $.getScripts = function (options) {
7 | var _options, _sync, _async, _response;
8 |
9 | _options = $.extend({
10 | 'async': false,
11 | 'cache': true
12 | }, options);
13 |
14 | if (typeof _options.urls === 'string') {
15 | _options.urls = [_options.urls];
16 | }
17 |
18 | _response = [];
19 |
20 | _sync = function () {
21 | $.ajax({
22 | url: _options.urls.shift(),
23 | dataType: 'script',
24 | cache: _options.cache,
25 | success: function () {
26 | _response.push(arguments);
27 | if (_options.urls.length > 0) {
28 | _sync();
29 | } else if (typeof options.success === 'function') {
30 | options.success($.merge([], _response));
31 | }
32 | }
33 | });
34 | };
35 |
36 | _async = function () {
37 | _response.push(arguments);
38 | if (_response.length === _options.urls.length &&
39 | typeof options.success === 'function') {
40 | options.success($.merge([], _response));
41 | }
42 | };
43 |
44 | if (_options.async === true) {
45 | for (var i = 0; i < _options.urls.length; i++) {
46 | $.ajax({
47 | url: _options.urls[i],
48 | dataType: 'script',
49 | cache: _options.cache,
50 | success: _async
51 | });
52 | }
53 | } else {
54 | _sync();
55 | }
56 | };
57 | }(jQuery));
--------------------------------------------------------------------------------
/tests/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | jQuery.simpleFAQ QUnit Test Runner
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/tests/tests.js:
--------------------------------------------------------------------------------
1 | module("Async");
2 | asyncTest("Remote With Cache", function() {
3 | angular = dojo = Prototype = null;
4 | try {
5 | (function($) {
6 | $.getScripts({
7 | urls: [
8 | 'http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js',
9 | 'http://ajax.googleapis.com/ajax/libs/dojo/1.9.3/dojo/dojo.js',
10 | 'http://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js'
11 | ],
12 | cache: true,
13 | async: false,
14 | success: function(response) {
15 | start();
16 | notEqual(typeof response, 'undefined', 'Response not undefined');
17 | notEqual(typeof angular, 'undefined', "Angular not undefined");
18 | notEqual(typeof dojo, 'undefined', "Dojo not undefined");
19 | notEqual(typeof Prototype, 'undefined', "Prototype not undefined");
20 | }
21 | });
22 | })(jQuery);
23 | } catch(e) {
24 | start();
25 | ok(false, 'General script failure');
26 | }
27 | });
28 |
29 | module("Sync");
30 | asyncTest("Remote With Cache", function() {
31 | angular = dojo = Prototype = null;
32 | try {
33 | (function($) {
34 | $.getScripts({
35 | urls: [
36 | 'http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js',
37 | 'http://ajax.googleapis.com/ajax/libs/dojo/1.9.3/dojo/dojo.js',
38 | 'http://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js'
39 | ],
40 | cache: true,
41 | async: false,
42 | success: function(response) {
43 | start();
44 | notEqual(typeof response, 'undefined', 'Response not undefined');
45 | notEqual(typeof angular, 'undefined', "Angular not undefined");
46 | notEqual(typeof dojo, 'undefined', "Dojo not undefined");
47 | notEqual(typeof Prototype, 'undefined', "Prototype not undefined");
48 | }
49 | });
50 | })(jQuery);
51 | } catch(e) {
52 | start();
53 | ok(false, 'General script failure');
54 | }
55 | });
--------------------------------------------------------------------------------