Test Failed
Push — master ( 656844...7b0727 )
by Justin
21:52 queued 17:47
created

styles/admin/bower_components/datatables.net-bs/js/dataTables.bootstrap.js   A

Complexity

Total Complexity 33
Complexity/F 4.71

Size

Lines of Code 170
Function Count 7

Duplication

Duplicated Lines 142
Ratio 83.53 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 0
c 1
b 0
f 1
nc 2048
dl 142
loc 170
rs 9.3999
wmc 33
mnd 4
bc 20
fnc 7
bpm 2.8571
cpm 4.7142
noi 5

3 Functions

Rating   Name   Duplication   Size   Complexity  
A dataTables.bootstrap.js ➔ define 0 3 1
A module.exports 0 14 4
B dataTables.bootstrap.js ➔ ?!? 142 142 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
/*! DataTables Bootstrap 3 integration
2
 * ©2011-2015 SpryMedia Ltd - datatables.net/license
3
 */
4
5
/**
6
 * DataTables integration for Bootstrap 3. This requires Bootstrap 3 and
7
 * DataTables 1.10 or newer.
8
 *
9
 * This file sets the defaults and adds options to DataTables to style its
10
 * controls using Bootstrap. See http://datatables.net/manual/styling/bootstrap
11
 * for further information.
12
 */
13
(function( factory ){
14
	if ( typeof define === 'function' && define.amd ) {
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
15
		// AMD
16
		define( ['jquery', 'datatables.net'], function ( $ ) {
17
			return factory( $, window, document );
18
		} );
19
	}
20
	else if ( typeof exports === 'object' ) {
21
		// CommonJS
22
		module.exports = function (root, $) {
23
			if ( ! root ) {
24
				root = window;
25
			}
26
27
			if ( ! $ || ! $.fn.dataTable ) {
28
				// Require DataTables, which attaches to jQuery, including
29
				// jQuery if needed and have a $ property so we can access the
30
				// jQuery object that is used
31
				$ = require('datatables.net')(root, $).$;
32
			}
33
34
			return factory( $, root, root.document );
35
		};
36
	}
37
	else {
38
		// Browser
39
		factory( jQuery, window, document );
40
	}
41 View Code Duplication
}(function( $, window, document, undefined ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
42
'use strict';
43
var DataTable = $.fn.dataTable;
44
45
46
/* Set the defaults for DataTables initialisation */
47
$.extend( true, DataTable.defaults, {
48
	dom:
49
		"<'row'<'col-sm-6'l><'col-sm-6'f>>" +
50
		"<'row'<'col-sm-12'tr>>" +
51
		"<'row'<'col-sm-5'i><'col-sm-7'p>>",
52
	renderer: 'bootstrap'
53
} );
54
55
56
/* Default class modification */
57
$.extend( DataTable.ext.classes, {
58
	sWrapper:      "dataTables_wrapper form-inline dt-bootstrap",
59
	sFilterInput:  "form-control input-sm",
60
	sLengthSelect: "form-control input-sm",
61
	sProcessing:   "dataTables_processing panel panel-default"
62
} );
63
64
65
/* Bootstrap paging button renderer */
66
DataTable.ext.renderer.pageButton.bootstrap = function ( settings, host, idx, buttons, page, pages ) {
67
	var api     = new DataTable.Api( settings );
68
	var classes = settings.oClasses;
69
	var lang    = settings.oLanguage.oPaginate;
70
	var aria = settings.oLanguage.oAria.paginate || {};
71
	var btnDisplay, btnClass, counter=0;
72
73
	var attach = function( container, buttons ) {
74
		var i, ien, node, button;
75
		var clickHandler = function ( e ) {
76
			e.preventDefault();
77
			if ( !$(e.currentTarget).hasClass('disabled') && api.page() != e.data.action ) {
78
				api.page( e.data.action ).draw( 'page' );
79
			}
80
		};
81
82
		for ( i=0, ien=buttons.length ; i<ien ; i++ ) {
83
			button = buttons[i];
84
85
			if ( $.isArray( button ) ) {
86
				attach( container, button );
87
			}
88
			else {
89
				btnDisplay = '';
90
				btnClass = '';
91
92
				switch ( button ) {
93
					case 'ellipsis':
94
						btnDisplay = '&#x2026;';
95
						btnClass = 'disabled';
96
						break;
97
98
					case 'first':
99
						btnDisplay = lang.sFirst;
100
						btnClass = button + (page > 0 ?
101
							'' : ' disabled');
102
						break;
103
104
					case 'previous':
105
						btnDisplay = lang.sPrevious;
106
						btnClass = button + (page > 0 ?
107
							'' : ' disabled');
108
						break;
109
110
					case 'next':
111
						btnDisplay = lang.sNext;
112
						btnClass = button + (page < pages-1 ?
113
							'' : ' disabled');
114
						break;
115
116
					case 'last':
117
						btnDisplay = lang.sLast;
118
						btnClass = button + (page < pages-1 ?
119
							'' : ' disabled');
120
						break;
121
122
					default:
123
						btnDisplay = button + 1;
124
						btnClass = page === button ?
125
							'active' : '';
126
						break;
127
				}
128
129
				if ( btnDisplay ) {
0 ignored issues
show
Bug introduced by
The variable btnDisplay is changed as part of the for loop for example by lang.sLast on line 117. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
130
					node = $('<li>', {
131
							'class': classes.sPageButton+' '+btnClass,
0 ignored issues
show
Bug introduced by
The variable btnClass is changed as part of the for loop for example by page === button ? "active": "" on line 124. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
132
							'id': idx === 0 && typeof button === 'string' ?
133
								settings.sTableId +'_'+ button :
134
								null
135
						} )
136
						.append( $('<a>', {
137
								'href': '#',
138
								'aria-controls': settings.sTableId,
139
								'aria-label': aria[ button ],
140
								'data-dt-idx': counter,
0 ignored issues
show
Bug introduced by
The variable counter is changed as part of the for loop for example by counter++ on line 151. Only the value of the last iteration will be visible in this function if it is called after the loop.
Loading history...
141
								'tabindex': settings.iTabIndex
142
							} )
143
							.html( btnDisplay )
144
						)
145
						.appendTo( container );
146
147
					settings.oApi._fnBindAction(
148
						node, {action: button}, clickHandler
149
					);
150
151
					counter++;
152
				}
153
			}
154
		}
155
	};
156
157
	// IE9 throws an 'unknown error' if document.activeElement is used
158
	// inside an iframe or frame. 
159
	var activeEl;
160
161
	try {
162
		// Because this approach is destroying and recreating the paging
163
		// elements, focus is lost on the select button which is bad for
164
		// accessibility. So we want to restore focus once the draw has
165
		// completed
166
		activeEl = $(host).find(document.activeElement).data('dt-idx');
167
	}
168
	catch (e) {}
0 ignored issues
show
Coding Style Comprehensibility Best Practice introduced by
Empty catch clauses should be used with caution; consider adding a comment why this is needed.
Loading history...
169
170
	attach(
171
		$(host).empty().html('<ul class="pagination"/>').children('ul'),
172
		buttons
173
	);
174
175
	if ( activeEl !== undefined ) {
176
		$(host).find( '[data-dt-idx='+activeEl+']' ).focus();
177
	}
178
};
179
180
181
return DataTable;
182
}));
183