diff --git a/core/modules/field_ui/field_ui.js b/core/modules/field_ui/field_ui.js index 3c9e5ae..f7bdf85 100644 --- a/core/modules/field_ui/field_ui.js +++ b/core/modules/field_ui/field_ui.js @@ -61,9 +61,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); + }); + } } }; @@ -87,19 +90,22 @@ tableDrag.row.prototype.onSwap = this.onSwap; // Create row handlers. - $(table).find('tr.draggable').each(function () { - // Extract server-side data for the row. - var row = this; - if (row.id in rowsData) { - var data = rowsData[row.id]; - data.tableDrag = tableDrag; - - // Create the row handler, make it accessible from the DOM row - // element. - var rowHandler = new rowHandlers[data.rowHandler](row, data); - $(row).data('fieldUIRowHandler', rowHandler); - } - }); + var $draggable = $(table).find('tr.draggable'); + if ($draggable.length) { + $draggable.each(function () { + // Extract server-side data for the row. + var row = this; + if (row.id in rowsData) { + var data = rowsData[row.id]; + data.tableDrag = tableDrag; + + // Create the row handler, make it accessible from the DOM row + // element. + var rowHandler = new rowHandlers[data.rowHandler](row, data); + $(row).data('fieldUIRowHandler', rowHandler); + } + }); + } }, /** @@ -161,26 +167,29 @@ */ 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'); + } + }); + } }, /**