GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#2837)
by
unknown
05:48
created

symphony/assets/js/src/symphony.selectable.js   A

Complexity

Total Complexity 16
Complexity/F 4

Size

Lines of Code 126
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
c 0
b 0
f 0
nc 15
dl 0
loc 126
rs 10
wmc 16
mnd 2
bc 13
fnc 4
bpm 3.25
cpm 4
noi 4

1 Function

Rating   Name   Duplication   Size   Complexity  
B $.fn.symphonySelectable 0 97 1
1
/**
2
 * @package assets
3
 */
4
5
(function($, Symphony) {
0 ignored issues
show
Unused Code introduced by
The parameter Symphony 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...
6
7
	/**
8
	 * Create selectable elements. Clicking an item will select it
9
	 * by adding the class <code>.selected</code>. Holding down the shift key
10
	 * while clicking multiple items creates a selection range. Holding the meta key
11
	 * (which is <code>cmd</code> on a Mac or <code>ctrl</code> on Windows) allows
12
	 * the selection of multiple items or the modification of an already selected
13
	 * range of items. Doubleclicking outside the selection list will
14
	 * remove the selection.
15
	 *
16
	 * @name $.symphonySelectable
17
	 * @class
18
	 *
19
	 * @param {Object} options An object specifying containing the attributes specified below
20
	 * @param {String} [options.items='tbody tr:has(input)'] Selector to find items that are selectable
21
	 * item. Needed to properly handle item highlighting when used in connection with the orderable plugin
22
	 * @param {String} [options.ignore='a'] Selector to find elements that should not propagate to the handle
23
	 * @param {String} [optinos.mode='single'] Either 'default' (click removes other selections) or 'additive' (click adds to exisiting selection)
24
	 *
25
	 * @example
26
27
			var selectable = $('table').symphonySelectable();
28
			selectable.find('a').mousedown(function(event) {
29
				event.stopPropagation();
30
			});
31
	 */
32
	$.fn.symphonySelectable = function(options) {
33
		var objects = this,
34
			settings = {
35
				items: 'tbody tr:has(input)',
36
				ignore: 'a',
37
				mode: 'single'
38
			};
39
40
		$.extend(settings, options);
41
42
	/*-------------------------------------------------------------------------
43
		Events
44
	-------------------------------------------------------------------------*/
45
46
		// Select
47
		objects.on('click.selectable', settings.items, function select(event) {
48
			var item = $(this),
49
				items = item.siblings().addBack(),
50
				object = $(event.liveFired),
51
				target = $(event.target),
52
				selection, deselection, first, last;
53
54
			// Ignored elements
55
			if(target.is(settings.ignore)) {
56
				return true;
57
			}
58
59
			// Remove text ranges
60
			if(window.getSelection) {
61
				window.getSelection().removeAllRanges();
62
			}
63
64
			// Range selection
65
			if((event.shiftKey) && items.filter('.selected').length > 0 && !object.is('.single')) {
66
67
				// Select upwards
68
				if(item.prevAll().filter('.selected').length > 0) {
69
					first = items.filter('.selected:first').index();
70
					last = item.index() + 1;
71
				}
72
73
				// Select downwards
74
				else {
75
					first = item.index();
76
					last = items.filter('.selected:last').index() + 1;
77
				}
78
79
				// Get selection
80
				selection = items.slice(first, last);
81
82
				// Deselect items outside the selection range
83
				deselection = items.filter('.selected').not(selection).removeClass('selected').trigger('deselect.selectable');
84
				deselection.find('input[type="checkbox"]:hidden:first').prop('checked', false);
85
86
				// Select range
87
				selection.addClass('selected').trigger('select.selectable');
88
				selection.find('input[type="checkbox"]:hidden:first').prop('checked', true);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
89
			}
90
91
			// Single selection
92
			else {
93
94
				// Press meta or ctrl key to adjust current range, otherwise the selection will be removed
95
				if((!event.metaKey && !event.ctrlKey && settings.mode != 'additive' &&  !target.is('input')) || object.is('.single')) {
96
					deselection = items.not(item).filter('.selected').removeClass('selected').trigger('deselect.selectable');
97
					deselection.find('input[type="checkbox"]:hidden:first').prop('checked', false);
98
				}
99
100
				// Toggle selection
101
				if(item.is('.selected')) {
102
					item.removeClass('selected').trigger('deselect.selectable');
103
					item.find('input[type="checkbox"]:hidden:first').prop('checked', false);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
104
				}
105
				else {
106
					item.addClass('selected').trigger('select.selectable');
107
					item.find('input[type="checkbox"]:hidden:first').prop('checked', true);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
108
				}
109
			}
110
111
		});
112
113
		// Remove all selections by doubleclicking the body
114
		$('body').bind('dblclick.selectable', function removeAllSelection() {
115
			objects.find(settings.items).removeClass('selected').trigger('deselect.selectable');
116
		});
117
118
	/*-------------------------------------------------------------------------
119
		Initialisation
120
	-------------------------------------------------------------------------*/
121
122
		// Make selectable
123
		objects.addClass('selectable');
124
125
	/*-----------------------------------------------------------------------*/
126
127
		return objects;
128
	};
129
130
})(window.jQuery, window.Symphony);
131