As far as I can see all 7x versions have had this problem; but I haven't tested further back than 7.32 since that's when I discovered it. Haven't tested other major versions.
Description: On page load the admin toolbar adds padding-top to the body element so it is not (partially) hidden under the toolbar. The toolbar is responsive so if the screen size changes the height of the toolbar may change; however the padding-top value is never updated.
Platforms/Browser: Should be replicateable/fixed by patch on all but tested with: Windows 7, Firefox 35.0(a2), IE 9 & 10, Chrome 38.
Replication:
- Load minimal site (any site will do really)
- Change viewport size or zoom - ie from maximized to one half of the screen in vertical orientation. Has to be big enough change to to change how many rows of buttons are on the toolbar.
- Now the toolbar will overlay or have a big gap between it and the content because it still has the original padding-top value.
Fix is very simple; just adding resize handler to update the padding-top value; patch file attached.
Comments
Comment #1
xjmComment #2
dawehner.
Comment #3
nickdickinsonwildeTested and I can confirm it is not a problem in 8.x - the toolbar being very different.
Comment #4
nickdickinsonwildeScreenshots:



Load maximized window:
resize window:
toolbar floats adjust and the toolbar is now taller. However the padding that is applied to the body is not updated so it pushes down over the header/title/top content (depending on site):
with patch on resize:
body padding is adjust to move up/down as required:
Comment #5
nod_Well that works very well.
There has been so much frustration with this, yet the patch is that simple :p
The binding isn't done in the right place though. We'll end up binding it a lot of times for nothing when ajax is involved. please move that code to Drupal.toolbar.init
Comment #6
nickdickinsonwildeMoved (and since I'm generally bad about not documenting also added a little comment). Updated patch attached.
Comment #7
nickdickinsonwildeComment #8
nod_Looked a bit more into it, because resize is used a lot it's worth spending some time on optimizations.
After that we're good to go. Ideal would be to add debouncing but it's a bit out of scope I think.
Comment #9
nickdickinsonwildeYeah optimization is always a good idea, thanks for help.
1. Oh yes; make the script itself take more time but compared to the browser recalcing a lot of extra probably better I'm assuming.
2. Yes. I need to do this more in all my projects, I'm good at always chaining if possible but I definitely should cache more. I gave a quick look and $(body) was used a couple other times (in onClick) handlers in the toolbar module so I replaced them as well, since that wasn't far out of scope.
3. Sure, I didn't actually know that was any performance difference, thanks for the tip.
Comment #10
nickdickinsonwildeComment #11
nickdickinsonwilde@Nod_: anything else I should do on this?
Thanks;
Nick
Comment #12
nod_wow long overdue review, sorry.
You can make it a local
$bodyvariable. There is no need to expose this in the Drupal object.The issue with this is that we're still hitting the DOM to get the size of body padding. We can know this value. I would rather create a new local variable and cache that padding value, updating it and the padding-top value only when it changes.
That way we limit our interactions with the DOM to the minimum.
Comment #13
nickdickinsonwildeFine, not like you're being paid. (I have lots of open source experience working at various positions within projects so I totally understand).
Re #1: okay sure, done.
Re #2: This one I can think of possible cases that would conflict (if something else is JavaScript modifying the Body's padding-top at somepoint after toolbar init); however I think the risk of that is pretty low. So did almost exactly the changes you suggested.
After doing those two things I did notice some other optimizations possible; Same as the body height check it was using $() so I cached that. Also a bunch of code was being run in the toolbar.height() function, that only needed to be run once on init (that was already being run unnecessarily whenever the lower toolbar was added/removed). So the patch has grown a fair bit actually and now despite the added resize processing the whole toolbar.js should be faster.
Comment #15
nickdickinsonwildeoops typo in the patch somehow.
Merry Christmas/Happy Holidays btw.
Comment #16
nod_It goes a little bit beyond a simple change but it makes a lot of sense.
It'll need to be profiled to check whether the additional changes have some visible (to the profiler, not user) perf improvements compared to the naive approach. I'm pretty sure it'll be the case because we get rid of a call to .css() in all browsers.
Provided the profiling shows improvement big +1 from me.
few nitpicks:
space and capital here:
// Since…This should be initialized in Drupal.behavior, we can't be sure the DOM is loaded outside a behavior. Edgecase-y but still.
Comment #17
nickdickinsonwilde1. Fixed capitalization
2. Moved to behaviour for setting the value; of course had to leave the variable declaration up at the top there so as to have them available inside the different functions.
Profiling; is that something I should be doing? If so got any instructions/links to instructions? I did a quick search and could only find PHP profilers for Drupal.
Thanks for your help improving both this and my JavaScript/Drupal skills :)
Comment #18
nickdickinsonwildeComment #19
nod_It's missing ";" on each line. Otherwise it's RTBC.
Profiling shows that Drupal.toolbar.height cost less than 1ms on a recent browser, I'm comfortable with that. Some of the slowness comes from the old version of jQuery, can't do much about it. I guess the only thing left if we want to be extra sure is to fire up IE6 and see how it goes. I don't have it though.
Comment #20
nickdickinsonwildehuh that's odd... Sublime *should* have warned me since I have jshint active but ah well, fixed that and review for any other typos or oddities and couldn't find any.
IE6... yes I have often done extra junk work to make websites support IE6 but I hate it and now that it is below 1% market I'm doing nothing extra to support it unless I absolutely have to.
Thanks for your help, Nod!
Happy New year!
Comment #21
nickdickinsonwildeSince the two errors that nod_ found were fixed 10 days and he said other than that it was RTBC, I'm marking it RTBC.
Comment #24
David_Rothstein commentedLooks like a testbot fluke.
Comment #27
David_Rothstein commentedTestbot fluke.
Comment #28
nod_For the record, #20 is indeed RTBC.
Comment #30
nickdickinsonwildeWhat is with that Test bot fluke silly thing!
Comment #31
David_Rothstein commentedThis seems really non-standard. Won't it break other code outside the toolbar module that is trying to use the Drupal.toolbar object?
For example, if you call Drupal.toolbar.height() from another module's behaviors, it seemed to work before but breaks after this patch...
A couple more minor notes:
Should have a space between the comma and the "10".