* connection-rhino.js formatting changes. * connection-xpcom.js Necko-only implementation courtesy peter.vanderbeken@pandora.be. * irc.js Fixed bug in error message. * munger.js Added ability to temporarily disable all rules. * test3-handlers.js not-implemented placeholder function. hide, delete, and clear current view functions. munger-toggle function. * test3-static.js disable munger by default. fix rheet regex. deleteToolbutton function. * test3.xul xul hookup for new functions. git-svn-id: svn://10.0.0.236/trunk@57072 18797224-902f-48f8-a5cc-f745e15eee43
114 lines
3.2 KiB
JavaScript
114 lines
3.2 KiB
JavaScript
function CMungerEntry (name, regex, className, tagName)
|
|
{
|
|
|
|
this.name = name;
|
|
this.tagName = (tagName) ? tagName : "html:span";
|
|
|
|
if (regex instanceof RegExp)
|
|
this.regex = regex;
|
|
else
|
|
this.lambdaMatch = regex;
|
|
|
|
if (typeof className == "function")
|
|
this.lambdaReplace = className;
|
|
else
|
|
this.className = className;
|
|
|
|
}
|
|
|
|
function CMunger ()
|
|
{
|
|
|
|
this.entries = new Object();
|
|
|
|
}
|
|
|
|
CMunger.prototype.enabled = true;
|
|
|
|
CMunger.prototype.addRule =
|
|
function mng_addrule (name, regex, className)
|
|
{
|
|
|
|
this.entries[name] = new CMungerEntry (name, regex, className);
|
|
|
|
}
|
|
|
|
CMunger.prototype.delRule =
|
|
function mng_delrule (name)
|
|
{
|
|
|
|
delete this.entries[name];
|
|
|
|
}
|
|
|
|
CMunger.prototype.munge =
|
|
function mng_munge (text, containerTag, eventDetails)
|
|
{
|
|
var entry;
|
|
var ary;
|
|
|
|
if (!containerTag)
|
|
containerTag = document.createElement (tagName);
|
|
|
|
if (this.enabled)
|
|
{
|
|
for (entry in this.entries)
|
|
{
|
|
if (typeof this.entries[entry].lambdaMatch == "function")
|
|
{
|
|
var rval;
|
|
|
|
rval = this.entries[entry].lambdaMatch(text, containerTag,
|
|
eventDetails,
|
|
this.entries[entry]);
|
|
if (rval)
|
|
ary = [(void 0), rval];
|
|
else
|
|
ary = null;
|
|
}
|
|
else
|
|
ary = text.match(this.entries[entry].regex);
|
|
|
|
if ((ary != null) && (ary[1]))
|
|
{
|
|
var startPos = text.indexOf(ary[1]);
|
|
|
|
if (typeof this.entries[entry].lambdaReplace == "function")
|
|
{
|
|
this.munge (text.substr(0,startPos), containerTag,
|
|
eventDetails);
|
|
this.entries[entry].lambdaReplace (ary[1], containerTag,
|
|
eventDetails,
|
|
this.entries[entry]);
|
|
this.munge (text.substr (startPos + ary[1].length,
|
|
text.length), containerTag,
|
|
eventDetails);
|
|
|
|
return containerTag;
|
|
}
|
|
else
|
|
{
|
|
this.munge (text.substr(0,startPos), containerTag,
|
|
eventDetails);
|
|
|
|
var subTag = document.createElement
|
|
(this.entries[entry].tagName);
|
|
|
|
subTag.setAttribute ("class", this.entries[entry].className);
|
|
subTag.appendChild (document.createTextNode (ary[1]));
|
|
containerTag.appendChild (subTag);
|
|
this.munge (text.substr (startPos + ary[1].length,
|
|
text.length), containerTag,
|
|
eventDetails);
|
|
|
|
return containerTag;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
containerTag.appendChild (document.createTextNode (text));
|
|
return containerTag;
|
|
|
|
}
|