Added update_year.sh (still not fully flexible) and updated all years with it.
[mailer.git] / js / ajax-loader.js
1 /**
2  * JavaScript for loading more JavaScripts with AJAX
3  * --------------------------------------------------------------------
4  * Copyright (c) 2003 - 2009 by Roland Haeder
5  * Copyright (c) 2009 - 2015 by Mailer Developer Team
6  * For more information visit: http://mxchange.org
7  *
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.
12  *
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.
17  *
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,
21  * MA  02110-1301  USA
22  */
23
24 // Loaded scripts counter
25 var resourceCounter = 0;
26
27 // This array holds a copy of resources which shall be loaded
28 var loadResources = new Array();
29
30 // Waiting for resources being loaded
31 function loadScriptsLocked () {
32         // Has all been loaded?
33         if (resourceCounter == loadResources.length) {
34                 // Then release ready()
35                 $.holdReady(false);
36         } else {
37                 // Recursive call again
38                 window.setTimeout('loadScriptsLocked()', 100);
39         }
40 }
41
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!';
48         } // END - if
49
50         // Make ready() as holded
51         $.holdReady(true);
52
53         // Transfer all resources to global array
54         loadResources = resources;
55
56         // Begin the loop for all JavaScript files
57         for (var i = 0; i < resources.length; i++) {
58                 // Is the script set?
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.');
62                 } // END - if
63
64                 // Load next script
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 + '!';
70                         } // END - if
71
72                         // Count it as loaded
73                         resourceCounter++;
74                 });
75
76                 // Wait here a little
77                 $('body').delay(100);
78         } // END - for
79
80         // Wait until all scripts are loaded (asynchronously)
81         loadScriptsLocked();
82
83         // All loaded
84         return true;
85 }