/
page-init.js
80 lines (73 loc) · 2.57 KB
/
page-init.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
try {
// init document events
// prevent default drag
document.addEventListener( 'dragstart', function (event) {
event.preventDefault();
} );
document.addEventListener( 'drop', function (event) {
event.preventDefault();
} );
document.addEventListener( 'dragover', function (event) {
event.preventDefault();
} );
// prevent contextmenu
document.addEventListener( 'contextmenu', function (event) {
event.preventDefault();
event.stopPropagation();
} );
// prevent go back
document.addEventListener( 'keydown', function (event) {
if ( event.keyCode === 8 ) {
if ( event.target === document.body ) {
event.preventDefault();
event.stopPropagation();
}
}
} );
window.onload = function () {
// NOTE: this will prevent mac touchpad scroll the body
document.body.onscroll = function ( event ) {
document.body.scrollLeft = 0;
document.body.scrollTop = 0;
};
};
// DISABLE: I disable this because developer may debug during initialize,
// and when he refresh at that time, the layout will be saved and
// reloaded layout will not be the expected one
// window.onunload = function () {
// if ( Editor && Editor.Panel ) {
// // NOTE: do not use Editor.saveLayout() which will be invoked in requestAnimationFrame.
// // It will not be called in window.onunload
// Editor.sendToCore( 'window:save-layout',
// Editor.Panel.dumpLayout(),
// Editor.requireIpcEvent );
// }
// else {
// Editor.sendToCore( 'window:save-layout',
// null,
// Editor.requireIpcEvent );
// }
// };
window.onerror = function ( message, filename, lineno, colno, error ) {
if ( Editor && Editor.sendToWindows ) {
Editor.sendToWindows('console:error', error.stack || error);
}
else {
console.error(error.stack || error);
}
// Just let default handler run.
return false;
};
}
catch ( error ) {
window.onload = function () {
var Remote = require('remote');
var currentWindow = Remote.getCurrentWindow();
currentWindow.setSize(800, 600);
currentWindow.center();
currentWindow.show();
currentWindow.openDevTools();
console.error(error.stack || error);
};
}