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 (#2835)
by
unknown
06:01
created

symphony/assets/js/src/symphony.orderable.js   A

Complexity

Total Complexity 21
Complexity/F 2.63

Size

Lines of Code 148
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 148
rs 10
wmc 21
mnd 3
bc 21
fnc 8
bpm 2.625
cpm 2.625
noi 3

1 Function

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