Index: modules/field_ui/field_ui.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 Subsystem: com.intellij.openapi.diff.impl.patch.BaseRevisionTextPatchEP <+>/**\n * @file\n * Attaches the behaviors for the Field UI module.\n */\n \n(function($) {\n\nDrupal.behaviors.fieldUIFieldOverview = {\n attach: function (context, settings) {\n $('table#field-overview', context).once('field-overview', function () {\n Drupal.fieldUIFieldOverview.attachUpdateSelects(this, settings);\n });\n }\n};\n\nDrupal.fieldUIFieldOverview = {\n /**\n * Implements dependent select dropdowns on the 'Manage fields' screen.\n */\n attachUpdateSelects: function(table, settings) {\n var widgetTypes = settings.fieldWidgetTypes;\n var fields = settings.fields;\n\n // Store the default text of widget selects.\n $('.widget-type-select', table).each(function () {\n this.initialValue = this.options[0].text;\n });\n\n // 'Field type' select updates its 'Widget' select.\n $('.field-type-select', table).each(function () {\n this.targetSelect = $('.widget-type-select', $(this).closest('tr'));\n\n $(this).bind('change keyup', function () {\n var selectedFieldType = this.options[this.selectedIndex].value;\n var options = (selectedFieldType in widgetTypes ? widgetTypes[selectedFieldType] : []);\n this.targetSelect.fieldUIPopulateOptions(options);\n });\n\n // Trigger change on initial pageload to get the right widget options\n // when field type comes pre-selected (on failed validation).\n $(this).trigger('change', false);\n });\n\n // 'Existing field' select updates its 'Widget' select and 'Label' textfield.\n $('.field-select', table).each(function () {\n this.targetSelect = $('.widget-type-select', $(this).closest('tr'));\n this.targetTextfield = $('.label-textfield', $(this).closest('tr'));\n this.targetTextfield\n .data('field_ui_edited', false)\n .bind('keyup', function (e) {\n $(this).data('field_ui_edited', $(this).val() != '');\n });\n\n $(this).bind('change keyup', function (e, updateText) {\n var updateText = (typeof updateText == 'undefined' ? true : updateText);\n var selectedField = this.options[this.selectedIndex].value;\n var selectedFieldType = (selectedField in fields ? fields[selectedField].type : null);\n var selectedFieldWidget = (selectedField in fields ? fields[selectedField].widget : null);\n var options = (selectedFieldType && (selectedFieldType in widgetTypes) ? widgetTypes[selectedFieldType] : []);\n this.targetSelect.fieldUIPopulateOptions(options, selectedFieldWidget);\n\n // Only overwrite the \"Label\" input if it has not been manually\n // changed, or if it is empty.\n if (updateText && !this.targetTextfield.data('field_ui_edited')) {\n this.targetTextfield.val(selectedField in fields ? fields[selectedField].label : '');\n }\n });\n\n // Trigger change on initial pageload to get the right widget options\n // and label when field type comes pre-selected (on failed validation).\n $(this).trigger('change', false);\n });\n }\n};\n\n/**\n * Populates options in a select input.\n */\njQuery.fn.fieldUIPopulateOptions = function (options, selected) {\n return this.each(function () {\n var disabled = false;\n if (options.length == 0) {\n options = [this.initialValue];\n disabled = true;\n }\n\n // If possible, keep the same widget selected when changing field type.\n // This is based on textual value, since the internal value might be\n // different (options_buttons vs. node_reference_buttons).\n var previousSelectedText = this.options[this.selectedIndex].text;\n\n var html = '';\n jQuery.each(options, function (value, text) {\n // Figure out which value should be selected. The 'selected' param\n // takes precedence.\n var is_selected = ((typeof selected != 'undefined' && value == selected) || (typeof selected == 'undefined' && text == previousSelectedText));\n html += '';\n });\n\n $(this).html(html).attr('disabled', disabled ? 'disabled' : '');\n });\n};\n\nDrupal.behaviors.fieldUIDisplayOverview = {\n attach: function (context, settings) {\n $('table#field-display-overview', context).once('field-display-overview', function() {\n Drupal.fieldUIOverview.attach(this, settings.fieldUIRowsData, Drupal.fieldUIDisplayOverview);\n });\n }\n};\n\nDrupal.fieldUIOverview = {\n /**\n * Attaches the fieldUIOverview behavior.\n */\n attach: function (table, rowsData, rowHandlers) {\n var tableDrag = Drupal.tableDrag[table.id];\n\n // Add custom tabledrag callbacks.\n tableDrag.onDrop = this.onDrop;\n tableDrag.row.prototype.onSwap = this.onSwap;\n\n // Create row handlers.\n $('tr.draggable', table).each(function () {\n // Extract server-side data for the row.\n var row = this;\n if (row.id in rowsData) {\n var data = rowsData[row.id];\n data.tableDrag = tableDrag;\n\n // Create the row handler, make it accessible from the DOM row element.\n var rowHandler = new rowHandlers[data.rowHandler](row, data);\n $(row).data('fieldUIRowHandler', rowHandler);\n }\n });\n },\n\n /**\n * Event handler to be attached to form inputs triggering a region change.\n */\n onChange: function () {\n var $trigger = $(this);\n var row = $trigger.closest('tr').get(0);\n var rowHandler = $(row).data('fieldUIRowHandler');\n\n var refreshRows = {};\n refreshRows[rowHandler.name] = $trigger.get(0);\n\n // Handle region change.\n var region = rowHandler.getRegion();\n if (region != rowHandler.region) {\n // Remove parenting.\n $('select.field-parent', row).val('');\n // Let the row handler deal with the region change.\n $.extend(refreshRows, rowHandler.regionChange(region));\n // Update the row region.\n rowHandler.region = region;\n }\n\n // Ajax-update the rows.\n Drupal.fieldUIOverview.AJAXRefreshRows(refreshRows);\n },\n\n /**\n * Lets row handlers react when a row is dropped into a new region.\n */\n onDrop: function () {\n var dragObject = this;\n var row = dragObject.rowObject.element;\n var rowHandler = $(row).data('fieldUIRowHandler');\n if (rowHandler !== undefined) {\n var regionRow = $(row).prevAll('tr.region-message').get(0);\n var region = regionRow.className.replace(/([^ ]+[ ]+)*region-([^ ]+)-message([ ]+[^ ]+)*/, '$2');\n\n if (region != rowHandler.region) {\n // Let the row handler deal with the region change.\n refreshRows = rowHandler.regionChange(region);\n // Update the row region.\n rowHandler.region = region;\n // Ajax-update the rows.\n Drupal.fieldUIOverview.AJAXRefreshRows(refreshRows);\n }\n }\n },\n\n /**\n * Refreshes placeholder rows in empty regions while a row is being dragged.\n *\n * Copied from block.js.\n *\n * @param table\n * The table DOM element.\n * @param rowObject\n * The tableDrag rowObject for the row being dragged.\n */\n onSwap: function (draggedRow) {\n var rowObject = this;\n $('tr.region-message', rowObject.table).each(function () {\n // If the dragged row is in this region, but above the message row, swap\n // it down one space.\n if ($(this).prev('tr').get(0) == rowObject.group[rowObject.group.length - 1]) {\n // Prevent a recursion problem when using the keyboard to move rows up.\n if ((rowObject.method != 'keyboard' || rowObject.direction == 'down')) {\n rowObject.swap('after', this);\n }\n }\n // This region has become empty.\n if ($(this).next('tr').is(':not(.draggable)') || $(this).next('tr').length == 0) {\n $(this).removeClass('region-populated').addClass('region-empty');\n }\n // This region has become populated.\n else if ($(this).is('.region-empty')) {\n $(this).removeClass('region-empty').addClass('region-populated');\n }\n });\n },\n\n /**\n * Triggers Ajax refresh of selected rows.\n *\n * The 'format type' selects can trigger a series of changes in child rows.\n * The #ajax behavior is therefore not attached directly to the selects, but\n * triggered manually through a hidden #ajax 'Refresh' button.\n *\n * @param rows\n * A hash object, whose keys are the names of the rows to refresh (they\n * will receive the 'ajax-new-content' effect on the server side), and\n * whose values are the DOM element in the row that should get an Ajax\n * throbber.\n */\n AJAXRefreshRows: function (rows) {\n // Separate keys and values.\n var rowNames = [];\n var ajaxElements = [];\n $.each(rows, function (rowName, ajaxElement) {\n rowNames.push(rowName);\n ajaxElements.push(ajaxElement);\n });\n\n if (rowNames.length) {\n // Add a throbber next each of the ajaxElements.\n var $throbber = $('