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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nod_’s picture

Title: Refactor toolbar.js » Refactor toolbar.js and make it use localStorage
frega’s picture

Status: Active » Needs review
FileSize
4.25 KB

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

nod_’s picture

Status: Needs review » Needs work

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.

frega’s picture

There'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.

nod_’s picture

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.

nod_’s picture

Title: Refactor toolbar.js and make it use localStorage » Refactor toolbar.js use localStorage remove cookie and no-js fallback

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

nod_’s picture

tag

nod_’s picture

Status: Needs work » Closed (duplicate)