carlwgeorge / centos / centos.org

Forked from centos/centos.org 3 years ago
Clone
401d07
/*! DataTables Bootstrap 3 integration
401d07
 * ©2011-2014 SpryMedia Ltd - datatables.net/license
401d07
 */
401d07
401d07
/**
401d07
 * DataTables integration for Bootstrap 3. This requires Bootstrap 3 and
401d07
 * DataTables 1.10 or newer.
401d07
 *
401d07
 * This file sets the defaults and adds options to DataTables to style its
401d07
 * controls using Bootstrap. See http://datatables.net/manual/styling/bootstrap
401d07
 * for further information.
401d07
 */
401d07
(function(window, document, undefined){
401d07
401d07
var factory = function( $, DataTable ) {
401d07
"use strict";
401d07
401d07
401d07
/* Set the defaults for DataTables initialisation */
401d07
$.extend( true, DataTable.defaults, {
401d07
	dom:
401d07
		"<'row'<'col-sm-0'l><'col-sm-12'f>>" +
401d07
		"<'row'<'col-sm-12'tr>>" +
401d07
		"<'row'<'col-sm-5'i><'col-sm-7'p>>",
401d07
	renderer: 'bootstrap'
401d07
} );
401d07
401d07
401d07
/* Default class modification */
401d07
$.extend( DataTable.ext.classes, {
401d07
	sWrapper:      "dataTables_wrapper form-inline dt-bootstrap",
401d07
	sFilterInput:  "form-control input-sm",
401d07
	sLengthSelect: "form-control input-sm"
401d07
} );
401d07
401d07
401d07
/* Bootstrap paging button renderer */
401d07
DataTable.ext.renderer.pageButton.bootstrap = function ( settings, host, idx, buttons, page, pages ) {
401d07
	var api     = new DataTable.Api( settings );
401d07
	var classes = settings.oClasses;
401d07
	var lang    = settings.oLanguage.oPaginate;
401d07
	var btnDisplay, btnClass;
401d07
401d07
	var attach = function( container, buttons ) {
401d07
		var i, ien, node, button;
401d07
		var clickHandler = function ( e ) {
401d07
			e.preventDefault();
401d07
			if ( !$(e.currentTarget).hasClass('disabled') ) {
401d07
				api.page( e.data.action ).draw( false );
401d07
			}
401d07
		};
401d07
401d07
		for ( i=0, ien=buttons.length ; i
401d07
			button = buttons[i];
401d07
401d07
			if ( $.isArray( button ) ) {
401d07
				attach( container, button );
401d07
			}
401d07
			else {
401d07
				btnDisplay = '';
401d07
				btnClass = '';
401d07
401d07
				switch ( button ) {
401d07
					case 'ellipsis':
401d07
						btnDisplay = '…';
401d07
						btnClass = 'disabled';
401d07
						break;
401d07
401d07
					case 'first':
401d07
						btnDisplay = lang.sFirst;
401d07
						btnClass = button + (page > 0 ?
401d07
							'' : ' disabled');
401d07
						break;
401d07
401d07
					case 'previous':
401d07
						btnDisplay = lang.sPrevious;
401d07
						btnClass = button + (page > 0 ?
401d07
							'' : ' disabled');
401d07
						break;
401d07
401d07
					case 'next':
401d07
						btnDisplay = lang.sNext;
401d07
						btnClass = button + (page < pages-1 ?
401d07
							'' : ' disabled');
401d07
						break;
401d07
401d07
					case 'last':
401d07
						btnDisplay = lang.sLast;
401d07
						btnClass = button + (page < pages-1 ?
401d07
							'' : ' disabled');
401d07
						break;
401d07
401d07
					default:
401d07
						btnDisplay = button + 1;
401d07
						btnClass = page === button ?
401d07
							'active' : '';
401d07
						break;
401d07
				}
401d07
401d07
				if ( btnDisplay ) {
401d07
					node = $('
  • ', {
  • 401d07
    							'class': classes.sPageButton+' '+btnClass,
    401d07
    							'aria-controls': settings.sTableId,
    401d07
    							'tabindex': settings.iTabIndex,
    401d07
    							'id': idx === 0 && typeof button === 'string' ?
    401d07
    								settings.sTableId +'_'+ button :
    401d07
    								null
    401d07
    						} )
    401d07
    						.append( $('', {
    401d07
    								'href': '#'
    401d07
    							} )
    401d07
    							.html( btnDisplay )
    401d07
    						)
    401d07
    						.appendTo( container );
    401d07
    401d07
    					settings.oApi._fnBindAction(
    401d07
    						node, {action: button}, clickHandler
    401d07
    					);
    401d07
    				}
    401d07
    			}
    401d07
    		}
    401d07
    	};
    401d07
    401d07
    	attach(
    401d07
    		$(host).empty().html('
      ').children('ul'),
    401d07
    		buttons
    401d07
    	);
    401d07
    };
    401d07
    401d07
    401d07
    /*
    401d07
     * TableTools Bootstrap compatibility
    401d07
     * Required TableTools 2.1+
    401d07
     */
    401d07
    if ( DataTable.TableTools ) {
    401d07
    	// Set the classes that TableTools uses to something suitable for Bootstrap
    401d07
    	$.extend( true, DataTable.TableTools.classes, {
    401d07
    		"container": "DTTT btn-group",
    401d07
    		"buttons": {
    401d07
    			"normal": "btn btn-default",
    401d07
    			"disabled": "disabled"
    401d07
    		},
    401d07
    		"collection": {
    401d07
    			"container": "DTTT_dropdown dropdown-menu",
    401d07
    			"buttons": {
    401d07
    				"normal": "",
    401d07
    				"disabled": "disabled"
    401d07
    			}
    401d07
    		},
    401d07
    		"print": {
    401d07
    			"info": "DTTT_print_info"
    401d07
    		},
    401d07
    		"select": {
    401d07
    			"row": "active"
    401d07
    		}
    401d07
    	} );
    401d07
    401d07
    	// Have the collection use a bootstrap compatible drop down
    401d07
    	$.extend( true, DataTable.TableTools.DEFAULTS.oTags, {
    401d07
    		"collection": {
    401d07
    			"container": "ul",
    401d07
    			"button": "li",
    401d07
    			"liner": "a"
    401d07
    		}
    401d07
    	} );
    401d07
    }
    401d07
    401d07
    }; // /factory
    401d07
    401d07
    401d07
    // Define as an AMD module if possible
    401d07
    if ( typeof define === 'function' && define.amd ) {
    401d07
    	define( ['jquery', 'datatables'], factory );
    401d07
    }
    401d07
    else if ( typeof exports === 'object' ) {
    401d07
        // Node/CommonJS
    401d07
        factory( require('jquery'), require('datatables') );
    401d07
    }
    401d07
    else if ( jQuery ) {
    401d07
    	// Otherwise simply initialise as normal, stopping multiple evaluation
    401d07
    	factory( jQuery, jQuery.fn.dataTable );
    401d07
    }
    401d07
    401d07
    401d07
    })(window, document);
    401d07