2 * JavaScript for loading more JavaScripts with AJAX
3 * --------------------------------------------------------------------
4 * Copyright (c) 2003 - 2009 by Roland Haeder
5 * Copyright (c) 2009 - 2016 by Mailer Developer Team
6 * For more information visit: http://mxchange.org
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
24 // Loaded scripts counter
25 var resourceCounter = 0;
27 // This array holds a copy of resources which shall be loaded
28 var loadResources = new Array();
30 // Waiting for resources being loaded
31 function loadScriptsLocked () {
32 // Has all been loaded?
33 if (resourceCounter == loadResources.length) {
34 // Then release ready()
37 // Recursive call again
38 window.setTimeout('loadScriptsLocked()', 100);
42 // Loads more JavaScript resources
43 function loadScripts (resources) {
44 // Abort here if resources is not defined
45 if (resources == undefined) {
46 // This is really bad ...
47 throw new 'loadScripts() called with no resources (JavaScript files) to load!';
50 // Make ready() as holded
53 // Transfer all resources to global array
54 loadResources = resources;
56 // Begin the loop for all JavaScript files
57 for (var i = 0; i < resources.length; i++) {
59 if (resources[i] == undefined) {
60 // Array element is missing, which means someone mades a boo boo ...
61 throw new ('resources[' + i + '] not set. Please fix your array.');
65 $.getScript(resources[i], function (data, textStatus) {
66 // Did something bad happen?
67 if (textStatus != 'success') {
68 // Throw an exception here
69 throw new 'Cannot load script ' + resources[i] + ' with status ' + textStatus + '!';
80 // Wait until all scripts are loaded (asynchronously)