Permalink
Browse files

Factor out 'getCommandList', reuse for /help function

  • Loading branch information...
1 parent a42f12d commit 9d2aab17152076a9adcaa4cea496e4de3fcba5b1 Benjol committed Nov 6, 2010
Showing with 28 additions and 16 deletions.
  1. +2 −0 README.md
  2. +26 −16 SEChatModifications.user.js
View
2 README.md
@@ -1,6 +1,8 @@
##SEChatModifications
Provides keyboard shortcuts and other commands via input text reducing the dependency on mouse usage. Currently the script adds the id to the right of each message and the commands take in this id to identify the selected message. Keyboard navigation support is also planned.
+* View list of all keyboard commands (except navigation)
+ *. `/help`
* Star a message
* `/star <id>`
* `<id>` is the numeric id of a message
View
42 SEChatModifications.user.js
@@ -487,7 +487,24 @@ with_plugin("http://stackflair.com/jquery.livequery.js", function ($) {
var selector = getHighlightSelector(match);
$(selector).expire().removeClass("highlight");
}
-
+
+ function getCommandList() {
+ var ul = $('<ul />').addClass('gm_room_list');
+ for (var i in commands) {
+ (function (current) {
+ $('<a />').click(function () {
+ $('#input').val('/' + current).focus();
+ return false;
+ }).attr('href', '#')
+ .text(current)
+ .wrap('<li />')
+ .parent()
+ .appendTo(ul);
+ })(i);
+ }
+ return ul;
+ }
+
function createClipItem(index, room, display, hide) {
var html = index + '. <em>' + room + '</em>';
@@ -592,7 +609,7 @@ with_plugin("http://stackflair.com/jquery.livequery.js", function ($) {
return CommandState.SucceededDoClear;
},
hl: function (match) {
- if(match == undefined) { //no parameters = show list
+ if(typeof match == 'undefined') { //no parameters = show list
var ul = $('<ul />').addClass('gm_room_list');
if (highlightStore.items.length > 0) {
@@ -968,6 +985,11 @@ with_plugin("http://stackflair.com/jquery.livequery.js", function ($) {
validateArgs(0);
window.location = "http://github.com/rchern/StackExchangeScripts/raw/master/SEChatModifications.user.js";
return CommandState.SucceededDoClear;
+ },
+ help: function () {
+ var ul = getCommandList();
+ ul = $(ul).before($('<span/>').text('List of recognised commands:'));
+ showNotification(ul, 10E3);
}
};
@@ -1011,19 +1033,7 @@ with_plugin("http://stackflair.com/jquery.livequery.js", function ($) {
input.val("");
}
if (returnVal == CommandState.NotFound) {
- var ul = $('<ul />').addClass('gm_room_list');
- for (var i in commands) {
- (function (current) {
- $('<a />').click(function () {
- $('#input').val('/' + current).focus();
- return false;
- }).attr('href', '#')
- .text(current)
- .wrap('<li />')
- .parent()
- .appendTo(ul);
- })(i);
- }
+ var ul = getCommandList();
ul = $(ul).before($('<span/>').text('Unknown command, try again, or use // to escape commands.'));
showNotification(ul, 10E3);
}
@@ -1039,7 +1049,7 @@ with_plugin("http://stackflair.com/jquery.livequery.js", function ($) {
var e = input.data("events").keydown; e.unshift(e.pop());
- // Persistant highlighting Restoration - code duplicated from command.hl (previously used addhl)
+ // Persistant highlighting Restoration
for (var i = 0; i < highlightStore.items.length; i++) {
addhl(highlightStore.items[i]);
}

0 comments on commit 9d2aab1

Please sign in to comment.