13693261870
2022-09-16 354b3dbfbffb3df45212a2a44dbbf48b4acc2594
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* tablesaw: A set of plugins for responsive tables
* Mode Switch: UI element to allow the user to change table modes: stack/swipe/columntoggle
* Copyright (c) 2013 Filament Group, Inc.
* MIT License
*/
 
;(function( win, $ ) {
 
    var S = {
        selectors: {
            init: 'table[data-tablesaw-mode-switch]'
        },
        attributes: {
            excludeMode: 'data-tablesaw-mode-exclude'
        },
        classes: {
            main: 'tablesaw-modeswitch',
            toolbar: 'tablesaw-toolbar'
        },
        modes: [ 'stack', 'swipe', 'columntoggle' ],
        init: function( table ) {
            var $table = $( table ),
                ignoreMode = $table.attr( S.attributes.excludeMode ),
                $toolbar = $table.prev().filter( '.tablesaw-bar' ),
                modeVal = '',
                $switcher = $( '<div>' ).addClass( S.classes.main + ' ' + S.classes.toolbar ).html(function() {
                    var html = [ '<label>' + Tablesaw.i18n.columns + ':' ],
                        dataMode = $table.attr( 'data-tablesaw-mode' ),
                        isSelected;
 
                    html.push( '<span class="btn btn-small">&#160;<select>' );
                    for( var j=0, k = S.modes.length; j<k; j++ ) {
                        if( ignoreMode && ignoreMode.toLowerCase() === S.modes[ j ] ) {
                            continue;
                        }
 
                        isSelected = dataMode === S.modes[ j ];
 
                        if( isSelected ) {
                            modeVal = S.modes[ j ];
                        }
 
                        html.push( '<option' +
                            ( isSelected ? ' selected' : '' ) +
                            ' value="' + S.modes[ j ] + '">' + Tablesaw.i18n.modes[ j ] + '</option>' );
                    }
                    html.push( '</select></span></label>' );
 
                    return html.join('');
                });
 
            var $otherToolbarItems = $toolbar.find( '.tablesaw-advance' ).eq( 0 );
            if( $otherToolbarItems.length ) {
                $switcher.insertBefore( $otherToolbarItems );
            } else {
                $switcher.appendTo( $toolbar );
            }
 
            $switcher.find( '.btn' ).tablesawbtn();
            $switcher.find( 'select' ).bind( 'change', S.onModeChange );
        },
        onModeChange: function() {
            var $t = $( this ),
                $switcher = $t.closest( '.' + S.classes.main ),
                $table = $t.closest( '.tablesaw-bar' ).nextUntil( $table ).eq( 0 ),
                val = $t.val();
 
            $switcher.remove();
            $table.data( 'table' ).destroy();
 
            $table.attr( 'data-tablesaw-mode', val );
            $table.table();
        }
    };
 
    $( win.document ).on( "tablesawcreate", function( e, Tablesaw ) {
        if( Tablesaw.$table.is( S.selectors.init ) ) {
            S.init( Tablesaw.table );
        }
    });
 
})( this, jQuery );