Comments

nod_’s picture

color.js

there is a #preview.once in a loop, take it out.
use .on everywhere (works with delegation).
the focus function unbind and rebind events, should be delegated.
lock update looks overly complicated.

Try decoupling everything with custom events in some places (updating related colors for example).

preview.js

Select elements first, then use them somewhere. Don't reselect from the ID, select the id then .find() what's needed.

oxyc’s picture

StatusFileSize
new7.39 KB

A starting point just optimizing selectors and delegates basically. No refactoring whatsoever yet.

jelle_s’s picture

Status: Active » Needs review

Changing issue status

oxyc’s picture

Status: Needs review » Needs work

Lots of this really need a rewrite and the id-selectors don't need to be scoped. I'll look into cleaning this up later this week unless someone else gets there first :)

seutje’s picture

Status: Needs work » Needs review
StatusFileSize
new569 bytes
new7.39 KB

First! :D

Only adding a slight optimisation because it seems like all the other $form.find('#id') calls seem to depend on the outcome of a .once() call. Probably able to optimize some more, but I don't have time to investigate possible repercussions right now.

jelle_s’s picture

Status: Needs review » Needs work
+++ b/core/modules/color/color.jsundefined
@@ -33,36 +33,37 @@ Drupal.behaviors.color = {
+        var $gradient = $preview.find('#gradient-' + i);
+++ b/core/modules/color/color.jsundefined
@@ -33,36 +33,37 @@ Drupal.behaviors.color = {
+    $form.find('#edit-scheme').on('change', function () {
+++ b/core/modules/color/color.jsundefined
@@ -33,36 +33,37 @@ Drupal.behaviors.color = {
+            callback($form.find('#edit-palette-' + fieldName), colors[fieldName], false, true);
+++ b/core/modules/color/color.jsundefined
@@ -172,7 +174,7 @@ Drupal.behaviors.color = {
+      $form.find('#edit-scheme').each(function () {
+++ b/core/modules/color/color.jsundefined
@@ -198,8 +200,9 @@ Drupal.behaviors.color = {
+    $form.find('#palette input.form-text')
+++ b/core/modules/color/preview.jsundefined
@@ -8,13 +8,15 @@
+      var $palette = $form.find('#palette');
+++ b/core/modules/color/preview.jsundefined
@@ -8,13 +8,15 @@
+      $form.find('#preview').css('backgroundColor', $palette.find('input[name="palette[base]"]').val());
+++ b/core/modules/color/preview.jsundefined
@@ -8,13 +8,15 @@
+      var $text = $form.find('#text');
+++ b/core/modules/color/preview.jsundefined
@@ -40,7 +42,7 @@
+            $form.find('#gradient-' + i + ' > div').each(gradientLineColor);

Had a quick look-through. These are all selectors selecting by id, so I think the .find() is unnecessary here?

kiphaas7’s picture

Investigate if adding basic events and detach makes sense, as described in #1763812: [META] Provide complete attach/detach with basic events

detach at least?

seutje’s picture

@#6: Did you check if they depend on that .once() call, cause I think they do. Perhaps they should be wrapped in a conditional that checks if $form is populated and then just runs it on the regular ID?

kiphaas7’s picture

I don't believe $(context).find(id) should be changed to $(id). Yes, 90% context === document, but the other 10% it doesn't, which means $context.find(id).lenght could equal 0, while $(id).length most probably always return 1.

One could argue that the .once() takes care of any double behavior happening, but if that's the case this should be documented somewhere. As this is a departure from D7 js conventions. Also, I'd think that $(context).find() is a bit more flexible than having to rely on .once().

jelle_s’s picture

you're right, I forgot about that. $(context).find(id) is better indeed.

nod_’s picture

tag

markhalliwell’s picture

Component: javascript » color.module
Issue summary: View changes
Issue tags: +JavaScript
Parent issue: » #1574470: Selectors clean-up
Related issues: +#1415788: Javascript winter clean-up, +#1662958: Clean up CSS/JS in color module

Fair enough, but this should then be part of the color.module component (also for our exposure) since it belongs to a specific module and is not standalone core JS. Added issue references.

droplet’s picture

Status: Needs work » Needs review

5: core-1751334-5.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 5: core-1751334-5.patch, failed testing.

internetdevels’s picture

Status: Needs work » Needs review
StatusFileSize
new7.47 KB

Hi, added new patch, previous patch can't be applied. :)

nod_’s picture

Status: Needs review » Needs work

JSHint error about indentation at:

            // Render gradient lines.
             $form.find('#gradient-' + i + ' > div').each(gradientLineColor);

Other than that, it looks good.

longwave’s picture

Status: Needs work » Needs review
StatusFileSize
new7.47 KB
new477 bytes
rteijeiro’s picture

StatusFileSize
new7.53 KB

Re-rolled!

andriyun’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Patch is outdated

drintios’s picture

Assigned: Unassigned » drintios
drintios’s picture

Assigned: drintios » Unassigned
drintios’s picture

Assigned: Unassigned » drintios
drintios’s picture

Assigned: drintios » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs reroll +Needs Review
StatusFileSize
new8.03 KB

Rerolled patch, fixed merge conflicts.

andypost’s picture

Issue tags: -Needs Review
+++ b/core/modules/color/preview.js
@@ -30,15 +29,18 @@
      * @param {number} width
      *   Width of gradient.
      */
-    callback: function (context, settings, form, farb, height, width) {
+
+    callback: function(context, settings, $form, farb, height, width) {

suppose this extra line is not needed

drintios’s picture

StatusFileSize
new8.26 KB

Updated patch, cleaned with eslint.

droplet’s picture

+++ b/core/modules/color/color.js
@@ -31,9 +31,8 @@
-      $('<div class="color-placeholder"></div>').once('color').prependTo(form);
-      var farb = $.farbtastic('.color-placeholder');
...
+      $('<div id="placeholder"></div>').once('color').prependTo($form);
+      var farb = $.farbtastic('#placeholder');

we don't do other code change in clean up

droplet’s picture

Status: Needs review » Needs work
vprocessor’s picture

Assigned: Unassigned » vprocessor
vprocessor’s picture

Hello guys,

droplet, I removed this strings in new patch, diff & patch attached

vprocessor’s picture

Status: Needs work » Needs review
vprocessor’s picture

Assigned: vprocessor » Unassigned
andypost’s picture

Assigned: Unassigned » nod_

Not sure about scope but variable renames looks reasonable
Let's get maintainers feedback

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

droplet’s picture

Assigned: nod_ » Unassigned
Status: Needs review » Postponed

Let's do it at ES6 or at least with a JS test covered.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

Version: 8.6.x-dev » 8.7.x-dev
Status: Postponed » Needs work

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Project: Drupal core » Color backport
Version: 9.5.x-dev » 2.x-dev
Component: color.module » Code
Issue tags: -JavaScript +JavaScript

Color has been removed from core, #3270899: Remove Color module from core.