steps.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. $(function(){
  2. $('#content').css('font-size','100%');
  3. stepCount = 0;
  4. console.log('%ci12bretro', 'font-weight: 900; font-size: 40px; color: #f00; text-shadow: 3px 3px 0 #000, 4px 4px 0 #fff; border-bottom: 8px double #f00; padding: 0 8px;');
  5. console.log('%chttps://youtube.com/c/i12bretro', 'font-size: 9px; margin-left: 60px;');
  6. stepsText = [];
  7. $('textarea').each(function(i,e){
  8. theTextarea = $(this);
  9. theTextarea.height((theTextarea[0].scrollHeight-5) +'px');
  10. });
  11. $('li').each(function(i,e){
  12. pi = 0;
  13. if(!$(this).hasClass('noCheckbox')){
  14. var uuid = `li_${(Math.floor(Math.random() * Math.floor(1000000))).toString()}_${i.toString()}`;
  15. $(this).contents().wrap(`<span id="${uuid}"><label for="cb_${uuid}"></label></span>`);
  16. $(this).prepend(`<input type="checkbox" class="completeBox" id="cb_${uuid}" rel="${uuid}" data-pi="${pi}" />`);
  17. pi++;
  18. }
  19. stepCount = pi;
  20. });
  21. $('code:not(.noCheckbox),div.codeBlock:not(.noCheckbox),textarea.codeBlock:not(.noCheckbox)').each(function(i,e){
  22. theElement = $(this);
  23. var lines = theElement.html().split("\n");
  24. theElement.empty();
  25. for(l=0;l<lines.length;l++){
  26. if($.trim(lines[l]) != '' && $.trim(lines[l]).substr(0,1) != '#' && $.trim(lines[l]).indexOf(' #') == -1 && lines[l].substr(0, 4).toUpperCase() != 'REM '){
  27. stepsText.push($('<p/>').html($.trim(lines[l]).replace(/<br \/>$|<br\/>$|<br>$/g,'')).text());
  28. theElement.append(`<input type="image" src="images/clipboard.png" value="" class="copy-text" data-step-index="${(stepsText.length-1)}" rel="copy_${i}_${l}" /><span id="copy_${i}_${l}">${lines[l]}</span>`);
  29. } else {
  30. theElement.append(lines[l]);
  31. }
  32. }
  33. });
  34. $(document).on('click','input.copy-text',function(){
  35. theButton = $(this);
  36. $('input.copy-text').attr('src','images/clipboard.png');
  37. $('span.copy-animation,span.copy-animation-ps,span.copy-animation-cmd').removeClass('copy-animation copy-animation-ps copy-animation-cmd');
  38. try {
  39. if($('#'+ theButton.attr('rel')).parent('div').hasClass('PS')){
  40. $('#'+ theButton.attr('rel')).addClass('copy-animation-ps');
  41. } else if($('#'+ theButton.attr('rel')).parent('div').hasClass('CMD')){
  42. $('#'+ theButton.attr('rel')).addClass('copy-animation-cmd');
  43. } else {
  44. $('#'+ theButton.attr('rel')).addClass('copy-animation');
  45. }
  46. console.log('%cCopied:', 'font-style: italic; color: #0f0;');
  47. console.log(`%c${stepsText[theButton.data('step-index')]}`, 'margin-left: 25px;');
  48. navigator.clipboard.writeText(stepsText[theButton.data('step-index')]);
  49. theButton.attr('src','images/clipboard_active.png');
  50. } catch(err) {
  51. }
  52. return false;
  53. });
  54. $(document).on('click','input.completeBox',function(){
  55. theBox = $(this);
  56. $('#'+ theBox.attr('rel')).addClass('strikethrough');
  57. theBox.prop('disabled',true);
  58. theBox.parent('li').prevAll().each(function(i,e){
  59. theLI = $(this);
  60. if(theLI.find('input[type=checkbox]').not(':checked')){
  61. $('#'+ theLI.find('input[type=checkbox]').attr('rel')).addClass('strikethrough');
  62. theLI.find('input[type=checkbox]').prop('checked',true).prop('disabled',true);
  63. }
  64. });
  65. });
  66. if(window.location.hostname.toLowerCase() !== 'i12bretro.lan'){
  67. $('#gridContainer').append('<div>&nbsp;</div><div id="footerLinks"></div>');
  68. $.ajax({ url: './includes/sites.json', type: 'get', dataType: 'json', success: function(r){
  69. $.each(r, function(k,v){
  70. $('#footerLinks').append(`<a href="${r[k].url}" target="_blank"><img src="${r[k].icon}" alt="${r[k].text}" title="${r[k].text}" /></a>`);
  71. });
  72. }
  73. });
  74. $('body').prepend('<div style="position: fixed; top: 15px; right: 15px; z-index: 100;"><button id="fontSizeUp">&#9650;<span>A</span></button>&nbsp;&nbsp;<button id="fontSizeDown"><span>A</span>&#9660;</button></div>');
  75. }
  76. fontAdjustment = 0;
  77. fontSizeDir = '';
  78. $(document).on('click','#fontSizeUp',function(){
  79. if(fontSizeDir == 'down'){
  80. fontAdjustment = 0;
  81. }
  82. fontAdjustment += 2;
  83. fontSizeDir = 'up';
  84. console.log(`Resized font ${fontSizeDir} ${fontAdjustment}%`);
  85. $('#content *:not(input[type=checkbox]').each(function(){
  86. fontSize = $(this).css('font-size');
  87. $(this).css('font-size', `calc(${fontSize} + ${fontAdjustment}%)`);
  88. });
  89. });
  90. $(document).on('click','#fontSizeDown',function(){
  91. if(fontSizeDir == 'up'){
  92. fontAdjustment = 0;
  93. }
  94. fontAdjustment -= 2;
  95. fontSizeDir = 'down';
  96. console.log(`Resized font ${fontSizeDir} ${fontAdjustment}%`);
  97. $('#content *:not(input[type=checkbox]').each(function(){
  98. fontSize = $(this).css('font-size');
  99. $(this).css('font-size', `calc(${fontSize} + ${fontAdjustment}%)`);
  100. });
  101. });
  102. });