'use strict';
var elements = require('./elements');
/**
* Represents a list of elements
* @constructor
*/
var ElementsArray = /** @function */function ElementsArray() {
/**
* @property {int} length of the array
* @memberof ElementsArray
*/
this.length = 0;
};
ElementsArray.prototype = {
/**
* Executes a callback once per array element
* <pre><code>
* $elements.forEach(function($element) {
* $element.addClass('someClass');
* });
* </pre></code>
*
* @param {Function} callback
* @return {ElementsArray} return this
*/
forEach: /** @function
* @param callback */function forEach(callback) {
this._forEach( /** @function
* @param e */function (e) {
callback.call(this, elements(e));
});
return this;
},
/**
* Return a new ElementsArray with elements wich passed the tests implemented by the provided function.
* <pre><code>
* $elements.some(function($element) {
* return $element.hasClass('someClass');
* });
* </pre></code>
*
* @param {Function} callback
* @return {ElementsArray} a new {ElementsArray}
*/
some: /** @function
* @param callback */function some(callback) {
var results = new ElementsArray();
this._forEach( /** @function
* @param e */function (e) {
if (callback.call(this, elements(e))) {
results.push(e);
}
});
return results;
},
/**
* The map() method creates a new array with the results
* of calling a provided function on every element in this array.
* <pre><code>
* $elements.map(function($element) {
* return $element.getAttribute('data-view');
* });
* </pre></code>
*
* @method
* @param {Function} callback
*/
map: /** @function
* @param callback */function map(callback) {
return this._map( /** @function
* @param e */function (e) {
callback.call(this, elements(e));
});
},
/**
* Executes a callback once per array element
* <pre><code>
* $elements._forEach(function(element) {
* elements.addClass(element, 'someClass');
* });
* </pre></code>
*
* @method
* @param {Function} callback
*/
_forEach: Array.prototype.forEach,
/**
* Push an element in this array
* <pre><code>
* $elements._push(element);
* </pre></code>
*
* @method
* @param {HTMLEement} element
*/
_push: Array.prototype.push,
/**
* The _map() method creates a new array with the results
* of calling a provided function on every element in this array.
* <pre><code>
* $elements._map(function(element) {
* return elements.getAttribute(element, 'data-view');
* });
* </pre></code>
*
* @method
* @param {Function} callback
*/
_map: Array.prototype.map,
/*_reduce: Array.prototype.reduce,
_some: Array.prototype.some,
_sort: Array.prototype.sort,
_indexOf: Array.prototype.indexOf,
*/
setValue: /** @function
* @param value */function setValue(value) {
this._forEach( /** @function
* @param e */function (e) {
elements.setValue(e, value);
});
}
};
module.exports = ElementsArray;
//# sourceMappingURL=elements_array.js.map |