From 2a61608dc769250e830bd6a58b4d1a88f41be7b4 Mon Sep 17 00:00:00 2001 From: Cory Gackenheimer Date: Thu, 4 Feb 2016 10:47:06 -0500 Subject: [PATCH] Table: Implment Classes Option post review changes Fixes gh-8341 --- js/widgets/table.columntoggle.js | 7 +++---- js/widgets/table.columntoggle.popup.js | 4 +++- js/widgets/table.js | 4 ---- js/widgets/table.reflow.js | 3 +-- tests/unit/table/columntoggle_core.js | 12 ++++++------ 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/js/widgets/table.columntoggle.js b/js/widgets/table.columntoggle.js index 6886026dfff..b2174fd6549 100644 --- a/js/widgets/table.columntoggle.js +++ b/js/widgets/table.columntoggle.js @@ -1,3 +1,4 @@ + /*! * jQuery Mobile Column-toggling Table @VERSION * http://jquerymobile.com @@ -63,7 +64,7 @@ return $.widget( "mobile.table", $.mobile.table, { this._updateHeaderPriorities(); }, - _updateVariableColumn: function( header, cells, priority/*, state */ ) { + _updateVariableColumn: function( header, cells, priority ) { this._addClass( cells, "ui-table-priority-" + priority ); }, @@ -167,7 +168,6 @@ return $.widget( "mobile.table", $.mobile.table, { _destroy: function() { if ( this.options.mode === "columntoggle" ) { if ( !this.options.enhanced ) { - this._removeClass( "ui-table-columntoggle" ); this.headers.each( $.proxy( function( index, element ) { var header, priority = $.mobile.getAttribute( element, "priority" ); @@ -175,8 +175,7 @@ return $.widget( "mobile.table", $.mobile.table, { if ( priority ) { header = $( element ); header - .add( header.jqmData( "cells" ) ) - .removeClass( this.options.classes.priorityPrefix + priority ); + .add( header.jqmData( "cells" ) ); } }, this ) ); } diff --git a/js/widgets/table.columntoggle.popup.js b/js/widgets/table.columntoggle.popup.js index 183c7ff7b3f..d5bfbd8525d 100644 --- a/js/widgets/table.columntoggle.popup.js +++ b/js/widgets/table.columntoggle.popup.js @@ -22,6 +22,7 @@ "./table.columntoggle", "./popup", "./controlgroup", + "./forms/button", "./widget.theme", "./forms/checkboxradio" ], factory ); } else { @@ -40,7 +41,7 @@ return $.widget( "mobile.table", $.mobile.table, { columnUi: true, classes: { "ui-table-columntoggle-popup": "", - "ui-table-columntoggle-btn": "ui-button ui-corner-all ui-shadow ui-mini" + "ui-table-columntoggle-btn": "ui-corner-all ui-shadow ui-mini" } }, @@ -274,6 +275,7 @@ return $.widget( "mobile.table", $.mobile.table, { "id='" + id + "-button' " + "data-" + $.mobile.ns + "rel='popup'>" + options.columnButtonText + "" ); + button.button(); this._addClass( button, "ui-table-columntoggle-btn" + ( buttonTheme ? " " + buttonTheme : "" ) ); diff --git a/js/widgets/table.js b/js/widgets/table.js index ca696ef3eb3..fd9813144f1 100644 --- a/js/widgets/table.js +++ b/js/widgets/table.js @@ -122,10 +122,6 @@ return $.widget( "mobile.table", { _destroy: function() { var table = this.element; - if ( !this.options.enhanced ) { - this._removeClass( "ui-table" ); - } - // We have to remove "cells" data even if the table was originally enhanced, because it is // added during refresh table.find( "thead tr" ).children().each( function() { diff --git a/js/widgets/table.reflow.js b/js/widgets/table.reflow.js index 760e97f8e36..cdd2897d386 100644 --- a/js/widgets/table.reflow.js +++ b/js/widgets/table.reflow.js @@ -77,7 +77,7 @@ return $.widget( "mobile.table", $.mobile.table, { iteration = parseInt( headerCell.getAttribute( "colspan" ), 10 ); if ( iteration ) { - cells = cells.filter( "td:nth-child("+ iteration + "n + " + colstart + ")" ); + cells = cells.filter( "td:nth-child(" + iteration + "n + " + colstart + ")" ); } } @@ -112,7 +112,6 @@ return $.widget( "mobile.table", $.mobile.table, { .removeAttr( colstartAttr ) .end() .end() - .removeClass( "ui-table-reflow" ) .children( "tbody" ) .find( "b.ui-table-cell-label" ) .remove(); diff --git a/tests/unit/table/columntoggle_core.js b/tests/unit/table/columntoggle_core.js index 57b1d675496..2a2a604d6bd 100644 --- a/tests/unit/table/columntoggle_core.js +++ b/tests/unit/table/columntoggle_core.js @@ -89,7 +89,7 @@ QUnit.skip( "_updateVariableColumn() adds priority classes to cells", }, null, cells, 2 ); assert.deepEqual( cells.is( function() { - return !$( this ).hasClass( "prio-prefix-2" ); + return assert.lacksClasses( $( this ), "prio-prefix-2" ); } ), false, "All cells have class 'prio-prefix-2'" ); } ); @@ -122,13 +122,13 @@ QUnit.skip( "_updateHeaderPriorities() iterates over headers and adds classes", assert.deepEqual( headers.eq( 0 ).add( headers.eq( 0 ).jqmData( "cells" ) ) .is( function() { - return !$( this ).hasClass( "prio-prefix-3" ); + return assert.lacksClasses( $( this ), "prio-prefix-3" ); } ), false, "first column cells all have priorty class, including header" ); assert.deepEqual( headers.eq( 1 ).add( headers.eq( 1 ).jqmData( "cells" ) ) .is( function() { - return !$( this ).hasClass( "prio-prefix-5" ); + return assert.lacksClasses( $( this ), "prio-prefix-5" ); } ), false, "second column cells all have priorty class, including header" ); } ); @@ -160,7 +160,7 @@ QUnit.skip( "_setColumnVisibility() forces column to be visible/hidden", }, header, visible ); assert.deepEqual( cells.add( header ).is( function() { - return $( this ).hasClass( expectedAbsent ); + return assert.hasClasses( this, expectedAbsent ); } ), false, "Neither header nor cells have class '" + expectedAbsent + "'" ); } @@ -212,8 +212,8 @@ QUnit.skip( "_unlock() removes classes from cells", function( assert ) { }, cellList ); assert.deepEqual( cellList.is( function() { - return $( this ).hasClass( "ui-table-cell-hidden" ) || - $( this ).hasClass( "ui-table-cell-visible" ); + return assert.hasClasses( $( this ), "ui-table-cell-hidden" ) || + assert.hasClasses( $( this ), "ui-table-cell-visible" ); } ), false, "Both 'ui-table-cell-hidden' and 'ui-table-cell-visible' have been removed" ); } );