Skip to content

Conversation

@mgol
Copy link
Member

@mgol mgol commented Mar 1, 2017

Fixes gh-3144
Closes gh-3199

Summary

This PR adds suppport for CSS Custom Properties (a.k.a. CSS Variables). This is a finalized version of the PR #3199 with passing tests.

Checklist

Mark an [x] for completed items, if you're not sure leave them unchecked and we can assist.

Thanks! Bots and humans will be around shortly to check it out.

@mgol mgol added the CSS label Mar 1, 2017
@mgol mgol added this to the 3.2.0 milestone Mar 1, 2017
@mgol mgol self-assigned this Mar 1, 2017
@mgol mgol requested review from gibson042 and markelog March 1, 2017 23:33
@jsf-clabot
Copy link

jsf-clabot commented Mar 1, 2017

CLA assistant check
All committers have signed the CLA.

@mgol mgol mentioned this pull request Mar 1, 2017
4 tasks
( value = hooks.set( elem, value, extra ) ) !== undefined ) {

style[ name ] = value;
if ( isCustomProp ) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally planned to remove it as discussed in #3199 to fix https://bugs.jquery.com/ticket/14394 but CSSStyleDeclaration#setProperty requires styles in the kebab-case format so whatever we decide about that I'd like it to land separately.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with breaking that out for a later fix, it does seem like all of this can be refactored better at that time.

src/css.js Outdated
// want to modify the value if it is a CSS custom property
// since they are user-defined.
if ( !isCustomProp ) {
name = jQuery.cssProps[ origName ] ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could simplify this logic with usual if..else or move it to the helper method? Like getName or something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is used only in jQuery.style & jQuery.css which have some duplicated code anyway. We have an issue to unify them (#2297) so this helper method would be used only once again when it's done.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would start now at least for the affected code, that issue is open for two years now

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can extract it but won't we want to de-extract it back once those two methods get unified?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just don't like this

name = jQuery.cssProps[ origName ] ||
  ( jQuery.cssProps[ origName ] = vendorPropName( origName ) || origName );

thingy :). Really hard to read

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. I do agree with that. And if you refactor it into if-elses then it get long enough that it makes sense to extract it, I get it now. On it.

test/unit/css.js Outdated

assert.equal( $elem.css( "--prop1" ), "val1", "Basic CSS custom property" );

// Support: Chrome 55, Safari 9.1-10.0 only
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to remove Chrome from here.

@mgol mgol removed the request for review from gibson042 March 6, 2017 18:51
mgol pushed a commit to mgol/jquery that referenced this pull request Mar 6, 2017
@mgol
Copy link
Member Author

mgol commented Mar 6, 2017

PR updated. I hope you like the changes, @markelog. :-)

mgol pushed a commit to mgol/jquery that referenced this pull request Mar 7, 2017
@mgol
Copy link
Member Author

mgol commented Mar 7, 2017

Rebased so that it can be tested in AMD mode.

Copy link
Member

@markelog markelog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High five!

@mgol
Copy link
Member Author

mgol commented Mar 7, 2017

@timmywil the PR changed a little since you last looked at it so PTAL.

( value = hooks.set( elem, value, extra ) ) !== undefined ) {

style[ name ] = value;
if ( isCustomProp ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with breaking that out for a later fix, it does seem like all of this can be refactored better at that time.

//
// getPropertyValue is needed for:
// .css('filter') (#12537)
// .css('--customProperty) (#3144)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for the comment!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the IE 9 mention above look like it referred to the whole comment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the support comment should be removed in favor of // .css('filter') in IE 9 only (#12537) as we won't be able to remove this code path anyway due to CSS vars.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah i was looking at the added lines and not thinking about it seeming to be related to IE9. I'd be fine with removing the // Support: comment since like you say it's no longer just an IE9 requirement.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR updated. Does it look OK now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep!

@mgol mgol merged commit 619bf98 into jquery:master Mar 7, 2017
@mgol mgol deleted the css-vars branch March 7, 2017 14:05
@mgol mgol removed the Needs review label Sep 25, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Development

Successfully merging this pull request may close these issues.

Request: support for CSS custom properties

5 participants