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