source: Dev/trunk/src/client/dijit/tests/_loadTest.js @ 483

Last change on this file since 483 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 3.4 KB
Line 
1(function(){
2var file;
3var head = document.documentElement.firstChild;
4while(head && head.tagName != "HEAD"){
5        head = head.nextSibling;
6}
7var script = head.lastChild;
8while(script){
9        if(script.tagName == "SCRIPT"){
10                if((script.getAttribute('src')||'').search('_loadTest') >= 0 && (!script.readyState || script.readyState == "interactive")){
11                        file = script.getAttribute('file');
12                        break;
13                }
14        }
15        script = script.previousSibling;
16}
17if(!file && window.location.href.search(/[?&]file[=]/i) > 0){
18        file = window.location.href.replace(/.*[?&]file=(([^&?]*)).*/i, "$2");
19}
20var readFile = function(file){
21        var xhr = null;
22        try{
23                xhr = new XMLHttpRequest();
24        }catch(e0){
25                try{
26                        xhr = new ActiveXObject('Msxml2.XMLHTTP');
27                }catch(e1){
28                        try{
29                                xhr = new ActiveXObject('Microsoft.XMLHTTP');
30                        }catch(e2){
31                                try{
32                                        xhr = new ActiveXObject('Msxml2.XMLHTTP.4.0');
33                                }catch(e3){
34                                }
35                        }
36                }
37        }
38        try{
39                xhr.open("GET", file, false);
40                xhr.send(null);
41        }catch(e){
42                return null
43        } // file not found
44        return xhr.responseText;
45};
46var text = readFile(file) || (file + " not found");
47var baseHref = file.replace(/^(.*\/)?[^\/]+$/, "$1");
48if(baseHref){
49        baseHref = window.location.href.replace(/[?].*/, "").replace(/[^\/]*$/, "")+baseHref;
50        text = text.replace(/(<HEAD\b([^>]|\s)*>)/i, "$1" + "<BASE href='" + baseHref + "'><\/BASE>");
51}
52// strip DOCTYPE and HTML tag
53text = text.replace(/^(.|\s)*?<html\b(([^>]|\s)*)>((.|\s)*)/i,
54        function(s,a1,htmlAttrs,a3,content){
55                // add attributes from target file's HTML tag - may not be necessary but we'll do it anyway for completeness
56                htmlAttrs = htmlAttrs.replace(/((\w+)\s*=\s*(['"]?)(.*?)(\3)?(\s+|$))/g,
57                        function(s, all, attr, quote, val){
58                                document.documentElement.setAttribute(attr, val);
59                                return "";
60                        });
61                return content.replace(/<\/html\b([^>]|\s)*>(.|\s)*?$/i, "");
62        });
63if(/MSIE/.test(navigator.userAgent)){ // need to load scripts serially
64        document._oldgetElementsByTagName_ = document.getElementsByTagName;
65        document.getElementsByTagName = function(tag){
66                // take over getElementsByTagName so I can take over script.getAttribute('src')
67                if(/^script$/i.test(tag)){
68                        var scripts = document.scripts;
69                        for(var i=0; i <scripts.length; i++){
70                                (function(script){
71                                        if(!('_oldGetAttribute' in script)){
72                                                var src = script.getAttribute('_oldsrc');
73                                                if(src){
74                                                        script._oldGetAttribute = script.getAttribute;
75                                                        script.getAttribute = function(attr){ return /^src$/i.test(attr) ? src : script._oldGetAttribute(attr); };
76                                                }
77                                        }
78                                }).call(this, scripts[i]);
79                        }
80                        return scripts;
81                }
82                return document._oldgetElementsByTagName_(tag);
83        };
84        document._oldwrite_ = document.write;
85        document.write = function(text){
86                text = text.replace(/<[!][-][-](.|\s){5,}?[-][-]>/g, "<!--?-->" // shorten long comments that may contain script tags
87                        ).replace(/(<script\s[^>]*)\bsrc\s*=\s*([^>]*>)/ig,
88                function(s,pre,post){
89                        if(s.search(/\sdefer\b/i) > 0){ return s; }
90                        //if(s.search(/\bxpopup.js\b/i) > 0){ return pre+">"; } // firewall popup blocker:  uncomment if you get out of stack space message
91                        var file = post.substr(0, post.search(/\s|>/)).replace(/['"]/g, "");
92                        var scriptText = readFile(baseHref+file);
93                        if(!scriptText){
94                                scriptText = readFile(file);
95                                if(!scriptText){ return s; }
96                        }
97                        return pre + "  _oldsrc=" + post + "eval(unescape('"+escape(scriptText)+"'))";
98                });
99                document._oldwrite_(text);
100        };
101}
102document.write(text);
103})();
Note: See TracBrowser for help on using the repository browser.