Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit f5978ec

Browse files
committed
Merge pull request #4374 from maks/no-inline-js
move inline js into external files
2 parents 6db6014 + c0a46b6 commit f5978ec

3 files changed

Lines changed: 129 additions & 80 deletions

File tree

src/dependencies.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*
22+
*/
23+
24+
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50, evil:true */
25+
/*global window, document:true, CollectionUtils:true */
26+
27+
window.setTimeout(function () {
28+
"use strict";
29+
var deps = { "Mustache": window.Mustache, "jQuery": window.$, "CodeMirror": window.CodeMirror, "RequireJS": window.require };
30+
var key, missingDeps = [];
31+
for (key in deps) {
32+
if (deps.hasOwnProperty(key) && !deps[key]) {
33+
missingDeps.push(key);
34+
}
35+
}
36+
if (missingDeps.length === 0) {
37+
return;
38+
}
39+
document.write("<h1>Missing libraries</h1>");
40+
document.write("<p>Oops! One or more required libraries could not be found.</p>");
41+
document.write("<ul>");
42+
missingDeps.forEach(function (key) {
43+
document.write("<li>" + key + "</li>");
44+
});
45+
46+
document.write("</ul>");
47+
document.write("<p>If you're running from a local copy of the Brackets source, please make sure submodules are updated by running:</p>");
48+
document.write("<pre>git submodule update --init</pre>");
49+
document.write("<p>If you're still having problems, please contact us via one of the channels mentioned at the bottom of the <a target=\"blank\" href=\"../README.md\">README</a>.</p>");
50+
document.write("<p><a href=\"#\" onclick=\"window.location.reload()\">Reload Brackets</a></p>");
51+
}, 1000);

src/index.html

Lines changed: 4 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -33,59 +33,10 @@
3333
nonstandard WebKit-specific syntax. -->
3434
<link rel="stylesheet" href="styles/quiet-scrollbars.css">
3535

36-
<!-- Warn about failed cross origin requests in Chrome -->
37-
<script type="application/javascript">
38-
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
39-
/*global brackets: true */
40-
(function () {
41-
"use strict";
42-
43-
// Function to test whether a given error represents an illegal cross origin access
44-
var testCrossOriginError;
45-
46-
if (navigator.userAgent.search(" Chrome/") !== -1) {
47-
// Chrome support
48-
testCrossOriginError = function (message, url, line) {
49-
return url === "" && line === 0 && message === "Script error.";
50-
};
51-
} else if (navigator.userAgent.slice(0, 6) === 'Opera/') {
52-
// Opera support
53-
testCrossOriginError = function (message, url, line) {
54-
return message === "Uncaught exception: DOMException: NETWORK_ERR";
55-
};
56-
}
57-
58-
// Abort if running in the shell, running on a server or not running in a supported and affected browser
59-
if (typeof (brackets) !== "undefined"
60-
|| document.location.href.substr(0, 7) !== "file://"
61-
|| !testCrossOriginError) {
62-
return;
63-
}
64-
65-
// Remember the current error handler to restore it once we're done
66-
var previousErrorHandler = window.onerror;
67-
68-
// Our error handler
69-
function handleError(message, url, line) {
70-
// Ignore this error if it does not look like the rather vague cross origin error in Chrome
71-
// Chrome will print it to the console anyway
72-
if (!testCrossOriginError(message, url, line)) {
73-
if (previousErrorHandler) {
74-
return previousErrorHandler(message, url, line);
75-
}
76-
return;
77-
}
78-
79-
// Show an error message
80-
alert("Oops! This application doesn't run in browsers yet.\n\nIt is built in HTML, but right now it runs as a desktop app so you can use it to edit local files. Please use the application shell in the following repo to run this application:\n\ngithub.com/adobe/brackets-shell");
81-
82-
// Restore the original handler for later errors
83-
window.onerror = previousErrorHandler;
84-
}
36+
<!-- NOTE: All scripts must be external for Chrome App support: http://developer.chrome.com/apps/app_csp.html -->
8537

86-
// Install our error handler
87-
window.onerror = handleError;
88-
}());
38+
<!-- Warn about failed cross origin requests in Chrome -->
39+
<script type="application/javascript" src="xorigin.js">
8940
</script>
9041

