]>
jfr.im git - irc/quakenet/qwebirc.git/blob - js/jslib.js
1 Array
.prototype.indexFromEnd = function(d
) {
5 return p
[p
.length
+ d
];
10 qwebirc
.util
.dictCopy = function(d
) {
18 /* how horribly inefficient */
19 String
.prototype.replaceAll = function(f
, t
) {
20 var i
= this.indexOf(f
);
30 /* how horribly inefficient (again) */
31 String
.prototype.splitMax = function(by
, max
) {
32 var items
= this.split(by
);
33 var newitems
= items
.slice(0, max
-1);
35 if(items
.length
>= max
)
36 newitems
.push(items
.slice(max
-1).join(by
));
41 qwebirc
.util
.setAtEnd = function(obj
) {
42 pos
= obj
.value
.length
;
44 if(obj
.createTextRange
) {
45 var range
= obj
.createTextRange();
46 range
.move("character", pos
);
48 } else if(obj
.selectionStart
) {
50 obj
.setSelectionRange(pos
, pos
);
54 /* returns the arguments */
55 qwebirc
.util
.parseURI = function(uri
) {
58 var start
= uri
.indexOf('?');
62 var querystring
= uri
.substring(start
+ 1);
64 var args
= querystring
.split("&");
66 for(i
=0;i
<args
.length
;i
++) {
67 var r
= args
[i
].splitMax("=", 2);
71 result
[unescape(r
[0])] = unescape(r
[1]);
77 qwebirc
.util
.DaysOfWeek
= {
87 qwebirc
.util
.MonthsOfYear
= {
102 qwebirc
.util
.NBSPCreate = function(text
, element
) {
103 var e
= text
.split(" ");
104 for(var i
=0;i
<e
.length
;i
++) {
105 var tn
= document
.createTextNode(e
[i
]);
106 element
.appendChild(tn
);
108 if(i
!= e
.length
- 1) {
109 var e2
= new Element("span");
110 e2
.set("html", " ");
111 element
.appendChild(e2
);
116 qwebirc
.util
.longtoduration = function(l
) {
117 var seconds
= l
% 60;
118 var minutes
= Math
.round((l
% 3600) / 60);
119 var hours
= Math
.round((l
% (3600 * 24)) / 3600);
120 var days
= Math
.round(l
/ (24*3600));
122 return days
+ " days " + hours
+ " hours " + minutes
+ " minutes " + seconds
+ " seconds";
125 qwebirc
.util
.pad = function(x
) {
132 RegExp
.escape = function(text
) {
133 if(!arguments
.callee
.sRE
) {
135 '/', '.', '*', '+', '?', '|',
136 '(', ')', '[', ']', '{', '}', '\\'
138 arguments
.callee
.sRE
= new RegExp('(\\' + specials
.join('|\\') + ')', 'g');
141 return text
.replace(arguments
.callee
.sRE
, '\\$1');