diff --git a/content/buffer.js b/content/buffer.js
index 94a408e1..d4cdb129 100644
--- a/content/buffer.js
+++ b/content/buffer.js
@@ -34,10 +34,10 @@ liberator.Buffer = function () //{{{
////////////////////// PRIVATE SECTION /////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////{{{
- const highlightClasses = ["Boolean", "ErrorMsg", "InfoMsg", "Keyword", "LineNr",
- "ModeMsg", "MoreMsg", "Normal", "Null", "Number", "Question", "StatusLine",
- "StatusLineBroken", "StatusLineSecure", "String", "Tag", "Title", "URL",
- "WarningMsg"];
+ const highlightClasses = ["Boolean", "ErrorMsg", "Function", "InfoMsg", "Keyword",
+ "LineNr", "ModeMsg", "MoreMsg", "Normal", "Null", "Number", "Question",
+ "StatusLine", "StatusLineBroken", "StatusLineSecure", "String", "Tag",
+ "Title", "URL", "WarningMsg"];
let name = liberator.config.name.toLowerCase();
const highlightDocs = "chrome://" + name + "/content/buffer.xhtml,chrome://browser/content/browser.xul";
@@ -927,7 +927,7 @@ liberator.Buffer = function () //{{{
nFeed++;
var type = feedTypes[feed.type] || feedTypes["application/rss+xml"];
if (verbose)
- yield [feed.title, liberator.util.highlightURL(feed.href, true) + ];
+ yield [feed.title, liberator.template.highlightURL(feed.href, true) + ];
}
}
}
@@ -982,11 +982,11 @@ liberator.Buffer = function () //{{{
}
yield ["Title", doc.title];
- yield ["URL", liberator.util.highlightURL(doc.location.toString(), true)];
+ yield ["URL", liberator.template.highlightURL(doc.location.toString(), true)];
var ref = "referrer" in doc && doc.referrer;
if (ref)
- yield ["Referrer", liberator.util.highlightURL(ref, true)];
+ yield ["Referrer", liberator.template.highlightURL(ref, true)];
if (pageSize[0])
yield ["File Size", pageSize[1] ? pageSize[1] + " (" + pageSize[0] + ")"
@@ -1004,7 +1004,7 @@ liberator.Buffer = function () //{{{
// get meta tag data, sort and put into pageMeta[]
var metaNodes = window.content.document.getElementsByTagName("meta");
- return Array.map(metaNodes, function (node) [(node.name || node.httpEquiv), liberator.util.highlightURL(node.content)])
+ return Array.map(metaNodes, function (node) [(node.name || node.httpEquiv), liberator.template.highlightURL(node.content)])
.sort(function (a, b) String.localeCompare(a[0].toLowerCase(), b[0].toLowerCase()));
});
@@ -1977,158 +1977,4 @@ liberator.Marks = function () //{{{
//}}}
}; //}}}
-liberator.template = {
- add: function (a, b) a + b,
- join: function (c) function (a, b) a + c + b,
-
- map: function (iter, fn, sep)
- {
- if (iter.length) /* Kludge? */
- iter = liberator.util.arrayIter(iter);
- let ret = <>>;
- let n = 0;
- for each (let i in iter)
- {
- let val = fn(i);
- if (val == undefined)
- continue;
- if (sep && n++)
- ret += sep;
- ret += val;
- }
- return ret;
- },
- map2: function (iter, fn, sep)
- {
- // Could cause performance problems.
- return this.map(Iterator(iter), function (x) fn.apply(null, x), sep);
- },
-
- maybeXML: function (xml)
- {
- if (typeof xml == "xml")
- return xml;
- try
- {
- return new XMLList(xml);
- }
- catch (e) {}
- return <>{xml}>;
- },
-
- generic: function (xml)
- {
- return <>:{liberator.commandline.getCommand()}
> + xml;
- },
-
- bookmarks: function (header, items)
- {
- return this.generic(
-
-
- | {header} | URL |
-
- {
- this.map(items, function (item)
-
- | {liberator.util.clip(item.title, 50)} |
-
- {item.url}
- {
- !(item.extra && item.extra.length) ? "" :
-
- }
- |
-
)
- }
-
);
- },
-
- jumps: function (index, elems)
- {
- return this.generic(
-
-
- | jump | title | URI |
-
- {
- this.map2(elems, function (idx, val)
-
- | {idx == index ? ">" : ""} |
- {Math.abs(idx - index)} |
- {val.title} |
- {val.URI.spec} |
-
)
- }
-
);
- },
-
- options: function (title, opts)
- {
- return this.generic(
-
-
- | --- {title} --- |
-
- {
- this.map(opts, function (opt)
-
- |
- {opt.pre}{opt.name}{opt.value}
- {opt.isDefault || opt.default == null ? "" : }
- |
-
)
- }
-
);
- },
-
- table: function (title, data, indent)
- {
- let table =
-
-
- | {title} |
-
- {
- this.map(data, function (datum)
-
- | {datum[0]} |
- {liberator.template.maybeXML(datum[1])} |
-
)
- }
-
;
- if (table.tr.length() > 1)
- return table;
- },
-
- tabular: function (headings, style, iter)
- {
- /* This might be mind-bogglingly slow. We'll see. */
- return this.generic(
-
-
- {
- this.map(headings, function (h)
- | {h} | )
- }
-
- {
- this.map(iter, function (row)
-
- {
- liberator.template.map2(row, function (i, d)
- | {d} | )
- }
-
)
- }
-
);
- },
-};
-
// vim: set fdm=marker sw=4 ts=4 et:
diff --git a/content/completion.js b/content/completion.js
index 4def5823..5b4cfe73 100644
--- a/content/completion.js
+++ b/content/completion.js
@@ -489,10 +489,12 @@ liberator.Completion = function () //{{{
if (!filter)
return [[a[0], a[1], favicon ? a[2] : null] for each (a in array)];
+ let result;
if (matchFromBeginning)
- return buildLongestStartingSubstring(array, filter, favicon);
+ result = buildLongestStartingSubstring(array, filter, favicon);
else
- return buildLongestCommonSubstring(array, filter, favicon);
+ result = buildLongestCommonSubstring(array, filter, favicon);
+ return result;
},
cached: function (key, filter, generate, method)
diff --git a/content/liberator.xul b/content/liberator.xul
index 5b751250..e5bb92d5 100644
--- a/content/liberator.xul
+++ b/content/liberator.xul
@@ -49,9 +49,10 @@ the terms of any one of the MPL, the GPL or the LGPL.
+
+
-
diff --git a/content/muttatorcompose.xul b/content/muttatorcompose.xul
index af932a59..9dd5f3ed 100644
--- a/content/muttatorcompose.xul
+++ b/content/muttatorcompose.xul
@@ -40,21 +40,22 @@ the terms of any one of the MPL, the GPL or the LGPL.
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
diff --git a/content/options.js b/content/options.js
index cb00a97e..a9edfc40 100644
--- a/content/options.js
+++ b/content/options.js
@@ -958,7 +958,7 @@ liberator.Options = function () //{{{
}
else
{
- option.value = <>={liberator.util.colorize(opt.value, false)}>;
+ option.value = <>={liberator.template.highlight(opt.value)}>;
}
yield option;
}
@@ -989,7 +989,7 @@ liberator.Options = function () //{{{
let option = {
isDefault: !userValue,
default: loadPreference(pref, null, true),
- value: <>={liberator.util.colorize(value, false)}>,
+ value: <>={liberator.template.highlight(value)}>,
name: pref,
pre: " ", /* Unicode nonbreaking space. */
};
diff --git a/content/template.js b/content/template.js
new file mode 100644
index 00000000..c0f65472
--- /dev/null
+++ b/content/template.js
@@ -0,0 +1,217 @@
+
+liberator.template = {
+ add: function (a, b) a + b,
+ join: function (c) function (a, b) a + c + b,
+
+ map: function (iter, fn, sep)
+ {
+ if (iter.length) /* Kludge? */
+ iter = liberator.util.arrayIter(iter);
+ let ret = <>>;
+ let n = 0;
+ for each (let i in iter)
+ {
+ let val = fn(i);
+ if (val == undefined)
+ continue;
+ if (sep && n++)
+ ret += sep;
+ ret += val;
+ }
+ return ret;
+ },
+ map2: function (iter, fn, sep)
+ {
+ // Could cause performance problems.
+ return this.map(Iterator(iter), function (x) fn.apply(null, x), sep);
+ },
+
+ maybeXML: function (xml)
+ {
+ if (typeof xml == "xml")
+ return xml;
+ try
+ {
+ return new XMLList(xml);
+ }
+ catch (e) {}
+ return <>{xml}>;
+ },
+
+ // if "processStrings" is true, any passed strings will be surrounded by " and
+ // any line breaks are displayed as \n
+ highlight: function (arg, processStrings)
+ {
+ // some objects like window.JSON or getBrowsers()._browsers need the try/catch
+ try
+ {
+ switch (arg == null ? "undefined" : typeof arg)
+ {
+ case "number":
+ return {arg};
+ case "string":
+ if (processStrings)
+ arg = <>{liberator.util.escapeString(arg)}>;
+ return {arg};
+ case "boolean":
+ return {arg};
+ case "function":
+ return {arg};
+ return {String(arg).replace(/\{(.|\n)*/, "{ ... }")}; /* } vim */
+ case "undefined":
+ return {arg};
+ case "object":
+ // for java packages value.toString() would crash so badly
+ // that we cannot even try/catch it
+ if (/^\[JavaPackage.*\]$/.test(arg))
+ return <>[JavaPackage]>;
+ return <>{arg}>;
+ default:
+ return ]]>;
+ }
+ }
+ catch (e)
+ {
+ return]]>;
+ }
+ },
+
+ highlightFilter: function (str, filter)
+ {
+ let lcstr = str.toLowerCase();
+ let lcfilter = filter.toLowerCase();
+ let s = <>>;
+ let start = 0;
+ let i;
+ while ((i = lca.indexOf(lcfilter, start)) > -1)
+ {
+ s += <>{str.substring(start, i)}>;
+ s += {str.substr(i, filter.length)};
+ start = i + filter.length;
+ }
+ return s + <>{str.substr(start)}>;
+ },
+
+ highlightURL: function (str, force)
+ {
+ if (force || /^[a-zA-Z]+:\/\//.test(str))
+ return {str};
+ else
+ return str;
+ },
+
+ generic: function (xml)
+ {
+ return <>:{liberator.commandline.getCommand()}
> + xml;
+ },
+
+ bookmarks: function (header, items)
+ {
+ return this.generic(
+
+
+ | {header} | URL |
+
+ {
+ this.map(items, function (item)
+
+ | {liberator.util.clip(item.title, 50)} |
+
+ {item.url}
+ {
+ !(item.extra && item.extra.length) ? "" :
+
+ }
+ |
+
)
+ }
+
);
+ },
+
+ jumps: function (index, elems)
+ {
+ return this.generic(
+
+
+ | jump | title | URI |
+
+ {
+ this.map2(elems, function (idx, val)
+
+ | {idx == index ? ">" : ""} |
+ {Math.abs(idx - index)} |
+ {val.title} |
+ {val.URI.spec} |
+
)
+ }
+
);
+ },
+
+ options: function (title, opts)
+ {
+ return this.generic(
+
+
+ | --- {title} --- |
+
+ {
+ this.map(opts, function (opt)
+
+ |
+ {opt.pre}{opt.name}{opt.value}
+ {opt.isDefault || opt.default == null ? "" : }
+ |
+
)
+ }
+
);
+ },
+
+ table: function (title, data, indent)
+ {
+ let table =
+
+
+ | {title} |
+
+ {
+ this.map(data, function (datum)
+
+ | {datum[0]} |
+ {liberator.template.maybeXML(datum[1])} |
+
)
+ }
+
;
+ if (table.tr.length() > 1)
+ return table;
+ },
+
+ tabular: function (headings, style, iter)
+ {
+ /* This might be mind-bogglingly slow. We'll see. */
+ return this.generic(
+
+
+ {
+ this.map(headings, function (h)
+ | {h} | )
+ }
+
+ {
+ this.map(iter, function (row)
+
+ {
+ liberator.template.map2(row, function (i, d)
+ | {d} | )
+ }
+
)
+ }
+
);
+ },
+};
+
diff --git a/content/util.js b/content/util.js
index c62a3bb8..3233e7fb 100644
--- a/content/util.js
+++ b/content/util.js
@@ -91,57 +91,6 @@ liberator.util = { //{{{
return str.length <= length ? str : str.substr(0, length - 3) + "...";
},
- // TODO: use :highlight color groups
- // if "processStrings" is true, any passed strings will be surrounded by " and
- // any line breaks are displayed as \n
- colorize: function (arg, processStrings)
- {
- var type = typeof arg;
-
- // some objects like window.JSON or getBrowsers()._browsers need the try/catch
- try
- {
- if (type == "number")
- {
- return {arg};
- }
- else if (type == "string")
- {
- if (processStrings)
- arg = <>"{arg.replace(/\n/, "\\n")}">;
-
- return {arg};
- }
- else if (type == "boolean")
- {
- return {arg};
- }
- else if (arg == null || arg == "undefined")
- {
- return {arg};
- }
- else if (type == "object" || type == "function")
- {
- // for java packages value.toString() would crash so badly
- // that we cannot even try/catch it
- if (/^\[JavaPackage.*\]$/.test(arg))
- return <>[JavaPackage]>;
-
- var str = arg.toString();
- if (typeof str == "string") // can be "undefined"
- return <>{str}>;
- else
- return <>undefined>;
- }
- }
- catch (e)
- {
- return <>]]>>;
- }
-
- return <>]]>>;
- },
-
copyToClipboard: function (str, verbose)
{
var clipboardHelper = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
@@ -208,7 +157,8 @@ liberator.util = { //{{{
}
for (let u = strNum[0].length - 3; u > 0; u -= 3) // make a 10000 a 10,000
- strNum[0] = strNum[0].substring(0, u) + "," + strNum[0].substring(u, strNum[0].length);
+ strNum[0] = strNum[0].substring(0, u)
+ + "," + strNum[0].substring(u, strNum[0].length);
if (unitIndex) // decimalPlaces only when > Bytes
strNum[0] += "." + strNum[1];
@@ -268,14 +218,6 @@ liberator.util = { //{{{
return ret;
},
- highlightURL: function (str, force)
- {
- if (force || /^[a-zA-Z]+:\/\//.test(str))
- return {str};
- else
- return str;
- },
-
// if color = true it uses HTML markup to color certain items
objectToString: function (object, color)
{
@@ -311,19 +253,16 @@ liberator.util = { //{{{
{
for (let i in object)
{
- var value;
+ let value = "";
try
{
value = object[i];
}
- catch (e)
- {
- value = "";
- }
+ catch (e) {}
if (color)
{
- value = this.colorize(value, true).toXMLString();
+ value = liberator.template.highlight(value, true).toXMLString();
i = {i}.toXMLString();
}
string += i + ": " + value + "\n";