quixote
Version:
CSS unit and integration testing
41 lines (30 loc) • 1.15 kB
JavaScript
// Copyright (c) 2014 Titanium I.T. LLC. All rights reserved. For license, see "README" or "LICENSE" file.
;
var ensure = require("./util/ensure.js");
var QElement = require("./q_element.js");
var Me = module.exports = function QElementList(nodeList, nickname) {
ensure.signature(arguments, [ Object, String ]);
this._nodeList = nodeList;
this._nickname = nickname;
};
Me.prototype.length = function length() {
ensure.signature(arguments, []);
return this._nodeList.length;
};
Me.prototype.at = function at(requestedIndex, nickname) {
ensure.signature(arguments, [ Number, [undefined, String] ]);
var index = requestedIndex;
var length = this.length();
if (index < 0) index = length + index;
ensure.that(
index >= 0 && index < length,
"'" + this._nickname + "'[" + requestedIndex + "] is out of bounds; list length is " + length
);
var element = this._nodeList[index];
if (nickname === undefined) nickname = this._nickname + "[" + index + "]";
return QElement.create(element, nickname);
};
Me.prototype.toString = function toString() {
ensure.signature(arguments, []);
return "'" + this._nickname + "' list";
};