Code coverage report for lib/$.js

Statements: 53.45% (31 / 58)      Branches: 8.33% (3 / 36)      Functions: 15.38% (2 / 13)      Lines: 53.45% (31 / 58)      Ignored: none     

All files » lib/ » $.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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192    1 1 1     1   1       4       4                       4   4           1   1   1   1                               1                                       1                       1                       1                         1                       1           1           1         1                 1   1     1           1               1                 1           1 1 1  
'use strict';
 
var Element = require('./element.js');
var elements = require('./elements.js');
var ElementsArray = require('./elements_array.js');
 
/** @namespace */
var $ = {};
 
$ = /** @function 
    * @param selector 
    * @param context */function (selector, context) {
    // HANDLE: $(), $(""), $(null), $(undefined), $(false)
    Iif (!selector) {
        return '?';
    }
 
    Iif (typeof selector === 'string') {
        if (selector.charAt(0) === '#' && selector.match(/^#([\w\-]+)$/)) {
            return $.byId(selector.substr(1));
        }
        // TODO : is it an optimization ? Shouldn't this be done by the browser,
        // in the native function querySelectorAll ?
        var m = selector.match(/^(\.)?([\w\-]+)$/);
        if (m) {
            return $[m[1] ? 'byClassName' : 'byTagName'](m[2], context);
        }
 
        return $.find(selector, context);
    } else Eif (selector.nodeType) {
        // DOM element
        return elements(selector);
    } else if (selector[0]) {
        return selector;
    }
};
 
exports = module.exports = $;
 
require('./element_prototype_and_array_prototype.js');
 
$.Element = Element;
 
$._toEltArray = /** @function 
                * @param results */function (results) {
    if (!results) {
        return new ElementsArray();
    }
    // Object.setPrototypeOf(results, ElementsArray.prototype);
    var ret = new ElementsArray();
    ret._push.apply(ret, results);
    return ret;
};
 
/**
 * Find an element by id
 * @param  {String} id
 * @return {Element}
 */
$.byId = /** @function 
         * @param id */function (id) {
    var element = document.getElementById(id);
 
    // Check parentNode to catch when Blackberry 4.6 returns
    // nodes that are no longer in the document #6963
    if (element && element.parentNode) {
        // Handle the case where IE and Opera return items
        // by name instead of ID ===> SEE es5-compat
 
        return elements(element);
    }
};
 
/**
 * Find the first element
 * @param  {String} selectors see document.querySelector
 * @param  {HTMLElement} context
 * @return {Element}
 */
$.first = /** @function 
          * @param selectors 
          * @param context */function (selectors, context) {
    var result = (context || document).querySelector(selectors);
    return result && elements(result);
};
/**
 * Find all elements corresponding to a selector
 * @param  {String} selectors
 * @param  {HTMLElement} context
 * @return {ElementsArray}
 */
$.find = /** @function 
         * @param selectors 
         * @param context */function (selectors, context) {
    return $._toEltArray((context || document).querySelectorAll(selectors));
};
 
/**
 * Find elements by class name
 * @param  {String} names
 * @param  {HTMLElement} context
 * @return {ElementsArray}
 */
$.byClassName = /** @function 
                * @param names 
                * @param context */function (names, context) {
    /* https://developer.mozilla.org/en-US/docs/Web/API/document.getElementsByClassName */
    return $._toEltArray((context || document).getElementsByClassName(names));
};
 
/**
 * Find elements by tag name
 * @param  {String} names
 * @param  {HTMLElement} context
 * @return {ElementsArray}
 */
$.byTagName = /** @function 
              * @param names 
              * @param context */function (names, context) {
    /* https://developer.mozilla.org/en-US/docs/Web/API/document.getElementsByTagName */
    return $._toEltArray((context || document).getElementsByTagName(names));
};
 
/**
 * Get all HTML elements by tag name
 * @param  {HTMLElement} context
 * @param  {String} tag
 */
$.getAll = /** @function 
           * @param context 
           * @param tag */function (context, tag) {
    return context.getElementsByTagName(tag || '*');
};
 
$.disposeElements = elements.disposeElements;
 
/**
 * Dispose an element
 * @param  {HTMLElement} element
 */
$.disposeElement = elements.disposeElement;
 
/**
 * @return {Boolean}
 */
$.isWindow = /** @function 
             * @param obj */function (obj) {
    return obj && obj.window == obj;
};
 
/**
 * Creates an element and wrap it with {Element}
 * @return {Element}
 */
$.create = /** @function 
           * @param tag */function (tag) {
    return new Element(document.createElement(tag));
};
 
require('./$.create');
 
/**
 * Creates an fragment and wrap it with {Element}
 * @return {Element}
 */
$.createFragment = /** @function */function () {
    return new Element(document.createDocumentFragment());
};
 
/**
 * Creates an simple text node
 * @return {Text}
 */
$.textNode = /** @function 
             * @param string */function (string) {
    return document.createTextNode(string);
};
 
/**
 * Parse an html string into an element
 * @return {Text}
 */
$.parse = /** @function 
          * @param string 
          * @param context */function (string, context) {
    return elements.parse(string, context);
};
 
window.$document = $(document);
window.$head = $(document.head);
window.$body = $(document.body);
//# sourceMappingURL=$.js.map