File datatables.js
has 6488 lines of code (exceeds 250 allowed). Consider refactoring. Open
/*
* MDBootstrap integration with Datatables
* Learn more: https://mdbootstrap.com/content/bootstrap-datatables/
* About MDBootstrap: https://mdbootstrap.com/
*
Function DataTable
has 495 lines of code (exceeds 25 allowed). Consider refactoring. Open
var DataTable = function ( options )
{
/**
* Perform a jQuery selector action on the table's TR elements (from the tbody) and
* return the resulting jQuery object.
Function _fnScrollDraw
has 169 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnScrollDraw ( settings )
{
// Given that this is such a monster function, a lot of variables are use
// to try and keep the minimised size as small as possible
var
Function _fnCalculateColumnWidths
has 136 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnCalculateColumnWidths ( oSettings )
{
var
table = oSettings.nTable,
columns = oSettings.aoColumns,
Function _fnAddOptionsHtml
has 109 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnAddOptionsHtml ( oSettings )
{
var classes = oSettings.oClasses;
var table = $(oSettings.nTable);
var holding = $('<div/>').insertBefore( table ); // Holding element for speed
Function _fnFeatureHtmlTable
has 103 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnFeatureHtmlTable ( settings )
{
var table = $(settings.nTable);
// Add the ARIA grid role to the table
Function _fnDraw
has 99 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnDraw( oSettings )
{
/* Provide a pre-callback function which can be used to cancel the draw is false is returned */
var aPreDraw = _fnCallbackFire( oSettings, 'aoPreDrawCallback', 'preDraw', [oSettings] );
if ( $.inArray( false, aPreDraw ) !== -1 )
Function _fnBuildAjax
has 91 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnBuildAjax( oSettings, data, fn )
{
// Compatibility with 1.9-, allow fnServerData and event to manipulate
_fnCallbackFire( oSettings, 'aoServerParams', 'serverParams', [data] );
Function bootstrap
has 90 lines of code (exceeds 25 allowed). Consider refactoring. Open
DataTable.ext.renderer.pageButton.bootstrap = function ( settings, host, idx, buttons, page, pages ) {
var api = new DataTable.Api( settings );
var classes = settings.oClasses;
var lang = settings.oLanguage.oPaginate;
var aria = settings.oLanguage.oAria.paginate || {};
Function _fnColumnOptions
has 86 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnColumnOptions( oSettings, iCol, oOptions )
{
var oCol = oSettings.aoColumns[ iCol ];
var oClasses = oSettings.oClasses;
var th = $(oCol.nTh);
Function _fnGetObjectDataFn
has 82 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnGetObjectDataFn( mSource )
{
if ( $.isPlainObject( mSource ) )
{
/* Build an object of get functions, and wrap them in a single call */
Function _
has 79 lines of code (exceeds 25 allowed). Consider refactoring. Open
_: function ( settings, host, idx, buttons, page, pages ) {
var classes = settings.oClasses;
var lang = settings.oLanguage.oPaginate;
var aria = settings.oLanguage.oAria.paginate || {};
var btnDisplay, btnClass, counter=0;
Function _fnSetObjectDataFn
has 77 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnSetObjectDataFn( mSource )
{
if ( $.isPlainObject( mSource ) )
{
/* Unlike get, only the underscore (global) option is used for for
Function _fnGetRowElements
has 73 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnGetRowElements( settings, row, colIdx, d )
{
var
tds = [],
td = row.firstChild,
Function _fnAjaxParameters
has 72 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnAjaxParameters( settings )
{
var
columns = settings.aoColumns,
columnCount = columns.length,
Function _fnSort
has 71 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnSort ( oSettings )
{
var
i, ien, iLen, j, jLen, k, kLen,
sDataType, nTh,
Function attach
has 71 lines of code (exceeds 25 allowed). Consider refactoring. Open
var attach = function( container, buttons ) {
var i, ien, node, button;
var clickHandler = function ( e ) {
e.preventDefault();
if ( !$(e.currentTarget).hasClass('disabled') && api.page() != e.data.action ) {
Function __column_selector
has 66 lines of code (exceeds 25 allowed). Consider refactoring. Open
var __column_selector = function ( settings, selector, opts )
{
var
columns = settings.aoColumns,
names = _pluck( columns, 'sName' ),
Function _fnDrawHead
has 65 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnDrawHead( oSettings, aoSource, bIncludeHidden )
{
var i, iLen, j, jLen, k, kLen, n, nLocalTr;
var aoLocal = [];
var aApplied = [];
Function attach
has 64 lines of code (exceeds 25 allowed). Consider refactoring. Open
var attach = function( container, buttons ) {
var i, ien, node, button;
var clickHandler = function ( e ) {
_fnPageChange( settings, e.data.action, true );
};
Function _fnLoadState
has 63 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnLoadState ( settings, oInit, callback )
{
var i, ien;
var columns = settings.aoColumns;
var loaded = function ( s ) {
Function loadedInit
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
var loadedInit = function () {
/*
* Sorting
* @todo For modularisation (1.11) this needs to do into a sort start up handler
*/
Function _fnFeatureHtmlFilter
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnFeatureHtmlFilter ( settings )
{
var classes = settings.oClasses;
var tableId = settings.sTableId;
var language = settings.oLanguage;
Function __row_selector
has 60 lines of code (exceeds 25 allowed). Consider refactoring. Open
var __row_selector = function ( settings, selector, opts )
{
var rows;
var run = function ( sel ) {
var selInt = _intVal( sel );
Function run
has 59 lines of code (exceeds 25 allowed). Consider refactoring. Open
var run = function ( s ) {
var selInt = _intVal( s );
// Selector - all
if ( s === '' ) {
Function __cell_selector
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
var __cell_selector = function ( settings, selector, opts )
{
var data = settings.aoData;
var rows = _selector_row_indexes( settings, opts );
var cells = _removeEmpty( _pluck_order( data, rows, 'anCells' ) );
Function run
has 56 lines of code (exceeds 25 allowed). Consider refactoring. Open
var run = function ( sel ) {
var selInt = _intVal( sel );
var i, ien;
var aoData = settings.aoData;
Function _fnPageChange
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnPageChange ( settings, action, redraw )
{
var
start = settings._iDisplayStart,
len = settings._iDisplayLength,
Function iterator
has 54 lines of code (exceeds 25 allowed). Consider refactoring. Open
iterator: function ( flatten, type, fn, alwaysNew ) {
var
a = [], ret,
i, ien, j, jen,
context = this.context,
Function _fnSortListener
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnSortListener ( settings, colIdx, append, callback )
{
var col = settings.aoColumns[ colIdx ];
var sorting = settings.aaSorting;
var asSorting = col.asSorting;
Function _selector_row_indexes
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
var _selector_row_indexes = function ( settings, opts )
{
var
i, ien, tmp, a=[],
displayFiltered = settings.aiDisplay,
Function loaded
has 51 lines of code (exceeds 25 allowed). Consider refactoring. Open
var loaded = function ( s ) {
if ( ! s || ! s.time ) {
callback();
return;
}
Function _fnApplyColumnDefs
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnApplyColumnDefs( oSettings, aoColDefs, aoCols, fn )
{
var i, iLen, j, jLen, k, kLen, def;
var columns = oSettings.aoColumns;
Function _fnSortFlatten
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnSortFlatten ( settings )
{
var
i, iLen, k, kLen,
aSort = [],
Function _fnCreateTr
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnCreateTr ( oSettings, iRow, nTrIn, anTds )
{
var
row = oSettings.aoData[iRow],
rowData = row._aData,
Function setData
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
var setData = function (data, val, src) {
var a = _fnSplitObjNotation( src ), b;
var aLast = a[a.length-1];
var arrayNotation, funcNotation, o, innerSrc;
Function _fnBuildHead
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnBuildHead( oSettings )
{
var i, ien, cell, row, column;
var thead = oSettings.nTHead;
var tfoot = oSettings.nTFoot;
Function run
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
var run = function ( s ) {
var fnSelector = typeof s === 'function';
if ( s === null || s === undefined || fnSelector ) {
// All cells and function selectors
Function _fnDetectHeader
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnDetectHeader ( aLayout, nThead )
{
var nTrs = $(nThead).children('tr');
var nTr, nCell;
var i, k, l, iLen, jLen, iColShifted, iColumn, iColspan, iRowspan;
Function _fnFilterData
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnFilterData ( settings )
{
var columns = settings.aoColumns;
var column;
var i, j, ien, jen, filterData, cellData, row;
Function _fnInitialise
has 43 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnInitialise ( settings )
{
var i, iLen, iAjaxStart=settings.iInitDisplayStart;
var columns = settings.aoColumns, column;
var features = settings.oFeatures;
Function __details_events
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
var __details_events = function ( settings )
{
var api = new _Api( settings );
var namespace = '.dt.DT_details';
var drawEvent = 'draw'+namespace;
Function _fnFeatureHtmlPaginate
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnFeatureHtmlPaginate ( settings )
{
var
type = settings.sPaginationType,
plugin = DataTable.ext.pager[ type ],
Function fetchData
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
var fetchData = function (data, type, src) {
var arrayNotation, funcNotation, out, innerSrc;
if ( src !== "" )
{
Function _fnBrowserDetect
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnBrowserDetect( settings )
{
// We don't need to do this every time DataTables is constructed, the values
// calculated are specific to the browser and OS configuration which we
// don't expect to change between initialisations
Function _fnFeatureHtmlLength
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnFeatureHtmlLength ( settings )
{
var
classes = settings.oClasses,
tableId = settings.sTableId,
Function _fnInvalidate
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnInvalidate( settings, rowIdx, src, colIdx )
{
var row = settings.aoData[ rowIdx ];
var i, ien;
var cellWrite = function ( cell, col ) {
Function _fnColumnTypes
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnColumnTypes ( settings )
{
var columns = settings.aoColumns;
var data = settings.aoData;
var types = DataTable.ext.type.detect;
Function jqueryui
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
jqueryui: function ( settings, cell, column, classes ) {
$('<div/>')
.addClass( classes.sSortJUIWrapper )
.append( cell.contents() )
.append( $('<span/>')
Consider simplifying this complex logical expression. Open
if ( ie67 || ! userInputs && ! scrollX && ! scrollY &&
columnCount == _fnVisbleColumns( oSettings ) &&
columnCount == headerCells.length
) {
for ( i=0 ; i<columnCount ; i++ ) {
Function __setColumnVis
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
var __setColumnVis = function ( settings, column, vis ) {
var
cols = settings.aoColumns,
col = cols[ column ],
data = settings.aoData,
Function _fnSortAria
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnSortAria ( settings )
{
var label;
var nextSort;
var columns = settings.aoColumns;
Function _toSettings
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
var _toSettings = function ( mixed )
{
var idx, jq;
var settings = DataTable.settings;
var tables = $.map( settings, function (el, i) {
Function _fnFilter
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnFilter( settings, input, force, regex, smart, caseInsensitive )
{
var rpSearch = _fnFilterCreateSearch( input, regex, smart, caseInsensitive );
var prevSearch = settings.oPreviousSearch.sSearch;
var displayMaster = settings.aiDisplayMaster;
Function _fnFilterComplete
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnFilterComplete ( oSettings, oInput, iForce )
{
var oPrevSearch = oSettings.oPreviousSearch;
var aoPrevSearch = oSettings.aoPreSearchCols;
var fnSaveFilter = function ( oFilter ) {
Function __details_add
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
var __details_add = function ( ctx, row, data, klass )
{
// Convert to array of TR elements
var rows = [];
var addRow = function ( r, k ) {
Function _fnGetCellData
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnGetCellData( settings, rowIdx, colIdx, type )
{
var draw = settings.iDraw;
var col = settings.aoColumns[colIdx];
var rowData = settings.aoData[rowIdx]._aData;
Function _fnAjaxUpdateDraw
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _fnAjaxUpdateDraw ( settings, json )
{
// v1.10 uses camelCase variables, while 1.9 uses Hungarian notation.
// Support both
var compat = function ( old, modern ) {
Function _numbers
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
function _numbers ( page, pages ) {
var
numbers = [],
buttons = extPagination.numbers_length,
half = Math.floor( buttons / 2 ),
Avoid deeply nested control flow statements. Open
if ( cache[k] === undefined ) {
cache[k] = _fnGetCellData( settings, k, i, 'type' );
}
Avoid deeply nested control flow statements. Open
if ( ! detectedType && j !== types.length-1 ) {
break;
}
Avoid deeply nested control flow statements. Open
if ( s( o, _fnGetCellData(settings, row, j), host.anCells ? host.anCells[j] : null ) ) {
a.push( o );
}
Avoid deeply nested control flow statements. Open
for ( var j=0, jLen=val.length ; j<jLen ; j++ )
{
o = {};
setData( o, val[j], innerSrc );
data[ a[i] ].push( o );
Avoid deeply nested control flow statements. Open
if ( typeof cellData !== 'string' && cellData.toString ) {
cellData = cellData.toString();
}
Avoid deeply nested control flow statements. Open
if ( cOption == aoFeatures[k].cFeature )
{
featureNode = aoFeatures[k].fnInit( oSettings );
break;
}
Function _fnFilter
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function _fnFilter( settings, input, force, regex, smart, caseInsensitive )
Avoid deeply nested control flow statements. Open
else if ( typeof aTargets[j] === 'number' && aTargets[j] < 0 )
{
/* Negative integer, right to left column counting */
fn( columns.length+aTargets[j], def );
}
Avoid deeply nested control flow statements. Open
if ( detectedType === 'html' ) {
break;
}
Avoid deeply nested control flow statements. Open
for ( j=0, jen=items.length ; j<jen ; j++ ) {
item = items[j];
if ( type === 'cell' ) {
ret = fn.call( apiInst, context[i], item.row, item.column, i, j );
Avoid deeply nested control flow statements. Open
if ( fomatters[ column.sType ] ) {
cellData = fomatters[ column.sType ]( cellData );
}
Avoid deeply nested control flow statements. Open
if ( cellData === null ) {
cellData = '';
}
Function _fnFilterColumn
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function _fnFilterColumn ( settings, searchStr, colIdx, regex, smart, caseInsensitive )
Function fnFilter
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
this.fnFilter = function( sInput, iColumn, bRegex, bSmart, bShowGlobal, bCaseInsensitive )
Avoid deeply nested control flow statements. Open
for ( k=0 ; k<iRowspan ; k++ )
{
aApplied[i+k][j+iColspan] = 1;
}
Avoid deeply nested control flow statements. Open
for ( k=0 ; k<iRowspan ; k++ )
{
aLayout[i+k][iColShifted+l] = {
"cell": nCell,
"unique": bUnique
Avoid deeply nested control flow statements. Open
if ( type === 'column-rows' ) {
rows = _selector_row_indexes( context[i], selector.opts );
}
Avoid deeply nested control flow statements. Open
while( columns.length <= aTargets[j] )
{
_fnAddColumn( oSettings );
}
Avoid deeply nested control flow statements. Open
if ( arrayNotation )
{
// Array notation
a[i] = a[i].replace(__reArray, '');
Avoid deeply nested control flow statements. Open
if ( data === null || data[ a[i] ] === undefined )
{
return undefined;
}
Function _
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
_: function ( settings, host, idx, buttons, page, pages ) {
Avoid deeply nested control flow statements. Open
if ( search == 'none' ) {
a.push( i );
}
else { // applied | removed
tmp = $.inArray( i, displayFiltered );
Function _fnReduce
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function _fnReduce ( that, fn, init, start, end, inc )
Function bootstrap
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
DataTable.ext.renderer.pageButton.bootstrap = function ( settings, host, idx, buttons, page, pages ) {
Consider simplifying this complex logical expression. Open
if ( nCell.nodeName.toUpperCase() == "TD" ||
nCell.nodeName.toUpperCase() == "TH" )
{
/* Get the col and rowspan attributes from the DOM and sanitise them */
iColspan = nCell.getAttribute('colspan') * 1;
Function fnUpdate
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
this.fnUpdate = function( mData, mRow, iColumn, bRedraw, bAction )
Function _selector_run
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
var _selector_run = function ( type, selector, selectFn, settings, opts )
Function number
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
number: function ( thousands, decimal, precision, prefix, postfix ) {
Function __columnData
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
var __columnData = function ( settings, column, r1, r2, rows ) {
Avoid too many return
statements within this function. Open
return host.length ?
[ host.data('dt-column') ] :
[];
Avoid too many return
statements within this function. Open
return function (data, type) { // row and meta also passed, but not used
return data[mSource];
};
Avoid too many return
statements within this function. Open
return function (data, val) { // meta is also passed in, but not used
data[mSource] = val;
};
Avoid too many return
statements within this function. Open
return aoData[ rowIdx ] && aoData[ rowIdx ].nTr === sel ?
[ rowIdx ] :
[];
Avoid too many return
statements within this function. Open
return aoData[ cellIdx.row ] && aoData[ cellIdx.row ].nTr === sel ?
[ cellIdx.row ] :
[];
Avoid too many return
statements within this function. Open
return [ _fnVisibleToColumnIndex( settings, idx ) ];
Avoid too many return
statements within this function. Open
return jq.map( function(i) {
idx = $.inArray( this, tables );
return idx !== -1 ? settings[idx] : null;
} ).toArray();
Avoid too many return
statements within this function. Open
return [ s._DT_CellIndex.column ];
Avoid too many return
statements within this function. Open
return host.length ?
[ host.data('dt-row') ] :
[];
Avoid too many return
statements within this function. Open
return [ rowObj.idx ];
Avoid too many return
statements within this function. Open
return jqResult;
Avoid too many return
statements within this function. Open
return $(nodes)
.filter( sel )
.map( function () {
return this._DT_RowIndex;
} )
Identical blocks of code found in 2 locations. Consider refactoring. Open
(function( factory ) {
"use strict";
if ( typeof define === 'function' && define.amd ) {
// AMD
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 60720.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Identical blocks of code found in 2 locations. Consider refactoring. Open
(function( factory ){
if ( typeof define === 'function' && define.amd ) {
// AMD
define( ['jquery', 'datatables.net'], function ( $ ) {
return factory( $, window, document );
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 1153.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76