<commit_before>//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
//>>description: Extends the table widget to a column toggle menu and responsive column visibility
//>>label: Table: Column Toggle
//>>group: Widgets
//>>css.structure: ../css/structure/jquery.mobile.table.columntoggle.css


define( [ "jquery", "./jquery.mobile.table", "../jquery.mobile.buttonMarkup", "./popup" ], function( $ ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, undefined ) {

$.mobile.table.prototype.options.mode = "columntoggle";

$.mobile.table.prototype.options.columnBtnTheme = null;

$.mobile.table.prototype.options.columnPopupTheme = null;

$.mobile.table.prototype.options.columnBtnText = "Columns...";

$.mobile.table.prototype.options.classes = $.extend(
   $.mobile.table.prototype.options.classes,
   {
      popup: "ui-table-columntoggle-popup",
      columnBtn: "ui-table-columntoggle-btn",
      priorityPrefix: "ui-table-priority-",
      columnToggleTable: "ui-table-columntoggle"
   }
);

$( document ).delegate( ":jqmData(role='table')", "tablecreate", function() {

   var $table = $( this ),
      self = $table.jqmData( "table" ),
      o = self.options;

   if( o.mode !== "columntoggle" ){
      return;
   }

   self.element.addClass( o.classes.columnToggleTable );

   var id = ( $table.attr( "id" ) || self.options.classes.popup ) + "-popup", //TODO BETTER FALLBACK ID HERE
      $menuButton = $( "<a href='#" + id + "' class='" + o.classes.columnBtn + "' data-rel='popup'>" + o.columnBtnText + "</a>" ),
      $popup = $( "<div data-role='popup' data-role='fieldcontain' class='" + o.classes.popup + "' id='" + id + "'></div>"),
      $menu = $("<fieldset data-role='controlgroup'></fieldset>").appendTo( $popup );

   // create the hide/show toggles
   self.headers.not( "td" ).each(function(){

      var priority = $( this ).jqmData( "priority" ),
         $cells = $( this ).add( $( this ).jqmData( "cells" ) );

      if( priority ){

         $cells.addClass( o.classes.priorityPrefix + priority );

         $("<label><input type='checkbox' checked />" + $( this ).text() + "</label>" )
            .appendTo( $menu )
            .children( 0 )
            .jqmData( "cells", $cells )
            .checkboxradio({
               theme: o.columnPopupTheme
            });
      }
   });

   $menuButton
      .insertBefore( $table )
      .buttonMarkup({
         theme: o.columnBtnTheme
      });

   $popup
      .insertBefore( $table )
      .popup();

   // bind change event listeners to inputs - TODO: move to a private method?
   $menu.on( "change", "input", function( e ){
      if( this.checked ){
         $( this ).jqmData( "cells" ).removeClass( "ui-table-cell-hidden" ).addClass( "ui-table-cell-visible" );
      }
      else {
         $( this ).jqmData( "cells" ).removeClass( "ui-table-cell-visible" ).addClass( "ui-table-cell-hidden" );
      }
   } );


   function refreshMenu(){
      $menu.find( "input" ).each( function(){
            this.checked = $( this ).jqmData( "cells" ).eq(0).is( ":visible" );
            $( this ).checkboxradio( "refresh" );
      } );
   }

   $( window ).on( "throttledresize", refreshMenu );

   // TODO. Why is a stack unwind needed here?
   // Maybe because we're waiting on CSS to be applied before that :visible check above can work
   setTimeout( refreshMenu, 0 );

});

})( jQuery );
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
});
//>>excludeEnd("jqmBuildExclude");
<commit_msg>exposed refresh as a public method of the columntoggle table<commit_after>//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
//>>description: Extends the table widget to a column toggle menu and responsive column visibility
//>>label: Table: Column Toggle
//>>group: Widgets
//>>css.structure: ../css/structure/jquery.mobile.table.columntoggle.css


define( [ "jquery", "./jquery.mobile.table", "../jquery.mobile.buttonMarkup", "./popup" ], function( $ ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, undefined ) {

$.mobile.table.prototype.options.mode = "columntoggle";

$.mobile.table.prototype.options.columnBtnTheme = null;

$.mobile.table.prototype.options.columnPopupTheme = null;

$.mobile.table.prototype.options.columnBtnText = "Columns...";

$.mobile.table.prototype.options.classes = $.extend(
   $.mobile.table.prototype.options.classes,
   {
      popup: "ui-table-columntoggle-popup",
      columnBtn: "ui-table-columntoggle-btn",
      priorityPrefix: "ui-table-priority-",
      columnToggleTable: "ui-table-columntoggle"
   }
);

$( document ).delegate( ":jqmData(role='table')", "tablecreate", function() {

   var $table = $( this ),
      self = $table.jqmData( "table" ),
      o = self.options;

   if( o.mode !== "columntoggle" ){
      return;
   }

   self.element.addClass( o.classes.columnToggleTable );

   var id = ( $table.attr( "id" ) || self.options.classes.popup ) + "-popup", //TODO BETTER FALLBACK ID HERE
      $menuButton = $( "<a href='#" + id + "' class='" + o.classes.columnBtn + "' data-rel='popup'>" + o.columnBtnText + "</a>" ),
      $popup = $( "<div data-role='popup' data-role='fieldcontain' class='" + o.classes.popup + "' id='" + id + "'></div>"),
      $menu = $("<fieldset data-role='controlgroup'></fieldset>").appendTo( $popup );

   // create the hide/show toggles
   self.headers.not( "td" ).each(function(){

      var priority = $( this ).jqmData( "priority" ),
         $cells = $( this ).add( $( this ).jqmData( "cells" ) );

      if( priority ){

         $cells.addClass( o.classes.priorityPrefix + priority );

         $("<label><input type='checkbox' checked />" + $( this ).text() + "</label>" )
            .appendTo( $menu )
            .children( 0 )
            .jqmData( "cells", $cells )
            .checkboxradio({
               theme: o.columnPopupTheme
            });
      }

   });

   $menuButton
      .insertBefore( $table )
      .buttonMarkup({
         theme: o.columnBtnTheme
      });

   $popup
      .insertBefore( $table )
      .popup();

   // bind change event listeners to inputs - TODO: move to a private method?
   $menu.on( "change", "input", function( e ){
      if( this.checked ){
         $( this ).jqmData( "cells" ).removeClass( "ui-table-cell-hidden" ).addClass( "ui-table-cell-visible" );
      }
      else {
         $( this ).jqmData( "cells" ).removeClass( "ui-table-cell-visible" ).addClass( "ui-table-cell-hidden" );
      }
   } );



   // refresh method
   self.refresh = function(){
      $menu.find( "input" ).each( function(){
            this.checked = $( this ).jqmData( "cells" ).eq(0).is( ":visible" );
            $( this ).checkboxradio( "refresh" );
      } );
   };

   $( window ).on( "throttledresize", self.refresh );

   // TODO. Why is a stack unwind needed here?
   // Maybe because we're waiting on CSS to be applied before that :visible check above can work
   setTimeout( self.refresh, 0 );

});

})( jQuery );
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
});
//>>excludeEnd("jqmBuildExclude");

{'fraction_non_alphanumeric': 0.18590470788428815, 'fraction_numerical': 0.0008508224617129892, 'mean_word_length': 2.8289902280130295, 'pattern_counts': {'":': 4, '<': 21, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6193681', 'n_tokens_mistral': 2291, 'n_tokens_neox': 2197, 'n_words': 485}