1999-09-06 21:09:47 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
2004-04-19 02:14:17 +04:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-11-06 06:43:54 +03:00
|
|
|
*
|
2004-04-19 02:14:17 +04: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/
|
1999-09-06 21:09:47 +04:00
|
|
|
*
|
2004-04-19 02:14:17 +04:00
|
|
|
* 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
|
|
|
*
|
2004-04-19 02:14:17 +04:00
|
|
|
* The Original Code is JSIRC Library.
|
1999-09-06 21:09:47 +04:00
|
|
|
*
|
2004-04-19 02:14:17 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* New Dimensions Consulting, Inc.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-09-06 21:09:47 +04:00
|
|
|
*
|
2004-04-19 02:14:17 +04:00
|
|
|
* Contributor(s):
|
|
|
|
* Robert Ginda, rginda@ndcico.com, original author
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-09-06 21:09:47 +04:00
|
|
|
|
2003-06-22 04:17:55 +04:00
|
|
|
var utils = new Object();
|
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
var DEBUG = true;
|
2004-12-20 01:52:37 +03:00
|
|
|
var dd, warn, TEST, ASSERT;
|
-- 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
|
|
|
|
2003-08-19 01:35:33 +04:00
|
|
|
if (DEBUG) {
|
|
|
|
var _dd_pfx = "";
|
|
|
|
var _dd_singleIndent = " ";
|
|
|
|
var _dd_indentLength = _dd_singleIndent.length;
|
|
|
|
var _dd_currentIndent = "";
|
|
|
|
var _dd_lastDumpWasOpen = false;
|
|
|
|
var _dd_timeStack = new Array();
|
|
|
|
var _dd_disableDepth = Number.MAX_VALUE;
|
|
|
|
var _dd_currentDepth = 0;
|
|
|
|
dd = function _dd(str) {
|
|
|
|
if (typeof str != "string") {
|
2003-09-24 04:49:09 +04:00
|
|
|
dump(str + "\n");
|
|
|
|
} else if (str == "") {
|
|
|
|
dump("<empty-string>\n");
|
2003-08-19 01:35:33 +04:00
|
|
|
} else if (str[str.length - 1] == "{") {
|
|
|
|
++_dd_currentDepth;
|
|
|
|
if (_dd_currentDepth >= _dd_disableDepth)
|
|
|
|
return;
|
|
|
|
if (str.indexOf("OFF") == 0)
|
|
|
|
_dd_disableDepth = _dd_currentDepth;
|
|
|
|
_dd_timeStack.push (new Date());
|
|
|
|
if (_dd_lastDumpWasOpen)
|
|
|
|
dump("\n");
|
|
|
|
dump (_dd_pfx + _dd_currentIndent + str);
|
|
|
|
_dd_currentIndent += _dd_singleIndent;
|
|
|
|
_dd_lastDumpWasOpen = true;
|
|
|
|
} else if (str[0] == "}") {
|
|
|
|
if (--_dd_currentDepth >= _dd_disableDepth)
|
|
|
|
return;
|
|
|
|
_dd_disableDepth = Number.MAX_VALUE;
|
|
|
|
var sufx = (new Date() - _dd_timeStack.pop()) / 1000 + " sec";
|
2004-09-15 22:39:16 +04:00
|
|
|
_dd_currentIndent =
|
2003-08-19 01:35:33 +04:00
|
|
|
_dd_currentIndent.substr(0, _dd_currentIndent.length -
|
|
|
|
_dd_indentLength);
|
|
|
|
if (_dd_lastDumpWasOpen)
|
|
|
|
dump(str + " " + sufx + "\n");
|
|
|
|
else
|
|
|
|
dump(_dd_pfx + _dd_currentIndent + str + " " +
|
|
|
|
sufx + "\n");
|
|
|
|
_dd_lastDumpWasOpen = false;
|
|
|
|
} else {
|
|
|
|
if (_dd_currentDepth >= _dd_disableDepth)
|
|
|
|
return;
|
|
|
|
if (_dd_lastDumpWasOpen)
|
|
|
|
dump("\n");
|
|
|
|
dump(_dd_pfx + _dd_currentIndent + str + "\n");
|
|
|
|
_dd_lastDumpWasOpen = false;
|
2004-09-15 22:39:16 +04:00
|
|
|
}
|
2003-08-19 01:35:33 +04:00
|
|
|
}
|
2004-12-20 01:52:37 +03:00
|
|
|
warn = function (msg) { dd("** WARNING " + msg + " **"); }
|
|
|
|
TEST = ASSERT = function _assert(expr, msg) {
|
|
|
|
if (!expr) {
|
|
|
|
var m = "** ASSERTION FAILED: " + msg + " **\n" +
|
|
|
|
getStackTrace();
|
|
|
|
try {
|
|
|
|
alert(m);
|
|
|
|
} catch(ex) {}
|
|
|
|
dd(m);
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2003-08-19 01:35:33 +04:00
|
|
|
} else {
|
2004-12-20 01:52:37 +03:00
|
|
|
dd = warn = TEST = ASSERT = function (){};
|
2003-08-19 01:35:33 +04:00
|
|
|
}
|
1999-09-06 21:09:47 +04:00
|
|
|
|
|
|
|
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;
|
2003-01-22 08:49:52 +03:00
|
|
|
jsenv.HAS_STREAM_PROVIDER = ("nsIStreamProvider" in Components.interfaces);
|
Bug 243629 - Landing of ChatZilla 0.9.63.
Lots of bugs fixed, including: 226223, 230328, 127662, 185729, 226410, 231150, 235650, 238551, 238716, 73257, 226408, 238612, 108087, 180577, 211461, 218070, 242381
and 147452.
r=samuel@sieb.net
2004-06-09 07:33:50 +04:00
|
|
|
jsenv.HAS_SERVER_SOCKETS = ("nsIServerSocket" in Components.interfaces);
|
1999-09-06 21:09:47 +04:00
|
|
|
|
|
|
|
function dumpObject (o, pfx, sep)
|
|
|
|
{
|
|
|
|
var p;
|
|
|
|
var s = "";
|
|
|
|
|
|
|
|
sep = (typeof sep == "undefined") ? " = " : sep;
|
2004-09-15 22:39:16 +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;
|
2004-09-15 22:39:16 +04:00
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
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;
|
2004-09-15 22:39:16 +04:00
|
|
|
|
2001-08-24 00:33:24 +04:00
|
|
|
try
|
|
|
|
{
|
|
|
|
t = typeof o[i];
|
|
|
|
}
|
|
|
|
catch (ex)
|
|
|
|
{
|
|
|
|
t = "ERROR";
|
|
|
|
}
|
2004-09-15 22:39:16 +04:00
|
|
|
|
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":
|
2003-10-22 03:47:35 +04:00
|
|
|
s += pfx + tee + i + " (object)";
|
|
|
|
if (o[i] == null)
|
|
|
|
{
|
|
|
|
s += " null\n";
|
|
|
|
break;
|
|
|
|
}
|
2004-09-15 22:39:16 +04:00
|
|
|
|
2003-10-22 03:47:35 +04:00
|
|
|
s += "\n";
|
2004-09-15 22:39:16 +04:00
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
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)
|
2004-09-15 22:39:16 +04:00
|
|
|
s += pfx + tee + i + " (" + t + ") " +
|
1999-09-06 21:09:47 +04:00
|
|
|
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;
|
2004-09-15 22:39:16 +04:00
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
default:
|
|
|
|
s += pfx + tee + i + " (" + t + ") " + o[i] + "\n";
|
2004-09-15 22:39:16 +04:00
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!compress)
|
|
|
|
s += pfx + "|\n";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
s += pfx + "*\n";
|
2004-09-15 22:39:16 +04:00
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
return s;
|
2004-09-15 22:39:16 +04:00
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
}
|
|
|
|
|
2003-10-11 04:21:05 +04:00
|
|
|
function ecmaEscape(str)
|
|
|
|
{
|
|
|
|
function replaceNonPrintables(ch)
|
|
|
|
{
|
2004-01-23 09:37:07 +03:00
|
|
|
var rv = ch.charCodeAt().toString(16);
|
2003-10-11 04:21:05 +04:00
|
|
|
if (rv.length == 1)
|
|
|
|
rv = "0" + rv;
|
|
|
|
else if (rv.length == 3)
|
|
|
|
rv = "u0" + rv;
|
|
|
|
else if (rv.length == 4)
|
|
|
|
rv = "u" + rv;
|
2004-09-15 22:39:16 +04:00
|
|
|
|
2003-10-11 04:21:05 +04:00
|
|
|
return "%" + rv;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Replace any character that is not in the 69 character set
|
|
|
|
// [ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@*_+-./]
|
|
|
|
// with an escape sequence. Two digit sequences in the form %XX are used
|
|
|
|
// for characters whose codepoint is less than 255, %uXXXX for all others.
|
|
|
|
// See section B.2.1 of ECMA-262 rev3 for more information.
|
|
|
|
return str.replace(/[^A-Za-z0-9@*_+.\-\/]/g, replaceNonPrintables);
|
|
|
|
}
|
|
|
|
|
|
|
|
function ecmaUnescape(str)
|
|
|
|
{
|
|
|
|
function replaceEscapes(seq)
|
|
|
|
{
|
2005-01-31 20:24:51 +03:00
|
|
|
var ary = seq.match(/([\da-f]{1,2})(.*)|u([\da-f]{1,4})/i);
|
2003-10-11 04:21:05 +04:00
|
|
|
if (!ary)
|
|
|
|
return "<ERROR>";
|
|
|
|
|
2004-01-23 09:37:07 +03:00
|
|
|
var rv;
|
2003-10-11 04:21:05 +04:00
|
|
|
if (ary[1])
|
|
|
|
{
|
|
|
|
// two digit escape, possibly with cruft after
|
|
|
|
rv = String.fromCharCode(parseInt(ary[1], 16)) + ary[2];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// four digits, no cruft
|
|
|
|
rv = String.fromCharCode(parseInt(ary[3], 16));
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Replace the escape sequences %X, %XX, %uX, %uXX, %uXXX, and %uXXXX with
|
|
|
|
// the characters they represent, where X is a hexadecimal digit.
|
|
|
|
// See section B.2.2 of ECMA-262 rev3 for more information.
|
|
|
|
return str.replace(/%u?([\da-f]{1,4})/ig, replaceEscapes);
|
|
|
|
}
|
|
|
|
|
2003-08-19 01:35:33 +04:00
|
|
|
function replaceVars(str, vars)
|
|
|
|
{
|
|
|
|
// replace "string $with a $variable", with
|
|
|
|
// "string " + vars["with"] + " with a " + vars["variable"]
|
|
|
|
|
|
|
|
function doReplace(symbol)
|
|
|
|
{
|
|
|
|
var name = symbol.substr(1);
|
|
|
|
if (name in vars)
|
|
|
|
return vars[name];
|
2004-09-15 22:39:16 +04:00
|
|
|
|
2003-08-19 01:35:33 +04:00
|
|
|
return "$" + name;
|
|
|
|
};
|
2004-09-15 22:39:16 +04:00
|
|
|
|
2003-08-19 01:35:33 +04:00
|
|
|
return str.replace(/(\$\w[\w\d\-]+)/g, doReplace);
|
|
|
|
}
|
2004-09-15 22:39:16 +04:00
|
|
|
|
2003-08-19 01:35:33 +04:00
|
|
|
function formatException (ex)
|
|
|
|
{
|
|
|
|
if (ex instanceof Error)
|
2004-09-15 22:39:16 +04:00
|
|
|
return getMsg (MSG_FMT_JSEXCEPTION, [ex.name, ex.message, ex.fileName,
|
2003-08-19 01:35:33 +04:00
|
|
|
ex.lineNumber]);
|
|
|
|
|
|
|
|
return String(ex);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2003-08-19 01:35:33 +04:00
|
|
|
var robj = new Object();
|
1999-10-10 01:26:52 +04:00
|
|
|
|
|
|
|
for (var p in obj)
|
|
|
|
robj[p] = obj[p];
|
|
|
|
|
|
|
|
return robj;
|
2004-09-15 22:39:16 +04:00
|
|
|
|
1999-10-10 01:26:52 +04:00
|
|
|
}
|
|
|
|
|
2003-08-19 01:35:33 +04:00
|
|
|
function Copy(source, dest, overwrite)
|
|
|
|
{
|
|
|
|
if (!dest)
|
|
|
|
dest = new Object();
|
2004-09-15 22:39:16 +04:00
|
|
|
|
2003-08-19 01:35:33 +04:00
|
|
|
for (var p in source)
|
|
|
|
{
|
|
|
|
if (overwrite || !(p in dest))
|
|
|
|
dest[p] = source[p];
|
|
|
|
}
|
2004-09-15 22:39:16 +04:00
|
|
|
|
2003-08-19 01:35:33 +04:00
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
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);
|
2004-09-15 22:39:16 +04:00
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
function _match (o, pattern)
|
|
|
|
{
|
2000-01-27 12:45:11 +03:00
|
|
|
if (pattern instanceof Function)
|
|
|
|
return pattern(o);
|
2004-09-15 22:39:16 +04:00
|
|
|
|
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] == "$")
|
2004-09-15 22:39:16 +04:00
|
|
|
val = eval ("o." +
|
2000-01-27 12:45:11 +03:00
|
|
|
p.substr(1,p.length).replace (/\$/g, "."));
|
|
|
|
else
|
|
|
|
*/
|
|
|
|
val = o[p];
|
2004-09-15 22:39:16 +04:00
|
|
|
|
2000-01-27 12:45:11 +03:00
|
|
|
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));
|
2004-09-15 22:39:16 +04:00
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
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;
|
2004-09-15 22:39:16 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function utils_lcfn(text)
|
|
|
|
{
|
|
|
|
return text.toLowerCase();
|
1999-09-06 21:09:47 +04:00
|
|
|
}
|
|
|
|
|
2004-09-15 22:39:16 +04:00
|
|
|
function matchEntry (partialName, list, lcFn)
|
2000-05-11 02:23:35 +04:00
|
|
|
{
|
2004-09-15 22:39:16 +04:00
|
|
|
|
2000-05-11 02:23:35 +04:00
|
|
|
if ((typeof partialName == "undefined") ||
|
|
|
|
(String(partialName) == ""))
|
2004-09-15 22:39:16 +04:00
|
|
|
{
|
|
|
|
var ary = new Array();
|
|
|
|
for (var i in list)
|
|
|
|
ary.push(i);
|
|
|
|
return ary;
|
|
|
|
}
|
2000-05-11 02:23:35 +04:00
|
|
|
|
2004-09-15 22:39:16 +04:00
|
|
|
if (typeof lcFn != "function")
|
|
|
|
lcFn = utils_lcfn;
|
2000-05-11 02:23:35 +04:00
|
|
|
|
2004-09-15 22:39:16 +04:00
|
|
|
ary = new Array();
|
|
|
|
|
|
|
|
for (i in list)
|
2000-05-11 02:23:35 +04:00
|
|
|
{
|
2004-09-15 22:39:16 +04:00
|
|
|
if (lcFn(list[i]).indexOf(lcFn(partialName)) == 0)
|
|
|
|
ary.push(i);
|
2000-05-11 02:23:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return ary;
|
2004-09-15 22:39:16 +04:00
|
|
|
|
2000-05-11 02:23:35 +04:00
|
|
|
}
|
|
|
|
|
2003-08-19 01:35:33 +04:00
|
|
|
function encodeChar(ch)
|
|
|
|
{
|
|
|
|
return "%" + ch.charCodeAt(0).toString(16);
|
|
|
|
}
|
|
|
|
|
|
|
|
function escapeFileName(fileName)
|
|
|
|
{
|
Bug 243629 - Landing of ChatZilla 0.9.63.
Lots of bugs fixed, including: 226223, 230328, 127662, 185729, 226410, 231150, 235650, 238551, 238716, 73257, 226408, 238612, 108087, 180577, 211461, 218070, 242381
and 147452.
r=samuel@sieb.net
2004-06-09 07:33:50 +04:00
|
|
|
return fileName.replace(/[^\w\d.,#\-_%]/g, encodeChar);
|
2003-08-19 01:35:33 +04:00
|
|
|
}
|
|
|
|
|
2004-09-15 22:39:16 +04:00
|
|
|
function getCommonPfx (list, lcFn)
|
2000-05-11 02:23:35 +04:00
|
|
|
{
|
|
|
|
var pfx = list[0];
|
|
|
|
var l = list.length;
|
2004-09-15 22:39:16 +04:00
|
|
|
|
|
|
|
if (typeof lcFn != "function")
|
|
|
|
lcFn = utils_lcfn;
|
|
|
|
|
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)
|
|
|
|
{
|
2004-09-15 22:39:16 +04:00
|
|
|
pfx = pfx.substr(0, c);
|
2001-12-04 03:20:48 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-09-15 22:39:16 +04:00
|
|
|
if (lcFn(pfx[c]) != lcFn(list[i][c]))
|
|
|
|
pfx = pfx.substr(0, c);
|
2001-12-04 03:20:48 +03:00
|
|
|
}
|
|
|
|
}
|
2000-05-11 02:23:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return pfx;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-08-19 01:35:33 +04:00
|
|
|
function openTopWin (url)
|
|
|
|
{
|
|
|
|
return openDialog (getBrowserURL(), "_blank", "chrome,all,dialog=no", url);
|
|
|
|
}
|
2004-09-15 22:39:16 +04:00
|
|
|
|
2003-08-19 01:35:33 +04:00
|
|
|
function getWindowByType (windowType)
|
|
|
|
{
|
|
|
|
const MEDIATOR_CONTRACTID =
|
|
|
|
"@mozilla.org/appshell/window-mediator;1";
|
|
|
|
const nsIWindowMediator = Components.interfaces.nsIWindowMediator;
|
|
|
|
|
|
|
|
var windowManager =
|
|
|
|
Components.classes[MEDIATOR_CONTRACTID].getService(nsIWindowMediator);
|
|
|
|
|
|
|
|
return windowManager.getMostRecentWindow(windowType);
|
|
|
|
}
|
|
|
|
|
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;
|
2004-09-15 22:39:16 +04:00
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
obj[newname] = obj[oldname];
|
|
|
|
delete obj[oldname];
|
2004-09-15 22:39:16 +04:00
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
var rv;
|
2004-10-24 23:31:38 +04:00
|
|
|
var cls = Components.classes[contractID];
|
|
|
|
|
|
|
|
if (!cls)
|
|
|
|
return null;
|
1999-09-06 21:09:47 +04:00
|
|
|
|
|
|
|
switch (typeof iface)
|
|
|
|
{
|
2004-10-24 23:31:38 +04:00
|
|
|
case "undefined":
|
|
|
|
rv = cls.createInstance();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "string":
|
|
|
|
rv = cls.createInstance(Components.interfaces[iface]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "object":
|
|
|
|
rv = cls.createInstance(iface);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rv = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function getService(contractID, iface)
|
|
|
|
{
|
|
|
|
if (!jsenv.HAS_XPCOM)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
var rv;
|
|
|
|
var cls = Components.classes[contractID];
|
|
|
|
|
|
|
|
if (!cls)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
switch (typeof iface)
|
|
|
|
{
|
|
|
|
case "undefined":
|
|
|
|
rv = cls.getService();
|
|
|
|
break;
|
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
case "string":
|
2004-10-24 23:31:38 +04:00
|
|
|
rv = cls.getService(Components.interfaces[iface]);
|
1999-09-06 21:09:47 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case "object":
|
2004-10-24 23:31:38 +04:00
|
|
|
rv = cls.getService(iface);
|
1999-09-06 21:09:47 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rv = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
2004-09-15 22:39:16 +04:00
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
}
|
|
|
|
|
2003-08-19 01:35:33 +04:00
|
|
|
function getContentWindow(frame)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (!frame || !("contentWindow" in frame))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return frame.contentWindow;
|
|
|
|
}
|
|
|
|
catch (ex)
|
|
|
|
{
|
|
|
|
// throws exception is contentWindow is gone
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2004-09-15 22:39:16 +04:00
|
|
|
|
2000-01-16 08:07:01 +03:00
|
|
|
return rv;
|
2004-09-15 22:39:16 +04:00
|
|
|
|
2000-01-16 08:07:01 +03:00
|
|
|
}
|
|
|
|
|
2003-08-19 01:35:33 +04:00
|
|
|
function len(o)
|
|
|
|
{
|
|
|
|
var l = 0;
|
2004-09-15 22:39:16 +04:00
|
|
|
|
2003-08-19 01:35:33 +04:00
|
|
|
for (var p in o)
|
|
|
|
++l;
|
2004-09-15 22:39:16 +04:00
|
|
|
|
2003-08-19 01:35:33 +04:00
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
function keys (o)
|
|
|
|
{
|
2001-03-14 05:35:29 +03:00
|
|
|
var rv = new Array();
|
2004-09-15 22:39:16 +04:00
|
|
|
|
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;
|
2004-09-15 22:39:16 +04:00
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function stringTrim (s)
|
|
|
|
{
|
|
|
|
if (!s)
|
|
|
|
return "";
|
1999-10-10 01:26:52 +04:00
|
|
|
s = s.replace (/^\s+/, "");
|
|
|
|
return s.replace (/\s+$/, "");
|
2004-09-15 22:39:16 +04:00
|
|
|
|
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
|
|
|
{
|
2002-07-19 09:53:27 +04:00
|
|
|
var seconds = roundTo(offset % 60, 2);
|
2003-04-22 04:34:03 +04:00
|
|
|
var minutes = Math.floor(offset / 60);
|
|
|
|
var hours = Math.floor(minutes / 60);
|
2001-03-14 05:35:29 +03:00
|
|
|
minutes = minutes % 60;
|
2003-04-22 04:34:03 +04:00
|
|
|
var days = Math.floor(hours / 24);
|
2001-03-14 05:35:29 +03:00
|
|
|
hours = hours % 24;
|
|
|
|
|
|
|
|
if (!format)
|
|
|
|
{
|
|
|
|
var ary = new Array();
|
|
|
|
if (days > 0)
|
2003-08-19 01:35:33 +04:00
|
|
|
ary.push (getMsg(MSG_DAYS, days));
|
2001-03-14 05:35:29 +03:00
|
|
|
if (hours > 0)
|
2003-08-19 01:35:33 +04:00
|
|
|
ary.push (getMsg(MSG_HOURS, hours));
|
2001-03-14 05:35:29 +03:00
|
|
|
if (minutes > 0)
|
2003-08-19 01:35:33 +04:00
|
|
|
ary.push (getMsg(MSG_MINUTES, minutes));
|
2001-12-06 03:45:29 +03:00
|
|
|
if (seconds > 0 || offset == 0)
|
2003-08-19 01:35:33 +04:00
|
|
|
ary.push (getMsg(MSG_SECONDS, seconds));
|
2001-03-14 05:35:29 +03:00
|
|
|
|
|
|
|
format = ary.join(", ");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
format = format.replace ("%d", days);
|
|
|
|
format = format.replace ("%h", hours);
|
|
|
|
format = format.replace ("%m", minutes);
|
|
|
|
format = format.replace ("%s", seconds);
|
|
|
|
}
|
2004-09-15 22:39:16 +04:00
|
|
|
|
2001-03-14 05:35:29 +03:00
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
2003-10-24 22:29:35 +04:00
|
|
|
function arrayHasElementAt(ary, i)
|
|
|
|
{
|
|
|
|
return typeof ary[i] != "undefined";
|
|
|
|
}
|
|
|
|
|
2001-03-14 05:35:29 +03:00
|
|
|
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;
|
|
|
|
}
|
2004-09-15 22:39:16 +04:00
|
|
|
|
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);
|
1999-09-06 21:09:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function arrayRemoveAt (ary, i)
|
|
|
|
{
|
1999-09-16 05:35:00 +04:00
|
|
|
ary.splice (i, 1);
|
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;
|
2004-09-15 22:39:16 +04:00
|
|
|
|
2001-03-14 05:35:29 +03:00
|
|
|
while (right.length > pos)
|
|
|
|
{
|
2004-09-15 22:39:16 +04:00
|
|
|
/* search for a nice place to break the word, fuzzfactor of +/-5,
|
2001-03-14 05:35:29 +03:00
|
|
|
* 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)
|
|
|
|
{
|
|
|
|
|
2002-02-13 03:11:57 +03:00
|
|
|
return ary[Math.floor(Math.random() * ary.length)];
|
1999-09-06 21:09:47 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function roundTo (num, prec)
|
|
|
|
{
|
|
|
|
|
2004-09-15 22:39:16 +04:00
|
|
|
return Math.round(num * Math.pow (10, prec)) / Math.pow (10, prec);
|
1999-09-06 21:09:47 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function randomRange (min, max)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (typeof min == "undefined")
|
|
|
|
min = 0;
|
|
|
|
|
|
|
|
if (typeof max == "undefined")
|
|
|
|
max = 1;
|
|
|
|
|
2002-02-13 03:11:57 +03:00
|
|
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
1999-09-06 21:09:47 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
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;
|
2004-09-15 22:39:16 +04:00
|
|
|
|
1999-10-10 01:26:52 +04:00
|
|
|
}
|
|
|
|
|
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;
|
2004-09-15 22:39:16 +04:00
|
|
|
|
1999-09-06 21:09:47 +04:00
|
|
|
}
|
-- 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.
|
2004-09-15 22:39:16 +04:00
|
|
|
*/
|
-- 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
|
|
|
function mapObjFunc(ary, func_name, data)
|
|
|
|
{
|
2004-09-15 22:39:16 +04:00
|
|
|
/*
|
-- 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
|
|
|
* 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]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-06-22 04:17:55 +04:00
|
|
|
function getSpecialDirectory(name)
|
|
|
|
{
|
|
|
|
if (!("directoryService" in utils))
|
|
|
|
{
|
|
|
|
const DS_CTR = "@mozilla.org/file/directory_service;1";
|
|
|
|
const nsIProperties = Components.interfaces.nsIProperties;
|
|
|
|
|
|
|
|
utils.directoryService =
|
|
|
|
Components.classes[DS_CTR].getService(nsIProperties);
|
|
|
|
}
|
|
|
|
|
|
|
|
return utils.directoryService.get(name, Components.interfaces.nsIFile);
|
|
|
|
}
|
|
|
|
|
2003-08-19 01:35:33 +04:00
|
|
|
function getFileFromURLSpec(url)
|
2003-06-22 04:17:55 +04:00
|
|
|
{
|
2003-08-19 01:35:33 +04:00
|
|
|
const nsIFileProtocolHandler = Components.interfaces.nsIFileProtocolHandler;
|
2004-09-15 22:39:16 +04:00
|
|
|
|
2004-10-24 23:31:38 +04:00
|
|
|
var service = getService("@mozilla.org/network/io-service;1",
|
|
|
|
"nsIIOService");
|
2004-12-31 00:15:06 +03:00
|
|
|
|
|
|
|
/* In sept 2002, bug 166792 moved this method to the nsIFileProtocolHandler
|
|
|
|
* interface, but we need to support older versions too. */
|
|
|
|
if ("getFileFromURLSpec" in service)
|
|
|
|
return service.getFileFromURLSpec(url);
|
|
|
|
|
|
|
|
/* In builds before 2002-08-15, there is no getFileFromURLSpec at all.
|
|
|
|
* Instead, we have nsIIOservice.initFileFromURLSpec(nsIFile, string).
|
|
|
|
*/
|
|
|
|
if ("initFileFromURLSpec" in service)
|
|
|
|
{
|
|
|
|
var file = newObject("@mozilla.org/file/local;1", "nsILocalFile");
|
|
|
|
service.initFileFromURLSpec(file, url);
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
2004-10-24 23:31:38 +04:00
|
|
|
var handler = service.getProtocolHandler("file");
|
2003-08-19 01:35:33 +04:00
|
|
|
handler = handler.QueryInterface(nsIFileProtocolHandler);
|
|
|
|
return handler.getFileFromURLSpec(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getURLSpecFromFile (file)
|
|
|
|
{
|
|
|
|
if (!file)
|
|
|
|
return null;
|
|
|
|
|
|
|
|
const IOS_CTRID = "@mozilla.org/network/io-service;1";
|
|
|
|
const LOCALFILE_CTRID = "@mozilla.org/file/local;1";
|
|
|
|
|
|
|
|
const nsIIOService = Components.interfaces.nsIIOService;
|
|
|
|
const nsILocalFile = Components.interfaces.nsILocalFile;
|
2004-09-15 22:39:16 +04:00
|
|
|
|
2003-08-19 01:35:33 +04:00
|
|
|
if (typeof file == "string")
|
|
|
|
{
|
|
|
|
var fileObj =
|
|
|
|
Components.classes[LOCALFILE_CTRID].createInstance(nsILocalFile);
|
|
|
|
fileObj.initWithPath(file);
|
|
|
|
file = fileObj;
|
|
|
|
}
|
2004-09-15 22:39:16 +04:00
|
|
|
|
2003-08-19 01:35:33 +04:00
|
|
|
var service = Components.classes[IOS_CTRID].getService(nsIIOService);
|
|
|
|
/* In sept 2002, bug 166792 moved this method to the nsIFileProtocolHandler
|
|
|
|
* interface, but we need to support older versions too. */
|
|
|
|
if ("getURLSpecFromFile" in service)
|
|
|
|
return service.getURLSpecFromFile(file);
|
|
|
|
|
|
|
|
var nsIFileProtocolHandler = Components.interfaces.nsIFileProtocolHandler;
|
|
|
|
var fileHandler = service.getProtocolHandler("file");
|
|
|
|
fileHandler = fileHandler.QueryInterface(nsIFileProtocolHandler);
|
|
|
|
return fileHandler.getURLSpecFromFile(file);
|
2003-06-22 04:17:55 +04:00
|
|
|
}
|
2003-10-11 04:21:05 +04:00
|
|
|
|
|
|
|
function alert(msg, parent, title)
|
|
|
|
{
|
|
|
|
var PROMPT_CTRID = "@mozilla.org/embedcomp/prompt-service;1";
|
|
|
|
var nsIPromptService = Components.interfaces.nsIPromptService;
|
2004-03-10 02:34:18 +03:00
|
|
|
var ps = Components.classes[PROMPT_CTRID].getService(nsIPromptService);
|
2003-10-11 04:21:05 +04:00
|
|
|
if (!parent)
|
|
|
|
parent = window;
|
|
|
|
if (!title)
|
|
|
|
title = MSG_ALERT;
|
|
|
|
ps.alert (parent, title, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
function confirm(msg, parent, title)
|
|
|
|
{
|
|
|
|
var PROMPT_CTRID = "@mozilla.org/embedcomp/prompt-service;1";
|
|
|
|
var nsIPromptService = Components.interfaces.nsIPromptService;
|
2004-03-10 02:34:18 +03:00
|
|
|
var ps = Components.classes[PROMPT_CTRID].getService(nsIPromptService);
|
2003-10-11 04:21:05 +04:00
|
|
|
if (!parent)
|
|
|
|
parent = window;
|
|
|
|
if (!title)
|
|
|
|
title = MSG_CONFIRM;
|
|
|
|
return ps.confirm (parent, title, msg);
|
|
|
|
}
|
|
|
|
|
2005-02-27 01:19:46 +03:00
|
|
|
function confirmEx(msg, buttons, defaultButton, checkText,
|
|
|
|
checkVal, parent, title)
|
|
|
|
{
|
|
|
|
/* Note that on versions before Mozilla 0.9, using 3 buttons,
|
|
|
|
* the revert or dontsave button, or custom button titles will NOT work.
|
|
|
|
*
|
|
|
|
* The buttons should be listed in the 'accept', 'cancel' and 'extra' order,
|
|
|
|
* and the exact button order is host app- and platform-dependant.
|
|
|
|
* For example, on Windows this is usually [button 1] [button 3] [button 2],
|
|
|
|
* and on Linux [button 3] [button 2] [button 1].
|
|
|
|
*/
|
|
|
|
var PROMPT_CTRID = "@mozilla.org/embedcomp/prompt-service;1";
|
|
|
|
var nsIPromptService = Components.interfaces.nsIPromptService;
|
|
|
|
var ps = Components.classes[PROMPT_CTRID].getService(nsIPromptService);
|
|
|
|
|
|
|
|
var buttonConstants = {
|
|
|
|
ok: ps.BUTTON_TITLE_OK,
|
|
|
|
cancel: ps.BUTTON_TITLE_CANCEL,
|
|
|
|
yes: ps.BUTTON_TITLE_YES,
|
|
|
|
no: ps.BUTTON_TITLE_NO,
|
|
|
|
save: ps.BUTTON_TITLE_SAVE,
|
|
|
|
revert: ps.BUTTON_TITLE_REVERT,
|
|
|
|
dontsave: ps.BUTTON_TITLE_DONT_SAVE
|
|
|
|
};
|
|
|
|
var buttonFlags = 0;
|
|
|
|
var buttonText = [null, null, null];
|
|
|
|
|
|
|
|
if (!isinstance(buttons, Array))
|
|
|
|
throw "buttons parameter must be an Array";
|
|
|
|
if ((buttons.length < 1) || (buttons.length > 3))
|
|
|
|
throw "the buttons array must have 1, 2 or 3 elements";
|
|
|
|
|
|
|
|
for (var i = 0; i < buttons.length; i++)
|
|
|
|
{
|
|
|
|
var buttonFlag = ps.BUTTON_TITLE_IS_STRING;
|
|
|
|
if ((buttons[i][0] == "!") && (buttons[i].substr(1) in buttonConstants))
|
|
|
|
buttonFlag = buttonConstants[buttons[i].substr(1)];
|
|
|
|
else
|
|
|
|
buttonText[i] = buttons[i];
|
|
|
|
|
|
|
|
buttonFlags += ps["BUTTON_POS_" + i] * buttonFlag;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore anything but a proper number
|
|
|
|
var defaultIsNumber = (typeof defaultButton == "number");
|
|
|
|
if (defaultIsNumber && arrayHasElementAt(buttons, defaultButton))
|
|
|
|
buttonFlags += ps["BUTTON_POS_" + defaultButton + "_DEFAULT"];
|
|
|
|
|
|
|
|
if (!parent)
|
|
|
|
parent = window;
|
|
|
|
if (!title)
|
|
|
|
title = MSG_CONFIRM;
|
|
|
|
if (!checkVal)
|
|
|
|
checkVal = new Object();
|
|
|
|
|
|
|
|
rv = ps.confirmEx(parent, title, msg, buttonFlags, buttonText[0],
|
|
|
|
buttonText[1], buttonText[2], checkText, checkVal);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2003-10-11 04:21:05 +04:00
|
|
|
function prompt(msg, initial, parent, title)
|
|
|
|
{
|
|
|
|
var PROMPT_CTRID = "@mozilla.org/embedcomp/prompt-service;1";
|
|
|
|
var nsIPromptService = Components.interfaces.nsIPromptService;
|
2004-03-10 02:34:18 +03:00
|
|
|
var ps = Components.classes[PROMPT_CTRID].getService(nsIPromptService);
|
2003-10-11 04:21:05 +04:00
|
|
|
if (!parent)
|
|
|
|
parent = window;
|
|
|
|
if (!title)
|
|
|
|
title = MSG_PROMPT;
|
|
|
|
rv = { value: initial };
|
|
|
|
|
|
|
|
if (!ps.prompt (parent, title, msg, rv, null, {value: null}))
|
|
|
|
return null;
|
|
|
|
|
2004-01-04 01:21:35 +03:00
|
|
|
return rv.value;
|
2003-10-11 04:21:05 +04:00
|
|
|
}
|
2003-11-19 01:39:26 +03:00
|
|
|
|
|
|
|
function promptPassword(msg, initial, parent, title)
|
|
|
|
{
|
|
|
|
var PROMPT_CTRID = "@mozilla.org/embedcomp/prompt-service;1";
|
|
|
|
var nsIPromptService = Components.interfaces.nsIPromptService;
|
2004-03-10 02:34:18 +03:00
|
|
|
var ps = Components.classes[PROMPT_CTRID].getService(nsIPromptService);
|
2003-11-19 01:39:26 +03:00
|
|
|
if (!parent)
|
|
|
|
parent = window;
|
|
|
|
if (!title)
|
|
|
|
title = MSG_PROMPT;
|
|
|
|
rv = { value: initial };
|
|
|
|
|
|
|
|
if (!ps.promptPassword (parent, title, msg, rv, null, {value: null}))
|
|
|
|
return null;
|
|
|
|
|
2004-01-04 01:21:35 +03:00
|
|
|
return rv.value;
|
2003-11-19 01:39:26 +03:00
|
|
|
}
|
2004-01-24 06:00:53 +03:00
|
|
|
|
|
|
|
function getHostmaskParts(hostmask)
|
|
|
|
{
|
|
|
|
var rv;
|
|
|
|
// A bit cheeky this, we try the matches here, and then branch
|
|
|
|
// according to the ones we like.
|
|
|
|
var ary1 = hostmask.match(/(\S*)!(\S*)@(.*)/);
|
|
|
|
var ary2 = hostmask.match(/(\S*)@(.*)/);
|
|
|
|
var ary3 = hostmask.match(/(\S*)!(.*)/);
|
|
|
|
if (ary1)
|
|
|
|
rv = { nick: ary1[1], user: ary1[2], host: ary1[3] };
|
|
|
|
else if (ary2)
|
|
|
|
rv = { nick: "*", user: ary2[1], host: ary2[2] };
|
|
|
|
else if (ary3)
|
|
|
|
rv = { nick: ary3[1], user: ary3[2], host: "*" };
|
|
|
|
else
|
|
|
|
rv = { nick: hostmask, user: "*", host: "*" };
|
|
|
|
// Make sure we got something for all fields.
|
|
|
|
if (!rv.nick)
|
|
|
|
rv.nick = "*";
|
|
|
|
if (!rv.user)
|
|
|
|
rv.user = "*";
|
|
|
|
if (!rv.host)
|
|
|
|
rv.host = "*";
|
|
|
|
// And re-construct the 'parsed' hostmask.
|
|
|
|
rv.mask = rv.nick + "!" + rv.user + "@" + rv.host;
|
|
|
|
return rv;
|
|
|
|
}
|
2004-09-15 22:39:16 +04:00
|
|
|
|
|
|
|
function isinstance(inst, base)
|
|
|
|
{
|
|
|
|
/* Returns |true| if |inst| was constructed by |base|. Not 100% accurate,
|
|
|
|
* but plenty good enough for us. This is to work around the fix for bug
|
|
|
|
* 254067 which makes instanceof fail if the two sides are 'from'
|
|
|
|
* different windows (something we don't care about).
|
|
|
|
*/
|
|
|
|
return (inst && inst.constructor && base &&
|
|
|
|
(inst.constructor.name == base.name));
|
|
|
|
}
|