steps.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. $(function(){
  2. $('textarea').each(function(i,e){
  3. theTextarea = $(this);
  4. theTextarea.height((theTextarea[0].scrollHeight-5) +'px');
  5. });
  6. $('li').each(function(i,e){
  7. if(!$(this).hasClass('noCheckbox')){
  8. var uuid = 'li_' + Math.floor(Math.random() * Math.floor(1000000)).toString() + '_' + i.toString();
  9. $(this).contents().wrap('<span id="'+ uuid +'"><label for="cb_'+ uuid +'"></label></span>');
  10. $(this).prepend('<input type="checkbox" class="completeBox" id="cb_' + uuid +'" rel="'+ uuid +'" />')
  11. }
  12. });
  13. $('code,div.codeBlock,textarea.codeBlock').each(function(i,e){
  14. theElement = $(this);
  15. var lines = theElement.html().split("\n");
  16. theElement.empty();
  17. for(l=0;l<lines.length;l++){
  18. if($.trim(lines[l]) != '' && $.trim(lines[l]).substr(0,1) != '#' && $.trim(lines[l]).indexOf(' #') == -1 && lines[l].substr(0, 4).toUpperCase() != 'REM '){
  19. theElement.append('<input type="image" src="images/clipboard.png" value="" class="copy-text" rel="copy_'+ i +'_'+ l +'" data-clipboard-text="'+ $.trim(lines[l].replace(/"/g, '&quot;')) +'" /><span id="copy_'+ i +'_'+ l +'">'+ lines[l] +'</span>');
  20. } else {
  21. theElement.append(lines[l]);
  22. }
  23. }
  24. });
  25. $(document).on('click','input.copy-text',function(){
  26. theButton = $(this);
  27. $('input.copy-text').attr('src','images/clipboard.png');
  28. $('span.copy-animation,span.copy-animation-ps').removeClass('copy-animation copy-animation-ps');
  29. try {
  30. if($('#'+ theButton.attr('rel')).parent('div').hasClass('PS')){
  31. $('#'+ theButton.attr('rel')).addClass('copy-animation-ps');
  32. } else if($('#'+ theButton.attr('rel')).parent('div').hasClass('CMD')){
  33. $('#'+ theButton.attr('rel')).addClass('copy-animation-cmd');
  34. } else {
  35. $('#'+ theButton.attr('rel')).addClass('copy-animation');
  36. }
  37. navigator.clipboard.writeText(theButton.data('clipboard-text').replace(/<[^>]*>?/gm, ''));
  38. theButton.attr('src','images/clipboard_active.png');
  39. } catch(err) {
  40. }
  41. return false;
  42. });
  43. $(document).on('click','input.completeBox',function(){
  44. theBox = $(this);
  45. $('#'+ theBox.attr('rel')).addClass('strikethrough');
  46. theBox.prop('disabled',true);
  47. theBox.parent('li').prevAll().each(function(i,e){
  48. theLI = $(this);
  49. if(theLI.find('input[type=checkbox]').not(':checked')){
  50. $('#'+ theLI.find('input[type=checkbox]').attr('rel')).addClass('strikethrough');
  51. theLI.find('input[type=checkbox]').prop('checked',true).prop('disabled',true);
  52. }
  53. });
  54. });
  55. });