summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2013-10-09 05:04:56 (GMT)
committerwebchick2013-10-09 05:04:56 (GMT)
commit122b07194451eabef4d48ae9b5f617ffb0f586a8 (patch)
tree2ed158c49ae5a5f2b06e9657f9c55736227671f6
parentcbb135027f9160de6e337e3833aefc85a662041c (diff)
Issue #2057371 by nod_, phiit, Jelle_S: Fixed Re-Replace all $.each() with filtered for loop.
-rw-r--r--core/modules/content_translation/content_translation.admin.js83
-rw-r--r--core/modules/user/user.js5
-rw-r--r--core/modules/views/js/ajax_view.js9
3 files changed, 54 insertions, 43 deletions
diff --git a/core/modules/content_translation/content_translation.admin.js b/core/modules/content_translation/content_translation.admin.js
index 72283a1..42ec2bd 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,60 @@
* 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 +97,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 +112,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 643b8b8..c104a6c 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 (drupalSettings && drupalSettings.views && drupalSettings.views.ajaxViews) {
- $.each(drupalSettings.views.ajaxViews, function(i, settings) {
- Drupal.views.instances[i] = new Drupal.views.ajaxView(settings);
- });
+ var ajaxViews = drupalSettings.views.ajaxViews;
+ for (var i in ajaxViews) {
+ if (ajaxViews.hasOwnProperty(i)) {
+ Drupal.views.instances[i] = new Drupal.views.ajaxView(ajaxViews[i]);
+ }
+ }
}
};