Drupal core prefixes classes needed to provide Javascript funtionality wir 'js-'. Commerce should do so as well to indicate which classes can be removed and which are required. One example in commerce_cart:
Current
commerce_cart.module:
<?php
/**
* Prepares variables for the cart block element template.
*/
function template_preprocess_commerce_cart_block(&$variables) {
$variables['attributes']['class'][] = 'cart--cart-block';
}
?>commerce_cart.js:
var $cart = $context.find('.cart--cart-block');
Should be
commerce_cart.module:
<?php
/**
* Prepares variables for the cart block element template.
*/
function template_preprocess_commerce_cart_block(&$variables) {
$variables['attributes']['class'][] = 'js-cart--cart-block';
}
?>commerce_cart.js:
var $cart = $context.find('.js-cart--cart-block');
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | prefix_classes_needed-2877358-3.patch | 7.26 KB | gauravjeet |
Comments
Comment #2
luksakComment #3
gauravjeet commentedHave prefixed class names with 'js-'. Only those class names been changed that are being added into Library via #attributes.
https://github.com/drupalcommerce/commerce/pull/743
Comment #4
thomas cysGreat work but in my opinion .js-* classes should only be used to denote behaviour.
Comment #5
luksakWhat do you mean by behavior?
The "js-" class prefixing is there to indicate that removing it might break javascript, right?
Comment #6
thomas cysWhat i mean is that you shouldn't style "js-" prefixed classes.
Comment #7
luksakOk, then we agree that all classes required by javascript should be prefixed?
Comment #8
thomas cysOfcourse but they shouldn't have css attached to them.
Comment #9
luksakYes, for that separate classes are needed. I guess we leave the existing ones in place and duplicate them with the js- prefix?
Comment #10
luksakIs it too late to get this in before a stable release?
Comment #11
bojanz commentedIt can still happen.
Comment #12
luksakThe patch is looking good so far. I encountered a few occurances of the .cart class:
CartBlock.php:
CartController.php:
I guess those are not needed by JS, but they are kind of hard to get rid of. Can we solve this differently?
Comment #13
luksakBut actually this is a different issue. We should move that HTML to templates. I created an issue for that: #2900616: Move HTML to twig templates
Comment #14
anybodyWould someone like to prepare this as MR against 3.0.x or should we close this won't fix due to inactivity since 2017?