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.
Can be written to minify much better, and use the same approach as #1569648: Follow-up: Use localStorage to store tableDrag.showWeight value for the display/toggle of the collapsing toolbar.
The cookie will still need to be used to keep the no-js fallback of the toggle, otherwise localStorage should be used to be able to toggle it on all open tabs. See how it's done on the other issue.
Comment | File | Size | Author |
---|---|---|---|
#2 | 1686256_toolbar_refactor_localstorage_2.patch | 4.25 KB | frega |
Comments
Comment #1
nod_Comment #2
frega CreditAttribution: frega commentedRefactored along the lines in #1569648: Follow-up: Use localStorage to store tableDrag.showWeight value.
Notes:
- displayToolbar is a bit of a misnomer for what that function does (redrawing/updating state)
- one could argue about having the toolbar not being a "static" class, but an instantiated singleton (but that's almost bikeshedding)
Comment #3
nod_That's a good start :)
There is a link in the toolbar module to have a php callback setting a cookie to provide a no-js toggle of this. So we have to work around that.
As far as review goes, I'd be happy with selecting the elements only once in the attach behavior and send that to the methods afterwards.
Comment #4
frega CreditAttribution: frega commentedThere's a whole bunch of functions that access the cookie - we either refactor the functionality significantly or revert to using a cookie? Accessing localStorage obviously is not possible from PHP. Please advise :)
function _toolbar_is_collapsed() { // checks cookie, called from many places ...
function toolbar_preprocess_html(&$vars) { // attaches a class toolbar to the body?
function toolbar_toggle_page() { // toggles cookie
etc.
Comment #5
nod_Also, you can see the patch over there #1541860-31: Reduce dependency on jQuery for reference, we still need to sort out the toggle cookie support.
Comment #6
nod_Let's remove all those things and the cookie. If there is no JS available the shortcut bar stays open.
You can update the patch and let's wait for feedback :)
Comment #7
nod_tag
Comment #8
nod_included in #1137920: Fix toolbar on small screen sizes and redesign toolbar for desktop