1 | /*
|
---|
2 | * Copyright 2014 Google Inc.
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
---|
5 | * use this file except in compliance with the License. You may obtain a copy of
|
---|
6 | * the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
---|
12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
---|
13 | * License for the specific language governing permissions and limitations under
|
---|
14 | * the License.
|
---|
15 | */
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * This startup script is used when we run superdevmode from an app server.
|
---|
19 | */
|
---|
20 | (function($wnd, $doc){
|
---|
21 | // document.head does not exist in IE8
|
---|
22 | var $head = $doc.head || $doc.getElementsByTagName('head')[0];
|
---|
23 | // Compute some codeserver urls so as the user does not need bookmarklets
|
---|
24 | var hostName = $wnd.location.hostname;
|
---|
25 | var serverUrl = 'http://' + hostName + ':9876';
|
---|
26 | var module = 'testelementalsockets';
|
---|
27 | var nocacheUrl = serverUrl + '/recompile-requester/' + module;
|
---|
28 |
|
---|
29 | // Insert the superdevmode nocache script in the first position of the head
|
---|
30 | var devModeScript = $doc.createElement('script');
|
---|
31 | devModeScript.src = nocacheUrl;
|
---|
32 |
|
---|
33 | // Everybody except IE8 does fire an error event
|
---|
34 | // This means that we do not detect a non running SDM with IE8.
|
---|
35 | if (devModeScript.addEventListener) {
|
---|
36 | var callback = function() {
|
---|
37 | // Don't show the confirmation dialogue twice (multimodule)
|
---|
38 | if (!$wnd.__gwt__sdm__confirmed &&
|
---|
39 | (!$wnd.__gwt_sdm__recompiler || !$wnd.__gwt_sdm__recompiler.loaded)) {
|
---|
40 | $wnd.__gwt__sdm__confirmed = true;
|
---|
41 | if ($wnd.confirm(
|
---|
42 | "Couldn't load " + module + " from Super Dev Mode\n" +
|
---|
43 | "server at " + serverUrl + ".\n" +
|
---|
44 | "Please make sure this server is ready.\n" +
|
---|
45 | "Do you want to try again?")) {
|
---|
46 | $wnd.location.reload();
|
---|
47 | }
|
---|
48 | }
|
---|
49 | };
|
---|
50 | devModeScript.addEventListener("error", callback, true);
|
---|
51 | }
|
---|
52 |
|
---|
53 | var injectScriptTag = function(){
|
---|
54 | $head.insertBefore(devModeScript, $head.firstElementChild || $head.children[0]);
|
---|
55 | };
|
---|
56 |
|
---|
57 | if (/loaded|complete/.test($doc.readyState)) {
|
---|
58 | injectScriptTag();
|
---|
59 | } else {
|
---|
60 | //defer app script insertion until the body is ready
|
---|
61 | if($wnd.addEventListener){
|
---|
62 | $wnd.addEventListener('load', injectScriptTag, false);
|
---|
63 | } else{
|
---|
64 | $wnd.attachEvent('onload', injectScriptTag);
|
---|
65 | }
|
---|
66 | }
|
---|
67 | })(window, document);
|
---|