]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - js/jslib.js
add option to run flash server
[irc/quakenet/qwebirc.git] / js / jslib.js
index b61038dc6d7e290b056f24a283779f0a40c24fe5..aa8f32de74f5189b0526a48867bb5aff10a2c085 100644 (file)
@@ -17,6 +17,7 @@ qwebirc.util.dictCopy = function(d) {
 
 /* how horribly inefficient */
 String.prototype.replaceAll = function(f, t) {
+  //return new RegExp("/" + RegExp.escape(f) + "/g").replace(f, RegExp.escape(t));
   var i = this.indexOf(f);
   var c = this;
  
@@ -117,15 +118,7 @@ qwebirc.util.pad = function(x) {
 }
 
 RegExp.escape = function(text) {
-  if(!arguments.callee.sRE) {
-    var specials = [
-      '/', '.', '*', '+', '?', '|',
-      '(', ')', '[', ']', '{', '}', '\\'
-    ];
-    arguments.callee.sRE = new RegExp('(\\' + specials.join('|\\') + ')', 'g');
-  }
-  
-  return text.replace(arguments.callee.sRE, '\\$1');
+  return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
 }
 
 qwebirc.ui.insertAt = function(position, parent, element) {
@@ -238,7 +231,7 @@ qwebirc.util.importJS = function(name, watchFor, onload) {
   document.getElementsByTagName("head")[0].appendChild(script);
 }
 
-qwebirc.util.createInput = function(type, parent, name, selected) {
+qwebirc.util.createInput = function(type, parent, name, selected, id) {
   var r;
   if(Browser.Engine.trident) {
     if(name) {
@@ -246,16 +239,27 @@ qwebirc.util.createInput = function(type, parent, name, selected) {
     } else {
       name = "";
     }
-    r = $(document.createElement("<input type=\"" + type + "\"" + name + " " + (selected?" checked":"") + "/>"));
-  } else {    
-    r = new Element("input");
-    r.type = type;
-    if(name)
-      r.name = name;
-      
-    if(selected)
-      r.checked = true;
+    if(id) {
+      id = " id=\"" + escape(id) + "\"";
+    } else {
+      id = "";
+    }
+    try {
+      return $(document.createElement("<input type=\"" + type + "\"" + name + id + " " + (selected?" checked":"") + "/>"));
+    } catch(e) {
+      /* fallthough, trying it the proper way... */
+    }
   }
+  
+  r = new Element("input");
+  r.type = type;
+  if(name)
+    r.name = name;
+  if(id)
+    r.id = id;
+      
+  if(selected)
+    r.checked = true;
     
   parent.appendChild(r);
   return r;
@@ -293,6 +297,11 @@ qwebirc.util.b64Decode = function(data) {
 
   var output = [];
   var table = qwebirc.util.b64Table;
+  
+  /* grossly inefficient... so sue me */
+  while(data.length % 4 != 0)
+    data = data + "=";
+    
   for(var i=0;i<data.length;) {
     var enc1 = table.indexOf(data.charAt(i++));
     var enc2 = table.indexOf(data.charAt(i++));
@@ -364,3 +373,27 @@ qwebirc.util.deviceHasKeyboard = function() {
   
   return v;
 }
+
+qwebirc.util.generateID_ID = 0;
+qwebirc.util.generateID = function() {
+  return "qqa-" + qwebirc.util.generateID_ID++;
+}
+
+qwebirc.util.__log = function(x) {
+  if(QWEBIRC_DEBUG) {
+    if(typeof console == "undefined") {
+      alert("log: " + x);
+    } else {
+      console.log(x);
+    }
+  }
+};
+
+qwebirc.util.logger = {
+  log: function(x) { qwebirc.util.__log("L " + x) },
+  info: function(x) { qwebirc.util.__log("I " + x) },
+  error: function(x) { qwebirc.util.__log("E " + x) },
+  warn: function(x) { qwebirc.util.__log("W " + x) }
+};
+
+qwebirc.util.log = qwebirc.util.logger.log;