Subversion-Projekte lars-tiefland.webanos.zeldi.de

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
4 lars 1
/*! DataTables Foundation integration
2
 * ©2011-2014 SpryMedia Ltd - datatables.net/license
3
 */
4
 
5
/**
6
 * DataTables integration for Foundation. This requires Foundation 5 and
7
 * DataTables 1.10 or newer.
8
 *
9
 * This file sets the defaults and adds options to DataTables to style its
10
 * controls using Foundation. See http://datatables.net/manual/styling/foundation
11
 * for further information.
12
 */
13
(function(window, document, undefined){
14
 
15
var factory = function( $, DataTable ) {
16
"use strict";
17
 
18
 
19
$.extend( DataTable.ext.classes, {
20
	sWrapper: "dataTables_wrapper dt-foundation"
21
} );
22
 
23
 
24
/* Set the defaults for DataTables initialisation */
25
$.extend( true, DataTable.defaults, {
26
	dom:
27
		"<'row'<'small-6 columns'l><'small-6 columns'f>r>"+
28
		"t"+
29
		"<'row'<'small-6 columns'i><'small-6 columns'p>>",
30
	renderer: 'foundation'
31
} );
32
 
33
 
34
/* Page button renderer */
35
DataTable.ext.renderer.pageButton.foundation = function ( settings, host, idx, buttons, page, pages ) {
36
	var api = new DataTable.Api( settings );
37
	var classes = settings.oClasses;
38
	var lang = settings.oLanguage.oPaginate;
39
	var btnDisplay, btnClass;
40
 
41
	var attach = function( container, buttons ) {
42
		var i, ien, node, button;
43
		var clickHandler = function ( e ) {
44
			e.preventDefault();
45
			if ( e.data.action !== 'ellipsis' ) {
46
				api.page( e.data.action ).draw( false );
47
			}
48
		};
49
 
50
		for ( i=0, ien=buttons.length ; i<ien ; i++ ) {
51
			button = buttons[i];
52
 
53
			if ( $.isArray( button ) ) {
54
				attach( container, button );
55
			}
56
			else {
57
				btnDisplay = '';
58
				btnClass = '';
59
 
60
				switch ( button ) {
61
					case 'ellipsis':
62
						btnDisplay = '&hellip;';
63
						btnClass = 'unavailable';
64
						break;
65
 
66
					case 'first':
67
						btnDisplay = lang.sFirst;
68
						btnClass = button + (page > 0 ?
69
							'' : ' unavailable');
70
						break;
71
 
72
					case 'previous':
73
						btnDisplay = lang.sPrevious;
74
						btnClass = button + (page > 0 ?
75
							'' : ' unavailable');
76
						break;
77
 
78
					case 'next':
79
						btnDisplay = lang.sNext;
80
						btnClass = button + (page < pages-1 ?
81
							'' : ' unavailable');
82
						break;
83
 
84
					case 'last':
85
						btnDisplay = lang.sLast;
86
						btnClass = button + (page < pages-1 ?
87
							'' : ' unavailable');
88
						break;
89
 
90
					default:
91
						btnDisplay = button + 1;
92
						btnClass = page === button ?
93
							'current' : '';
94
						break;
95
				}
96
 
97
				if ( btnDisplay ) {
98
					node = $('<li>', {
99
							'class': classes.sPageButton+' '+btnClass,
100
							'aria-controls': settings.sTableId,
101
							'tabindex': settings.iTabIndex,
102
							'id': idx === 0 && typeof button === 'string' ?
103
								settings.sTableId +'_'+ button :
104
								null
105
						} )
106
						.append( $('<a>', {
107
								'href': '#'
108
							} )
109
							.html( btnDisplay )
110
						)
111
						.appendTo( container );
112
 
113
					settings.oApi._fnBindAction(
114
						node, {action: button}, clickHandler
115
					);
116
				}
117
			}
118
		}
119
	};
120
 
121
	attach(
122
		$(host).empty().html('<ul class="pagination"/>').children('ul'),
123
		buttons
124
	);
125
};
126
 
127
 
128
/*
129
 * TableTools Foundation compatibility
130
 * Required TableTools 2.1+
131
 */
132
if ( DataTable.TableTools ) {
133
	// Set the classes that TableTools uses to something suitable for Foundation
134
	$.extend( true, DataTable.TableTools.classes, {
135
		"container": "DTTT button-group",
136
		"buttons": {
137
			"normal": "button small",
138
			"disabled": "disabled"
139
		},
140
		"collection": {
141
			"container": "DTTT_dropdown dropdown-menu",
142
			"buttons": {
143
				"normal": "",
144
				"disabled": "disabled"
145
			}
146
		},
147
		"select": {
148
			"row": "active"
149
		}
150
	} );
151
 
152
	// Have the collection use a bootstrap compatible dropdown
153
	$.extend( true, DataTable.TableTools.DEFAULTS.oTags, {
154
		"collection": {
155
			"container": "ul",
156
			"button": "li",
157
			"liner": "a"
158
		}
159
	} );
160
}
161
 
162
}; // /factory
163
 
164
 
165
// Define as an AMD module if possible
166
if ( typeof define === 'function' && define.amd ) {
167
	define( ['jquery', 'datatables'], factory );
168
}
169
else if ( typeof exports === 'object' ) {
170
    // Node/CommonJS
171
    factory( require('jquery'), require('datatables') );
172
}
173
else if ( jQuery ) {
174
	// Otherwise simply initialise as normal, stopping multiple evaluation
175
	factory( jQuery, jQuery.fn.dataTable );
176
}
177
 
178
 
179
})(window, document);
180