Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu not closing on body click #342

Open
kirstylmarks opened this issue Mar 26, 2018 · 1 comment
Open

Menu not closing on body click #342

kirstylmarks opened this issue Mar 26, 2018 · 1 comment

Comments

@kirstylmarks
Copy link

kirstylmarks commented Mar 26, 2018

I have implemented the following code:

`$j(document).ready(function() {

    $j('body').click(function(){ // when 'btnClose' is clicked…

        $j.sidr('close', 'sidr');  // close the div with the ID of "sidr"

    });

});`

However the above is not closing my menu. I have looked through the site and cannot see anything that would conflict with this. I have also tried this on a parent site which again does not seem to work.

Ideas welcomed please as ideally need to get this working.

Thanks

@jigarius
Copy link

Here's how I did it:

// Ensure sidr close on blur.
$(document.body).click(function (e) {
  // If a sidr is open.
  if ($.sidr('status').opened) {
    var isBlur = true;
    // If the event is not coming from within the sidr.
    if ($(e.target).closest('.sidr').length !== 0) {
      isBlur = false;
    }
    // If the event is not coming from within a trigger.
    if ($(e.target).closest('.js-sidr-trigger').length !== 0) {
      isBlur = false;
    }
    // Close sidr is unfocused.
    if (isBlur) {
      $.sidr('close', $.sidr('status').opened);
    }
  }
});

Hope it helps.

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

No branches or pull requests

2 participants