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.
Separating configuration from initialization of the jQuery animations and general moving things around to reduce function nesting and function length.
Comments
Comment #1
nod_Related: #209420: Remove the scrolling animation in collapsible.js
Comment #2
frega CreditAttribution: frega commentedassigning for dcmuc code sprint
Comment #3
frega CreditAttribution: frega commentedThis is an *initial* stab at refactoring this. Created a CollapsibleFieldset-object/wrapper for each instance on the page (à la verticaltab). Not finished yet, but @nod_ is this what you intended in terms of refactoring?
Comment #4
frega CreditAttribution: frega commentedThis is an *initial* stab at refactoring this. Created a CollapsibleFieldset-object/wrapper for each instance on the page (à la verticaltab). Not finished yet, but @nod_ is this what you intended in terms of refactoring?
Comment #5
nod_yeah that's a good start :)
the created fieldset should be stored somewhere (don't take example on Drupal.ajax, the new tableheader patch is better to look at)
there are some semicolons missing, run your code though jshint early on as well :)
the setup and toggle method could probably be simplified
whenever you have an object for options, try to add that to an accesible thing somewhere in Drupal.autocomplete or drupal.settings
Comment #6
frega CreditAttribution: frega commentedContinued on refactoring in the patch. Further splitting up into separate methods.
Re: Drupal.settings - introducing Drupal.settings.collapsibleFieldset (optional).
Todo/Questions:
1) Do we want to scrollIntoView at every step of the animation, do we want to scrollIntoView at all?
2) Settings per fieldset?
Comment #7
frega CreditAttribution: frega commentedOops, missed a superfluous var self = this; in the constructor.
Comment #8
ethanw CreditAttribution: ethanw commentedReviewed patch for functionality, all okay.
Make two slight changes, as discussed at the sprint: use jQuery.extend for Drupal.settings parameters, as they were initially used for settings arguments and removed a `that` var where jQuery proxy had been used instead.
Comment #9
frega CreditAttribution: frega commentedRerolled last patch because git/jshint were nagging about trailing whitespace ;)
Comment #10
nod_Just a few changes and it should be good:
you can move the content of the setup function inside the constructor directly,
Create a Drupal.CollapsibleFieldset.fieldsets = []; where you'll put the objects you create in the behavior. Have a look at tableheader to see what I mean.
separate the .once() call and the actual loop over the results, that'll help later on.
Nice work so far :)
Comment #11
frega CreditAttribution: frega commentedRerolled according to #10.
Notes:
1) Do we want to scrollIntoView at every step of the animation, do we want to scrollIntoView at all?
2) Do we need individual settings per fieldset (i.e. passing those to the constructor?)
PS. This is a great example where backbonejs would help us organize and standardize "representation" and "state" in the client in a clean and consistent fashion :)
Comment #12
frega CreditAttribution: frega commentedMissed setting to "needs review", sorry. Notes etc. still applies.
Comment #13
seutje CreditAttribution: seutje commentedscrollIntoView should be gone soon: #209420: Remove the scrolling animation in collapsible.js will probably break this partially. Considering it's a rather small change and it's been UX approved, maybe we should just incorporate it into this refactoring?
Comment #14
frega CreditAttribution: frega commentedI am more than happy to remove that stuff - @nod_ any opinions?
Comment #15
frega CreditAttribution: frega commentedAfter rereading #209420: Remove the scrolling animation in collapsible.js (seems pretty unanimous), I rerolled the patch removing the scrollIntoView-part (saves 800 bytes, yay!).
Comment #16
seutje CreditAttribution: seutje commentedIt makes sense to send the settings to the constructor, otherwise any settings passed to the attach handler are simply ignored. And it seems nice to have the ability to have separate settings per collapsible fieldset.
Attached patch removes some whitespace and passes the settings to the constructor.
Also: I learned how to make interdiffs :D
Comment #17
seutje CreditAttribution: seutje commentedAlso gave this a quick manual test on IE8 just to make sure, seems to work as expected.
Comment #18
frega CreditAttribution: frega commentedFixed small bug in #16 pushing the settings-var onto the Drupal.CollapsibleFieldset.fieldsets-array rather than providing it to the constructor. Changed the constructor so that it does not merge all of Drupal.settings into the local settings-property.
Comment #19
nod_in setupSummary there is
it should be
You can get rid of the default varible in the constructor, the object can be the first parameter for $.extend()
onLegendclick, e.preventDefault() should be first (in calse the toggle crashes for some reason). and you shouldn't return anything.
The slidedown configuration object in toggle() could be nice to have as an object member in case we want to change those settings.
That line don't need to be in attach, would be better right after the constructor is defined (and without the || check, just Drupal.CollapsibleFieldset.fieldsets = [];)
in the attach still just send
settings.collapsibleFieldset
as the second parameter of the constructor.Comment #20
frega CreditAttribution: frega commentedRerolled patch as per #19.
I didn't quite understand this bit: "The slidedown configuration object in toggle() could be nice to have as an object member in case we want to change those settings." - You would you like to be able to inject other options (or override others?). $.slideDown afaik only takes duration, easing and complete, but I might be wrong :)
Comment #21
frega CreditAttribution: frega commentedMissed the state change again, sorry.
Comment #22
frega CreditAttribution: frega commentedRefactored as per IRC to be more similar to tableheader (i.e. Drupal.CollapsibleFieldset = CollapsibleFieldset;) allowing for better minification; settings will be passed to slideUp/slideDown-animation functions, new: additional events "completeSlideDown" and "completeSlideUp" to allow for custom stuff.
Comment #23
frega CreditAttribution: frega commentedFixed coding-standard, and refactor $.each to for-loop.
Comment #24
frega CreditAttribution: frega commentedMissing space "onLegendClick"
Comment #25
nod_Works great, thanks for sticking up with the painful review process :D
Comment #26
nod_another patch broke this one, need reroll.
Comment #27
seutje CreditAttribution: seutje commentedreroll, it was the removal of return false and addition of e.preventDefault() that broke it, but those changes were already incorporated in this one.
Comment #28
seutje CreditAttribution: seutje commentedadding reference to what broke this patch: #1749782: Use event.preventDefault(); and event.stopPropagation(); instead of return false;
Comment #29
nod_All good now. Back to RTBC.
Comment #30
webchickIn general I think I follow what's going on here, and seems like reasonable clean-up.
Committed and pushed to 8.x. Thanks!
Comment #31
Kiphaas7 CreditAttribution: Kiphaas7 commentedBONUS: Investigate if adding basic events and detach makes sense, as described in #1763812: [META] Provide complete attach/detach with basic events.
I think it does make sense to trigger some basic 'collapse initialized/removed' along with a detach.