www/js/jquery/jquery-ui-slideraccess-addon.js   A
last analyzed

Complexity

Total Complexity 16
Complexity/F 2

Size

Lines of Code 84
Function Count 8

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
nc 64
dl 0
loc 84
rs 10
c 0
b 0
f 0
wmc 16
mnd 1
bc 9
fnc 8
bpm 1.125
cpm 2
noi 7

1 Function

Rating   Name   Duplication   Size   Complexity  
B $.fn.extend.sliderAccess 0 78 4
1
/*
2
 * jQuery UI Slider Access
3
 * By: Trent Richardson [http://trentrichardson.com]
4
 * Version 0.2
5
 * Last Modified: 12__regexoperators___/12/2011
6
 *
7
 * Copyright 2011 Trent Richardson
8
 * Dual licensed under the MIT and GPL licenses.
9
 * http://trentrichardson.com/Impromptu/GPL-LICENSE.txt
10
 * http://trentrichardson.com/Impromptu/MIT-LICENSE.txt
11
 *
12
 */
13
 (function ($) {
14
15
     $.fn.extend({
16
         sliderAccess: function (options) {
17
             options = options || {};
18
             options.touchonly = options.touchonly !== undefined ? options.touchonly : true; // by default only show it if touch device
19
20
             if (options.touchonly === true && !("ontouchend" in document))
21
                 return $(this);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
22
23
             return $(this).each(function (i, obj) {
0 ignored issues
show
Unused Code introduced by
The parameter obj is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter i is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
24
                 var $t = $(this),
25
                     o = $.extend({}, {
26
                                 where: 'after',
27
                                 step: $t.slider('option', 'step'),
28
                                 upIcon: 'ui-icon-plus',
29
                                 downIcon: 'ui-icon-minus',
30
                                 text: false,
31
                                 upText: '+',
32
                                 downText: '-',
33
                                 buttonset: true,
34
                                 buttonsetTag: 'span',
35
                                 speed: 150
36
                         }, options),
37
                     $buttons = $('<' + o.buttonsetTag + ' class="ui-slider-access">' +
38
                         '<button data-icon="' + o.downIcon + '" data-step="-' + o.step + '">' + o.downText + '</button>' +
39
                         '<button data-icon="' + o.upIcon + '" data-step="' + o.step + '">' + o.upText + '</button>' +
40
                         '</' + o.buttonsetTag + '>');
41
42
                 $buttons.children('button').each(function (j, jobj) {
0 ignored issues
show
Unused Code introduced by
The parameter j is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter jobj is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
43
                     var $jt = $(this),
44
                         timeout = null,
45
                         increment = function($jt, $t, e) {
46
                                 var step = $jt.data('step'),
47
                                    curr = $t.slider('value'),
48
                                    newval = curr += step * 1,
0 ignored issues
show
Unused Code introduced by
The assignment to variable curr seems to be never used. Consider removing it.
Loading history...
49
                                    minval = $t.slider('option', 'min'),
50
                                    maxval = $t.slider('option', 'max');
51
                                e.preventDefault();
52
                                if (newval < minval || newval > maxval)
53
                                    return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
54
                                $t.slider('value', newval);
55
                                $t.slider("option", "slide").call($t, null, { value: newval });
56
                             };
57
                         
58
                     $jt.button({
59
                         text: o.text,
60
                         icons: { primary: $jt.data('icon') }
61
                     })
62
                     .bind('touchstart mousedown', function (e) {
63
                         increment($jt, $t, e);
64
                         timeout = setInterval(function () {
65
                             increment($jt, $t, e);
66
                         }, o.speed);
67
                     });
68
69
                     $(document).bind('touchend mouseup', function () {
70
                             clearInterval(timeout);
71
                             return false;
72
                         });
73
74
                 });
75
76
                 // before or after
77
                 $t[o.where]($buttons);
78
79
                 if (o.buttonset) {
80
                     $buttons.removeClass('ui-corner-right').removeClass('ui-corner-left').buttonset();
81
                     $buttons.eq(0).addClass('ui-corner-left');
82
                     $buttons.eq(1).addClass('ui-corner-right');
83
                 }
84
85
                 // adjust the width so we don't break the original layout
86
                 var bOuterWidth = $buttons.css({
87
                     marginLeft: (o.where == 'after' ? 10 : 0),
88
                     marginRight: (o.where == 'before' ? 10 : 0)
89
                 }).outerWidth(true) + 5;
90
                 var tOuterWidth = $t.outerWidth(true);
91
                 $t.css('display', 'inline-block').width(tOuterWidth - bOuterWidth);
92
             });
93
         }
94
     });
95
96
 })(jQuery);