cancel.js 857 B

12345678910111213141516171819202122232425262728
  1. 'use strict';
  2. {
  3. // Call function fn when the DOM is loaded and ready. If it is already
  4. // loaded, call the function now.
  5. // http://youmightnotneedjquery.com/#ready
  6. function ready(fn) {
  7. if (document.readyState !== 'loading') {
  8. fn();
  9. } else {
  10. document.addEventListener('DOMContentLoaded', fn);
  11. }
  12. }
  13. ready(function() {
  14. function handleClick(event) {
  15. event.preventDefault();
  16. if (window.location.search.indexOf('&_popup=1') === -1) {
  17. window.history.back(); // Go back if not a popup.
  18. } else {
  19. window.close(); // Otherwise, close the popup.
  20. }
  21. }
  22. document.querySelectorAll('.cancel-link').forEach(function(el) {
  23. el.addEventListener('click', handleClick);
  24. });
  25. });
  26. }