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.js error (missing: .js-context-menu) #49

Open
ungoldman opened this issue Oct 21, 2015 · 2 comments
Open

menu.js error (missing: .js-context-menu) #49

ungoldman opened this issue Oct 21, 2015 · 2 comments
Labels

Comments

@ungoldman
Copy link

I'm noticing dist/template-app/menu.js is trying to attach a click event to .js-context-menu but there's no element in dist/template-app/index.html that matches that. I looked around in each of the releases and wasn't able to find it there either.

Uncaught TypeError: Cannot read property 'addEventListener' of null
  (anonymous function) @ menu.js:24

https://github.com/connors/photon/blob/master/dist/template-app/js/menu.js#L24

Really cool project btw. Looks fantastic.

@developit
Copy link
Contributor

I believe it's supposed to be referring to something similar to this:
https://github.com/connors/photon/blob/master/docs/demo-app.html#L51-L53

... but that doesn't appear to have been included in the template-app example.

@ungoldman
Copy link
Author

I think it's an incomplete adaptation of https://github.com/atom/electron/blob/master/docs/api/menu.md.

window.addEventListener('contextmenu', function (e) {
  e.preventDefault();
  menu.popup(remote.getCurrentWindow());
}, false);

One way around the error produced by the current implementation in this repo would be to modify it like this:

document.addEventListener('DOMContentLoaded', function () {
  var nodeList = document.querySelectorAll('.js-context-menu')

  Array.prototype.forEach.call(nodeList, function (item) {
    item.addEventListener('contextmenu', function (event) {
      menu.popup(remote.getCurrentWindow());
    })
  })
})

That way there will be no error if the node list is empty. I'm using this workaround in https://github.com/ngoldman/proton without any issues so far.

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

No branches or pull requests

3 participants