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.orderable.js   A

Complexity

Total Complexity 21
Complexity/F 2.63

Size

Lines of Code 147
Function Count 8

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
c 0
b 0
f 0
nc 2
dl 0
loc 147
rs 10
wmc 21
mnd 3
bc 21
fnc 8
bpm 2.625
cpm 2.625
noi 4

1 Function

Rating   Name   Duplication   Size   Complexity  
B $.fn.symphonyOrderable 0 124 1
1
/**
2
 * @package assets
3
 */
4
5
(function($, Symphony) {
6
7
	/**
8
	 * Create orderable elements.
9
	 *
10
	 * @name $.symphonyOrderable
11
	 * @class
12
	 *
13
	 * @param {Object} options An object specifying containing the attributes specified below
14
	 * @param {String} [options.items='li'] Selector to find items to be orderable
15
	 * @param {String} [options.handles='*'] Selector to find children that can be grabbed to re-order
16
	 * @param {String} [options.ignore='input, textarea, select'] Selector to find elements that should not propagate to the handle
17
	 * @param {Integer} [options.delay=250] Time used to delay actions
18
	 *
19
	 * @example
20
21
			$('table').symphonyOrderable({
22
				items: 'tr',
23
				handles: 'td'
24
			});
25
	 */
26
	$.fn.symphonyOrderable = function(options) {
27
		var objects = this,
28
			settings = {
29
				items: 'li',
30
				handles: '*',
31
				ignore: 'input, textarea, select, a',
32
				delay: 250
33
			};
34
35
		$.extend(settings, options);
36
37
	/*-------------------------------------------------------------------------
38
		Events
39
	-------------------------------------------------------------------------*/
40
41
		// Start ordering
42
		objects.on('mousedown.orderable', settings.items + ' ' + settings.handles, function startOrdering(event) {
43
			var handle = $(this),
44
				item = handle.parents(settings.items),
45
				object = handle.parents('.orderable');
46
47
			// Needed to prevent browsers from selecting texts and focusing textinputs
48
			if(!$(event.target).is('input, textarea')) {
49
				event.preventDefault();
50
			}
51
52
			if(!handle.is(settings.ignore) && !$(event.target).is(settings.ignore)) {
53
				object.data('ordering', 1);
54
55
				// Highlight item
56
				if(object.is('.selectable, .collapsible')) {
57
58
					// Delay ordering to avoid conflicts with scripts bound to the click event
59
					setTimeout(function() {
60
						if(object.data('ordering') == 1) {
0 ignored issues
show
Best Practice introduced by
Comparing object.data("ordering") to 1 using the == operator is not safe. Consider using === instead.
Loading history...
61
							object.trigger('orderstart.orderable', [item]);
62
							item.addClass('ordering');
63
						}
64
					}, settings.delay);
65
				}
66
				else {
67
					object.trigger('orderstart.orderable', [item]);
68
					item.addClass('ordering');
69
				}
70
			}
71
		});
72
73
		// Stop ordering
74
		objects.on('mouseup.orderable mouseleave.orderable', function stopOrdering(event) {
0 ignored issues
show
Unused Code introduced by
The parameter event 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...
75
			var object = $(this),
76
				item;
77
78
			if(object.data('ordering') == 1) {
0 ignored issues
show
Best Practice introduced by
Comparing object.data("ordering") to 1 using the == operator is not safe. Consider using === instead.
Loading history...
79
				item = object.find('.ordering');
80
				item.removeClass('ordering');
81
				object.data('ordering', 0);
82
				object.trigger('orderstop.orderable', [item]);
83
84
				// Lock item to avoid conflicts with scripts bound to the click event
85
				object.trigger('orderstoplock.orderable', [item]);
86
				item.addClass('locked');
87
				setTimeout(function() {
88
					item.removeClass('locked');
89
					object.trigger('orderstopunlock.orderable', [item]);
90
				}, settings.delay);
91
			}
92
		});
93
94
		// Order items
95
		$(document).on('mousemove.orderable', '.orderable:has(.ordering)', function order(event) {
96
			var object = $(this);
97
			if (object.data('ordering') != 1) {
0 ignored issues
show
Best Practice introduced by
Comparing object.data("ordering") to 1 using the != operator is not safe. Consider using !== instead.
Loading history...
98
				return;
99
			}
100
			// Only keep what we need from event object
101
			var pageY = event.pageY;
102
			Symphony.Utilities.requestAnimationFrame(function () {
103
				var item = object.find('.ordering');
104
105
				// If there is still an ordering item in DOM
106
				if (!item.length) {
107
					return;
108
				}
109
110
				var top = item.offset().top,
111
					bottom = top + item.outerHeight(),
112
					prev, next;
113
114
				// Remove text ranges
115
				if(window.getSelection) {
116
					window.getSelection().removeAllRanges();
117
				}
118
119
				// Move item up
120
				if(pageY < top) {
121
					prev = item.prev(settings.items);
122
					if(prev.length > 0) {
123
						item.insertBefore(prev);
124
						object.trigger('orderchange', [item]);
125
					}
126
				}
127
128
				// Move item down
129
				else if(pageY > bottom) {
130
					next = item.next(settings.items);
131
					if(next.length > 0) {
132
						item.insertAfter(next);
133
						object.trigger('orderchange', [item]);
134
					}
135
				}
136
			});
137
		});
138
139
	/*-------------------------------------------------------------------------
140
		Initialisation
141
	-------------------------------------------------------------------------*/
142
143
		// Make orderable
144
		objects.addClass('orderable');
145
146
	/*-----------------------------------------------------------------------*/
147
148
		return objects;
149
	};
150
151
})(window.jQuery, window.Symphony);
152