aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Kavlie <akavlie@gmail.com>2011-11-06 12:46:59 -0700
committerAaron Kavlie <akavlie@gmail.com>2011-11-06 12:46:59 -0700
commit3f26923dbef4ea367bc0db3b2bc2c13ff9ffc6b6 (patch)
tree4be2f31b32f585f8a71630b3dc42c99377b4b8aa
parentbd1700c865cb9efa046249c621c9591794c11b00 (diff)
downloadreevo-webirc-3f26923dbef4ea367bc0db3b2bc2c13ff9ffc6b6.tar.gz
reevo-webirc-3f26923dbef4ea367bc0db3b2bc2c13ff9ffc6b6.zip
Replace global string replace for message type revisions with custom swapCommand function.
Also, put in a module pattern for augmentation of global module, so as to not pollute global namespace.
-rw-r--r--app.js4
-rw-r--r--js/util.js17
2 files changed, 15 insertions, 6 deletions
diff --git a/app.js b/app.js
index 925463a..ad0667c 100644
--- a/app.js
+++ b/app.js
@@ -1,6 +1,6 @@
1$(function() { 1$(function() {
2 // Our global object 2 // Our global object
3 window.irc = {}; 3 window.irc = window.irc || {};
4 4
5 // socket.io init 5 // socket.io init
6 var socket = io.connect('http://localhost'); 6 var socket = io.connect('http://localhost');
@@ -332,7 +332,7 @@ $(function() {
332 revised = command; 332 revised = command;
333 break; 333 break;
334 } 334 }
335 return replaceString(command, revised, text); 335 return irc.utils.swapCommand(command, revised, text);
336 }, 336 },
337 337
338 sendInput: function(e) { 338 sendInput: function(e) {
diff --git a/js/util.js b/js/util.js
index fc0c2a7..d0e053d 100644
--- a/js/util.js
+++ b/js/util.js
@@ -69,7 +69,16 @@ if ( !Array.prototype.forEach ) {
69// UTILITY FUNCTIONS 69// UTILITY FUNCTIONS
70// ================= 70// =================
71 71
72// Replaces oldString with newString in the string haystack 72window.irc = (function(module) {
73function replaceString(oldString, newString, haystack) { 73 module.utils = {
74 return haystack.split(oldString).join(newString); 74 // Replaces oldString with newString at beginning of text
75} \ No newline at end of file 75 swapCommand: function(oldString, newString, text) {
76 if (text.substring(0, oldString.length) === oldString)
77 return newString + text.substring(oldString.length, text.length);
78 else
79 throw 'String "' + oldString + '" not found at beginning of text';
80 }
81 }
82
83 return module
84})(window.irc || {});