diff --git a/core/modules/content_translation/content_translation.admin.js b/core/modules/content_translation/content_translation.admin.js index 72283a1..76329a5 100644 --- a/core/modules/content_translation/content_translation.admin.js +++ b/core/modules/content_translation/content_translation.admin.js @@ -1,4 +1,4 @@ -(function ($) { +(function ($, Drupal, drupalSettings) { "use strict"; @@ -6,52 +6,61 @@ * Forces applicable options to be checked as translatable. */ Drupal.behaviors.contentTranslationDependentOptions = { - attach: function (context, settings) { - var $options = settings.contentTranslationDependentOptions; - var $collections = []; + attach: function (context) { + var $context = $(context); + var options = drupalSettings.contentTranslationDependentOptions; + var $fields, dependent_columns; + + + function fieldsChangeHandler ($fields, dependent_columns) { + return function (e) { + Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependent_columns, $(e.target)); + }; + } // We're given a generic name to look for so we find all inputs containing // that name and copy over the input values that require all columns to be // translatable. - if ($options.dependent_selectors) { - $.each($options.dependent_selectors, function($field, $dependent_columns) { - $collections.push({ elements : $(context).find('input[name^="' + $field + '"]'), dependent_columns : $dependent_columns }); - }); - } + if (options.dependent_selectors) { + for (var field in options.dependent_selectors) { + if (options.dependent_selectors.hasOwnProperty(field)) { + $fields = $context.find('input[name^="' + field + '"]'); + dependent_columns = options.dependent_selectors[field]; - $.each($collections, function($index, $collection) { - var $fields = $collection.elements; - var $dependent_columns = $collection.dependent_columns; + $fields.on('change', fieldsChangeHandler($fields, dependent_columns)); + Drupal.behaviors.contentTranslationDependentOptions.check($fields, dependent_columns); + } + } + } + }, + check: function ($fields, dependent_columns, $changed) { + var $element = $changed; + var column; - $fields.change(function() { - Drupal.behaviors.contentTranslationDependentOptions.check($fields, $dependent_columns, $(this)); - }); + function filterFieldsList (index, field) { + return $(field).val() === column; + } - // Run the check function on first trigger of this behavior. - Drupal.behaviors.contentTranslationDependentOptions.check($fields, $dependent_columns, false); - }); - }, - check: function($fields, $dependent_columns, $changed) { // A field that has many different translatable parts can also define one // or more columns that require all columns to be translatable. - $.each($dependent_columns, function($index, $column) { - var $element = $changed; + for (var index in dependent_columns) { + if (dependent_columns.hasOwnProperty(index)) { + column = dependent_columns[index]; - if(!$element) { - $fields.each(function() { - if($(this).val() === $column) { - $element = $(this); - return false; - } - }); - } + if (!$changed) { + $element = $fields.filter(filterFieldsList); + } + + if ($element.is('input[value="' + column + '"]:checked')) { + $fields.prop('checked', true) + .not($element).prop('disabled', true); + } + else { + $fields.prop('disabled', false); + } - if($element.is('input[value="' + $column + '"]:checked')) { - $fields.prop('checked', true).not($element).prop('disabled', true); - } else { - $fields.prop('disabled', false); } - }); + } } }; @@ -89,7 +98,8 @@ Drupal.behaviors.contentTranslation = { else { $settings.hide(); } - }).on('click', 'table .field-settings .translatable :input', function (e) { + }) + .on('click', 'table .field-settings .translatable :input', function (e) { var $target = $(e.target); var $fieldSettings = $target.closest('.field-settings'); var $columnSettings = $fieldSettings.nextUntil('.field-settings, .bundle-settings'); @@ -103,4 +113,4 @@ Drupal.behaviors.contentTranslation = { } }; -})(jQuery); +})(jQuery, Drupal, drupalSettings); diff --git a/core/modules/user/user.js b/core/modules/user/user.js index 45181fb..564cebd 100644 --- a/core/modules/user/user.js +++ b/core/modules/user/user.js @@ -75,9 +75,8 @@ Drupal.behaviors.password = { }; // Monitor input events. - $.each([passwordInput, confirmInput], function () { - this.bind('input', passwordCheck); - }); + passwordInput.on('input', passwordCheck); + confirmInput.on('input', passwordCheck); }); } }; diff --git a/core/modules/views/js/ajax_view.js b/core/modules/views/js/ajax_view.js index 50d3750..07b476c 100644 --- a/core/modules/views/js/ajax_view.js +++ b/core/modules/views/js/ajax_view.js @@ -12,9 +12,12 @@ Drupal.behaviors.ViewsAjaxView = {}; Drupal.behaviors.ViewsAjaxView.attach = function() { if (Drupal.settings && Drupal.settings.views && Drupal.settings.views.ajaxViews) { - $.each(Drupal.settings.views.ajaxViews, function(i, settings) { - Drupal.views.instances[i] = new Drupal.views.ajaxView(settings); - }); + var ajaxViews = Drupal.settings.views.ajaxViews; + for (var i in ajaxViews) { + if (ajaxViews.hasOwnProperty(i)) { + Drupal.views.instances[i] = new Drupal.views.ajaxView(ajaxViews[i]); + } + } } };