1
|
/*!
|
2
|
* DataTables UIKit integration
|
3
|
* author: tzd
|
4
|
*/
|
5
|
|
6
|
(function(window, document, undefined){
|
7
|
|
8
|
var factory = function( $, DataTable ) {
|
9
|
"use strict";
|
10
|
|
11
|
|
12
|
/* Set the defaults for DataTables initialisation */
|
13
|
$.extend( true, DataTable.defaults, {
|
14
|
dom:
|
15
|
"<'dt-uikit-header'<'uk-grid'<'uk-width-medium-2-3'l><'uk-width-medium-1-3'f>>>" +
|
16
|
"<'uk-overflow-container'tr>" +
|
17
|
"<'dt-uikit-footer'<'uk-grid'<'uk-width-medium-3-10'i><'uk-width-medium-7-10'p>>>",
|
18
|
renderer: 'uikit',
|
19
|
"order": []
|
20
|
} );
|
21
|
|
22
|
|
23
|
/* Default class modification */
|
24
|
$.extend( DataTable.ext.classes, {
|
25
|
sWrapper: "dataTables_wrapper form-inline dt-uikit",
|
26
|
sFilterInput: "md-input",
|
27
|
sLengthSelect: "dt-selectize",
|
28
|
"sPaging": ""
|
29
|
} );
|
30
|
|
31
|
/* Bootstrap paging button renderer */
|
32
|
DataTable.ext.renderer.pageButton.uikit = function ( settings, host, idx, buttons, page, pages ) {
|
33
|
var api = new DataTable.Api( settings );
|
34
|
var classes = settings.oClasses;
|
35
|
var lang = settings.oLanguage.oPaginate;
|
36
|
var btnDisplay, btnClass, counter=0;
|
37
|
|
38
|
var attach = function( container, buttons ) {
|
39
|
var i, ien, node, button;
|
40
|
var clickHandler = function ( e ) {
|
41
|
e.preventDefault();
|
42
|
if ( !$(e.currentTarget).hasClass('disabled') ) {
|
43
|
api.page( e.data.action ).draw( false );
|
44
|
}
|
45
|
};
|
46
|
|
47
|
for ( i=0, ien=buttons.length ; i<ien ; i++ ) {
|
48
|
button = buttons[i];
|
49
|
|
50
|
if ( $.isArray( button ) ) {
|
51
|
attach( container, button );
|
52
|
}
|
53
|
else {
|
54
|
btnDisplay = '';
|
55
|
btnClass = '';
|
56
|
|
57
|
switch ( button ) {
|
58
|
case 'ellipsis':
|
59
|
btnDisplay = '…';
|
60
|
btnClass = 'uk-disabled';
|
61
|
break;
|
62
|
|
63
|
case 'first':
|
64
|
btnDisplay = '<i class="uk-icon-angle-double-left"/>';
|
65
|
btnClass = button + (page > 0 ?
|
66
|
'' : ' uk-disabled');
|
67
|
break;
|
68
|
|
69
|
case 'previous':
|
70
|
btnDisplay = lang.sPrevious;
|
71
|
btnClass = button + (page > 0 ?
|
72
|
'' : ' uk-disabled');
|
73
|
break;
|
74
|
|
75
|
case 'next':
|
76
|
btnDisplay = lang.sNext;
|
77
|
btnClass = button + (page < pages-1 ?
|
78
|
'' : ' uk-disabled');
|
79
|
break;
|
80
|
|
81
|
case 'last':
|
82
|
btnDisplay = '<i class="uk-icon-angle-double-right"/>';
|
83
|
btnClass = button + (page < pages-1 ?
|
84
|
'' : ' uk-disabled');
|
85
|
break;
|
86
|
|
87
|
default:
|
88
|
btnDisplay = button + 1;
|
89
|
btnClass = page === button ?
|
90
|
'uk-active' : '';
|
91
|
break;
|
92
|
}
|
93
|
|
94
|
if ( btnDisplay ) {
|
95
|
node = $('<li>', {
|
96
|
'class': classes.sPageButton+' '+btnClass,
|
97
|
'id': idx === 0 && typeof button === 'string' ?
|
98
|
settings.sTableId +'_'+ button :
|
99
|
null
|
100
|
} )
|
101
|
.append( $('<a>', {
|
102
|
'href': '#',
|
103
|
'aria-controls': settings.sTableId,
|
104
|
'data-dt-idx': counter,
|
105
|
'tabindex': settings.iTabIndex
|
106
|
} )
|
107
|
.html( btnDisplay )
|
108
|
)
|
109
|
.appendTo( container );
|
110
|
|
111
|
settings.oApi._fnBindAction(
|
112
|
node, {action: button}, clickHandler
|
113
|
);
|
114
|
|
115
|
counter++;
|
116
|
}
|
117
|
}
|
118
|
}
|
119
|
};
|
120
|
|
121
|
var activeEl;
|
122
|
|
123
|
try {
|
124
|
activeEl = $(document.activeElement).data('dt-idx');
|
125
|
}
|
126
|
catch (e) {}
|
127
|
|
128
|
attach(
|
129
|
$(host).empty().html('<ul class="uk-pagination"/>').children('ul'),
|
130
|
buttons
|
131
|
);
|
132
|
|
133
|
if ( activeEl ) {
|
134
|
$(host).find( '[data-dt-idx='+activeEl+']' ).focus();
|
135
|
}
|
136
|
};
|
137
|
|
138
|
};
|
139
|
|
140
|
$('body').on( 'init.dt', '.dt-uikit', function () {
|
141
|
|
142
|
if(!$(this).hasClass('md-processed')) {
|
143
|
var dt_filter = $(this).find('.dataTables_filter'),
|
144
|
search_label = dt_filter.children('label').text();
|
145
|
|
146
|
dt_filter.find('.md-input').attr('placeholder',search_label).unwrap();
|
147
|
|
148
|
dt_filter.contents().filter(function(){
|
149
|
return (this.nodeType == 3);
|
150
|
}).remove();
|
151
|
|
152
|
// reinitialize md inputs
|
153
|
altair_md.inputs();
|
154
|
|
155
|
// initilaize selectize
|
156
|
$(this).find('.dt-selectize').selectize({
|
157
|
dropdownParent: 'body',
|
158
|
onDropdownOpen: function($dropdown) {
|
159
|
$dropdown
|
160
|
.hide()
|
161
|
.velocity('slideDown', {
|
162
|
duration: 200,
|
163
|
easing: easing_swiftOut
|
164
|
})
|
165
|
},
|
166
|
onDropdownClose: function($dropdown) {
|
167
|
$dropdown
|
168
|
.show()
|
169
|
.velocity('slideUp', {
|
170
|
duration: 200,
|
171
|
easing: easing_swiftOut
|
172
|
})
|
173
|
}
|
174
|
});
|
175
|
|
176
|
$(this).find('.ColVis_MasterButton').addClass('md-btn');
|
177
|
|
178
|
$(this).addClass('md-processed');
|
179
|
}
|
180
|
|
181
|
});
|
182
|
|
183
|
|
184
|
// Define as an AMD module if possible
|
185
|
if ( typeof define === 'function' && define.amd ) {
|
186
|
define( ['jquery', 'datatables'], factory );
|
187
|
}
|
188
|
else if ( typeof exports === 'object' ) {
|
189
|
// Node/CommonJS
|
190
|
factory( require('jquery'), require('datatables') );
|
191
|
}
|
192
|
else if ( jQuery ) {
|
193
|
// Otherwise simply initialise as normal, stopping multiple evaluation
|
194
|
factory( jQuery, jQuery.fn.dataTable );
|
195
|
}
|
196
|
|
197
|
|
198
|
})(window, document);
|