diff --git a/core/modules/field_ui/field_ui.js b/core/modules/field_ui/field_ui.js index 3ee0dab..d0e9d13 100644 --- a/core/modules/field_ui/field_ui.js +++ b/core/modules/field_ui/field_ui.js @@ -54,9 +54,12 @@ Drupal.behaviors.fieldUIDisplayOverview = { attach: function (context, settings) { - $(context).find('table#field-display-overview').once('field-display-overview').each(function () { - Drupal.fieldUIOverview.attach(this, settings.fieldUIRowsData, Drupal.fieldUIDisplayOverview); - }); + var $fieldDisplayOverview = $(context).find('table#field-display-overview').once('field-display-overview'); + if ($fieldDisplayOverview.length) { + $fieldDisplayOverview.each(function () { + Drupal.fieldUIOverview.attach(this, settings.fieldUIRowsData, Drupal.fieldUIDisplayOverview); + }); + } } }; @@ -72,7 +75,8 @@ tableDrag.row.prototype.onSwap = this.onSwap; // Create row handlers. - $(table).find('tr.draggable').each(function () { + var $draggable = $(table).find('tr.draggable'); + if ($draggable.length) { // Extract server-side data for the row. var row = this; if (row.id in rowsData) { @@ -83,7 +87,7 @@ var rowHandler = new rowHandlers[data.rowHandler](row, data); $(row).data('fieldUIRowHandler', rowHandler); } - }); + } }, /** @@ -147,25 +151,28 @@ */ onSwap: function (draggedRow) { var rowObject = this; - $(rowObject.table).find('tr.region-message').each(function () { - var $this = $(this); - // If the dragged row is in this region, but above the message row, swap - // it down one space. - if ($this.prev('tr').get(0) === rowObject.group[rowObject.group.length - 1]) { - // Prevent a recursion problem when using the keyboard to move rows up. - if ((rowObject.method !== 'keyboard' || rowObject.direction === 'down')) { - rowObject.swap('after', this); + var $regionMessage = $(rowObject.table).find('tr.region-message'); + if ($regionMessage.length) { + $regionMessage.each(function () { + var $this = $(this); + // If the dragged row is in this region, but above the message row, swap + // it down one space. + if ($this.prev('tr').get(0) === rowObject.group[rowObject.group.length - 1]) { + // Prevent a recursion problem when using the keyboard to move rows up. + if ((rowObject.method !== 'keyboard' || rowObject.direction === 'down')) { + rowObject.swap('after', this); + } } - } - // This region has become empty. - if ($this.next('tr').is(':not(.draggable)') || $this.next('tr').length === 0) { - $this.removeClass('region-populated').addClass('region-empty'); - } - // This region has become populated. - else if ($this.is('.region-empty')) { - $this.removeClass('region-empty').addClass('region-populated'); - } - }); + // This region has become empty. + if ($this.next('tr').is(':not(.draggable)') || $this.next('tr').length === 0) { + $this.removeClass('region-populated').addClass('region-empty'); + } + // This region has become populated. + else if ($this.is('.region-empty')) { + $this.removeClass('region-empty').addClass('region-populated'); + } + }); + } }, /**