Changed plugin usage (enabled properties are no longer required)

pull/172/head
Matthew Hasbach 10 years ago
parent 4bd060d900
commit 6ada1d0def

@ -14,37 +14,40 @@
* *
* @example * @example
* $('#myTable').DataTable({ * $('#myTable').DataTable({
* conditionalPagination: true
* });
*
* @example
* $('#myTable').DataTable({
* conditionalPagination: { * conditionalPagination: {
* enable: true, * style: 'fade',
* fade: { * speed: 500 // optional
* enable: true,
* speed: 'fast'
* }
* } * }
* }); * });
*/ */
(function(window, document, $) { (function(window, document, $) {
$(document).on('init.dt', function(e, settings) { $(document).on('init.dt', function(e, dtSettings) {
if ($.isPlainObject(settings.oInit.conditionalPagination) && settings.oInit.conditionalPagination.enable) { var options = dtSettings.oInit.conditionalPagination;
var api = new $.fn.dataTable.Api(settings),
fade = settings.oInit.conditionalPagination.fade, if ($.isPlainObject(options) || options === true) {
fadeSpeed = 'slow', var config = $.isPlainObject(options) ? options : {},
fadeEnable = false, api = new $.fn.dataTable.Api(dtSettings),
speed = 'slow',
conditionalPagination = function() { conditionalPagination = function() {
var $pagination = $(api.table().container()).find('div.dataTables_paginate'); var $pagination = $(api.table().container()).find('div.dataTables_paginate');
if (api.page.info().pages <= 1) { if (api.page.info().pages <= 1) {
if (fadeEnable) { if (config.style === 'fade') {
$pagination.stop().fadeOut(fadeSpeed); $pagination.stop().fadeOut(speed);
} }
else { else {
$pagination.hide(); $pagination.hide();
} }
} }
else { else {
if (fadeEnable) { if (config.style === 'fade') {
$pagination.stop().fadeIn(fadeSpeed); $pagination.stop().fadeIn(speed);
} }
else { else {
$pagination.show(); $pagination.show();
@ -52,14 +55,8 @@
} }
}; };
if ($.isPlainObject(fade)) { if ($.isNumeric(config.speed) || $.type(config.speed) === 'string') {
if (fade.enable === true) { speed = config.speed;
fadeEnable = true;
}
if ($.isNumeric(fade.speed) || $.type(fade.speed) === 'string') {
fadeSpeed = fade.speed;
}
} }
conditionalPagination(); conditionalPagination();

Loading…
Cancel
Save