Code coverage report for lib/elements_array.js

Statements: 23.53% (4 / 17)      Branches: 0% (0 / 2)      Functions: 0% (0 / 9)      Lines: 23.53% (4 / 17)      Ignored: none     

All files » lib/ » elements_array.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135    1           1               1                                                                                                                                                                                                                                         1  
'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