Skip to content

Commit 06058b7

Browse files
committed
Corrected control appearance on small screen devices
1 parent f793a8c commit 06058b7

File tree

3 files changed

+58
-44
lines changed

3 files changed

+58
-44
lines changed

css/dataTables.alphabetSearch.css

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,46 @@
11
div.alphabet {
22
position: relative;
3-
display: table;
4-
width: 100%;
5-
margin-bottom: 1em;
3+
margin-bottom: 1.4em;
64
}
75

8-
div.alphabet span.alphabet_letter {
9-
display: table-cell;
10-
color: #3174c7;
6+
div.alphabet a {
7+
box-sizing: content-box;
8+
display: inline-block;
119
cursor: pointer;
1210
text-align: center;
13-
width: 3.5%;
11+
text-decoration: none;
12+
min-width: 1.3em;
13+
padding: 0 0.2em;
14+
opacity: 0.8;
1415
}
1516

16-
div.alphabet span.alphabet_letter:hover {
17-
text-decoration: underline;
17+
div.alphabet a.active {
18+
opacity: 1;
19+
font-weight: bold;
1820
}
1921

20-
div.alphabet span.active {
21-
color: black;
22+
div.alphabet a.empty {
23+
opacity: 0.3;
2224
}
2325

24-
div.alphabet span.empty {
25-
color: red;
26+
div.alphabet a.empty.active {
27+
opacity: 1;
2628
}
2729

28-
div.alphabet_info_display {
29-
padding-right: 1em;
30+
div.alphabet .alphabet_info_display {
31+
padding: 0 0.5em 0 0;
3032
}
3133

32-
div.alphabet_info {
33-
display: block;
34+
div.alphabet div.alphabet_info {
3435
position: absolute;
3536
background-color: #111;
3637
border-radius: 3px;
37-
color: white;
38-
top: 2em;
39-
height: 1.8em;
40-
padding-top: 0.4em;
38+
color: #FFF;
39+
margin-top: 0.2em;
40+
padding: 0.2em 0.4em;
4141
text-align: center;
42-
z-index: 1;
42+
opacity: 0;
43+
transition: opacity .4s ease-in-out;
4344
}
4445

4546
tr.alphabet_group, tr.alphabet_group:hover {

js/dataTables.alphabetSearch.js

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! AlphabetSearch for DataTables v1.1.4
1+
/*! AlphabetSearch for DataTables v1.2.0-dev
22
* 2014 SpryMedia Ltd - datatables.net/license
33
* Gyrocode - MIT License
44
*/
@@ -7,7 +7,7 @@
77
* @summary AlphabetSearch
88
* @description Show an set of alphabet buttons alongside a table providing
99
* search input options
10-
* @version 1.1.4
10+
* @version 1.2.0-dev
1111
* @file dataTables.alphabetSearch.js
1212
* @author SpryMedia Ltd (www.sprymedia.co.uk)
1313
* @contact www.sprymedia.co.uk/contact
@@ -19,7 +19,7 @@
1919
* License MIT - http://datatables.net/license/mit
2020
*
2121
* For more detailed information please see:
22-
* http://www.gyrocode.com/articles/jquery-datatables-alphabetical-search
22+
* https://www.gyrocode.com/projects/jquery-datatables-alphabetsearch/
2323
*/
2424
(function(){
2525

@@ -50,8 +50,8 @@ $.fn.dataTable.Api.register( 'alphabetSearch.recalc()', function ( searchTerm )
5050
// Search plug-in
5151
$.fn.dataTable.ext.search.push( function ( context, searchData ) {
5252
// Ensure that table has alphabet search feature enabled
53-
if ( ! context.hasOwnProperty('alphabetSearch') ) {
54-
return true;
53+
if ( ! context.hasOwnProperty('alphabetSearch') ) {
54+
return true;
5555
}
5656

5757
// Ensure that there is a search applied to this table before running it
@@ -166,25 +166,29 @@ function draw ( table, alphabet, context )
166166
var columnData = table.column(context.alphabetSearch.column, { search: 'applied' } ).data();
167167
var bins = bin( columnData );
168168

169-
$('<span class="alphabet_letter' + ((!context.alphabetSearch.letter) ? ' active' : '') + '"/>')
169+
$('<a/>')
170+
.attr( 'href', 'javascript:;' )
170171
.data( 'letter', '' )
171172
.data( 'match-count', columnData.length )
173+
.addClass(
174+
((!context.alphabetSearch.letter) ? 'active' : '')
175+
)
172176
.html( context.oLanguage.alphabetSearch.infoAll )
173177
.appendTo( alphabet );
174178

175179
for ( var i=0 ; i<context.oLanguage.alphabetSearch.alphabet.length ; i++ ) {
176180
var letter = context.oLanguage.alphabetSearch.alphabet[i];
177181

178-
$('<span/>')
182+
$('<a/>')
183+
.attr( 'href', 'javascript:;' )
179184
.data( 'letter', letter )
180185
.data( 'match-count', bins[letter] || 0 )
181186
.addClass(
182-
'alphabet_letter'
183-
+ (! bins[letter] ? ' empty' : '')
187+
(! bins[letter] ? 'empty' : '')
184188
+ ((context.alphabetSearch.letter === letter) ? ' active' : '')
185189
)
186190
.html(
187-
(letter === '#') ? '0-9' : letter
191+
letter
188192
)
189193
.appendTo( alphabet );
190194
}
@@ -299,7 +303,10 @@ $.fn.dataTable.AlphabetSearch = function ( context ) {
299303

300304

301305
// Trigger a search
302-
alphabet.on( 'click', 'span.alphabet_letter', function () {
306+
alphabet.on( 'click', 'a', function (e) {
307+
// Prevent default behavior
308+
e.preventDefault();
309+
303310
alphabet.find( '.active' ).removeClass( 'active' );
304311
$(this).addClass( 'active' );
305312

@@ -310,17 +317,23 @@ $.fn.dataTable.AlphabetSearch = function ( context ) {
310317

311318
// Mouse events to show helper information
312319
alphabet
313-
.on( 'mouseenter', 'span.alphabet_letter', function () {
314-
alphabet
315-
.find('div.alphabet_info')
320+
.on( 'mouseenter', 'a', function () {
321+
var $el = $(this);
322+
var el_pos = $el.position();
323+
324+
var $alphabet_info = $('.alphabet_info', alphabet);
325+
326+
$alphabet_info.html( $el.data('match-count') );
327+
328+
// Display helper centered horizontally under the letter
329+
$alphabet_info
316330
.css( {
317331
opacity: 1,
318-
left: $(this).position().left,
319-
width: $(this).width()
320-
} )
321-
.html( $(this).data('match-count') );
332+
left: el_pos.left + Math.round(($el.outerWidth() - $alphabet_info.outerWidth())/2),
333+
top: $(this).position().top + $el.outerHeight()
334+
} );
322335
} )
323-
.on( 'mouseleave', 'span.alphabet_letter', function () {
336+
.on( 'mouseleave', 'a', function () {
324337
alphabet
325338
.find('div.alphabet_info')
326339
.css('opacity', 0);
@@ -349,7 +362,7 @@ $.fn.dataTable.AlphabetSearch = function ( context ) {
349362

350363
// If there are no rows found and letter is selected
351364
if(!rows.length && context.alphabetSearch){
352-
var letter = (context.alphabetSearch.letter === '#') ? '0-9' : context.alphabetSearch.letter;
365+
var letter = context.alphabetSearch.letter;
353366

354367
$(api.table().body()).prepend(
355368
'<tr class="alphabet_group"><td colspan="' + col_total + '">' + letter + '</td></tr>'

js/dataTables.alphabetSearch.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)