Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nod_’s picture

frega’s picture

Assigned: Unassigned » frega

assigning for dcmuc code sprint

frega’s picture

Assigned: frega » Unassigned
Status: Active » Needs review

This 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?

frega’s picture

This 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?

nod_’s picture

Status: Needs review » Needs work

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

frega’s picture

Status: Needs work » Needs review
FileSize
7.94 KB

Continued 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?

frega’s picture

Oops, missed a superfluous var self = this; in the constructor.

ethanw’s picture

Reviewed 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.

frega’s picture

Rerolled last patch because git/jshint were nagging about trailing whitespace ;)

nod_’s picture

Status: Needs review » Needs work

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 :)

frega’s picture

Rerolled 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 :)

frega’s picture

Status: Needs work » Needs review
FileSize
7.96 KB

Missed setting to "needs review", sorry. Notes etc. still applies.

seutje’s picture

scrollIntoView 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?

frega’s picture

I am more than happy to remove that stuff - @nod_ any opinions?

frega’s picture

After rereading #209420: Remove the scrolling animation in collapsible.js (seems pretty unanimous), I rerolled the patch removing the scrollIntoView-part (saves 800 bytes, yay!).

seutje’s picture

It 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

seutje’s picture

Also gave this a quick manual test on IE8 just to make sure, seems to work as expected.

frega’s picture

Fixed 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.

nod_’s picture

Status: Needs review » Needs work

in setupSummary there is

this.$node.
  bind()
  .trigger();

it should be

this.$node
  .bind()
  .trigger();

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.

      Drupal.CollapsibleFieldset.fieldsets = Drupal.CollapsibleFieldset.fieldsets || [];

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.

frega’s picture

Rerolled 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 :)

frega’s picture

Status: Needs work » Needs review

Missed the state change again, sorry.

frega’s picture

Refactored 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.

frega’s picture

Fixed coding-standard, and refactor $.each to for-loop.

frega’s picture

Missing space "onLegendClick"

nod_’s picture

Status: Needs review » Reviewed & tested by the community

Works great, thanks for sticking up with the painful review process :D

nod_’s picture

Status: Reviewed & tested by the community » Needs work

another patch broke this one, need reroll.

seutje’s picture

Status: Needs work » Needs review
FileSize
7.67 KB

reroll, it was the removal of return false and addition of e.preventDefault() that broke it, but those changes were already incorporated in this one.

seutje’s picture

nod_’s picture

Status: Needs review » Reviewed & tested by the community

All good now. Back to RTBC.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

In general I think I follow what's going on here, and seems like reasonable clean-up.

Committed and pushed to 8.x. Thanks!

Kiphaas7’s picture

BONUS: 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.

Automatically closed -- issue fixed for 2 weeks with no activity.