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

trigger "toggle" action #3

Open
jamesarosen opened this issue Apr 4, 2017 · 3 comments
Open

trigger "toggle" action #3

jamesarosen opened this issue Apr 4, 2017 · 3 comments

Comments

@jamesarosen
Copy link

The native <details> element triggers a toggle action whenever it is toggled.

Something like the following might work:

function clickHandler (e) {
  if (e.target.nodeName.toLowerCase() === 'summary') {
    var details = e.target.parentNode
    if (!details) return

    var shouldContinue = dispatchToggleEvent(details);
    if (!shouldContinue) return

    if (details.getAttribute('open')) {
      details.open = false
      details.removeAttribute('open')
    } else {
      details.open = true
      details.setAttribute('open', 'open')
    }
  }
}

function dispatchToggleEvent (details) {
  var toggleEvent;
  try {
    toggleEvent = new CustomEvent('toggle', { bubbles: true, canceable: true });
  } catch(e) {
    toggleEvent = document.createEvent('CustomEvent');
    toggleEvent.initCustomEvent('toggle', true, true, null);
  }

  return details.dispatchEvent(toggleEvent);
}

I don't have access to enough browsers to test this thoroughly, though.

stevenvachon added a commit to stevenvachon/details-polyfill that referenced this issue Apr 26, 2017
@stevenvachon
Copy link

Ditch this lib and use https://www.npmjs.com/package/details-element-polyfill

@rstacruz
Copy link
Owner

rstacruz commented May 28, 2017

When suggesting alternatives, it'd be helpful if you can provide some reasons to back up your suggestion rather than just saying "ditch this and use X".

Nevertheless, PR's would be welcome for this. :) @stevenvachon you can send in your change as a pull request so you don't have to maintain a fork of this repo.

@stevenvachon
Copy link

@rstacruz you were ignoring all communication regarding this project for at least 6 months.

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

3 participants