9142
<!-- TODO (Issue #278): switch between runtime LESS compilation in dev mode and precompiled version -->
@@ -120,34 +71,7 @@
12071
<script src="thirdparty/requirejs/require.js" data-main="brackets"></script>
12172

12273
<!-- Verify that all dependencies are loaded. -->
123-
<script>
124-
window.setTimeout(function () {
125-
var deps = { "Mustache": window.Mustache, "jQuery": window.$, "CodeMirror": window.CodeMirror, "RequireJS": window.require };
126-
var key, allOK = true;
127-
for (key in deps) {
128-
if (!deps[key]) {
129-
allOK = false;
130-
break;
131-
}
132-
}
133-
if (allOK) {
134-
return;
135-
}
136-
document.write("<h1>Missing libraries</h1>");
137-
document.write("<p>Oops! One or more required libraries could not be found.</p>");
138-
document.write("<ul>");
139-
for (key in deps) {
140-
if (!deps[key]) {
141-
document.write("<li>" + key + "</li>");
142-
}
143-
}
144-
document.write("</ul>");
145-
document.write("<p>If you're running from a local copy of the Brackets source, please make sure submodules are updated by running:</p>");
146-
document.write("<pre>git submodule update --init</pre>");
147-
document.write("<p>If you're still having problems, please contact us via one of the channels mentioned at the bottom of the <a target=\"blank\" href=\"../README.md\">README</a>.</p>");
148-
document.write("<p><a href=\"#\" onclick=\"window.location.reload()\">Reload Brackets</a></p>");
149-
}, 1000);
150-
</script>
74+
<script src="dependencies.js"></script>
15175

15276
</body>
15377
</html>

src/xorigin.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*
22+
*/
23+
24+
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
25+
/*global brackets: true, navigator:true, document:true, window:true */
26+
(function () {
27+
"use strict";
28+
29+
// Function to test whether a given error represents an illegal cross origin access
30+
var testCrossOriginError;
31+
32+
if (navigator.userAgent.search(" Chrome/") !== -1) {
33+
// Chrome support
34+
testCrossOriginError = function (message, url, line) {
35+
return url === "" && line === 0 && message === "Script error.";
36+
};
37+
} else if (navigator.userAgent.slice(0, 6) === 'Opera/') {
38+
// Opera support
39+
testCrossOriginError = function (message, url, line) {
40+
return message === "Uncaught exception: DOMException: NETWORK_ERR";
41+
};
42+
}
43+
44+
// Abort if running in the shell, running on a server or not running in a supported and affected browser
45+
if (typeof (brackets) !== "undefined" ||
46+
document.location.href.substr(0, 7) !== "file://" ||
47+
!testCrossOriginError) {
48+
return;
49+
}
50+
51+
// Remember the current error handler to restore it once we're done
52+
var previousErrorHandler = window.onerror;
53+
54+
// Our error handler
55+
function handleError(message, url, line) {
56+
// Ignore this error if it does not look like the rather vague cross origin error in Chrome
57+
// Chrome will print it to the console anyway
58+
if (!testCrossOriginError(message, url, line)) {
59+
if (previousErrorHandler) {
60+
return previousErrorHandler(message, url, line);
61+
}
62+
return;
63+
}
64+
65+
// Show an error message
66+
alert("Oops! This application doesn't run in browsers yet.\n\nIt is built in HTML, but right now it runs as a desktop app so you can use it to edit local files. Please use the application shell in the following repo to run this application:\n\ngithub.com/adobe/brackets-shell");
67+
68+
// Restore the original handler for later errors
69+
window.onerror = previousErrorHandler;
70+
}
71+
72+
// Install our error handler
73+
window.onerror = handleError;
74+
}());

0 commit comments

Comments
 (0)