Part of the JavaScript selectors clean-up effort.
#1574470: Selectors clean-up
#1415788: Javascript winter clean-up

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task, bartik preview functionality code clean up.
Issue priority Normal
Prioritized changes The main goal of this issue is maintainability and performance. Making the code easier to understand (and to follow our jQuery variable naming convention) as well as restricting scope with which DOM elements are selected.

Comments

nod_’s picture

horrible selectors

nod_’s picture

tag

eli-f’s picture

JSHint complains

Line 13: callback: function(context, settings, form, farb, height, width) {

'width' is defined but never used.

Line 13: callback: function(context, settings, form, farb, height, width) {

'height' is defined but never used.

Line 13: callback: function(context, settings, form, farb, height, width) {

'farb' is defined but never used.

Also, when I get D8 up and running I can refactor the selectors to be more efficient.

eli-f’s picture

Status: Active » Reviewed & tested by the community
StatusFileSize
new3.81 KB

First revision patch. I need to look at where Drupal.color.callback is called to remove the arguments no longer used in this method.

eli-f’s picture

StatusFileSize
new3.81 KB

I am corrected the patch naming so it can be tested properly.
EDIT
I actually still did not name it correctly... I shall ask around before uploading another.

nod_’s picture

Status: Reviewed & tested by the community » Needs review

proper way to send patch is to put it as Need review and someone else not involved in the patch to put it as reviewed and tested by the community. You can't do that on your own for core patches :)

had a quick look, looks ok :)

eli-f’s picture

Gotcha. Thanks for the tip;

rteijeiro’s picture

StatusFileSize
new1.81 KB
new4.01 KB

I have reviewed the patch and added some improvements. Also added a interdiff.txt for easy reviewing ;)

Status: Needs review » Needs work
Issue tags: -JavaScript clean-up, -Needs JavaScript testing

The last submitted patch, 1751436-bartik-color-js-cleanup-8.patch, failed testing.

rteijeiro’s picture

Status: Needs work » Needs review
Issue tags: +JavaScript clean-up, +Needs JavaScript testing
nod_’s picture

StatusFileSize
new4.01 KB

Only change is for the variable declaration so that they follow core standards.

jgrubb’s picture

Hey, I'm really sorry that I'm late to the party, but is there a reason that the core standards are this way? Most of the javascript coding world has settled on the single var pattern, ala patch #8. If this convention were used everywhere, it would probably add up to a larger than trivial amount over the wire. We also wouldn't have knowledgable JS developers coming to Drupal and wondering what we're doing. I can't find where it's stated that it should be this way, and why.

Thank you...

nod_’s picture

Yes you're a few months late to the party. #1483396: [policy, no patch] JavaScript coding standards for variable declarations, look at #16

"Most of the javascript coding world has settled on the single var pattern", nodejs is not the javascript world, it's part of it. As a wikipedia editor would say: "need references".

Also if code style is your thing and you want the doc to be updated, check out #1778828: [policy, no patch] Update JS coding standards.

markhalliwell’s picture

Issue tags: +color module

tagging for my reference (component maintainer now)

Status: Needs review » Needs work

The last submitted patch, 11: core-js-bartik-jshint-1751436-11.patch, failed testing.

manuel garcia’s picture

Issue summary: View changes
Parent issue: » #1574470: Selectors clean-up
rteijeiro’s picture

Status: Needs work » Needs review
StatusFileSize
new4.04 KB

Re-rolled!

pguillard’s picture

After patch application, I played with the Bartik color scheme preview for a while, was silent in the Chrome/FFx console.

nod_’s picture

Status: Needs review » Needs work

we want a "var" for each variable here:


      var $preview = $form.find('#preview'),
          $previewBlock = $preview.find('#preview-block'),
          $palette = $form.find('#palette'),
          $colorVals = $palette.find('input[name*=palette]'),
          paletteValues = {},
          gradientStart, gradientEnd;

Status: Needs work » Needs review
nod_’s picture

Status: Needs review » Needs work
dimaro’s picture

Status: Needs work » Needs review
StatusFileSize
new1.02 KB
new4.04 KB

Add the proposed changes in #20

rteijeiro’s picture

Status: Needs review » Reviewed & tested by the community

Let's wait for testbot and @nod_'s opinion but looks RTBC. Thanks @dimaro!

nod_’s picture

RTBC++

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs issue summary update
Testing JavaScript using eslint


core/themes/bartik/color/preview.js
  17:6  error  Split 'var' declaration into multiple statements  one-var

✖ 1 problem (1 error, 0 warnings)

eslint test failed

Plus this issue is a normal task so we need to outline how it fits within the allowable Drupal 8 beta criteria. Can someone add Drupal 8 beta phase evaluation template to the issue summary.

pguillard’s picture

StatusFileSize
new607 bytes
new4.05 KB

Corrected

alexpott’s picture

Status: Needs work » Needs review
nod_’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: -color module, -Needs JavaScript testing, -Needs issue summary update

Beta eval added.

Code lint properly and color preview still works.

xjm’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs issue summary update

The summary suggests this patch has a performance impact; can someone clarify what that is? (Also in the parent issue at #1574470: Selectors clean-up since I imagine that would apply to other child issues as well.)

xjm’s picture

Also, is there any disruption from this to contrib or custom modules or themes? Any JS BC break?

nod_’s picture

Status: Needs review » Needs work

Perf impact is present but not that important. There is no API change, it's internal bartik refactoring. The color api is defined in the color module, bartik is using it like any other contrib module would.

About the perf, we're reducing our selection scope, instead of selecting elements from the wrapping <form> element, we're selecting elements from inside <div id="preview"> only.

Do we still to update the IS or does this makes it clear enough?

This needs reroll though.

pguillard’s picture

Status: Needs work » Needs review
StatusFileSize
new4.25 KB
new5.21 KB

Patch re-rolled

xjm’s picture

@nod_, I'd suggest updating the summary of #1574470: Selectors clean-up, since whether or not this patch has actual performance impact affects whether it can be accepted during the beta. See https://www.drupal.org/core/beta-changes. In general, internal refactorings are no longer allowed during the beta phase, for both PHP and JavaScript. If the performance impact is negligible, it might be better to postpone these cleanups.

droplet’s picture

Status: Needs review » Needs work
Issue tags: -Needs issue summary update +Needs reroll, +js-novice, +Novice

If anyone could help to reroll it. I promise you I will help you review it and get it move forward.

Now, it's only needed some basic caching for selectors,eg

form.find('.color-preview

droplet’s picture

Priority: Normal » Minor
zeeshan_khan’s picture

Assigned: Unassigned » zeeshan_khan
Issue tags: +drupalconasia2016
zeeshan_khan’s picture

Status: Needs work » Needs review

I couldn't find any more code to cached as I see all selectors are being cached properly. :)

droplet’s picture

Looking at wrong file ?

http://cgit.drupalcode.org/drupal/tree/core/themes/bartik/color/preview.js

Every lines are needed some work :) Thanks!

sashi.kiran’s picture

Issue tags: -drupalconasia2016 ++drupalconasia2016
StatusFileSize
new4.3 KB

I have updated the patch.

droplet’s picture

Status: Needs review » Needs work

Patch #33 is outdated. You can't reroll it directly. Many code is already removed.

sashi.kiran’s picture

Assigned: zeeshan_khan » sashi.kiran
Issue tags: -+drupalconasia2016 +drupalconasia2016

@Droplet: I have just checked the Patch #33 with the latest code and I am able to find all the lines in the Patch.

Following line was mismatching, which I have updated:

form.find('.color-preview .color-preview-header').attr('style', "background-color: " + gradient_start + "; background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(" + gradient_start + "), to(" + gradient_end + ")); background-image: -moz-linear-gradient(-90deg, " + gradient_start + ", " + gradient_end + ");");

Please correct me if I am wrong :) Thanks!

The last submitted patch, 40: selectors_clean_up-1751436-34.patch, failed testing.

droplet’s picture

Assigned: sashi.kiran » droplet
droplet’s picture

Issue tags: -Needs reroll
StatusFileSize
new3.94 KB

@sashi.kiran,

You may right :) Sadly, I think Patch #34 / #42 are not so reviewable.

Since it's rarely used in other pages, I think only a simple improves is acceptable.

droplet’s picture

Assigned: droplet » Unassigned
dimaro’s picture

Status: Needs work » Needs review

@droplet Update this issue to run your patch.

nod_’s picture

Status: Needs review » Reviewed & tested by the community

#45 is good to go.

We're going for something simple so while #34/#40 work an are an improvement, the color module needs a refactoring and we can improve that when it'll happen, for now we try to change as little as possible.

zeeshan_khan’s picture

manjit.singh’s picture

Ready to ship .. hu ha
RTBC ++

  • catch committed 321b0db on 8.1.x
    Issue #1751436 by pguillard, rteijeiro, eli-f, dimaro, nod_, droplet,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.1.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.