mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 07:28:00 +01:00
Revert "Move util.Array to modules.Array_."
This reverts commit d6cdda48a18c9fa05365b50046470fec9935fd3c. Array_ method chaining needs fixing.
This commit is contained in:
@@ -328,7 +328,7 @@ function Bookmarks() //{{{
|
|||||||
args.completeFilter = have.pop();
|
args.completeFilter = have.pop();
|
||||||
|
|
||||||
let prefix = filter.substr(0, filter.length - args.completeFilter.length);
|
let prefix = filter.substr(0, filter.length - args.completeFilter.length);
|
||||||
let tags = Array_([b.tags for ([k, b] in Iterator(cache.bookmarks))]).flatten().uniq();
|
let tags = util.Array.uniq(util.Array.flatten([b.tags for ([k, b] in Iterator(cache.bookmarks))]));
|
||||||
|
|
||||||
return [[prefix + tag, tag] for ([i, tag] in Iterator(tags)) if (have.indexOf(tag) < 0)];
|
return [[prefix + tag, tag] for ([i, tag] in Iterator(tags)) if (have.indexOf(tag) < 0)];
|
||||||
}
|
}
|
||||||
@@ -1023,7 +1023,7 @@ function History() //{{{
|
|||||||
let sh = window.getWebNavigation().sessionHistory;
|
let sh = window.getWebNavigation().sessionHistory;
|
||||||
let obj = [];
|
let obj = [];
|
||||||
obj.index = sh.index;
|
obj.index = sh.index;
|
||||||
obj.__iterator__ = function () Array_.iteritems(this);
|
obj.__iterator__ = function () util.Array.iteritems(this);
|
||||||
for (let i in util.range(0, sh.count))
|
for (let i in util.range(0, sh.count))
|
||||||
{
|
{
|
||||||
obj[i] = { index: i, __proto__: sh.getEntryAtIndex(i, false) };
|
obj[i] = { index: i, __proto__: sh.getEntryAtIndex(i, false) };
|
||||||
@@ -1044,7 +1044,7 @@ function History() //{{{
|
|||||||
liberator.beep();
|
liberator.beep();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
let index = Math_.constrain(current + steps, start, end);
|
let index = util.Math.constrain(current + steps, start, end);
|
||||||
window.getWebNavigation().gotoIndex(index);
|
window.getWebNavigation().gotoIndex(index);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -71,7 +71,7 @@ function Buffer() //{{{
|
|||||||
{
|
{
|
||||||
let values = ZoomManager.zoomValues;
|
let values = ZoomManager.zoomValues;
|
||||||
let cur = values.indexOf(ZoomManager.snap(ZoomManager.zoom));
|
let cur = values.indexOf(ZoomManager.snap(ZoomManager.zoom));
|
||||||
let i = Math_.constrain(cur + steps, 0, values.length - 1);
|
let i = util.Math.constrain(cur + steps, 0, values.length - 1);
|
||||||
|
|
||||||
if (i == cur && fullZoom == ZoomManager.useFullZoom)
|
if (i == cur && fullZoom == ZoomManager.useFullZoom)
|
||||||
liberator.beep();
|
liberator.beep();
|
||||||
@@ -96,7 +96,7 @@ function Buffer() //{{{
|
|||||||
if (win.scrollMaxX > 0 || win.scrollMaxY > 0)
|
if (win.scrollMaxX > 0 || win.scrollMaxY > 0)
|
||||||
return win;
|
return win;
|
||||||
|
|
||||||
for (let frame in Array_.itervalues(win.frames))
|
for (let frame in util.Array.itervalues(win.frames))
|
||||||
if (frame.scrollMaxX > 0 || frame.scrollMaxY > 0)
|
if (frame.scrollMaxX > 0 || frame.scrollMaxY > 0)
|
||||||
return frame;
|
return frame;
|
||||||
|
|
||||||
@@ -359,7 +359,7 @@ function Buffer() //{{{
|
|||||||
|
|
||||||
if (elements.length > 0)
|
if (elements.length > 0)
|
||||||
{
|
{
|
||||||
count = Math_.constrain(count, 1, elements.length);
|
count = util.Math.constrain(count, 1, elements.length);
|
||||||
buffer.focusElement(elements[count - 1]);
|
buffer.focusElement(elements[count - 1]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -648,7 +648,7 @@ function Buffer() //{{{
|
|||||||
level = buffer.textZoom + parseInt(arg, 10);
|
level = buffer.textZoom + parseInt(arg, 10);
|
||||||
|
|
||||||
// relative args shouldn't take us out of range
|
// relative args shouldn't take us out of range
|
||||||
level = Math_.constrain(level, ZOOM_MIN, ZOOM_MAX);
|
level = util.Math.constrain(level, ZOOM_MIN, ZOOM_MAX);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return void liberator.echoerr("E488: Trailing characters");
|
return void liberator.echoerr("E488: Trailing characters");
|
||||||
@@ -805,7 +805,7 @@ function Buffer() //{{{
|
|||||||
const ACCESS_READ = Ci.nsICache.ACCESS_READ;
|
const ACCESS_READ = Ci.nsICache.ACCESS_READ;
|
||||||
let cacheKey = doc.location.toString().replace(/#.*$/, "");
|
let cacheKey = doc.location.toString().replace(/#.*$/, "");
|
||||||
|
|
||||||
for (let proto in Array_.itervalues(["HTTP", "FTP"]))
|
for (let proto in util.Array.itervalues(["HTTP", "FTP"]))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -460,7 +460,7 @@ function Commands() //{{{
|
|||||||
__iterator__: function ()
|
__iterator__: function ()
|
||||||
{
|
{
|
||||||
let sorted = exCommands.sort(function (a, b) a.name > b.name);
|
let sorted = exCommands.sort(function (a, b) a.name > b.name);
|
||||||
return Array_.itervalues(sorted);
|
return util.Array.itervalues(sorted);
|
||||||
},
|
},
|
||||||
|
|
||||||
/** @property {string} The last executed Ex command line. */
|
/** @property {string} The last executed Ex command line. */
|
||||||
@@ -652,7 +652,7 @@ function Commands() //{{{
|
|||||||
argCount = "*";
|
argCount = "*";
|
||||||
|
|
||||||
var args = []; // parsed options
|
var args = []; // parsed options
|
||||||
args.__iterator__ = function () Array_.iteritems(this);
|
args.__iterator__ = function () util.Array.iteritems(this);
|
||||||
args.string = str; // for access to the unparsed string
|
args.string = str; // for access to the unparsed string
|
||||||
args.literalArg = "";
|
args.literalArg = "";
|
||||||
|
|
||||||
@@ -1150,7 +1150,7 @@ function Commands() //{{{
|
|||||||
{
|
{
|
||||||
command: this.name,
|
command: this.name,
|
||||||
bang: true,
|
bang: true,
|
||||||
options: Array_.toObject(
|
options: util.Array.toObject(
|
||||||
[[v, typeof cmd[k] == "boolean" ? null : cmd[k]]
|
[[v, typeof cmd[k] == "boolean" ? null : cmd[k]]
|
||||||
// FIXME: this map is expressed multiple times
|
// FIXME: this map is expressed multiple times
|
||||||
for ([k, v] in Iterator({ argCount: "-nargs", bang: "-bang", count: "-count", description: "-description" }))
|
for ([k, v] in Iterator({ argCount: "-nargs", bang: "-bang", count: "-count", description: "-description" }))
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ CompletionContext.prototype = {
|
|||||||
let prefix = self.value.substring(minStart, context.offset);
|
let prefix = self.value.substring(minStart, context.offset);
|
||||||
return context.items.map(function makeItem(item) ({ text: prefix + item.text, item: item.item }));
|
return context.items.map(function makeItem(item) ({ text: prefix + item.text, item: item.item }));
|
||||||
});
|
});
|
||||||
return { start: minStart, items: Array_.flatten(items), longestSubstring: this.longestAllSubstring };
|
return { start: minStart, items: util.Array.flatten(items), longestSubstring: this.longestAllSubstring };
|
||||||
}
|
}
|
||||||
catch (e)
|
catch (e)
|
||||||
{
|
{
|
||||||
@@ -279,7 +279,7 @@ CompletionContext.prototype = {
|
|||||||
lists.pop());
|
lists.pop());
|
||||||
if (!substrings) // FIXME: How is this undefined?
|
if (!substrings) // FIXME: How is this undefined?
|
||||||
return [];
|
return [];
|
||||||
return Array_.uniq(substrings);
|
return util.Array.uniq(substrings);
|
||||||
},
|
},
|
||||||
// Temporary
|
// Temporary
|
||||||
get longestAllSubstring()
|
get longestAllSubstring()
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ function AutoCommands() //{{{
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
||||||
__iterator__: function () Array_.itervalues(store),
|
__iterator__: function () util.Array.itervalues(store),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a new autocommand. <b>cmd</b> will be executed when one of the
|
* Adds a new autocommand. <b>cmd</b> will be executed when one of the
|
||||||
|
|||||||
@@ -786,7 +786,7 @@ function Hints() //{{{
|
|||||||
/////////////////////////////////////////////////////////////////////////////{{{
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|
||||||
const DEFAULT_HINTTAGS =
|
const DEFAULT_HINTTAGS =
|
||||||
Array_(["input[not(@type='hidden')]", "a", "area", "iframe", "textarea", "button", "select"])
|
util.Array(["input[not(@type='hidden')]", "a", "area", "iframe", "textarea", "button", "select"])
|
||||||
.map(function (spec) [spec, "xhtml:" + spec]).flatten()
|
.map(function (spec) [spec, "xhtml:" + spec]).flatten()
|
||||||
.concat("*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @role='link']")
|
.concat("*[@onclick or @onmouseover or @onmousedown or @onmouseup or @oncommand or @role='link']")
|
||||||
.map(function (node) "//" + node).join(" | ");
|
.map(function (node) "//" + node).join(" | ");
|
||||||
|
|||||||
@@ -283,7 +283,7 @@ function IO() //{{{
|
|||||||
|
|
||||||
// TODO: Use a set/specifiable list here:
|
// TODO: Use a set/specifiable list here:
|
||||||
let lines = [cmd.serial().map(commands.commandToString) for (cmd in commands) if (cmd.serial)];
|
let lines = [cmd.serial().map(commands.commandToString) for (cmd in commands) if (cmd.serial)];
|
||||||
lines = Array_.flatten(lines);
|
lines = util.Array.flatten(lines);
|
||||||
|
|
||||||
// source a user .vimperatorrc file
|
// source a user .vimperatorrc file
|
||||||
lines.unshift('"' + liberator.version + "\n");
|
lines.unshift('"' + liberator.version + "\n");
|
||||||
@@ -399,7 +399,7 @@ function IO() //{{{
|
|||||||
completion.charset = function (context) {
|
completion.charset = function (context) {
|
||||||
context.anchored = false;
|
context.anchored = false;
|
||||||
context.generate = function () {
|
context.generate = function () {
|
||||||
let names = Array_(
|
let names = util.Array(
|
||||||
"more1 more2 more3 more4 more5 unicode".split(" ").map(function (key)
|
"more1 more2 more3 more4 more5 unicode".split(" ").map(function (key)
|
||||||
options.getPref("intl.charsetmenu.browser." + key).split(', '))
|
options.getPref("intl.charsetmenu.browser." + key).split(', '))
|
||||||
).flatten().uniq();
|
).flatten().uniq();
|
||||||
@@ -477,7 +477,7 @@ function IO() //{{{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Array_.flatten(commands);
|
return util.Array.flatten(commands);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ const liberator = (function () //{{{
|
|||||||
{
|
{
|
||||||
let opts = [v.opts for ([k, v] in Iterator(groups))];
|
let opts = [v.opts for ([k, v] in Iterator(groups))];
|
||||||
opts = opts.map(function (opt) [[k, v[0]] for ([k, v] in Iterator(opt))]);
|
opts = opts.map(function (opt) [[k, v[0]] for ([k, v] in Iterator(opt))]);
|
||||||
return Array_.flatten(opts);
|
return util.Array.flatten(opts);
|
||||||
},
|
},
|
||||||
validator: function (val) Option.validateCompleter.call(this, val) &&
|
validator: function (val) Option.validateCompleter.call(this, val) &&
|
||||||
[v for ([k, v] in Iterator(groups))].every(function (g) !g.validator || g.validator(val))
|
[v for ([k, v] in Iterator(groups))].every(function (g) !g.validator || g.validator(val))
|
||||||
@@ -880,7 +880,7 @@ const liberator = (function () //{{{
|
|||||||
return Array.map(doc.getElementsByClassName("tag"),
|
return Array.map(doc.getElementsByClassName("tag"),
|
||||||
function (elem) [elem.textContent, file]);
|
function (elem) [elem.textContent, file]);
|
||||||
});
|
});
|
||||||
return Array_.flatten(res);
|
return util.Array.flatten(res);
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -337,7 +337,7 @@ function Mappings() //{{{
|
|||||||
function (context, obj, args)
|
function (context, obj, args)
|
||||||
{
|
{
|
||||||
let mode = args[0];
|
let mode = args[0];
|
||||||
return Array_.flatten(
|
return util.Array.flatten(
|
||||||
[
|
[
|
||||||
[[name, map.description] for ([i, name] in Iterator(map.names))]
|
[[name, map.description] for ([i, name] in Iterator(map.names))]
|
||||||
for ([i, map] in Iterator(user[mode].concat(main[mode])))
|
for ([i, map] in Iterator(user[mode].concat(main[mode])))
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ const modes = (function () //{{{
|
|||||||
|
|
||||||
NONE: 0,
|
NONE: 0,
|
||||||
|
|
||||||
__iterator__: function () Array_.itervalues(this.all),
|
__iterator__: function () util.Array.itervalues(this.all),
|
||||||
|
|
||||||
get all() mainModes.slice(),
|
get all() mainModes.slice(),
|
||||||
|
|
||||||
|
|||||||
@@ -378,11 +378,11 @@ Option.prototype = {
|
|||||||
switch (operator)
|
switch (operator)
|
||||||
{
|
{
|
||||||
case "+":
|
case "+":
|
||||||
newValue = Array_(this.values).concat(values).uniq(true);
|
newValue = util.Array.uniq(Array.concat(this.values, values), true);
|
||||||
break;
|
break;
|
||||||
case "^":
|
case "^":
|
||||||
// NOTE: Vim doesn't prepend if there's a match in the current value
|
// NOTE: Vim doesn't prepend if there's a match in the current value
|
||||||
newValue = Array_(values).concat(this.values).uniq(true);
|
newValue = util.Array.uniq(Array.concat(values, this.values), true);
|
||||||
break;
|
break;
|
||||||
case "-":
|
case "-":
|
||||||
newValue = this.values.filter(function (item) values.indexOf(item) == -1);
|
newValue = this.values.filter(function (item) values.indexOf(item) == -1);
|
||||||
|
|||||||
@@ -470,7 +470,7 @@ function Styles(name, store)
|
|||||||
sss.unregisterSheet(uri, agent ? sss.AGENT_SHEET : sss.USER_SHEET);
|
sss.unregisterSheet(uri, agent ? sss.AGENT_SHEET : sss.USER_SHEET);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
let (array = Array_)
|
let (array = util.Array)
|
||||||
{
|
{
|
||||||
util.extend(Styles.prototype, {
|
util.extend(Styles.prototype, {
|
||||||
get sites() array([v.sites for ([k, v] in this.userSheets)]).flatten().uniq().__proto__,
|
get sites() array([v.sites for ([k, v] in this.userSheets)]).flatten().uniq().__proto__,
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const template = { //{{{
|
|||||||
map: function map(iter, func, sep, interruptable)
|
map: function map(iter, func, sep, interruptable)
|
||||||
{
|
{
|
||||||
if (iter.length) // FIXME: Kludge?
|
if (iter.length) // FIXME: Kludge?
|
||||||
iter = Array_.itervalues(iter);
|
iter = util.Array.itervalues(iter);
|
||||||
let ret = <></>;
|
let ret = <></>;
|
||||||
let n = 0;
|
let n = 0;
|
||||||
for each (let i in Iterator(iter))
|
for each (let i in Iterator(iter))
|
||||||
|
|||||||
@@ -216,7 +216,7 @@ function CommandLine() //{{{
|
|||||||
this.index += diff;
|
this.index += diff;
|
||||||
if (this.index < 0 || this.index > this.store.length)
|
if (this.index < 0 || this.index > this.store.length)
|
||||||
{
|
{
|
||||||
this.index = Math_.constrain(this.index, 0, this.store.length);
|
this.index = util.Math.constrain(this.index, 0, this.store.length);
|
||||||
liberator.beep();
|
liberator.beep();
|
||||||
// I don't know why this kludge is needed. It
|
// I don't know why this kludge is needed. It
|
||||||
// prevents the caret from moving to the end of
|
// prevents the caret from moving to the end of
|
||||||
@@ -436,7 +436,7 @@ function CommandLine() //{{{
|
|||||||
idx = null;
|
idx = null;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
idx = Math_.constrain(idx, 0, this.items.length - 1);
|
idx = util.Math.constrain(idx, 0, this.items.length - 1);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -525,7 +525,7 @@ function CommandLine() //{{{
|
|||||||
if (this.type.list)
|
if (this.type.list)
|
||||||
completionList.show();
|
completionList.show();
|
||||||
|
|
||||||
this.wildIndex = Math_.constrain(this.wildIndex + 1, 0, this.wildtypes.length - 1);
|
this.wildIndex = util.Math.constrain(this.wildIndex + 1, 0, this.wildtypes.length - 1);
|
||||||
this.preview();
|
this.preview();
|
||||||
|
|
||||||
statusTimer.tell();
|
statusTimer.tell();
|
||||||
@@ -1895,7 +1895,7 @@ function ItemList(id) //{{{
|
|||||||
let end = startIndex + options["maxitems"];
|
let end = startIndex + options["maxitems"];
|
||||||
function getRows(context)
|
function getRows(context)
|
||||||
{
|
{
|
||||||
function fix(n) Math_.constrain(n, 0, len);
|
function fix(n) util.Math.constrain(n, 0, len);
|
||||||
let len = context.items.length;
|
let len = context.items.length;
|
||||||
let start = off;
|
let start = off;
|
||||||
end -= !!context.message + context.incomplete;
|
end -= !!context.message + context.incomplete;
|
||||||
@@ -1924,7 +1924,7 @@ function ItemList(id) //{{{
|
|||||||
|
|
||||||
for (let [i, row] in Iterator(context.getRows(start, end, doc)))
|
for (let [i, row] in Iterator(context.getRows(start, end, doc)))
|
||||||
nodes[i] = row;
|
nodes[i] = row;
|
||||||
for (let [i, row] in Array_.iteritems(nodes))
|
for (let [i, row] in util.Array.iteritems(nodes))
|
||||||
{
|
{
|
||||||
if (!row)
|
if (!row)
|
||||||
continue;
|
continue;
|
||||||
@@ -2285,7 +2285,7 @@ function StatusLine() //{{{
|
|||||||
// tab numbers set
|
// tab numbers set
|
||||||
if (options.get("guioptions").has("n", "N"))
|
if (options.get("guioptions").has("n", "N"))
|
||||||
{
|
{
|
||||||
for (let [i, tab] in Array_.iteritems(getBrowser().mTabs))
|
for (let [i, tab] in util.Array.iteritems(getBrowser().mTabs))
|
||||||
tab.setAttribute("ordinal", i + 1);
|
tab.setAttribute("ordinal", i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -183,9 +183,10 @@ const util = { //{{{
|
|||||||
*
|
*
|
||||||
* @param {object} obj The object to alter.
|
* @param {object} obj The object to alter.
|
||||||
* @param {string} key The name of the property to memoize.
|
* @param {string} key The name of the property to memoize.
|
||||||
* @param {function} getter A function of zero to two arguments which will
|
* @param {function} getter A function of zero to two arguments which
|
||||||
* return the property's value. <b>obj</b> is passed as the first
|
* will return the property's value. <b>obj</b> is
|
||||||
* argument, <b>key</b> as the second.
|
* passed as the first argument, <b>key</b> as the
|
||||||
|
* second.
|
||||||
*/
|
*/
|
||||||
memoize: function memoize(obj, key, getter)
|
memoize: function memoize(obj, key, getter)
|
||||||
{
|
{
|
||||||
@@ -405,6 +406,23 @@ const util = { //{{{
|
|||||||
return ary;
|
return ary;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Math utility methods.
|
||||||
|
* @singleton
|
||||||
|
*/
|
||||||
|
Math: {
|
||||||
|
/**
|
||||||
|
* Returns the specified <b>value</b> constrained to the range <b>min</b> -
|
||||||
|
* <b>max</b>.
|
||||||
|
*
|
||||||
|
* @param {number} value The value to constrain.
|
||||||
|
* @param {number} min The minimum constraint.
|
||||||
|
* @param {number} max The maximum constraint.
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
constrain: function constrain(value, min, max) Math.min(Math.max(min, value), max)
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a URI string into a URI object.
|
* Converts a URI string into a URI object.
|
||||||
*
|
*
|
||||||
@@ -440,7 +458,7 @@ const util = { //{{{
|
|||||||
if (typeof object != "object")
|
if (typeof object != "object")
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const NAMESPACES = Array_.toObject([
|
const NAMESPACES = util.Array.toObject([
|
||||||
[NS, 'liberator'],
|
[NS, 'liberator'],
|
||||||
[XHTML, 'html'],
|
[XHTML, 'html'],
|
||||||
[XUL, 'xul']
|
[XUL, 'xul']
|
||||||
@@ -459,7 +477,7 @@ const util = { //{{{
|
|||||||
}
|
}
|
||||||
let tag = "<" + [namespaced(elem)].concat(
|
let tag = "<" + [namespaced(elem)].concat(
|
||||||
[namespaced(a) + "=" + template.highlight(a.value, true)
|
[namespaced(a) + "=" + template.highlight(a.value, true)
|
||||||
for ([i, a] in Array_.iteritems(elem.attributes))]).join(" ");
|
for ([i, a] in util.Array.iteritems(elem.attributes))]).join(" ");
|
||||||
|
|
||||||
if (!elem.firstChild || /^\s*$/.test(elem.firstChild) && !elem.firstChild.nextSibling)
|
if (!elem.firstChild || /^\s*$/.test(elem.firstChild) && !elem.firstChild.nextSibling)
|
||||||
tag += '/>';
|
tag += '/>';
|
||||||
@@ -709,18 +727,19 @@ const util = { //{{{
|
|||||||
}
|
}
|
||||||
}; //}}}
|
}; //}}}
|
||||||
|
|
||||||
|
// TODO: Why don't we just push all util.BuiltinType up into modules? --djk
|
||||||
/**
|
/**
|
||||||
* Array utility methods.
|
* Array utility methods.
|
||||||
*/
|
*/
|
||||||
var Array_ = function Array_(ary) {
|
util.Array = function Array_(ary) {
|
||||||
var obj = {
|
var obj = {
|
||||||
__proto__: ary,
|
__proto__: ary,
|
||||||
__iterator__: function () this.iteritems(),
|
__iterator__: function () this.iteritems(),
|
||||||
__noSuchMethod__: function (meth, args)
|
__noSuchMethod__: function (meth, args)
|
||||||
{
|
{
|
||||||
let res = (Array_[meth] || Array[meth]).apply(null, [this.__proto__].concat(args));
|
let res = (util.Array[meth] || Array[meth]).apply(null, [this.__proto__].concat(args));
|
||||||
if (Array_.isinstance(res))
|
if (util.Array.isinstance(res))
|
||||||
return Array_(res);
|
return util.Array(res);
|
||||||
return res;
|
return res;
|
||||||
},
|
},
|
||||||
concat: function () [].concat.apply(this.__proto__, arguments),
|
concat: function () [].concat.apply(this.__proto__, arguments),
|
||||||
@@ -728,7 +747,7 @@ var Array_ = function Array_(ary) {
|
|||||||
};
|
};
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
Array_.isinstance = function isinstance(obj) {
|
util.Array.isinstance = function isinstance(obj) {
|
||||||
return Object.prototype.toString.call(obj) == "[object Array]";
|
return Object.prototype.toString.call(obj) == "[object Array]";
|
||||||
};
|
};
|
||||||
/**
|
/**
|
||||||
@@ -741,7 +760,7 @@ Array_.isinstance = function isinstance(obj) {
|
|||||||
* @... {string} 0 - Key
|
* @... {string} 0 - Key
|
||||||
* @... 1 - Value
|
* @... 1 - Value
|
||||||
*/
|
*/
|
||||||
Array_.toObject = function toObject(assoc)
|
util.Array.toObject = function toObject(assoc)
|
||||||
{
|
{
|
||||||
let obj = {};
|
let obj = {};
|
||||||
assoc.forEach(function ([k, v]) { obj[k] = v; });
|
assoc.forEach(function ([k, v]) { obj[k] = v; });
|
||||||
@@ -756,7 +775,7 @@ Array_.toObject = function toObject(assoc)
|
|||||||
* @param {Array} ary
|
* @param {Array} ary
|
||||||
* @returns {Array}
|
* @returns {Array}
|
||||||
*/
|
*/
|
||||||
Array_.flatten = function flatten(ary) Array.concat.apply([], ary),
|
util.Array.flatten = function flatten(ary) Array.concat.apply([], ary),
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an Iterator for an array's values.
|
* Returns an Iterator for an array's values.
|
||||||
@@ -764,7 +783,7 @@ Array_.flatten = function flatten(ary) Array.concat.apply([], ary),
|
|||||||
* @param {Array} ary
|
* @param {Array} ary
|
||||||
* @returns {Iterator(Object)}
|
* @returns {Iterator(Object)}
|
||||||
*/
|
*/
|
||||||
Array_.itervalues = function itervalues(ary)
|
util.Array.itervalues = function itervalues(ary)
|
||||||
{
|
{
|
||||||
let length = ary.length;
|
let length = ary.length;
|
||||||
for (let i = 0; i < length; i++)
|
for (let i = 0; i < length; i++)
|
||||||
@@ -777,7 +796,7 @@ Array_.itervalues = function itervalues(ary)
|
|||||||
* @param {Array} ary
|
* @param {Array} ary
|
||||||
* @returns {Iterator([{number}, {Object}])}
|
* @returns {Iterator([{number}, {Object}])}
|
||||||
*/
|
*/
|
||||||
Array_.iteritems = function iteritems(ary)
|
util.Array.iteritems = function iteritems(ary)
|
||||||
{
|
{
|
||||||
let length = ary.length;
|
let length = ary.length;
|
||||||
for (let i = 0; i < length; i++)
|
for (let i = 0; i < length; i++)
|
||||||
@@ -793,7 +812,7 @@ Array_.iteritems = function iteritems(ary)
|
|||||||
* @param {boolean} unsorted
|
* @param {boolean} unsorted
|
||||||
* @returns {Array}
|
* @returns {Array}
|
||||||
*/
|
*/
|
||||||
Array_.uniq = function uniq(ary, unsorted)
|
util.Array.uniq = function uniq(ary, unsorted)
|
||||||
{
|
{
|
||||||
let ret = [];
|
let ret = [];
|
||||||
if (unsorted)
|
if (unsorted)
|
||||||
@@ -814,24 +833,6 @@ Array_.uniq = function uniq(ary, unsorted)
|
|||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Math utility methods.
|
|
||||||
* @singleton
|
|
||||||
*/
|
|
||||||
var Math_ = {
|
|
||||||
__proto__ : Math,
|
|
||||||
/**
|
|
||||||
* Returns the specified <b>value</b> constrained to the range <b>min</b> -
|
|
||||||
* <b>max</b>.
|
|
||||||
*
|
|
||||||
* @param {number} value The value to constrain.
|
|
||||||
* @param {number} min The minimum constraint.
|
|
||||||
* @param {number} max The maximum constraint.
|
|
||||||
* @returns {number}
|
|
||||||
*/
|
|
||||||
constrain: function constrain(value, min, max) Math.min(Math.max(min, value), max)
|
|
||||||
};
|
|
||||||
|
|
||||||
function Struct()
|
function Struct()
|
||||||
{
|
{
|
||||||
let self = this instanceof Struct ? this : new Struct();
|
let self = this instanceof Struct ? this : new Struct();
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ function Library() // {{{
|
|||||||
{
|
{
|
||||||
let albums = toJSArray(MAIN_LIBRARY.getItemsByProperty(SBProperties.artistName, artist))
|
let albums = toJSArray(MAIN_LIBRARY.getItemsByProperty(SBProperties.artistName, artist))
|
||||||
.map(function (track) track.getProperty(SBProperties.albumName));
|
.map(function (track) track.getProperty(SBProperties.albumName));
|
||||||
return Array_.uniq(albums);
|
return util.Array.uniq(albums);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -402,7 +402,7 @@ function Player() // {{{
|
|||||||
if (/^[+-]/.test(arg))
|
if (/^[+-]/.test(arg))
|
||||||
level = player.volume + level;
|
level = player.volume + level;
|
||||||
|
|
||||||
player.volume = Math_.constrain(level, 0, 1);
|
player.volume = util.Math.constrain(level, 0, 1);
|
||||||
},
|
},
|
||||||
{ argCount: "1" });
|
{ argCount: "1" });
|
||||||
|
|
||||||
@@ -567,7 +567,7 @@ function Player() // {{{
|
|||||||
let min = 0;
|
let min = 0;
|
||||||
let max = gMM.playbackControl.duration - 5000; // TODO: 5s buffer like cmus desirable?
|
let max = gMM.playbackControl.duration - 5000; // TODO: 5s buffer like cmus desirable?
|
||||||
|
|
||||||
gMM.playbackControl.position = Math_.constrain(position, min, max);
|
gMM.playbackControl.position = util.Math.constrain(position, min, max);
|
||||||
},
|
},
|
||||||
|
|
||||||
// FIXME: 10% ?
|
// FIXME: 10% ?
|
||||||
|
|||||||
Reference in New Issue
Block a user