Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / bootstrap.js
1 /**
2  * Load the library located at the same path with this file
3  *
4  * Will automatically load ext-all-debug.js if any of these conditions is true:
5  * - Current hostname is localhost
6  * - Current hostname is an IP v4 address
7  * - Current protocol is "file:"
8  *
9  * Will load ext-all.js (minified) otherwise
10  */
11 (function() {
12
13     var scripts = document.getElementsByTagName('script'),
14         localhostTests = [
15             /^localhost$/,
16             /\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(:\d{1,5})?\b/ // IP v4
17         ],
18         host = window.location.hostname,
19         isDevelopment = null,
20         queryString = window.location.search,
21         test, path, i, ln, scriptSrc, match;
22
23     for (i = 0, ln = scripts.length; i < ln; i++) {
24         scriptSrc = scripts[i].src;
25
26         match = scriptSrc.match(/bootstrap\.js$/);
27
28         if (match) {
29             path = scriptSrc.substring(0, scriptSrc.length - match[0].length);
30             break;
31         }
32     }
33
34     if (queryString.match('(\\?|&)debug') !== null) {
35         isDevelopment = true;
36     }
37     else if (queryString.match('(\\?|&)nodebug') !== null) {
38         isDevelopment = false;
39     }
40
41     if (isDevelopment === null) {
42         for (i = 0, ln = localhostTests.length; i < ln; i++) {
43             test = localhostTests[i];
44
45             if (host.search(test) !== -1) {
46                 isDevelopment = true;
47                 break;
48             }
49         }
50     }
51
52     if (isDevelopment === null && window.location.protocol === 'file:') {
53         isDevelopment = true;
54     }
55
56     document.write('<script type="text/javascript" src="' + path + 'ext-all' + ((isDevelopment) ? '-debug' : '') + '.js"></script>');
57
58 })();