X-Git-Url: https://jfr.im/git/irc/quakenet/qwebirc.git/blobdiff_plain/3c3ddb143ab908af85456d1cfcc675256d302bbd..0fc80ad2b9b14a97062e2a7eca6117f09f3234d2:/js/jslib.js diff --git a/js/jslib.js b/js/jslib.js index 7e75d03..89f64ec 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) @@ -50,16 +51,16 @@ qwebirc.util.parseURI = function(uri) { var args = querystring.split("&"); - for(i=0;i=0;start--) { + if(l[start] == ' ') { + start = start + 1; + break; + } + } + } + + if(start < 0) + start = 0; + + var s = text.substring(start); + var pos = s.indexOf(" "); + if(pos != -1) + s = s.substring(0, pos); + + return [start, s]; +} + +String.prototype.startsWith = function(what) { + return this.substring(0, what.length) == what; +} + +String.prototype.endsWith = function(what) { + return this.substring(this.length - what.length, this.length) == what; +}; + +/* NOT cryptographically secure! */ +qwebirc.util.randHexString = function(numBytes) { + var getByte = function() { + return (((1+Math.random())*0x100)|0).toString(16).substring(1); + }; + + var l = []; + for(var i=0;i"; + 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.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; +} + +qwebirc.util.composeAnd = function() { + var xargs = arguments; + + return function() { + for(var i=0;i -1; + } + + for(var i=0;i