Permalink
Browse files

refactored talker-substitute, made it more robust

  • Loading branch information...
cloudhead
cloudhead committed Feb 25, 2010
1 parent b364113 commit 8a511c5663ac02f85e506f428ffe6a877e3e4a2b
Showing with 22 additions and 5 deletions.
  1. +22 −5 talker-substitute.js
View
@@ -4,19 +4,36 @@
// string example: s/wordl/world
// regexp example: r/^w/W
//
+plugin.onMessageSend = function (event) {
+ var match;
+ if (match = event.content.match(/^([sr])\/(.+?)\/([^\/]*)(?:\/([gi])?)?$/)) {
+ event.substitute = {
+ type: match[1],
+ match: match[2],
+ replace: match[3],
+ options: match[4] || ''
+ };
+ Talker.sendMessage(event, "");
+ Talker.getMessageBox().val('');
+ return false;
+ }
+};
plugin.onMessageReceived = function (event) {
var match, row, messages, search;
- if (match = event.content.match(/^([sr])\/(.+?)\/([^\/]*)(?:\/([gi])?)?$/)) {
+ if (event.substitute) {
row = $("#log tr[author='" + event.user.name + "'].message:last");
- if (Talker.getMessageBox().val() === match[0]) { Talker.getMessageBox().val('') }
messages = row.find('.line');
- if (match[1] == 'r') { search = new(RegExp)(match[2], match[3] || '') }
- else { search = match[2] }
+ if (event.substitute.type == 'r') {
+ search = new(RegExp)(event.substitute.match, event.substitute.options);
+ } else { search = event.substitute.match }
for (var i = 0; i < messages.length; i++) {
- messages[i].innerHTML = messages[i].innerHTML.replace(search, match[3]);
+ messages[i].innerHTML = messages[i].innerHTML
+ .replace(search, "<span style='text-decoration: line-through'>" +
+ event.substitute.match + "</span> " +
+ event.substitute.replace);
}
return false;
}

0 comments on commit 8a511c5

Please sign in to comment.