Feature - searchPanes: Code style with Prettier

pull/355/head
Allan Jardine 7 years ago
parent 797c3e6f90
commit e9c4e4a8ea

@ -8,15 +8,13 @@
// - State saving integration
// - Fix regex characters - (CEO) for example
(function(factory) {
if (typeof define === 'function' && define.amd) {
// AMD
define(['jquery', 'datatables.net'], function($) {
return factory($, window, document);
});
}
else if ( typeof exports === 'object' ) {
} else if (typeof exports === 'object') {
// CommonJS
module.exports = function(root, $) {
if (!root) {
@ -29,16 +27,14 @@
return factory($, root, root.document);
};
}
else {
} else {
// Browser
factory(jQuery, window, document);
}
}(function( $, window, document, undefined ) {
})(function($, window, document, undefined) {
'use strict';
var DataTable = $.fn.dataTable;
function SearchPanes(settings, opts) {
var that = this;
var table = new DataTable.Api(settings);
@ -55,7 +51,10 @@ function SearchPanes ( settings, opts ) {
dt: table
};
table.columns(opts.columns).eq(0).each( function ( idx ) {
table
.columns(opts.columns)
.eq(0)
.each(function(idx) {
that._pane(idx);
});
@ -68,7 +67,6 @@ function SearchPanes ( settings, opts ) {
});
}
$.extend(SearchPanes.prototype, {
_binData: function(data) {
var out = {};
@ -80,8 +78,7 @@ $.extend( SearchPanes.prototype, {
if (!out[d]) {
out[d] = 1;
}
else {
} else {
out[d]++;
}
});
@ -114,18 +111,29 @@ $.extend( SearchPanes.prototype, {
// On initialisation, do we need to set a filtering value from a
// saved state or init option?
var search = column.search();
search = search.length && search[0] ?
search[0].substr( 1, search[0].length-2 ).split('|') :
[];
search =
search.length && search[0]
? search[0].substr(1, search[0].length - 2).split('|')
: [];
var data = column.data().unique().sort().toArray();
var data = column
.data()
.unique()
.sort()
.toArray();
for (var i = 0, ien = data.length; i < ien; i++) {
if (data[i]) {
var li = $('<li/>')
.html( '<span class="'+itemClasses.label+'">'+data[i]+'</span>' )
.html(
'<span class="' + itemClasses.label + '">' + data[i] + '</span>'
)
.data('filter', data[i])
.append( $('<span/>').addClass( itemClasses.count ).html( bins[ data[i] ] ) );
.append(
$('<span/>')
.addClass(itemClasses.count)
.html(bins[data[i]])
);
if ($.inArray(data[i], search) !== -1) {
li.addClass(itemClasses.selected);
@ -140,9 +148,21 @@ $.extend( SearchPanes.prototype, {
.data('column', idx)
.addClass(paneClasses.container)
.addClass(search.length ? paneClasses.active : '')
.append( $('<button type="button">&times;</button>').addClass(this.classes.clear) )
.append( $('<div/>').addClass(paneClasses.title).html( $(column.header()).text() ) )
.append( $('<div/>').addClass(paneClasses.scroller).append( list ) )
.append(
$('<button type="button">&times;</button>').addClass(
this.classes.clear
)
)
.append(
$('<div/>')
.addClass(paneClasses.title)
.html($(column.header()).text())
)
.append(
$('<div/>')
.addClass(paneClasses.scroller)
.append(list)
)
);
},
@ -163,14 +183,17 @@ $.extend( SearchPanes.prototype, {
.column(pane.data('column'))
.search('')
.draw();
}
else {
} else {
pane.addClass(classes.pane.active);
table
.column(pane.data('column'))
.search( $.map( filters, function (filter) {
.search(
$.map(filters, function(filter) {
return $(filter).data('filter');
} ).join('|'), true, false )
}).join('|'),
true,
false
)
.draw();
}
}
@ -192,8 +215,6 @@ SearchPanes.classes = {
}
};
$(document).on('init.dt', function(e, settings, json) {
if (e.namespace !== 'dt') {
return;
@ -210,6 +231,4 @@ $(document).on( 'init.dt', function (e, settings, json) {
}
}
});
}));
});

Loading…
Cancel
Save