Skip to content
This repository has been archived by the owner on Feb 7, 2020. It is now read-only.

Menu stays open on iOS when clicking back #4

Open
nickcernis opened this issue Jun 2, 2017 · 1 comment
Open

Menu stays open on iOS when clicking back #4

nickcernis opened this issue Jun 2, 2017 · 1 comment

Comments

@nickcernis
Copy link

nickcernis commented Jun 2, 2017

Low priority, but when tapping a menu item on iOS and then tapping back, the menu appears open instead of closed.

iphone image on 2017-06-02 at 18-44-34

Reproducible on https://demo.studiopress.com/infinity/ on iPhone by:

  1. Tapping the Journal link.
  2. Tapping the back button or swiping right from the left screen edge.

The menu remains open instead of closed.

The cause is document.ready not firing on iOS when clicking back. We likely need to run _maybeClose again on the pageshow event.

As a proof of concept, this in Genesis → Theme Settings → Footer Scripts solves the issue:

<script>
    jQuery(window).on('pageshow', function () {
        var mainMenuButtonClass = 'menu-toggle',
            subMenuButtonClass  = 'sub-menu-toggle',
            responsiveMenuClass = 'genesis-responsive-menu';

        jQuery('.' + mainMenuButtonClass + ', .' + responsiveMenuClass + ' .sub-menu-toggle')
            .removeClass('activated')
            .attr('aria-expanded', false)
            .attr('aria-pressed', false);

        jQuery('.' + responsiveMenuClass + ', .' + responsiveMenuClass + ' .sub-menu')
            .attr('style', '');
    });
</script>
@cjkoepke
Copy link
Contributor

cjkoepke commented Jun 8, 2017

From my research the onpageshow event works as a cache event, but not on first-load (not sure if this is problematic or not). Apple's bfcache of Safari on iOS will not cache framed pages, however, and from their own documentation suggest adding a blank iframe:

Safaris Back/Forward cache (the cache pulled from when a visitor presses the Back or Forward browser buttons) can also be thwarted by insuring that your page contains a frame. Frame-based pages are never stored in the back / forward cache and you can insure your non-frame based page behaves similarly by adding the invisible iframe below.

<iframe style="height:0px;width:0px;visibility:hidden" src="about:blank">
	this frame prevents back forward cache
</iframe>

I'm not sure I like the idea of injecting and empty frame into the DOM, however, so onpageshow might be the best option. However, you'd still likely get a flash of the open nav before it closed (due to the caching).

It might be worth considering if this is really an issue, though — technically, returning to the last screen with the nav open is an accurate representation of the previous state of the page.

I'm tempted to leave this alone, but am open to comments on whether this is something we want to prevent. Feel free to chime in @dreamwhisper and @bgardner, if you have any thoughts.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants