Skip to content

Commit 64f6fa8

Browse files
committed
v0.2.3 updated. Hoykey system is added.
1 parent faeacc5 commit 64f6fa8

File tree

5 files changed

+181
-19
lines changed

5 files changed

+181
-19
lines changed

bbs_UI.js

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,11 @@ function UI_register_func(){
110110
$(this).fadeOut();
111111
});
112112

113-
$('#reply-post-button').live('click', function(){
113+
$('.reply-post-button').live('click', function(){
114114
postPrepare(bbs_type.write_post.reply, UI_prepare_getQuote);
115115
});
116116

117-
$('#new-post-normal').live('click', function(){
117+
$('.new-post-normal').live('click', function(){
118118
postPrepare(bbs_type.write_post.new, UI_prepare_post_modal);
119119
});
120120

@@ -123,6 +123,7 @@ function UI_register_func(){
123123
$('#write-post-panel .cancel-button').live('click', function(){
124124
if (confirm('确定舍弃当前未发布文章吗?')) {
125125
$('#write-post-panel').modal('hide');
126+
bbs_topmost_stack.pop();
126127
}
127128
});
128129

@@ -188,6 +189,7 @@ function UI_prepare_post_modal(){
188189
show: false
189190
});
190191
$('#write-post-panel').modal('toggle');
192+
bbs_topmost_stack.push('#write-post-panel');
191193
}
192194

193195
function UI_write_post(){
@@ -208,7 +210,10 @@ function UI_write_post(){
208210
}
209211
var type = $('#write-post-panel').attr('post-type');
210212

213+
$('#write-post-panel').modal('hide');
214+
bbs_topmost_stack.pop();
211215
UI_show_backdrop();
216+
212217
writePost(type, title, content, qmd_num, anony, UI_update);
213218
}
214219

@@ -237,6 +242,8 @@ function UI_init() {
237242
title: '矮油',
238243
content: '此功能尚未实现,我们将在后续版本中添加,敬请谅解。'
239244
});
245+
246+
bbs_topmost_stack.splice(0);
240247
}
241248

242249
function UI_login_finished(result){
@@ -256,6 +263,7 @@ function UI_login_finished(result){
256263

257264
function UI_logout(){
258265
removeSessionCookie();
266+
bbs_topmost_stack.splice(0);
259267
$('#unlogged-navbar').show();
260268
$('#unlogged-panel').show();
261269
$('#logged-navbar').hide();
@@ -329,6 +337,7 @@ function UI_maindiv_update(pathTerm) {
329337
$('#boardlist-table').hide();
330338
$('#board-table').hide();
331339
$('#post-view').hide();
340+
bbs_topmost_stack.splice(0);
332341
if (pathTerm.type == bbs_type.path.allboard ||
333342
pathTerm.type == bbs_type.path.favboard ||
334343
pathTerm.type == bbs_type.path.folder) {
@@ -338,6 +347,7 @@ function UI_maindiv_update(pathTerm) {
338347
$('#boardlist-table-body').append(entryStr);
339348
}
340349
$('#boardlist-table').show();
350+
bbs_topmost_stack.push('#boardlist-table');
341351
} else if (pathTerm.type == bbs_type.path.board) {
342352
$('#board-table-body').empty();
343353
for (var i = 0; i < pathTerm.data.length; ++i) {
@@ -355,10 +365,12 @@ function UI_maindiv_update(pathTerm) {
355365
}
356366

357367
$('#board-table').show();
368+
bbs_topmost_stack.push('#board-table');
358369
} else if (pathTerm.type == bbs_type.path.post) {
359370
$('#post-view-area').empty();
360371
$('#post-view-area').html(pathTerm.data.content);
361372
$('#post-view').show();
373+
bbs_topmost_stack.push('#post-view');
362374
}
363375
}
364376

@@ -413,4 +425,54 @@ function UI_generate_post_entry(entry){
413425
+ '<td>' + entry.title + '</td>'
414426
+ '</tr>';
415427
return entryStr;
428+
}
429+
430+
431+
function UI_register_hotkeys(){
432+
//Ctrl + Enter(13) on #write-post-panel: Publish post;
433+
var publishPostHotkey = new Hotkey(13, true, false,
434+
'#write-post-panel', '#publish-post-button', 'click');
435+
436+
//Esc(27) on #write-post-panel: Cancel posting;
437+
var cancelPostHotkey = new Hotkey(27, false, false,
438+
'#write-post-panel', '#cancel-post-button', 'click');
439+
440+
//Left(37) and Right(39) on #post-view: next post and prev post;
441+
var prevPostHotkey = new Hotkey(37, false, false,
442+
'#post-view', '.prev-post-button', 'click');
443+
var nextPostHotkey = new Hotkey(39, false, false,
444+
'#post-view', '.next-post-button', 'click');
445+
446+
//Ctrl + Left/Right on #post-view: Same topic next/prev post;
447+
var SpPrevPostHotkey = new Hotkey(37, true, false,
448+
'#post-view', '.st-prev-button', 'click');
449+
var SpNextPostHotkey = new Hotkey(39, true, false,
450+
'#post-view', '.st-next-button', 'click');
451+
452+
//Left and Right on #board-table: next and prev page of posts;
453+
var prevPageHotkey = new Hotkey(37, false, false,
454+
'#board-table', '.prev-page-button', 'click');
455+
var nextPageHotkey = new Hotkey(39, false, false,
456+
'#board-table', '.next-page-button', 'click');
457+
458+
//r on #post-view: reply in normal mode;
459+
var replyHotkey = new Hotkey(82, false, false,
460+
'#post-view', '.reply-post-button[type=S]', 'click');
461+
462+
//p on #board-table: write a new post in normal mode;
463+
var writePostHotkey = new Hotkey(80, false, false,
464+
'#board-table', '.new-post-normal', 'click');
465+
466+
bbs_hotkey_manager.untriggerAll();
467+
bbs_hotkey_manager.add(publishPostHotkey);
468+
bbs_hotkey_manager.add(cancelPostHotkey);
469+
bbs_hotkey_manager.add(prevPostHotkey);
470+
bbs_hotkey_manager.add(nextPostHotkey);
471+
bbs_hotkey_manager.add(SpPrevPostHotkey);
472+
bbs_hotkey_manager.add(SpNextPostHotkey);
473+
bbs_hotkey_manager.add(prevPageHotkey);
474+
bbs_hotkey_manager.add(nextPageHotkey);
475+
bbs_hotkey_manager.add(replyHotkey);
476+
bbs_hotkey_manager.add(writePostHotkey);
477+
bbs_hotkey_manager.triggerAll();
416478
}

bbs_hotkey.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
function Hotkey(keyCode, ctrl, alt, selector, target, trigger){
2+
this.keyCode = keyCode;
3+
this.ctrlPressed = ctrl;
4+
this.altPressed = alt;
5+
this.selector = selector;
6+
this.trigger = trigger;
7+
this.target = target;
8+
9+
this.getMask = function() {
10+
var code = 0;
11+
code += this.ctrlPressed ? 1 : 0;
12+
code += this.altPressed ? 2 : 0;
13+
return code;
14+
}
15+
}
16+
17+
18+
function HotkeyManager() {
19+
this.hotkeyMap = new Array();
20+
21+
this.add = function(hotkey) {
22+
var code = hotkey.getMask();
23+
var list = this.hotkeyMap[hotkey.selector];
24+
if (list == null) {
25+
this.hotkeyMap[hotkey.selector] = new Array();
26+
}
27+
list = this.hotkeyMap[hotkey.selector][hotkey.keyCode];
28+
if (list == null) {
29+
this.hotkeyMap[hotkey.selector][hotkey.keyCode] = new Array(4);
30+
};
31+
list = this.hotkeyMap[hotkey.selector][hotkey.keyCode];
32+
if (list[code] != null) {
33+
return false;
34+
} else {
35+
this.hotkeyMap[hotkey.selector][hotkey.keyCode][code] = hotkey;
36+
}
37+
return true;
38+
};
39+
40+
this.get = function(hotkey) {
41+
var list = this.hotkeyMap[hotkey.selector];
42+
if (list == null) return null;
43+
list = list[hotkey.keyCode];
44+
if (list == null) return null;
45+
return list[hotkey.getMask()];
46+
};
47+
48+
this.remove = function(hotkey) {
49+
var list = this.hotkeyMap[hotkey.selector];
50+
if (list == null) return false;
51+
list = list[hotkey.keyCode];
52+
if (list == null) return false;
53+
this.hotkeyMap[hotkey.selector][hotkey.keyCode][hotkey.getMask()] = null;
54+
return true;
55+
};
56+
57+
this.triggerAll = function() {
58+
var manager = this;
59+
$(document).keyup(function(event) {
60+
var keycode = event.keyCode;
61+
var mask = 0;
62+
mask += event.ctrlKey ? 1 : 0;
63+
mask += event.altKey ? 2 : 0;
64+
var selector = bbs_topmost_stack[bbs_topmost_stack.length - 1];
65+
var list = manager.hotkeyMap[selector];
66+
if (list == null) {
67+
return;
68+
}
69+
var list = list[keycode];
70+
if (list == null) return;
71+
var hotkey = list[mask];
72+
if (hotkey == null) return;
73+
if (hotkey.selector != selector) {
74+
return;
75+
}
76+
$(hotkey.target).trigger(hotkey.trigger);
77+
});
78+
};
79+
80+
this.untriggerAll = function() {
81+
$(document).unbind('keypress');
82+
$(document).unbind('keydown');
83+
$(document).unbind('keyup');
84+
};
85+
}
86+
87+
var bbs_hotkey_manager = new HotkeyManager();
88+
var bbs_topmost_stack = new Array();

config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var bbs_error_session = 'SESSION_ERROR';
1010

1111
var bbs_info = {
1212
title : '9# BBS - Rowell ',
13-
version : '0.2.2',
13+
version : '0.2.3',
1414
send_source : '[Sent from Rowell v'
1515
};
1616

index.html

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,24 +108,24 @@ <h1>您尚未登录</h1>
108108
<li><ul class='nav nav-pills path'></ul></li>
109109
<li class='pull-right'>
110110
<div class='btn-group hide' id='reply-button'>
111-
<button class='btn btn-large btn-success' href='javascript:void(0)' id='reply-post-button' type='S'>回复 </button>
111+
<button class='btn btn-large btn-success reply-post-button' href='javascript:void(0)' type='S'>回复 </button>
112112
<button class='btn btn-large btn-success dropdown-toggle' data-toggle='dropdown'>
113113
<span class='caret caret-white'></span>
114114
</button>
115115
<ul class='dropdown-menu'>
116-
<li><a href='javascript:void(0)' id='reply-post-button' type='S'>普通模式(S)回复</a></li>
117-
<li><a href='javascript:void(0)' id='reply-post-button' type='R'>R模式回复</a></li>
118-
<li><a href='javascript:void(0)' id='reply-post-button' type='A'>A模式回复</a></li>
119-
<li><a href='javascript:void(0)' id='reply-post-button' type='N'>N模式回复</a></li>
116+
<li><a href='javascript:void(0)' class='reply-post-button' type='S'>普通模式(S)回复</a></li>
117+
<li><a href='javascript:void(0)' class='reply-post-button' type='R'>R模式回复</a></li>
118+
<li><a href='javascript:void(0)' class='reply-post-button' type='A'>A模式回复</a></li>
119+
<li><a href='javascript:void(0)' class='reply-post-button' type='N'>N模式回复</a></li>
120120
</ul>
121121
</div>
122122
<div class='btn-group hide' id='post-button'>
123-
<button class='btn btn-large btn-danger' href='javascript:void(0)' id='new-post-normal'>发帖</button>
123+
<button class='btn btn-large btn-danger new-post-normal' href='javascript:void(0)'>发帖</button>
124124
<button class='btn btn-large btn-danger dropdown-toggle' data-toggle='dropdown'>
125125
<span class='caret'></span>
126126
</button>
127127
<ul class='dropdown-menu'>
128-
<li><a href='javascript:void(0)' id='new-post-normal'>普通模式</a></li>
128+
<li><a href='javascript:void(0)' class='new-post-normal'>普通模式</a></li>
129129
<li><a href='javascript:void(0)' class='unimplemented'>Latex模式(X)</a></li>
130130
<li><a href='javascript:void(0)' class='unimplemented'>使用模板(T)</a></li>
131131
</ul>
@@ -273,8 +273,8 @@ <h3 id='post-panel-title'>发表新文章</h3>
273273
</form>
274274
</div>
275275
<div class='modal-footer'>
276-
<a class='btn btn-primary' id='publish-post-button' data-dismiss='modal'>发表</a>
277-
<a class='btn cancel-button'>取消</a>
276+
<a class='btn btn-primary' id='publish-post-button'>发表</a>
277+
<a class='btn cancel-button' id='cancel-post-button'>取消</a>
278278
</div>
279279
</div>
280280

@@ -336,10 +336,12 @@ <h3 id='post-panel-title'>发表新文章</h3>
336336
<script src='bbs_UI.js'></script>
337337
<script src='bbs_post.js'></script>
338338
<script src='bbs_path.js'></script>
339+
<script src='bbs_hotkey.js'></script>
339340

340341
<script type='text/javascript'>
341342
$(document).ready(function(){
342343
UI_register_func();
344+
UI_register_hotkeys();
343345
UI_init();
344346
UI_session_retrieved($.cookie(bbs_session_cookie));
345347
});

readme.md

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Rowell is a pure front-end web UI for you-know-which bbs. The web terminal relies on pybbs developed by Henryhu as back-end data exchange interface, and
66
Bootstrap from Twitter as the front-end framework.
77

8-
Rowell is still being developed and has released its 0.2.2 version, which supports the following functionals:
8+
Rowell is still being developed and has released its 0.2.3 version, which supports the following functionals:
99

1010
* Login/logout with session cookies.
1111

@@ -15,7 +15,7 @@ Rowell is still being developed and has released its 0.2.2 version, which suppor
1515

1616
* Post reading and navigations.
1717

18-
* Writing new posts in normal mode, reply posts in S/R/N/A modes. Anonymous posting is not supported yet, random qmd is not supported yet.
18+
* Writing new posts in normal mode, reply posts in S/R/N/A modes. Anonymous posting and random qmd are supported.
1919

2020

2121
##How to Use it
@@ -26,9 +26,7 @@ You can now try our alpha version at:
2626

2727
Later we will try to set a build on the department internal servers. However since it is pure front-end, you can simply checkout all codes, and open index.html as a local webpage in your browser, or build it anywhere that supports HTTP service. Note that if Rowell is opened locally, it will be unable to save cookies and therefore cannot hold your login informations.
2828

29-
Rowell has been tested on Firefox 8+ and Chrome 19+ browsers. However, since Rowell greatly uses CORS, ajax and other techniques in developing, it may fail on elder versions of Firefox and Chrome, and may fail for unknown problem on IE. We will keep improving your experience on all browsers by efforts on compatibility, but we claim that
30-
31-
WE WILL NEVER BE RESPONSIBLE FOR IE USERS!!!
29+
Rowell has been tested on Firefox 8+ and Chrome 19+ browsers. IE is not recommended for browsing, and we are sorry for this incompatibility.
3230

3331
##Development Plan
3432

@@ -38,13 +36,25 @@ WE WILL NEVER BE RESPONSIBLE FOR IE USERS!!!
3836

3937
* Simple ASCII art interpreter.
4038

41-
* Random qmd and anonymous posting.
42-
4339
* Personal information viewing, searching and editing.
4440

4541
* Favboards management.
4642

4743
##Change Logs
44+
####Version 0.2.3
45+
Release date: 07/26/2012
46+
47+
Cumulative update. Various modifications and new functions.
48+
49+
* A expandible hotkey management system is added to Rowell, with several hotkeys added: left and right arrow keys for prev/next, p and r for writing and replying posts, ctrl+Enter and esc for quick publishing and cancelling posts being written.
50+
51+
* Anonymous posting is now supported on anonymous-available boards. It will automatically detects the availability of anonymous posting.
52+
53+
* Random qmd is now supported, Default qmd settings(number or random) will be stored.
54+
55+
* Several UI adjustments: top sub-navigation bars are added. Margins and positions are adjusted.
56+
57+
* A rare bug on ASCII control chars is fixed.
4858

4959
####Version 0.2.2
5060
Release date: 07/02/2012

0 commit comments

Comments
 (0)