When binding JS events to HTML classes or element IDs, it makes it tricky to know when modifying the HTML whether modifying the class will break some JS. You can't test every extension.
I propose using a js- namespace for classes which have JavaScript events binded to them (and those classes should never be styled).
Another alternative would be a `data-hook` attribute, e.g. `data-hook="alert-box"`.
It just makes stuff less fragile. I would be able and willing to implement this.
Ticket: https://tracker.phpbb.com/browse/PHPBB3-12806
Don't bind to class selectors or IDs
- callumacrae
- Former Team Member
- Posts: 1046
- Joined: Tue Apr 27, 2010 9:37 am
- Location: England
- Contact:
Re: Don't bind to class selectors or IDs
+1
I'd prefer the js- prefixed classes. Is there any parsing speed advantage to using data-attr?
I'd prefer the js- prefixed classes. Is there any parsing speed advantage to using data-attr?
Re: Don't bind to class selectors or IDs
+1
I'd prefer custom data attributes.
I'd prefer custom data attributes.
- callumacrae
- Former Team Member
- Posts: 1046
- Joined: Tue Apr 27, 2010 9:37 am
- Location: England
- Contact:
Re: Don't bind to class selectors or IDs
It's actually mad slow.PayBas wrote:Is there any parsing speed advantage to using data-attr?
Doesn't really matter, though. Just don't do it in a loop in a loop.
To anyone who think a 400% difference is significant: it's a 0.000008959 second difference. Nobody cares xD
Re: Don't bind to class selectors or IDs
+1
either way is fine for me.
only caveat is those classes that are for behaviors which can be applied via js IE: is-visible, is-hidden, etc...
these can be applied via js but never used as hooks.
just pointing out for clarification.
@callumacrae some of the functions are going to need completely re-written, such as the parser https://tracker.phpbb.com/browse/PHPBB3-12806
either way is fine for me.
only caveat is those classes that are for behaviors which can be applied via js IE: is-visible, is-hidden, etc...
these can be applied via js but never used as hooks.
just pointing out for clarification.
@callumacrae some of the functions are going to need completely re-written, such as the parser https://tracker.phpbb.com/browse/PHPBB3-12806
Re: Don't bind to class selectors or IDs
+1
Above message may contain errors in grammar, spelling or wrongly chosen words. This is because I'm not a native speaker. My apologies in advance.
- callumacrae
- Former Team Member
- Posts: 1046
- Joined: Tue Apr 27, 2010 9:37 am
- Location: England
- Contact:
Re: Don't bind to class selectors or IDs
Not everything needs to be converted. The more the better, and all new code can use it.hanakin wrote:+1
either way is fine for me.
only caveat is those classes that are for behaviors which can be applied via js IE: is-visible, is-hidden, etc...
these can be applied via js but never used as hooks.
just pointing out for clarification.
@callumacrae some of the functions are going to need completely re-written, such as the parser https://tracker.phpbb.com/browse/PHPBB3-12806
Converting stuff to use this isn't actually that tricky, though.
Re: Don't bind to class selectors or IDs
+1
I prefer the data- attribute version, btw.
I prefer the data- attribute version, btw.