Index: misc/tabledrag.js =================================================================== RCS file: /cvs/drupal/drupal/misc/tabledrag.js,v retrieving revision 1.33 diff -u -p -r1.33 tabledrag.js --- misc/tabledrag.js 8 Dec 2009 03:10:51 -0000 1.33 +++ misc/tabledrag.js 17 Jan 2010 20:25:02 -0000 @@ -83,8 +83,18 @@ Drupal.tableDrag = function (table, tabl // Match immediate children of the parent element to allow nesting. $('> tr.draggable, > tbody > tr.draggable', table).each(function() { self.makeDraggable(this); }); - // Hide columns containing affected form elements. - this.hideColumns(); + // Hide or show weight and parent columns according to user preference. + // This aids screenreader accessibility so users can enter weight values. + // Initialize the weight columns for the show/hide toggle. + self.initColumns(); + // Add a link before the table for users to show or hide weight columns. + $(table).before($('') + .append(Drupal.t('Show/hide weight fields')) + .click(function () { + self.toggleShowWeight(self); + return false; + }) + ); // Add mouse bindings to the document. The self variable is passed along // as event handlers do not have direct access to the tableDrag object. @@ -93,10 +103,12 @@ Drupal.tableDrag = function (table, tabl }; /** - * Hide the columns containing form elements according to the settings for - * this tableDrag instance. + * Initialize weight/parent columns to be hidden by default. + * + * Identify and mark each cell with a CSS class so we can easily toggle show/hide it. + * Finally, hide columns if user does not have a 'showWeight' cookie. */ -Drupal.tableDrag.prototype.hideColumns = function () { +Drupal.tableDrag.prototype.initColumns = function () { for (var group in this.tableSettings) { // Find the first field in this group. for (var d in this.tableSettings[group]) { @@ -108,7 +120,7 @@ Drupal.tableDrag.prototype.hideColumns = } } - // Hide the column containing this field. + // Mark the column containing this field so it can be hidden. if (hidden && cell[0] && cell.css('display') != 'none') { // Add 1 to our indexes. The nth-child selector is 1 based, not 0 based. // Match immediate children of the parent element to allow nesting. @@ -128,21 +140,76 @@ Drupal.tableDrag.prototype.hideColumns = if (index > 0) { cell = row.children(':nth-child(' + index + ')'); if (cell[0].colSpan > 1) { - // If this cell has a colspan, simply reduce it. - cell[0].colSpan = cell[0].colSpan - 1; + // If this cell has a colspan, mark it so we can reduce the colspan. + $(cell[0]).addClass('tabledrag-reduce-colspan'); } else { - // Hide table body cells, but remove table header cells entirely - // (Safari doesn't hide properly). - parentTag == 'thead' ? cell.remove() : cell.css('display', 'none'); + // Mark this cell so we can hide it. + $(cell[0]).addClass('tabledrag-hide'); } } }); } } + // Now hide cells and reduce colspans unless user cookie is set. + var show = $.cookie('Drupal.tableDrag.showWeight'); + if (show != 1) { + Drupal.tableDrag.prototype.hideColumns(); + } }; /** + * Hide the columns containing weight/parent form elements. + * Undo showColumns(). + */ +Drupal.tableDrag.prototype.hideColumns = function () { + // Turn off display of weight/parent cells and headers. + $('.tabledrag-hide').css('display', 'none'); + // Reduce colspan of any effected multi-span columns. + $('.tabledrag-reduce-colspan').each(function() { this.colSpan = this.colSpan - 1; }); +} + +/** + * Show the columns containing weight/parent form elements + * Undo hideColumns(). + */ +Drupal.tableDrag.prototype.showColumns = function () { + // Increase colspan back to columns it was reduced. + $('.tabledrag-reduce-colspan').each(function() { this.colSpan = this.colSpan + 1; }); + // Turn on display of weight/parent cells and headers. + $('.tabledrag-hide').css('display', 'table-cell'); +} + +/** + * Toggle visibility of weight/parent columns. Use a saved cookie to store the + * user preference. + */ +Drupal.tableDrag.prototype.toggleShowWeight = function (self) { + // Retrieve the tableDrag status from a stored cookie. + var show = $.cookie('Drupal.tableDrag.showWeight'); + + // Show or hide columns with weight fields and toggle the cookie value. + if (show == 1) { + $.cookie('Drupal.tableDrag.showWeight', 0, { + path: Drupal.settings.basePath, + // The cookie should "never" expire. + expires: 36500, + } + ); + this.hideColumns(); + } + else { + $.cookie('Drupal.tableDrag.showWeight', 1, { + path: Drupal.settings.basePath, + // The cookie should "never" expire. + expires: 36500, + } + ); + this.showColumns(); + } +} + +/** * Find the target used within a particular row and group. */ Drupal.tableDrag.prototype.rowSettings = function (group, row) { Index: modules/menu/menu.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/menu/menu.admin.inc,v retrieving revision 1.71 diff -u -p -r1.71 menu.admin.inc --- modules/menu/menu.admin.inc 3 Jan 2010 21:01:04 -0000 1.71 +++ modules/menu/menu.admin.inc 17 Jan 2010 20:25:03 -0000 @@ -99,13 +99,15 @@ function _menu_overview_tree_form($tree) '#type' => 'weight', '#delta' => 50, '#default_value' => isset($form_state[$mlid]['weight']) ? $form_state[$mlid]['weight'] : $item['weight'], + '#title_display' => 'invisible', + '#title' => t('Weight for') . ' ' . $item['title'], ); $form[$mlid]['mlid'] = array( '#type' => 'hidden', '#value' => $item['mlid'], ); $form[$mlid]['plid'] = array( - '#type' => 'textfield', + '#type' => 'hidden', '#default_value' => isset($form_state[$mlid]['plid']) ? $form_state[$mlid]['plid'] : $item['plid'], '#size' => 6, ); Index: modules/field_ui/field_ui.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/field_ui/field_ui.admin.inc,v retrieving revision 1.36 diff -u -p -r1.36 field_ui.admin.inc --- modules/field_ui/field_ui.admin.inc 13 Jan 2010 05:43:01 -0000 1.36 +++ modules/field_ui/field_ui.admin.inc 17 Jan 2010 20:25:03 -0000 @@ -137,7 +137,9 @@ function field_ui_field_overview_form($f '#type' => 'textfield', '#default_value' => $weight, '#size' => 3, - ), + '#title_display' => 'invisible', + '#title' => t('Weight for') . ' ' . check_plain($instance['label']), + ), 'hidden_name' => array( '#type' => 'hidden', '#default_value' => $instance['field_name'], Index: modules/block/block.admin.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/block/block.admin.inc,v retrieving revision 1.72 diff -u -p -r1.72 block.admin.inc --- modules/block/block.admin.inc 15 Jan 2010 10:59:21 -0000 1.72 +++ modules/block/block.admin.inc 17 Jan 2010 20:25:03 -0000 @@ -80,6 +80,8 @@ function block_admin_display_form($form, '#type' => 'weight', '#default_value' => $block['weight'], '#delta' => $weight_delta, + '#title_display' => 'invisible', + '#title' => t('Weight for') . ' ' . check_plain($block['info']), ); $form[$key]['region'] = array( '#type' => 'select',