Explorar o código

Starting to make functions private.

Nathaniel van Diepen %!s(int64=11) %!d(string=hai) anos
pai
achega
0b882e0506
Modificáronse 3 ficheiros con 157 adicións e 150 borrados
  1. 59 52
      omnomirc_www/Omnom_Misc.js
  2. 1 1
      omnomirc_www/Omnom_Parser.js
  3. 97 97
      omnomirc_www/Omnom_Tab.js

+ 59 - 52
omnomirc_www/Omnom_Misc.js

@@ -16,37 +16,46 @@
     You should have received a copy of the GNU General Public License
     along with OmnomIRC.  If not, see <http://www.gnu.org/licenses/>.
 */ 
-
+(function(window,undefined){
 //******************************
 // Start Indicator functions   *
 //******************************
-indicatorTimer = false;
-function startIndicator() {
-	if (!indicatorTimer) {
-		indicatorTimer = setInterval(updateIndicator,50);
-		indicatorPixels = Array(true,true,true,true,true,false,false,false);
-	}
-}
-function updateIndicator() {
-	var indicator = document.getElementById('indicator');
-	indicator.innerHTML = "";
-	for (var i=0;i<8;i++) {
-		if (indicatorPixels[i])
-			indicator.innerHTML+="<div style='padding:0;margin:0;width:3px;height:3px;background-color:black;'></div>";
-		else
-			indicator.innerHTML+="<div style='padding:0;margin:0;width:3px;height:3px;'></div>";
-	}
-	var temp = indicatorPixels[7];
-	for (i=6;i>=0;i--) {
-		indicatorPixels[(i+1)] = indicatorPixels[i];
+	var indicatorTimer = false,
+		oldMessages = [],
+		messageCounter = 1,
+		currentMessage,
+		startIndicator = window.startIndicator = function(){
+			if(!indicatorTimer){
+				indicatorTimer = setInterval(updateIndicator,50);
+				indicatorPixels = Array(true,true,true,true,true,false,false,false);
+			}
+		},
+		stopIndicator = window.stopIndicator = function() {
+			clearInterval(indicatorTimer);
+			document.getElementById('indicator').innerHTML = '';
+			indicatorTimer = false;
+		};
+	function updateIndicator() {
+		var indicator = document.getElementById('indicator'),
+			div,
+			temp = indicatorPixels[7];
+		indicator.innerHTML = "";
+		for (var i=0;i<8;i++){
+			div = document.createElement('div');
+			div.style.padding = 0;
+			div.style.margin = 0;
+			div.style.width = '3px';
+			div.style.height = '3px';
+			if (indicatorPixels[i]){
+				div.style.backgroundColor = 'black';
+			}
+			indicator.appendChild(div);
+		}
+		for(i=6;i>=0;i--){
+			indicatorPixels[(i+1)] = indicatorPixels[i];
+		}
+		indicatorPixels[0] = temp;
 	}
-	indicatorPixels[0] = temp;
-}
-function stopIndicator() {
-	clearInterval(indicatorTimer);
-	document.getElementById('indicator').innerHTML = '';
-	indicatorTimer = false;
-}
 //******************************
 // End Indicator functions     *
 //******************************
@@ -54,35 +63,33 @@ function stopIndicator() {
 //******************************
 // Start old messages functions*
 //******************************
-var oldMessages = new Array();
-var messageCounter = 1;
-var currentMessage;
-window.addEventListener('keydown',function(e) {
-	if (document.activeElement.id=="message") {
-		var messageBoxElement = document.getElementById("message");
-		if (messageCounter==oldMessages.length)currentMessage=messageBoxElement.value;
-		if (oldMessages.length!=0) {
-			if (e.keyCode==38) { //up
-				if (messageCounter!=0)messageCounter--;
-				messageBoxElement.value = oldMessages[messageCounter];
-			} else if (e.keyCode==40) { //down
-				if (messageCounter!=oldMessages.length)messageCounter++;
-				if (messageCounter==oldMessages.length) {
-					messageBoxElement.value = currentMessage;
-				} else {
+	window.addEventListener('keydown',function(e) {
+		if (document.activeElement.id=="message") {
+			var messageBoxElement = document.getElementById("message");
+			if (messageCounter==oldMessages.length)currentMessage=messageBoxElement.value;
+			if (oldMessages.length!=0) {
+				if (e.keyCode==38) { //up
+					if (messageCounter!=0)messageCounter--;
 					messageBoxElement.value = oldMessages[messageCounter];
+				} else if (e.keyCode==40) { //down
+					if (messageCounter!=oldMessages.length)messageCounter++;
+					if (messageCounter==oldMessages.length) {
+						messageBoxElement.value = currentMessage;
+					} else {
+						messageBoxElement.value = oldMessages[messageCounter];
+					}
 				}
 			}
 		}
+	}, false);
+	var readOldMessagesCookies = window.readOldMessagesCookies = function() {
+		oldMessages = [];
+		var temp = getCookie("oldMessages-"+getChannelEn());
+		if (temp!=null)
+			oldMessages = temp.split("\n");
+		messageCounter = oldMessages.length;
 	}
-}, false);
-function readOldMessagesCookies() {
-	oldMessages = Array();
-	var temp = getCookie("oldMessages-"+getChannelEn());
-	if (temp!=null)
-		oldMessages = temp.split("\n");
-	messageCounter = oldMessages.length;
-}
 //******************************
 // End old messages functions  *
-//******************************
+//******************************
+})(window);

+ 1 - 1
omnomirc_www/Omnom_Parser.js

@@ -822,7 +822,7 @@
 //******************************
 // Tab Completion Start        *
 //******************************
-	function searchUser(start,startAt){
+	var searchUser = window.searchUser = function(start,startAt){
 		if(!startAt){
 			startAt = 0;
 		}

+ 97 - 97
omnomirc_www/Omnom_Tab.js

@@ -1,97 +1,97 @@
-/*
-    OmnomIRC COPYRIGHT 2010,2011 Netham45
-
-    This file is part of OmnomIRC.
-
-    OmnomIRC is free software: you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation, either version 3 of the License, or
-    (at your option) any later version.
-
-    OmnomIRC is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with OmnomIRC.  If not, see <http://www.gnu.org/licenses/>.
-*/
-
-message = document.getElementById("message");
-if(message.addEventListener ) {
-	message.addEventListener("keydown",keyHandler,false);
-	} else if(message.attachEvent ) {
-        message.attachEvent("onkeydown",keyHandler);
-    }
-isInTab = false;
-tabWord = "";
-tabCount = 0;
-startPos = 0;
-endPos = 0;
-endPosO = 0;
-    function keyHandler(e) {
-		if (getCurrentWord() == "")
-			return true;
-        var TABKEY = 9;
-        if(e.keyCode == TABKEY) {
-            if(e.preventDefault) {
-                e.preventDefault();
-            }
-			tabWord = getCurrentWord();
-			getTabComplete();
-			tabCount++;
-			isInTab = true;
-			setTimeout(1,1); //Who woulda thought that a bogus call makes it not parse it in FF4?
-            return false;
-        }
-		else
-		{
-			tabWord = "";
-			tabCount = 0;
-			isInTab = false;
-		}
-    }
-	function getCurrentWord()
-	{
-		if (isInTab)
-			return tabWord;
-		startPos = message.selectionStart;
-		endPos = message.selectionStart;
-		
-		startChar = message.value.charAt(startPos);
-		while (startChar != " " && --startPos > 0)
-			startChar = message.value.charAt(startPos);
-		if (startChar == " ") startPos++;
-		endChar = message.value.charAt(endPos);
-		while (endChar != " " && ++endPos <= message.value.length)
-			endChar = message.value.charAt(endPos);
-		endPosO = endPos;		
-		return message.value.substr(startPos,endPos - startPos).trim();
-	}
-	function getTabComplete()
-	{		
-		if (!isInTab)
-		{
-			startPos = message.selectionStart;
-		
-			startChar = message.value.charAt(startPos);
-			while (startChar != " " && --startPos > 0)
-				startChar = message.value.charAt(startPos);
-			if (startChar == " ") startChar+=2;
-		
-			endPos = message.selectionStart;
-			endChar = message.value.charAt(endPos);
-			while (endChar != " " && ++endPos <= message.value.length)
-				endChar = message.value.charAt(endPos);
-			if (endChar == " ") endChar-=2;
-		}
-		name = searchUser(getCurrentWord(),tabCount);
-		if (name == getCurrentWord())
-		{
-			tabCount = 0;
-			name = searchUser(getCurrentWord(),tabCount);
-		}
-			
-		message.value = message.value.substr(0,startPos) + name + message.value.substr(endPos + 1);
-		endPos = endPosO + name.length;
-	}
+/*
+    OmnomIRC COPYRIGHT 2010,2011 Netham45
+
+    This file is part of OmnomIRC.
+
+    OmnomIRC is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    OmnomIRC is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with OmnomIRC.  If not, see <http://www.gnu.org/licenses/>.
+*/
+(function(window,undefined){
+	var message = document.getElementById("message"),
+		isInTab = false,
+		tabWord = "",
+		tabCount = 0,
+		startPos = 0,
+		endPos = 0,
+		endPosO = 0;
+	if(message.addEventListener ){
+		message.addEventListener("keydown",keyHandler,false);
+	} else if(message.attachEvent ){
+		message.attachEvent("onkeydown",keyHandler);
+	}
+    function keyHandler(e){
+		if (getCurrentWord() == "")
+			return true;
+        var TABKEY = 9;
+        if(e.keyCode == TABKEY){
+            if(e.preventDefault) {
+                e.preventDefault();
+            }
+			tabWord = getCurrentWord();
+			getTabComplete();
+			tabCount++;
+			isInTab = true;
+			//setTimeout(1,1); //Who woulda thought that a bogus call makes it not parse it in FF4?
+            return false;
+        }else{
+			tabWord = "";
+			tabCount = 0;
+			isInTab = false;
+		}
+    }
+	function getCurrentWord(){
+		if (isInTab){
+			return tabWord;
+		}
+		startPos = message.selectionStart;
+		endPos = message.selectionStart;
+		startChar = message.value.charAt(startPos);
+		while (startChar != " " && --startPos > 0){
+			startChar = message.value.charAt(startPos);
+		}
+		if (startChar == " ") startPos++;
+		endChar = message.value.charAt(endPos);
+		while (endChar != " " && ++endPos <= message.value.length){
+			endChar = message.value.charAt(endPos);
+		}
+		endPosO = endPos;		
+		return message.value.substr(startPos,endPos - startPos).trim();
+	}
+	function getTabComplete(){		
+		if (!isInTab){
+			startPos = message.selectionStart;
+			startChar = message.value.charAt(startPos);
+			while (startChar != " " && --startPos > 0){
+				startChar = message.value.charAt(startPos);
+			}
+			if (startChar == " "){
+				startChar+=2;
+			}
+			endPos = message.selectionStart;
+			endChar = message.value.charAt(endPos);
+			while (endChar != " " && ++endPos <= message.value.length){
+				endChar = message.value.charAt(endPos);
+			}
+			if (endChar == " "){
+				endChar-=2;
+			}
+		}
+		name = searchUser(getCurrentWord(),tabCount);
+		if (name == getCurrentWord()){
+			tabCount = 0;
+			name = searchUser(getCurrentWord(),tabCount);
+		}
+		message.value = message.value.substr(0,startPos) + name + message.value.substr(endPos + 1);
+		endPos = endPosO + name.length;
+	}
+})(window);