Skip to content

Commit 83c45ef

Browse files
committed
enable shortcuts in sandbox
1 parent 4446710 commit 83c45ef

File tree

4 files changed

+43
-35
lines changed

4 files changed

+43
-35
lines changed

rss_content.html

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<head>
44
<meta charset="utf-8">
55
<base href="about:blank" target="_blank" />
6+
<meta http-equiv="Content-Security-Policy" content="script-src 'self'; object-src 'self'; frame-src 'none';">
67
<style>
78
html { font-size: 100% }
89
body { padding: 20px 30px; margin: 0; font-family: Arial; font-size: 0.9rem; line-height: 1.5; word-wrap: break-word; }

scripts/app/app.js

+33-33
Original file line numberDiff line numberDiff line change
@@ -135,52 +135,52 @@ function (comm, Layout, $, doc, Actions, FeedsLayout, ArticlesLayout, ContentLay
135135
report: function() {
136136
var report = new ReportView();
137137
document.body.appendChild(report.render().el);
138-
}
139-
}));
140-
141-
// Prevent context-menu when alt is pressed
142-
document.addEventListener('keyup', function(e) {
143-
if (e.keyCode == 18) {
144-
e.preventDefault();
145-
}
146-
});
147-
138+
},
139+
handleKeyDown: function(e) {
140+
var ac = document.activeElement;
141+
if (ac && (ac.tagName == 'INPUT' || ac.tagName == 'TEXTAREA')) {
142+
return;
143+
}
148144

149-
document.addEventListener('keydown', function(e) {
150-
var ac = document.activeElement
151-
if (ac && (ac.tagName == 'INPUT' || ac.tagName == 'TEXTAREA')) {
152-
return;
153-
}
145+
var str = '';
146+
if (e.ctrlKey) str += 'ctrl+';
147+
if (e.shiftKey) str += 'shift+';
154148

155-
var str = '';
156-
if (e.ctrlKey) str += 'ctrl+';
157-
if (e.shiftKey) str += 'shift+';
149+
if (e.keyCode > 46 && e.keyCode < 91) {
150+
str += String.fromCharCode(e.keyCode).toLowerCase();
151+
} else if (e.keyCode in shortcuts.keys) {
152+
str += shortcuts.keys[e.keyCode];
153+
} else {
154+
return;
155+
}
158156

159-
if (e.keyCode > 46 && e.keyCode < 91) {
160-
str += String.fromCharCode(e.keyCode).toLowerCase();
161-
} else if (e.keyCode in shortcuts.keys) {
162-
str += shortcuts.keys[e.keyCode];
163-
} else {
164-
return;
165-
}
157+
var focus = document.activeElement.getAttribute('name');
166158

167-
var focus = document.activeElement.getAttribute('name');
159+
if (focus && focus in shortcuts) {
160+
if (str in shortcuts[focus]) {
161+
app.actions.execute( shortcuts[focus][str], e);
162+
e.preventDefault();
163+
return;
164+
}
165+
}
168166

169-
if (focus && focus in shortcuts) {
170-
if (str in shortcuts[focus]) {
171-
app.actions.execute( shortcuts[focus][str], e);
167+
if (str in shortcuts.global) {
168+
app.actions.execute( shortcuts.global[str], e);
172169
e.preventDefault();
173-
return;
174170
}
175171
}
172+
}));
176173

177-
if (str in shortcuts.global) {
178-
app.actions.execute( shortcuts.global[str], e);
174+
// Prevent context-menu when alt is pressed
175+
document.addEventListener('keyup', function(e) {
176+
if (e.keyCode == 18) {
179177
e.preventDefault();
180178
}
181-
182179
});
183180

184181

182+
document.addEventListener('keydown', app.handleKeyDown);
183+
184+
185185
return app;
186186
});

scripts/app/staticdb/shortcuts.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@ define({
6969
'home': 'content:scrollToTop',
7070
'del': 'content:delete',
7171
'd': 'content:delete',
72-
'r': 'content:mark'
72+
'k': 'content:mark'
73+
},
74+
sandbox: {
75+
'del': 'content:delete',
76+
'd': 'content:delete',
77+
'k': 'content:mark'
7378
},
7479
keys: {
7580
8: 'backspace',

scripts/app/views/SandboxView.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ define(['backbone', 'modules/Locale'], function(BB, Locale) {
77
},
88
initialize: function() {
99
this.$el.attr('src', 'rss_content.html');
10-
this.$el.attr('sandbox', 'allow-popups allow-same-origin');
10+
this.$el.attr('name', 'sandbox');
11+
/*this.$el.attr('sandbox', 'allow-popups allow-same-origin');*/
1112
this.$el.attr('frameborder', 0);
1213
this.$el.attr('tabindex', -1);
1314
},
@@ -17,6 +18,7 @@ define(['backbone', 'modules/Locale'], function(BB, Locale) {
1718
handleLoad: function() {
1819
this.loaded = true;
1920
this.el.contentDocument.querySelector('#smart-rss-url').innerHTML = Locale.c.FULL_ARTICLE;
21+
this.el.contentDocument.addEventListener('keydown', app.handleKeyDown);
2022
this.trigger('load');
2123
}
2224
});

0 commit comments

Comments
 (0)