1999-09-06 21:09:47 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The contents of this file are subject to the Mozilla Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-09-06 21:09:47 +04:00
|
|
|
*
|
|
|
|
* The Original Code is JSIRC Library
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is New Dimensions Consulting,
|
1999-11-06 06:43:54 +03:00
|
|
|
* Inc. Portions created by New Dimensions Consulting, Inc. are
|
|
|
|
* Copyright (C) 1999 New Dimenstions Consulting, Inc. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-09-06 21:09:47 +04:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Robert Ginda, rginda@ndcico.com, original author
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* JavaScript utility functions.
|
|
|
|
*
|
|
|
|
* 1999-08-15 rginda@ndcico.com v1.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
var DEBUG = true;
|
|
|
|
|
-- CHATZILLA CHANGES ONLY --
sr = scc, r = syd
fix for bug 57633, which also fixes 27805,40636,41343,51352,54145,56708,57104,57138, and some other random unfiled bugs.
2000-11-01 12:33:16 +03:00
|
|
|
var dumpln;
|
|
|
|
var dd;
|
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
if (typeof document == "undefined") /* in xpcshell */
|
|
|
|
dumpln = print;
|
|
|
|
else
|
1999-09-16 05:35:00 +04:00
|
|
|
if (typeof dump == "function")
|
|
|
|
dumpln = function (str) {dump (str + "\n");}
|
2000-01-27 12:45:11 +03:00
|
|
|
else if (jsenv.HAS_RHINO)
|
|
|
|
dumpln = function (str) {var out = java.lang.System.out;
|
|
|
|
out.println(str); out.flush(); }
|
1999-09-16 05:35:00 +04:00
|
|
|
else
|
1999-10-10 01:26:52 +04:00
|
|
|
dumpln = function () {} /* no suitable function */
|
1999-09-06 21:09:47 +04:00
|
|
|
|
|
|
|
if (DEBUG)
|
|
|
|
dd = dumpln;
|
|
|
|
else
|
|
|
|
dd = function (){};
|
|
|
|
|
|
|
|
var jsenv = new Object();
|
2000-01-16 08:07:01 +03:00
|
|
|
jsenv.HAS_SECURITYMANAGER = ((typeof netscape == "object") &&
|
|
|
|
(typeof netscape.security == "object"));
|
2001-06-07 04:50:20 +04:00
|
|
|
jsenv.HAS_XPCOM = ((typeof Components == "object") &&
|
|
|
|
(typeof Components.classes == "object"));
|
1999-09-06 21:09:47 +04:00
|
|
|
jsenv.HAS_JAVA = (typeof java == "object");
|
|
|
|
jsenv.HAS_RHINO = (typeof defineClass == "function");
|
1999-09-15 06:04:24 +04:00
|
|
|
jsenv.HAS_DOCUMENT = (typeof document == "object");
|
2001-06-07 04:50:20 +04:00
|
|
|
jsenv.HAS_NSPR_EVENTQ = jsenv.HAS_DOCUMENT;
|
1999-09-06 21:09:47 +04:00
|
|
|
|
|
|
|
function dumpObject (o, pfx, sep)
|
|
|
|
{
|
|
|
|
var p;
|
|
|
|
var s = "";
|
|
|
|
|
|
|
|
sep = (typeof sep == "undefined") ? " = " : sep;
|
1999-10-10 01:26:52 +04:00
|
|
|
pfx = (typeof pfx == "undefined") ? "" : pfx;
|
1999-09-06 21:09:47 +04:00
|
|
|
|
|
|
|
for (p in o)
|
|
|
|
{
|
|
|
|
if (typeof (o[p]) != "function")
|
|
|
|
s += pfx + p + sep + o[p] + "\n";
|
|
|
|
else
|
|
|
|
s += pfx + p + sep + "function\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Dumps an object in tree format, recurse specifiec the the number of objects
|
|
|
|
* to recurse, compress is a boolean that can uncompress (true) the output
|
|
|
|
* format, and level is the number of levels to intitialy indent (only useful
|
|
|
|
* internally.) A sample dumpObjectTree (o, 1) is shown below.
|
|
|
|
*
|
|
|
|
* + parent (object)
|
|
|
|
* + users (object)
|
|
|
|
* | + jsbot (object)
|
|
|
|
* | + mrjs (object)
|
|
|
|
* | + nakkezzzz (object)
|
|
|
|
* | *
|
|
|
|
* + bans (object)
|
|
|
|
* | *
|
|
|
|
* + topic (string) 'ircclient.js:59: nothing is not defined'
|
|
|
|
* + getUsersLength (function) 9 lines
|
|
|
|
* *
|
|
|
|
*/
|
|
|
|
function dumpObjectTree (o, recurse, compress, level)
|
|
|
|
{
|
|
|
|
var s = "";
|
|
|
|
var pfx = "";
|
|
|
|
|
|
|
|
if (typeof recurse == "undefined")
|
|
|
|
recurse = 0;
|
|
|
|
if (typeof level == "undefined")
|
|
|
|
level = 0;
|
|
|
|
if (typeof compress == "undefined")
|
|
|
|
compress = true;
|
|
|
|
|
|
|
|
for (var i = 0; i < level; i++)
|
|
|
|
pfx += (compress) ? "| " : "| ";
|
|
|
|
|
|
|
|
var tee = (compress) ? "+ " : "+- ";
|
|
|
|
|
|
|
|
for (i in o)
|
|
|
|
{
|
2001-08-24 00:33:24 +04:00
|
|
|
var t, ex;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
t = typeof o[i];
|
|
|
|
}
|
|
|
|
catch (ex)
|
|
|
|
{
|
|
|
|
t = "ERROR";
|
|
|
|
}
|
1999-09-06 21:09:47 +04:00
|
|
|
|
|
|
|
switch (t)
|
|
|
|
{
|
|
|
|
case "function":
|
2000-08-30 04:30:53 +04:00
|
|
|
var sfunc = String(o[i]).split("\n");
|
1999-09-06 21:09:47 +04:00
|
|
|
if (sfunc[2] == " [native code]")
|
-- CHATZILLA CHANGES ONLY --
sr = scc, r = syd
fix for bug 57633, which also fixes 27805,40636,41343,51352,54145,56708,57104,57138, and some other random unfiled bugs.
2000-11-01 12:33:16 +03:00
|
|
|
sfunc = "[native code]";
|
1999-09-06 21:09:47 +04:00
|
|
|
else
|
2001-04-15 04:04:32 +04:00
|
|
|
if (sfunc.length == 1)
|
|
|
|
sfunc = String(sfunc);
|
|
|
|
else
|
|
|
|
sfunc = sfunc.length + " lines";
|
1999-09-06 21:09:47 +04:00
|
|
|
s += pfx + tee + i + " (function) " + sfunc + "\n";
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "object":
|
|
|
|
s += pfx + tee + i + " (object)\n";
|
|
|
|
if (!compress)
|
|
|
|
s += pfx + "|\n";
|
|
|
|
if ((i != "parent") && (recurse))
|
|
|
|
s += dumpObjectTree (o[i], recurse - 1,
|
|
|
|
compress, level + 1);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "string":
|
|
|
|
if (o[i].length > 200)
|
|
|
|
s += pfx + tee + i + " (" + t + ") " +
|
|
|
|
o[i].length + " chars\n";
|
|
|
|
else
|
|
|
|
s += pfx + tee + i + " (" + t + ") '" + o[i] + "'\n";
|
|
|
|
break;
|
|
|
|
|
2001-08-24 00:33:24 +04:00
|
|
|
case "ERROR":
|
|
|
|
s += pfx + tee + i + " (" + t + ") ?\n";
|
|
|
|
break;
|
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
default:
|
|
|
|
s += pfx + tee + i + " (" + t + ") " + o[i] + "\n";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!compress)
|
|
|
|
s += pfx + "|\n";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
s += pfx + "*\n";
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-10-10 01:26:52 +04:00
|
|
|
/*
|
|
|
|
* Clones an existing object (Only the enumerable properties
|
|
|
|
* of course.) use as a function..
|
|
|
|
* var c = Clone (obj);
|
|
|
|
* or a constructor...
|
|
|
|
* var c = new Clone (obj);
|
|
|
|
*/
|
|
|
|
function Clone (obj)
|
|
|
|
{
|
|
|
|
robj = new Object();
|
|
|
|
|
|
|
|
for (var p in obj)
|
|
|
|
robj[p] = obj[p];
|
|
|
|
|
|
|
|
return robj;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
/*
|
|
|
|
* matches a real object against one or more pattern objects.
|
|
|
|
* if you pass an array of pattern objects, |negate| controls wether to check
|
|
|
|
* if the object matches ANY of the patterns, or NONE of the patterns.
|
|
|
|
*/
|
|
|
|
function matchObject (o, pattern, negate)
|
|
|
|
{
|
|
|
|
negate = Boolean(negate);
|
|
|
|
|
|
|
|
function _match (o, pattern)
|
|
|
|
{
|
2000-01-27 12:45:11 +03:00
|
|
|
if (pattern instanceof Function)
|
|
|
|
return pattern(o);
|
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
for (p in pattern)
|
|
|
|
{
|
|
|
|
var val;
|
2000-01-27 12:45:11 +03:00
|
|
|
/* nice to have, but slow as molases, allows you to match
|
|
|
|
* properties of objects with obj$prop: "foo" syntax */
|
|
|
|
/*
|
|
|
|
if (p[0] == "$")
|
|
|
|
val = eval ("o." +
|
|
|
|
p.substr(1,p.length).replace (/\$/g, "."));
|
|
|
|
else
|
|
|
|
*/
|
|
|
|
val = o[p];
|
|
|
|
|
|
|
|
if (pattern[p] instanceof Function)
|
1999-09-06 21:09:47 +04:00
|
|
|
{
|
|
|
|
if (!pattern[p](val))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-01-27 12:45:11 +03:00
|
|
|
var ary = (new String(val)).match(pattern[p]);
|
|
|
|
if (ary == null)
|
1999-09-06 21:09:47 +04:00
|
|
|
return false;
|
2000-01-27 12:45:11 +03:00
|
|
|
else
|
|
|
|
o.matchresult = ary;
|
1999-09-06 21:09:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(pattern instanceof Array))
|
|
|
|
return Boolean (negate ^ _match(o, pattern));
|
|
|
|
|
|
|
|
for (var i in pattern)
|
|
|
|
if (_match (o, pattern[i]))
|
1999-09-14 02:59:41 +04:00
|
|
|
return !negate;
|
1999-09-06 21:09:47 +04:00
|
|
|
|
|
|
|
return negate;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-05-11 02:23:35 +04:00
|
|
|
function matchEntry (partialName, list)
|
|
|
|
{
|
|
|
|
|
|
|
|
if ((typeof partialName == "undefined") ||
|
|
|
|
(String(partialName) == ""))
|
|
|
|
return list;
|
|
|
|
|
|
|
|
var ary = new Array();
|
|
|
|
|
|
|
|
for (var i in list)
|
|
|
|
{
|
|
|
|
if (list[i].indexOf(partialName) == 0)
|
|
|
|
ary.push (list[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ary;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCommonPfx (list)
|
|
|
|
{
|
|
|
|
var pfx = list[0];
|
|
|
|
var l = list.length;
|
|
|
|
|
2001-12-04 03:20:48 +03:00
|
|
|
for (var i = 0; i < l; i++)
|
2000-05-11 02:23:35 +04:00
|
|
|
{
|
2001-12-04 03:20:48 +03:00
|
|
|
for (var c = 0; c < pfx.length; ++c)
|
|
|
|
{
|
|
|
|
if (c >= list[i].length)
|
|
|
|
{
|
2000-05-11 02:23:35 +04:00
|
|
|
pfx = pfx.substr (0, c);
|
2001-12-04 03:20:48 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pfx[c] != list[i][c])
|
|
|
|
pfx = pfx.substr (0, c);
|
|
|
|
}
|
|
|
|
}
|
2000-05-11 02:23:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return pfx;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
function renameProperty (obj, oldname, newname)
|
|
|
|
{
|
|
|
|
|
1999-09-14 02:59:41 +04:00
|
|
|
if (oldname == newname)
|
|
|
|
return;
|
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
obj[newname] = obj[oldname];
|
|
|
|
delete obj[oldname];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-09-14 03:57:52 +04:00
|
|
|
function newObject(contractID, iface)
|
1999-09-06 21:09:47 +04:00
|
|
|
{
|
2000-01-18 06:29:17 +03:00
|
|
|
if (!jsenv.HAS_XPCOM)
|
1999-12-05 06:47:18 +03:00
|
|
|
return null;
|
1999-09-16 05:35:00 +04:00
|
|
|
|
2000-09-14 03:57:52 +04:00
|
|
|
var obj = Components.classes[contractID].createInstance();
|
1999-09-06 21:09:47 +04:00
|
|
|
var rv;
|
|
|
|
|
|
|
|
switch (typeof iface)
|
|
|
|
{
|
|
|
|
case "string":
|
|
|
|
rv = obj.QueryInterface(Components.interfaces[iface]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "object":
|
|
|
|
rv = obj.QueryInterface[iface];
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rv = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-01-16 08:07:01 +03:00
|
|
|
function getPriv (priv)
|
|
|
|
{
|
|
|
|
if (!jsenv.HAS_SECURITYMANAGER)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
var rv = true;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege(priv);
|
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
|
|
|
dd ("getPriv: unable to get privlege '" + priv + "': " + e);
|
|
|
|
rv = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
function keys (o)
|
|
|
|
{
|
2001-03-14 05:35:29 +03:00
|
|
|
var rv = new Array();
|
1999-09-06 21:09:47 +04:00
|
|
|
|
|
|
|
for (var p in o)
|
2001-03-14 05:35:29 +03:00
|
|
|
rv.push(p);
|
1999-09-06 21:09:47 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function stringTrim (s)
|
|
|
|
{
|
|
|
|
if (!s)
|
|
|
|
return "";
|
1999-10-10 01:26:52 +04:00
|
|
|
s = s.replace (/^\s+/, "");
|
|
|
|
return s.replace (/\s+$/, "");
|
1999-09-06 21:09:47 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-12-06 03:45:29 +03:00
|
|
|
/* the offset should be in seconds, it will be rounded to 2 decimal places */
|
|
|
|
function formatDateOffset (offset, format)
|
2001-03-14 05:35:29 +03:00
|
|
|
{
|
2001-12-06 03:45:29 +03:00
|
|
|
offset = roundTo(offset, 2);
|
|
|
|
var seconds = offset % 60;
|
|
|
|
var minutes = parseInt(offset / 60);
|
|
|
|
var hours = parseInt(minutes / 60);
|
2001-03-14 05:35:29 +03:00
|
|
|
minutes = minutes % 60;
|
2001-12-06 03:45:29 +03:00
|
|
|
var days = parseInt(hours / 24);
|
2001-03-14 05:35:29 +03:00
|
|
|
hours = hours % 24;
|
|
|
|
|
|
|
|
if (!format)
|
|
|
|
{
|
|
|
|
var ary = new Array();
|
|
|
|
if (days > 0)
|
|
|
|
ary.push (days + " days");
|
|
|
|
if (hours > 0)
|
|
|
|
ary.push (hours + " hours");
|
|
|
|
if (minutes > 0)
|
|
|
|
ary.push (minutes + " minutes");
|
2001-12-06 03:45:29 +03:00
|
|
|
if (seconds > 0 || offset == 0)
|
2001-03-14 05:35:29 +03:00
|
|
|
ary.push (seconds + " seconds");
|
|
|
|
|
|
|
|
format = ary.join(", ");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
format = format.replace ("%d", days);
|
|
|
|
format = format.replace ("%h", hours);
|
|
|
|
format = format.replace ("%m", minutes);
|
|
|
|
format = format.replace ("%s", seconds);
|
|
|
|
}
|
|
|
|
|
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
function arrayContains (ary, elem)
|
|
|
|
{
|
|
|
|
return (arrayIndexOf (ary, elem) != -1);
|
|
|
|
}
|
1999-09-06 21:09:47 +04:00
|
|
|
|
2001-03-14 05:35:29 +03:00
|
|
|
function arrayIndexOf (ary, elem)
|
|
|
|
{
|
|
|
|
for (var i in ary)
|
|
|
|
if (ary[i] == elem)
|
|
|
|
return i;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
function arrayInsertAt (ary, i, o)
|
|
|
|
{
|
|
|
|
|
1999-09-16 05:35:00 +04:00
|
|
|
ary.splice (i, 0, o);
|
|
|
|
|
|
|
|
/* doh, forgot about that 'splice' thing
|
1999-09-06 21:09:47 +04:00
|
|
|
if (ary.length < i)
|
|
|
|
{
|
|
|
|
this[i] = o;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var j = ary.length; j > i; j--)
|
|
|
|
ary[j] = ary[j - 1];
|
|
|
|
|
|
|
|
ary[i] = o;
|
1999-09-16 05:35:00 +04:00
|
|
|
*/
|
1999-09-06 21:09:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function arrayRemoveAt (ary, i)
|
|
|
|
{
|
|
|
|
|
1999-09-16 05:35:00 +04:00
|
|
|
ary.splice (i, 1);
|
|
|
|
|
|
|
|
/* doh, forgot about that 'splice' thing
|
1999-09-06 21:09:47 +04:00
|
|
|
if (ary.length < i)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (var j = i; j < ary.length; j++)
|
|
|
|
ary[j] = ary[j + 1];
|
|
|
|
|
|
|
|
ary.length--;
|
1999-09-16 05:35:00 +04:00
|
|
|
*/
|
1999-09-06 21:09:47 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2000-05-15 09:58:30 +04:00
|
|
|
/* length should be an even number >= 6 */
|
|
|
|
function abbreviateWord (str, length)
|
|
|
|
{
|
|
|
|
if (str.length <= length || length < 6)
|
|
|
|
return str;
|
|
|
|
|
|
|
|
var left = str.substr (0, (length / 2) - 1);
|
|
|
|
var right = str.substr (str.length - (length / 2) + 1);
|
|
|
|
|
|
|
|
return left + "..." + right;
|
|
|
|
}
|
|
|
|
|
2001-03-14 05:35:29 +03:00
|
|
|
/*
|
|
|
|
* Inserts the string |hyphen| into string |str| every |pos| characters.
|
|
|
|
* If there are any wordbreaking characters in |str| within -/+5 characters of
|
|
|
|
* of a |pos| then the hyphen is inserted there instead, in order to produce a
|
|
|
|
* "cleaner" break.
|
|
|
|
*/
|
|
|
|
function hyphenateWord (str, pos, hyphen)
|
2000-06-01 09:31:04 +04:00
|
|
|
{
|
2001-03-14 05:35:29 +03:00
|
|
|
if (str.length <= pos)
|
|
|
|
return str;
|
2000-06-01 09:31:04 +04:00
|
|
|
if (typeof hyphen == "undefined")
|
|
|
|
hyphen = " ";
|
|
|
|
|
2001-03-14 05:35:29 +03:00
|
|
|
/* search for a nice place to break the word, fuzzfactor of +/-5, centered
|
|
|
|
* around |pos| */
|
|
|
|
var splitPos =
|
|
|
|
str.substring(pos - 5, pos + 5).search(/[^A-Za-z0-9]/);
|
|
|
|
|
|
|
|
splitPos = (splitPos != -1) ? pos - 4 + splitPos : pos;
|
|
|
|
var left = str.substr (0, splitPos);
|
|
|
|
var right = hyphenateWord(str.substr (splitPos), pos, hyphen);
|
2000-06-01 09:31:04 +04:00
|
|
|
|
|
|
|
return left + hyphen + right;
|
|
|
|
}
|
|
|
|
|
2001-03-14 05:35:29 +03:00
|
|
|
/*
|
|
|
|
* Like hyphenateWord, except individual chunks of the word are returned as
|
|
|
|
* elements of an array.
|
|
|
|
*/
|
|
|
|
function splitLongWord (str, pos)
|
|
|
|
{
|
|
|
|
if (str.length <= pos)
|
|
|
|
return [str];
|
|
|
|
|
|
|
|
var ary = new Array();
|
|
|
|
var right = str;
|
|
|
|
|
|
|
|
while (right.length > pos)
|
|
|
|
{
|
|
|
|
/* search for a nice place to break the word, fuzzfactor of +/-5,
|
|
|
|
* centered around |pos| */
|
|
|
|
var splitPos =
|
|
|
|
right.substring(pos - 5, pos + 5).search(/[^A-Za-z0-9]/);
|
|
|
|
|
|
|
|
splitPos = (splitPos != -1) ? pos - 4 + splitPos : pos;
|
|
|
|
ary.push(right.substr (0, splitPos));
|
|
|
|
right = right.substr (splitPos);
|
|
|
|
}
|
|
|
|
|
|
|
|
ary.push (right);
|
|
|
|
|
|
|
|
return ary;
|
|
|
|
}
|
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
function getRandomElement (ary)
|
|
|
|
{
|
|
|
|
var i = parseInt (Math.random() * ary.length)
|
|
|
|
if (i == ary.length) i = 0;
|
|
|
|
|
|
|
|
return ary[i];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function roundTo (num, prec)
|
|
|
|
{
|
|
|
|
|
2001-08-24 00:33:24 +04:00
|
|
|
return parseInt (Math.round(num * Math.pow (10, prec))) /
|
1999-09-06 21:09:47 +04:00
|
|
|
Math.pow (10, prec);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function randomRange (min, max)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (typeof min == "undefined")
|
|
|
|
min = 0;
|
|
|
|
|
|
|
|
if (typeof max == "undefined")
|
|
|
|
max = 1;
|
|
|
|
|
|
|
|
var rv = (parseInt(Math.round((Math.random() * (max - min)) + min )));
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-10-10 01:26:52 +04:00
|
|
|
function getStackTrace ()
|
|
|
|
{
|
|
|
|
|
|
|
|
if (!jsenv.HAS_XPCOM)
|
|
|
|
return "No stack trace available.";
|
|
|
|
|
|
|
|
var frame = Components.stack.caller;
|
|
|
|
var str = "<top>";
|
|
|
|
|
|
|
|
while (frame)
|
|
|
|
{
|
2001-08-24 00:33:24 +04:00
|
|
|
var name = frame.name ? frame.name : "[anonymous]";
|
1999-10-10 01:26:52 +04:00
|
|
|
str += "\n" + name + "@" + frame.lineNumber;
|
|
|
|
frame = frame.caller;
|
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
function getInterfaces (cls)
|
|
|
|
{
|
1999-09-16 05:35:00 +04:00
|
|
|
if (!jsenv.HAS_XPCOM)
|
1999-12-05 06:47:18 +03:00
|
|
|
return null;
|
1999-09-16 05:35:00 +04:00
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
var rv = new Object();
|
|
|
|
var e;
|
|
|
|
|
|
|
|
for (var i in Components.interfaces)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var ifc = Components.interfaces[i];
|
|
|
|
cls.QueryInterface(ifc);
|
|
|
|
rv[i] = ifc;
|
|
|
|
}
|
|
|
|
catch (e)
|
|
|
|
{
|
|
|
|
/* nada */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
}
|
-- CHATZILLA CHANGES ONLY --
checking in patch from Josh Gough, <exv@randomc.com>
muchas gracias!
irc.js
add whois, invite
utils.js
added map and mapObjFunc
chatzilla.xul
add cntxt menu for userlist
commands.js
hook up /away, op, deop, voice, devoice, echo, invite, and kick commands
hadlers.js
onload hack
whois, away, deop, op, voice, devoice, echo, invite, kick command implementations
static.js
more of the onload hack
addEventListener on toolbuttons
listbox.js
selection code
chatzilla.css
selicted list item style
2000-04-24 04:40:56 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls a named function for each element in an array, sending
|
|
|
|
* the same parameter each call.
|
|
|
|
*
|
|
|
|
* @param ary an array of objects
|
|
|
|
* @param func_name string name of function to call.
|
|
|
|
* @param data data object to pass to each object.
|
|
|
|
*/
|
|
|
|
function mapObjFunc(ary, func_name, data)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* WARNING: Caller assumes resonsibility to verify ary
|
|
|
|
* and func_name
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (var i in ary)
|
|
|
|
ary[i][func_name](data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Passes each element of an array to a given function object.
|
|
|
|
*
|
|
|
|
* @param func a function object.
|
|
|
|
* @param ary an array of values.
|
|
|
|
*/
|
|
|
|
function map(func, ary) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* WARNING: Caller assumnes responsibility to verify
|
|
|
|
* func and ary.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (var i in ary)
|
|
|
|
func(ary[i]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|