lesson.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Licensed under a BSD license. See license.html for license
  2. /* eslint-disable strict */
  3. 'use strict'; // eslint-disable-line
  4. /* global jQuery, settings, contributors */
  5. (function($){
  6. function getQueryParams() {
  7. return Object.fromEntries(new URLSearchParams(window.location.search).entries());
  8. }
  9. //
  10. function replaceParams(str, subs) {
  11. return str.replace(/\${(\w+)}/g, function(m, key) {
  12. return subs[key];
  13. });
  14. }
  15. function showContributors() {
  16. // contribTemplate: 'Thank you
  17. // <a href="${html_url}">
  18. // <img src="${avatar_url}">${login}<a/>
  19. // for <a href="https://github.com/${owner}/${repo}/commits?author=${login}">${contributions} contributions</a>',
  20. try {
  21. const subs = {...settings, ...contributors[Math.random() * contributors.length | 0]};
  22. const template = settings.contribTemplate;
  23. const html = replaceParams(template, subs);
  24. const parent = document.querySelector('#forkongithub>div');
  25. const div = document.createElement('div');
  26. div.className = 'contributors';
  27. div.innerHTML = html;
  28. parent.appendChild(div);
  29. } catch (e) {
  30. console.error(e);
  31. }
  32. }
  33. showContributors();
  34. $(document).ready(function($){
  35. if (window.prettyPrint) {
  36. window.prettyPrint();
  37. }
  38. $('span[class=com]')
  39. .addClass('translate yestranslate')
  40. .attr('translate', 'yes');
  41. const params = getQueryParams();
  42. if (params.doubleSpace || params.doublespace) {
  43. document.body.className = document.body.className + ' doubleSpace';
  44. }
  45. $('.language').on('change', function() {
  46. window.location.href = this.value;
  47. });
  48. if (window.threejsLessonUtils) {
  49. window.threejsLessonUtils.afterPrettify();
  50. }
  51. });
  52. }(jQuery));
  53. // ios needs this to allow touch events in an iframe
  54. window.addEventListener('touchstart', {});