Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Following #1428524: Replace all $.each() with filtered for loop, we are to replace all jQuery.each() calls with filtered for loops. This is to be appllied to all non-jQuery objects iterations.
Because for is much faster and $.each() changes the loop scope and doesn't filter properties which causes bugs (in autocomplete for example).
Related
Comment | File | Size | Author |
---|---|---|---|
#15 | 1660952-jquery.each-15.patch | 1.34 KB | seutje |
#12 | core-1660952-12.patch | 2.61 KB | Jelle_S |
#10 | core-1660952-10.patch | 2.46 KB | Jelle_S |
#8 | core-1660952-8.patch | 2.12 KB | Jelle_S |
#3 | for.patch | 2.04 KB | RobLoach |
Comments
Comment #1
tim.plunkettAlso be sure to look for
this.each()
when jQuery is 'this'.Comment #2
RobLoachComment #3
RobLoachUntested.
Comment #4
nod_That's how real men do it.
I tested, worked for me, except that I can't seem to find a page where
menu.admin.js
is added (so yeah, field_ui.js worked).Comment #5
nod_#3: for.patch queued for re-testing.
Comment #7
nod_I was expecting a fail to apply error but not random testbot failure. I guess it doesn't need a reroll then.
Comment #8
Jelle_SProblem was that in menu.admin.js the options variable is an object, not an array, changed to
for
loop to afor in
loop.Comment #9
nod_very minor thing, is it possible to replace the variable name
i
tovalue
?(edit) and more importantly, the jquery selector needs to be out of the loop that's pretty doggy like that.
Comment #10
Jelle_SYou mean this selector right? That's the result of a shameless copy-paste and trying to do a quick-fix on replacing the loop ;-)
new patch attached
Comment #11
Jelle_SJust on a side note: can't we change this to
$('#edit-menu-parent')
since HTML ids are supposed to be unique anyway?And an other question, not necessarily related to this issue, but I've had it on my mind since a while now:
What is best practice:
or
Comment #12
Jelle_Sfixed one
for
that should have been afor in
loop.Also in field_ui.js line 86, there's a
this.each()
wherethis
is a jQuery object. Should this be changed to a for loop?I talked with @seutje about it, and we both seemed to think this was a valid use case to use the
jQuery.each()
function, but we would like some feedback on this (@nod_ ?)Comment #13
nod_Oh yeah we're not replacing the jQueryElement.each just the $.each.
For now :)
Comment #14
nod_if you rename
value
asindex
inmenu.admin.js
that's RTBC :)Comment #15
seutje CreditAttribution: seutje commentedthe
menu.admin.js
changes were incorporated in #1751398: Selectors clean-up: menu module, along with some others, so I'm rerolling this one without that bit, so either won't break if the other goes in first.Comment #16
seutje CreditAttribution: seutje commenteddamn status
Comment #17
Jelle_SI'd put it on RTBC if I hadn't worked on this patch as well :-( ;-)
In other words: Looks good to me...
Comment #18
nod_#15: 1660952-jquery.each-15.patch queued for re-testing.
Comment #19
nod_Still applies and still a proper fix.
Comment #20
catchCommitted/pushed to 8.x, thanks!