mobify/pikabu — pull request #46 by sunyatasattva (2014-11-19 12:25:03+00:00)
Title: Resize event mistakenly fired, sidebar in view check incorrect (fix)

I came across this bug because scrolling on my site suddenly didn't work anymore. I assume this is a new iOS Safari bug, but it seems that the `resize` event was fired on scroll.

So, in the event handler for the `resize` and `orientationchange` events, I added a fix to check if a resize of the viewport really happened (I only check for width, as I assume that's what we only care about).

This alone, however, would not explain why my scrolling wouldn't work (although this fixes the issue in a sense). The problem is that, further down (line 325 onwards), the code checks to see if any of the sidebars are visible, and proceeds to lock the viewport height.

Unfortunately, this is not how the [Zepto `:visible` selector](https://github.com/madrobby/zepto/blob/0f920c14759ad77e36006d38bf66e3dcd1eb33db/src/selector.js#L8) works. Rather, it just checks if the element has a `width` or `height` and it's not `display: none`. So, it basically always returns `true` for the sidebars.

What I did instead, is to check the offsets of the sidebars to determine if they are in view.