Rev 17770 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 17770 | Rev 17773 | ||
---|---|---|---|
Line 43... | Line 43... | ||
43 | {top: top+"px", left: left+"px"}); |
43 | {top: top+"px", left: left+"px"}); |
44 | } |
44 | } |
45 | }(jQuery("#one_element"))); |
45 | }(jQuery("#one_element"))); |
46 | }); |
46 | }); |
47 | jQuery("#wait").fadeOut(); |
47 | jQuery("#wait").fadeOut(); |
48 | } |
- | |
49 | - | ||
50 | /** |
- | |
51 | * imports jQuery (JS), jQuery-UI (JS and CSS) |
- | |
52 | * parametes url1 .. url3 are for jquery.js, jquery-ui.js, jquery-ui.css |
- | |
53 | **/ |
- | |
54 | function importScript(url1, url2, url3){ |
- | |
55 | var script1, script2, link; |
- | |
56 | script1 = document.createElement('script'); |
- | |
57 | script1.src = url1; |
- | |
58 | document.head.appendChild(script1); |
- | |
59 | script2 = document.createElement('script'); |
- | |
60 | script2.src = url2; |
- | |
61 | document.head.appendChild(script2); |
- | |
62 | link = document.createElement('link'); |
- | |
63 | link.rel = "stylesheet"; |
- | |
64 | link.type = "text/css"; |
- | |
65 | link.href = url3; |
- | |
66 | document.head.appendChild(link); |
- | |
67 | } |
48 | } |
68 | 49 | ||
69 | function jQueryIsHere(){ |
50 | function jQueryIsHere(){ |
70 | result = true; |
51 | result = true; |
71 | try { |
52 | try { |
72 | if (! jQuery) result = false; |
53 | if (! jQuery) result = false; |
73 | } |
54 | } |
74 | catch(e) { |
55 | catch(e) { |
75 | if(e.name == "ReferenceError") { |
56 | if(e.name == "ReferenceError") { |
76 | result = false; |
57 | result = false; |
77 | } |
58 | } |
78 | } |
59 | } |
79 | return result |
60 | return result |
- | 61 | } |
|
- | 62 | ||
- | 63 | function scriptLoader(scriptUrl){ |
|
- | 64 | /* copied from https://stackoverflow.com/questions/538745/how-to-tell-if-a-script-tag-failed-to-load */ |
|
- | 65 | return new Promise(function (res, rej) { |
|
- | 66 | let script = document.createElement('script'); |
|
- | 67 | script.src = scriptUrl; |
|
- | 68 | script.type = 'text/javascript'; |
|
- | 69 | script.onerror = rej; |
|
- | 70 | script.async = true; |
|
- | 71 | script.onload = res; |
|
- | 72 | script.addEventListener('error',rej); |
|
- | 73 | script.addEventListener('load',res); |
|
- | 74 | document.head.appendChild(script); |
|
- | 75 | }) |
|
- | 76 | } |
|
- | 77 | ||
- | 78 | function cssLoader(cssUrl){ |
|
- | 79 | return new Promise(function (res, rej) { |
|
- | 80 | let link = document.createElement('link'); |
|
- | 81 | link.href = cssUrl; |
|
- | 82 | link.rel = 'stylesheet'; |
|
- | 83 | link.type = 'text/css'; |
|
- | 84 | link.onerror = rej; |
|
- | 85 | link.async = true; |
|
- | 86 | link.onload = res; |
|
- | 87 | link.addEventListener('error',rej); |
|
- | 88 | link.addEventListener('load',res); |
|
- | 89 | document.head.appendChild(link); |
|
- | 90 | }) |
|
80 | } |
91 | } |
81 | 92 | ||
82 | function tryLocal(){ |
93 | function tryLocal(){ |
83 |
|
94 | return Promise.all([ |
84 | "http://localhost/javascript/jquery/jquery.js", |
95 | scriptLoader("http://localhost/javascript/jquery/jquery.js"), |
85 | "http://localhost/javascript/jquery-ui/jquery-ui.js", |
96 | scriptLoader("http://localhost/javascript/jquery-ui/jquery-ui.js"), |
86 | "http://localhost/javascript/jquery-ui/css/smoothness/jquery-ui.css" |
97 | cssLoader("http://localhost/javascript/jquery-ui/css/smoothness/jquery-ui.css")]); |
87 | ); |
- | |
88 | } |
98 | } |
89 | 99 | ||
90 | function tryRemote(){ |
100 | function tryRemote(){ |
91 |
|
101 | return Promise.all([ |
92 | "https://code.jquery.com/jquery-1.11.3.js", |
102 | scriptLoader("https://code.jquery.com/jquery-1.11.3.js"), |
93 | "https://code.jquery.com/ui/1.13.2/jquery-ui.js", |
103 | scriptLoader("https://code.jquery.com/ui/1.13.2/jquery-ui.js"), |
94 | "https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css" |
104 | cssLoader("https://code.jquery.com/ui/1.13.2/themes/base/jquery-ui.css") |
95 | ); |
105 | ]); |
96 | - | ||
97 | } |
106 | } |
98 | 107 | ||
99 | window.onload = function(){ |
108 | window.onload = function(){ |
100 |
|
109 | let p1 = new Promise((res, rej) => { |
101 | if ( |
110 | if (jQueryIsHere()) res("jQuery found immediately"); |
- | 111 | else rej("no jQuery immediately") |
|
102 | } |
112 | }) |
- | 113 | .then((msg) => { |
|
- | 114 | console.log(msg); |
|
103 |
|
115 | add_interaction(); |
- | 116 | }) |
|
104 |
|
117 | .catch((msg) =>{ |
105 |
|
118 | console.log(msg); |
106 |
|
119 | tryLocal().then((values) => { |
- | 120 | console.log(values, "local scripts and css files not found"); |
|
107 | add_interaction(); |
121 | add_interaction(); |
- | 122 | }).catch((reason) => { |
|
- | 123 | console.log(reason); |
|
- | 124 | tryRemote().then((values) => { |
|
- | 125 | console.log(values); |
|
- | 126 | add_interaction(); |
|
- | 127 | }).catch((reason) => { |
|
- | 128 | console.log(reason, "remote scripts and css files not found"); |
|
- | 129 | }); |
|
108 | } |
130 | }); |
- | 131 | }) |
|
109 | }; |
132 | }; |