src/main/webapp/jquery/js/jquery.dataTables_bootstrap.js
author Tomas Zeman <tzeman@volny.cz>
Tue, 05 Jun 2012 15:40:44 +0200
changeset 103 6a2a19785cd8
parent 46 3092875edd20
permissions -rw-r--r--
977f2e215a04b181 Task report
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
46
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     1
/*
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     2
 * http://datatables.net/media/blog/bootstrap_2/DT_bootstrap.js
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     3
 *
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     4
 * @copyright Copyright 2008-2012 Allan Jardine, all rights reserved.
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     5
 *
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     6
 * This source file is free software, under either the GPL v2 license or a
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     7
 * BSD style license, available at:
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     8
 *   http://datatables.net/license_gpl2
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
     9
 *   http://datatables.net/license_bsd
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    10
 * 
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    11
 * This source file is distributed in the hope that it will be useful, but 
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    12
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    13
 * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    14
 * 
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    15
 * For details please refer to: http://www.datatables.net
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    16
 */
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    17
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    18
/* Default class modification */
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    19
$.extend( $.fn.dataTableExt.oStdClasses, {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    20
	"sWrapper": "dataTables_wrapper form-inline"
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    21
} );
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    22
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    23
/* API method to get paging information */
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    24
$.fn.dataTableExt.oApi.fnPagingInfo = function ( oSettings )
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    25
{
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    26
	return {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    27
		"iStart":         oSettings._iDisplayStart,
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    28
		"iEnd":           oSettings.fnDisplayEnd(),
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    29
		"iLength":        oSettings._iDisplayLength,
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    30
		"iTotal":         oSettings.fnRecordsTotal(),
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    31
		"iFilteredTotal": oSettings.fnRecordsDisplay(),
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    32
		"iPage":          Math.ceil( oSettings._iDisplayStart / oSettings._iDisplayLength ),
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    33
		"iTotalPages":    Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength )
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    34
	};
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    35
}
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    36
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    37
/* Bootstrap style pagination control */
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    38
$.extend( $.fn.dataTableExt.oPagination, {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    39
	"bootstrap": {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    40
		"fnInit": function( oSettings, nPaging, fnDraw ) {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    41
			var oLang = oSettings.oLanguage.oPaginate;
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    42
			var fnClickHandler = function ( e ) {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    43
				e.preventDefault();
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    44
				if ( oSettings.oApi._fnPageChange(oSettings, e.data.action) ) {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    45
					fnDraw( oSettings );
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    46
				}
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    47
			};
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    48
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    49
			$(nPaging).addClass('pagination').append(
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    50
				'<ul>'+
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    51
					'<li class="prev disabled"><a href="#">&larr; '+oLang.sPrevious+'</a></li>'+
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    52
					'<li class="next disabled"><a href="#">'+oLang.sNext+' &rarr; </a></li>'+
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    53
				'</ul>'
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    54
			);
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    55
			var els = $('a', nPaging);
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    56
			$(els[0]).bind( 'click.DT', { action: "previous" }, fnClickHandler );
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    57
			$(els[1]).bind( 'click.DT', { action: "next" }, fnClickHandler );
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    58
		},
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    59
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    60
		"fnUpdate": function ( oSettings, fnDraw ) {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    61
			var iListLength = 5;
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    62
			var oPaging = oSettings.oInstance.fnPagingInfo();
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    63
			var an = oSettings.aanFeatures.p;
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    64
			var i, j, sClass, iStart, iEnd, iHalf=Math.floor(iListLength/2);
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    65
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    66
			if ( oPaging.iTotalPages < iListLength) {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    67
				iStart = 1;
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    68
				iEnd = oPaging.iTotalPages;
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    69
			}
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    70
			else if ( oPaging.iPage <= iHalf ) {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    71
				iStart = 1;
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    72
				iEnd = iListLength;
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    73
			} else if ( oPaging.iPage >= (oPaging.iTotalPages-iHalf) ) {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    74
				iStart = oPaging.iTotalPages - iListLength + 1;
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    75
				iEnd = oPaging.iTotalPages;
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    76
			} else {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    77
				iStart = oPaging.iPage - iHalf + 1;
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    78
				iEnd = iStart + iListLength - 1;
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    79
			}
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    80
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    81
			for ( i=0, iLen=an.length ; i<iLen ; i++ ) {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    82
				// Remove the middle elements
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    83
				$('li:gt(0)', an[i]).filter(':not(:last)').remove();
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    84
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    85
				// Add the new list items and their event handlers
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    86
				for ( j=iStart ; j<=iEnd ; j++ ) {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    87
					sClass = (j==oPaging.iPage+1) ? 'class="active"' : '';
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    88
					$('<li '+sClass+'><a href="#">'+j+'</a></li>')
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    89
						.insertBefore( $('li:last', an[i])[0] )
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    90
						.bind('click', function (e) {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    91
							e.preventDefault();
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    92
							oSettings._iDisplayStart = (parseInt($('a', this).text(),10)-1) * oPaging.iLength;
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    93
							fnDraw( oSettings );
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    94
						} );
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    95
				}
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    96
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    97
				// Add / remove disabled classes from the static elements
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    98
				if ( oPaging.iPage === 0 ) {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
    99
					$('li:first', an[i]).addClass('disabled');
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   100
				} else {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   101
					$('li:first', an[i]).removeClass('disabled');
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   102
				}
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   103
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   104
				if ( oPaging.iPage === oPaging.iTotalPages-1 || oPaging.iTotalPages === 0 ) {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   105
					$('li:last', an[i]).addClass('disabled');
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   106
				} else {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   107
					$('li:last', an[i]).removeClass('disabled');
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   108
				}
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   109
			}
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   110
		}
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   111
	}
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   112
} );
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   113
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   114
/* Table initialisation */
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   115
$(document).ready(function() {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   116
	$('#example').dataTable( {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   117
		"sDom": "<'row'<'span6'l><'span6'f>r>t<'row'<'span6'i><'span6'p>>",
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   118
		"sPaginationType": "bootstrap",
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   119
		"oLanguage": {
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   120
			"sLengthMenu": "_MENU_ records per page"
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   121
		}
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   122
	} );
3092875edd20 imported patch datatables+bootstrap-2.patch
Tomas Zeman <tzeman@volny.cz>
parents:
diff changeset
   123
} );