steps.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. $(function(){
  2. stepCount = 0;
  3. 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;');
  4. console.log('%chttps://youtube.com/c/i12bretro', 'font-size: 9px; margin-left: 60px;');
  5. stepsText = [];
  6. $('textarea').each(function(i,e){
  7. theTextarea = $(this);
  8. theTextarea.height((theTextarea[0].scrollHeight-5) +'px');
  9. });
  10. $('li').each(function(i,e){
  11. pi = 0;
  12. if(!$(this).hasClass('noCheckbox')){
  13. var uuid = `li_${(Math.floor(Math.random() * Math.floor(1000000))).toString()}_${i.toString()}`;
  14. $(this).contents().wrap(`<span id="${uuid}"><label for="cb_${uuid}"></label></span>`);
  15. $(this).prepend(`<input type="checkbox" class="completeBox" id="cb_${uuid}" rel="${uuid}" data-pi="${pi}" />`);
  16. pi++;
  17. }
  18. stepCount = pi;
  19. });
  20. $('code,div.codeBlock,textarea.codeBlock').each(function(i,e){
  21. theElement = $(this);
  22. var lines = theElement.html().split("\n");
  23. theElement.empty();
  24. for(l=0;l<lines.length;l++){
  25. if($.trim(lines[l]) != '' && $.trim(lines[l]).substr(0,1) != '#' && $.trim(lines[l]).indexOf(' #') == -1 && lines[l].substr(0, 4).toUpperCase() != 'REM '){
  26. stepsText.push($('<p/>').html($.trim(lines[l]).replace(/<br \/>$|<br\/>$|<br>$/g,'')).text());
  27. 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>`);
  28. } else {
  29. theElement.append(lines[l]);
  30. }
  31. }
  32. });
  33. $(document).on('click','input.copy-text',function(){
  34. theButton = $(this);
  35. $('input.copy-text').attr('src','images/clipboard.png');
  36. $('span.copy-animation,span.copy-animation-ps,span.copy-animation-cmd').removeClass('copy-animation copy-animation-ps copy-animation-cmd');
  37. try {
  38. if($('#'+ theButton.attr('rel')).parent('div').hasClass('PS')){
  39. $('#'+ theButton.attr('rel')).addClass('copy-animation-ps');
  40. } else if($('#'+ theButton.attr('rel')).parent('div').hasClass('CMD')){
  41. $('#'+ theButton.attr('rel')).addClass('copy-animation-cmd');
  42. } else {
  43. $('#'+ theButton.attr('rel')).addClass('copy-animation');
  44. }
  45. console.log('%cCopied:', 'font-style: italic; color: #0f0;');
  46. console.log(`%c${stepsText[theButton.data('step-index')]}`, 'margin-left: 25px;');
  47. navigator.clipboard.writeText(stepsText[theButton.data('step-index')]);
  48. theButton.attr('src','images/clipboard_active.png');
  49. } catch(err) {
  50. }
  51. return false;
  52. });
  53. $(document).on('click','input.completeBox',function(){
  54. theBox = $(this);
  55. $('#'+ theBox.attr('rel')).addClass('strikethrough');
  56. theBox.prop('disabled',true);
  57. theBox.parent('li').prevAll().each(function(i,e){
  58. theLI = $(this);
  59. if(theLI.find('input[type=checkbox]').not(':checked')){
  60. $('#'+ theLI.find('input[type=checkbox]').attr('rel')).addClass('strikethrough');
  61. theLI.find('input[type=checkbox]').prop('checked',true).prop('disabled',true);
  62. }
  63. });
  64. });
  65. $('#gridContainer').append('<div /><div id="footerLinks"/>');
  66. $.ajax({ url: './includes/sites.json', type: 'get', dataType: 'json', success: function(r){
  67. $.each(r, function(k,v){
  68. $('#footerLinks').append(`<a href="${r[k].url}" target="_blank"><img src="${r[k].icon}" alt="${r[k].text}" title="${r[k].text}" /></a>`);
  69. });
  70. }
  71. });
  72. });