lesson.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <!-- Licensed under a BSD license. See license.html for license -->
  2. 'use strict';
  3. (function($){
  4. function getQueryParams() {
  5. const params = {};
  6. if (window.location.search) {
  7. window.location.search.substring(1).split('&').forEach(function(pair) {
  8. const keyValue = pair.split('=').map(function(kv) {
  9. return decodeURIComponent(kv);
  10. });
  11. params[keyValue[0]] = keyValue[1];
  12. });
  13. }
  14. return params;
  15. }
  16. $(document).ready(function($){
  17. var linkImgs = function(bigHref) {
  18. return function() {
  19. var a = document.createElement('a');
  20. a.href = bigHref;
  21. a.title = this.alt;
  22. a.className = this.className;
  23. a.setAttribute('align', this.align);
  24. this.setAttribute('align', '');
  25. this.className = '';
  26. this.style.border = '0px';
  27. return a;
  28. };
  29. };
  30. var linkSmallImgs = function(ext) {
  31. return function() {
  32. var src = this.src;
  33. return linkImgs(src.substr(0, src.length - 7) + ext);
  34. };
  35. };
  36. var linkBigImgs = function() {
  37. var src = $(this).attr('big');
  38. return linkImgs(src);
  39. };
  40. $('img[big$=".jpg"]').wrap(linkBigImgs);
  41. $('img[src$="-sm.jpg"]').wrap(linkSmallImgs('.jpg'));
  42. $('img[src$="-sm.gif"]').wrap(linkSmallImgs('.gif'));
  43. $('img[src$="-sm.png"]').wrap(linkSmallImgs('.png'));
  44. $('pre>code')
  45. .unwrap()
  46. .replaceWith(function() {
  47. return $('<pre class="prettyprint showlinemods">' + this.innerHTML + '</pre>');
  48. });
  49. if (window.prettyPrint) {
  50. window.prettyPrint();
  51. }
  52. var params = getQueryParams();
  53. if (params.doubleSpace || params.doublespace) {
  54. document.body.className = document.body.className + ' doubleSpace';
  55. }
  56. $('.language').on('change', function() {
  57. window.location.href = this.value;
  58. });
  59. });
  60. }(jQuery));