lesson.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Licensed under a BSD license. See license.html for license
  2. /* eslint-disable strict */
  3. 'use strict'; // eslint-disable-line
  4. ( function () {
  5. if ( window.frameElement ) {
  6. // in iframe
  7. document.querySelectorAll( 'a' ).forEach( a => {
  8. // we have to send all links to the parent
  9. // otherwise we'll end up with 3rd party
  10. // sites under the frame.
  11. a.addEventListener( 'click', e => {
  12. // opening a new tab?
  13. if ( a.target === '_blank' ) {
  14. return;
  15. }
  16. // change changing hashes?
  17. if ( a.origin !== window.location.origin || a.pathname !== window.location.pathname ) {
  18. e.preventDefault();
  19. }
  20. window.parent.setUrl( a.href );
  21. } );
  22. } );
  23. window.parent.setTitle( document.title );
  24. } else {
  25. if ( window.location.protocol !== 'file:' ) {
  26. const re = /^(.*?\/manual\/)(.*?)$/;
  27. const [ , baseURL, articlePath ] = re.exec( window.location.href );
  28. const href = `${baseURL}#${articlePath.replace( '.html', '' )}`;
  29. window.location.replace( href ); // lgtm[js/client-side-unvalidated-url-redirection]
  30. }
  31. }
  32. if ( window.prettyPrint ) {
  33. window.prettyPrint();
  34. }
  35. // help translation services translate comments.
  36. document.querySelectorAll( 'span[class=com]' ).forEach( elem => {
  37. elem.classList.add( 'translate', 'yestranslate' );
  38. elem.setAttribute( 'translate', 'yes' );
  39. } );
  40. if ( window.threejsLessonUtils ) {
  41. window.threejsLessonUtils.afterPrettify();
  42. }
  43. }() );
  44. // ios needs this to allow touch events in an iframe
  45. window.addEventListener( 'touchstart', {} );