docs/js/jquery.smooth-scroll.js   A
last analyzed

Complexity

Total Complexity 8
Complexity/F 1.6

Size

Lines of Code 32
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 21
c 0
b 0
f 0
dl 0
loc 32
rs 10
wmc 8
mnd 3
bc 3
fnc 5
bpm 0.6
cpm 1.6
noi 2

1 Function

Rating   Name   Duplication   Size   Complexity  
A jquery.smooth-scroll.js ➔ filterPath 0 6 2
1
$(document).ready(function() {
2
    function filterPath(string) {
3
        return string
4
            .replace(/^\//,'')
5
            .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
6
            .replace(/\/$/,'');
7
    }
8
    var locationPath = filterPath(location.pathname);
9
10
    $('a[href*=#]').each(function() {
11
        var thisPath = filterPath(this.pathname) || locationPath;
12
        if (  locationPath == thisPath
13
            && (location.hostname == this.hostname || !this.hostname)
14
            && this.hash.replace(/#/,'') ) {
15
            var $target = $(this.hash), target = this.hash;
0 ignored issues
show
Unused Code introduced by
The variable $target seems to be never used. Consider removing it.
Loading history...
16
            if (target) {
17
                $(this).click(function(event) {
18
                    if (!$(this.hash).offset()) {
19
                        return;
20
                    }
21
22
                    event.preventDefault();
23
                    position = $(this.hash).offset().top;
0 ignored issues
show
Bug introduced by
The variable position seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.position.
Loading history...
24
25
                    $('html,body').animate({scrollTop: position}, 400, function() {
26
                        location.hash = target;
27
                    });
28
                });
29
            }
30
        }
31
    });
32
});
33