node_modules/wire/sizzle.js

Maintainability

67.29

Lines of code

52

Created with Raphaël 2.1.002550751002015-1-52014-12-42014-12-3

2015-5-18
Maintainability: 67.29

Created with Raphaël 2.1.00153045602015-1-52014-12-42014-12-3

2015-5-18
Lines of Code: 52

Difficulty

26.67

Estimated Errors

0.32

Function weight

By Complexity

Created with Raphaël 2.1.0addClass4

By SLOC

Created with Raphaël 2.1.0<anonymous>52
1
/** @license MIT License (c) copyright B Cavalier & J Hann */
2
 
3
/**
4
 * wire/sizzle plugin
5
 * Adds querySelectorAll functionality to wire using John Resig's Sizzle library.
6
 * Sizzle must be wrapped in an AMD define().  Kris Zyp has a version of this at
7
 * http://github.com/kriszyp/sizzle
8
 *
9
 * wire is part of the cujo.js family of libraries (http://cujojs.com/)
10
 *
11
 * Licensed under the MIT License at:
12
 * http://www.opensource.org/licenses/mit-license.php
13
 *
14
 * @author John Hann (@unscriptable)
15
 */
16
 
17
define(['./lib/plugin-base/dom', 'sizzle'], function(createDomPlugin, sizzle) {
18
 
19
    /**
20
     * The usual addClass function
21
     *
22
     * @param node
23
     * @param cls {String} space separated list of classes
24
     */
25
    function addClass(node, cls) {
26
        var className = node.className ? ' ' + node.className + ' ' : '';
27
 
28
        cls = cls.split(/\s+/);
29
 
30
        for (var i = 0, len = cls.length; i < len; i++) {
31
            var c = ' ' + cls[i];
32
            if(className.indexOf(c + ' ') < 0) {
33
                className += c;
34
            }
35
        }
36
 
37
        node.className = className.slice(1, className.length);
38
    }
39
 
40
    /**
41
     * The usual removeClass function
42
     *
43
     * @param node
44
     * @param cls {String} space separated list of classes
45
     */
46
    function removeClass(node, cls) {
47
        var className = ' ' + node.className + ' ';
48
 
49
        cls = cls.split(/\s+/);
50
 
51
        for (var i = 0, len = cls.length; i < len; i++) {
52
            var c = ' ' + cls[i] + ' ';
53
            className = className.replace(c, ' ');
54
        }
55
 
56
        node.className = className.replace(/(^\s+|\s+$)/g, '');
57
    }
58
 
59
    return createDomPlugin({
60
        query: sizzle,
61
        first: function (selector, root) {
62
            return sizzle(selector, root)[0];
63
        },
64
        addClass: addClass,
65
        removeClass: removeClass
66
    });
67
 
68
});