style.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. function setActiveStyleSheet(title) {
  2. var i, a, main;
  3. for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
  4. if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
  5. a.disabled = true;
  6. if(a.getAttribute("title") == title) a.disabled = false;
  7. }
  8. }
  9. }
  10. function getActiveStyleSheet() {
  11. var i, a;
  12. for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
  13. if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  14. }
  15. return null;
  16. }
  17. function getPreferredStyleSheet() {
  18. var i, a;
  19. for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
  20. if(a.getAttribute("rel").indexOf("style") != -1
  21. && a.getAttribute("rel").indexOf("alt") == -1
  22. && a.getAttribute("title")
  23. ) return a.getAttribute("title");
  24. }
  25. return null;
  26. }
  27. function createCookie(name,value,days) {
  28. if (days) {
  29. var date = new Date();
  30. date.setTime(date.getTime()+(days*24*60*60*1000));
  31. var expires = "; expires="+date.toGMTString();
  32. }
  33. else expires = "";
  34. document.cookie = name+"="+value+expires+"; path=/";
  35. }
  36. function readCookie(name) {
  37. var nameEQ = name + "=";
  38. var ca = document.cookie.split(';');
  39. for(var i=0;i < ca.length;i++) {
  40. var c = ca[i];
  41. while (c.charAt(0)==' ') c = c.substring(1,c.length);
  42. if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  43. }
  44. return null;
  45. }
  46. window.onload = function(e) {
  47. var cookie = readCookie("style");
  48. var title = cookie ? cookie : getPreferredStyleSheet();
  49. setActiveStyleSheet(title);
  50. }
  51. window.onunload = function(e) {
  52. var title = getActiveStyleSheet();
  53. createCookie("style", title, 365);
  54. }
  55. var cookie = readCookie("style");
  56. var title = cookie ? cookie : getPreferredStyleSheet();
  57. setActiveStyleSheet(title);
  58. function addText(elId,text) {
  59. text = ">>" + text + " \n";
  60. document.getElementById(elId).value += text;
  61. document.getElementById(elId).focus();
  62. }
  63. "use strict";
  64. function r(f){/in/.test(document.readyState)?setTimeout('r('+f+')',9):f()}
  65. r(function(){
  66. if(!document.getElementsByClassName) {
  67. // IE8 support
  68. var getElementsByClassName = function(node, classname) {
  69. var a = [];
  70. var re = new RegExp('(^| )'+classname+'( |$)');
  71. var els = node.getElementsByTagName("*");
  72. for(var i=0,j=els.length; i<j; i++)
  73. if(re.test(els[i].className))a.push(els[i]);
  74. return a;
  75. }
  76. var videos = getElementsByClassName(document.body,"youtube");
  77. }
  78. else {
  79. var videos = document.getElementsByClassName("youtube");
  80. }
  81. var nb_videos = videos.length;
  82. for (var i=0; i<nb_videos; i++) {
  83. // Based on the YouTube ID, we can easily find the thumbnail image
  84. videos[i].style.backgroundImage = 'url(http://i.ytimg.com/vi/' + videos[i].id + '/mqdefault.jpg)';
  85. // Overlay the Play icon to make it look like a video player
  86. var play = document.createElement("div");
  87. play.setAttribute("class","play");
  88. videos[i].appendChild(play);
  89. videos[i].onclick = function() {
  90. // Create an iFrame with autoplay set to true
  91. var iframe = document.createElement("iframe");
  92. var iframe_url = "https://www.youtube.com/embed/" + this.id + "?autoplay=1&autohide=1";
  93. if (this.getAttribute("data-params")) iframe_url+='&'+this.getAttribute("data-params");
  94. iframe.setAttribute("src",iframe_url);
  95. iframe.setAttribute("frameborder",'0');
  96. // The height and width of the iFrame should be the same as parent
  97. iframe.style.width = this.style.width;
  98. iframe.style.height = this.style.height;
  99. // Replace the YouTube thumbnail with YouTube Player
  100. this.parentNode.replaceChild(iframe, this);
  101. }
  102. }
  103. });