/* * tablesaw: A set of plugins for responsive tables * Sortable column headers * Copyright (c) 2013 Filament Group, Inc. * MIT License */ ;(function( $ ) { function getSortValue( cell ) { return $.map( cell.childNodes, function( el ) { var $el = $( el ); if( $el.is( 'input, select' ) ) { return $el.val(); } else if( $el.hasClass( 'tablesaw-cell-label' ) ) { return; } return $.trim( $el.text() ); }).join( '' ); } var pluginName = "tablesaw-sortable", initSelector = "table[data-" + pluginName + "]", sortableSwitchSelector = "[data-" + pluginName + "-switch]", attrs = { defaultCol: "data-tablesaw-sortable-default-col", numericCol: "data-tablesaw-sortable-numeric" }, classes = { head: pluginName + "-head", ascend: pluginName + "-ascending", descend: pluginName + "-descending", switcher: pluginName + "-switch", tableToolbar: 'tablesaw-toolbar', sortButton: pluginName + "-btn" }, methods = { _create: function( o ){ return $( this ).each(function() { var init = $( this ).data( "init" + pluginName ); if( init ) { return false; } $( this ) .data( "init"+ pluginName, true ) .trigger( "beforecreate." + pluginName ) [ pluginName ]( "_init" , o ) .trigger( "create." + pluginName ); }); }, _init: function(){ var el = $( this ), heads, $switcher; var addClassToTable = function(){ el.addClass( pluginName ); }, addClassToHeads = function( h ){ $.each( h , function( i , v ){ $( v ).addClass( classes.head ); }); }, makeHeadsActionable = function( h , fn ){ $.each( h , function( i , v ){ var b = $( "