X-Git-Url: https://jfr.im/git/irc/quakenet/qwebirc.git/blobdiff_plain/c8bfbafdeba4b9d568f04dd2354d139613c0054e..885c700662410d28c11424a90809bc3082c0b3e9:/js/jslib.js
diff --git a/js/jslib.js b/js/jslib.js
index b07fba1..c8e8664 100644
--- a/js/jslib.js
+++ b/js/jslib.js
@@ -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;
@@ -40,7 +41,7 @@ String.prototype.splitMax = function(by, max) {
/* returns the arguments */
qwebirc.util.parseURI = function(uri) {
- var result = {}
+ var result = new QHash();
var start = uri.indexOf('?');
if(start == -1)
@@ -55,11 +56,11 @@ qwebirc.util.parseURI = function(uri) {
if(r.length < 2)
continue;
- result[unescape(r[0])] = unescape(r[1]);
+ result.put(unescape(r[0]), unescape(r[1]));
}
return result;
-}
+};
qwebirc.util.DaysOfWeek = {
0: "Sun",
@@ -102,9 +103,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";
}
@@ -117,15 +118,33 @@ 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(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
+};
+
+RegExp.fromIRCPattern = function(t) {
+ /* escape everything but ? . and * */
+ var t = t.replace(/[-[\]{}()+,\\^$|#\s]/g, "\\$&");
+ t = t.split("");
+ var out = [];
+
+ /* now process the rest */
+ for(var i=0;i"));
- } else {
+ try {
+ var h = "";
+ r = $(document.createElement(h));
+ if (type == "radio") {
+ r.addEvent("click", function () {
+ $(document.body).getElements("input[name=" + name + "]").forEach(function (x) {
+ x.setAttribute("defaultChecked", x.checked ? "defaultChecked" : "");
+ });
+ });
+ }
+ created = true;
+ } catch (e) {
+ /* fallthough, trying it the proper way... */
+ }
+ }
+
+ if(!created) {
r = new Element("input");
- r.type = type;
- if(name)
- r.name = name;
-
- if(selected)
- r.checked = true;
+ r.setAttribute("type", type);
}
-
+ if(name)
+ r.setAttribute("name", name);
+ if(id)
+ r.setAttribute("id", id);
+ if(selected) {
+ r.setAttribute("checked", "checked");
+ if(type == "radio" && Browser.Engine.trident)
+ r.setAttribute("defaultChecked", "defaultChecked");
+ }
+
parent.appendChild(r);
return r;
}
@@ -293,6 +336,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 -1;
+ }
+
+ for(var i=0;i