]> jfr.im git - irc/quakenet/qwebirc.git/blobdiff - js/jslib.js
Add a much better QuakeNet login system.
[irc/quakenet/qwebirc.git] / js / jslib.js
index e58bd954257941a924e91539a421cbe097766260..ba9acf0e3478d188f1b1f562334dee79e4708552 100644 (file)
@@ -102,9 +102,9 @@ qwebirc.util.NBSPCreate = function(text, element) {
 
 qwebirc.util.longtoduration = function(l) {
   var seconds = l % 60;
-  var minutes = Math.round((l % 3600) / 60);
-  var hours = Math.round((l % (3600 * 24)) / 3600);
-  var days = Math.round(l / (24*3600));
+  var minutes = Math.floor((l % 3600) / 60);
+  var hours = Math.floor((l % (3600 * 24)) / 3600);
+  var days = Math.floor(l / (24*3600));
   
   return days + " days " + hours + " hours " + minutes + " minutes " + seconds + " seconds";
 }
@@ -238,7 +238,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,12 +246,19 @@ qwebirc.util.createInput = function(type, parent, name, selected) {
     } else {
       name = "";
     }
-    r = $(document.createElement("<input type=\"" + type + "\"" + name + " " + (selected?" checked":"") + "/>"));
+    if(id) {
+      id = " id=\"" + escape(id) + "\"";
+    } else {
+      id = "";
+    }
+    r = $(document.createElement("<input type=\"" + type + "\"" + name + id + " " + (selected?" checked":"") + "/>"));
   } else {    
     r = new Element("input");
     r.type = type;
     if(name)
       r.name = name;
+    if(id)
+      r.id = id;
       
     if(selected)
       r.checked = true;
@@ -293,6 +300,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++));
@@ -312,3 +324,60 @@ qwebirc.util.b64Decode = function(data) {
 
   return output.join("");
 }
+
+qwebirc.util.composeAnd = function() {
+ var xargs = arguments;
+
+  return function() {
+    for(var i=0;i<xargs.length;i++)
+      if(!xargs[i].apply(this, arguments))
+        return false;
+        
+    return true;
+  }
+}
+
+qwebirc.util.invertFn = function(fn) {
+  return function() {
+    return !fn.apply(this, arguments);
+  }
+}
+
+qwebirc.util.deviceHasKeyboard = function() {
+  var determine = function() {
+    if(Browser.Engine.ipod)
+      return true;
+
+    var MOBILE_UAs = ["Nintendo Wii", " PIE", "BlackBerry", "IEMobile", "Windows CE", "Nokia", "Opera Mini", "Mobile", "mobile", "Pocket", "pocket", "Android"];
+    /* safari not included because iphones/ipods send that, and we checked for iphone/ipod specifically above */
+    var DESKTOP_UAs = ["Chrome", "Firefox", "Camino", "Iceweasel", "K-Meleon", "Konqueror", "SeaMonkey", "Windows NT", "Windows 9"];
+
+    var ua = navigator.userAgent;
+
+    var contains = function(v) {
+      return ua.indexOf(v) > -1;
+    }
+
+    for(var i=0;i<MOBILE_UAs.length;i++)
+      if(contains(MOBILE_UAs[i]))
+        return false;
+      
+    for(var i=0;i<DESKTOP_UAs.length;i++)
+      if(contains(DESKTOP_UAs[i]))
+        return true;
+      
+    return false;
+  };
+  var v = determine();
+  
+  qwebirc.util.deviceHasKeyboard = function() {
+    return v;
+  }
+  
+  return v;
+}
+
+qwebirc.util.generateID_ID = 0;
+qwebirc.util.generateID = function() {
+  return "qqa-" + qwebirc.util.generateID_ID++;
+}
\ No newline at end of file