script.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. var $saveCode = $('#save-code');
  2. var $place = $('.container');
  3. var $pre = $('#pre-code');
  4. var $buttonPlace = $('#buttons');
  5. var $addPlace = $('#add-place');
  6. var $form = $('#form');
  7. function crateTextArea() {
  8. var $panel = $('<div>').addClass('panel panel-primary').appendTo($place);
  9. var $panelHead = $('<div>').addClass('panel-heading').text('Code spase').appendTo($panel);
  10. var $panelBody = $('<div>').addClass('panel-body').appendTo($panel);
  11. var $formGroup = $('<div>').addClass('form-group').attr('id', 'form').appendTo($panelBody);
  12. var $label = $('<label>').attr('for', 'code').text('Enter your code:').appendTo($formGroup);
  13. var $textarea = $('<textarea>').addClass('form-control').attr({'id': 'code','rows': 5}).appendTo($formGroup);
  14. var $pre = $('<pre>').attr('id', 'pre-code').appendTo($formGroup).hide();
  15. var $buttonSave = $('<button>').attr('id', 'save-code').addClass('btn btn-info').text('Save').appendTo($panelBody)
  16. .one('click', function(event){
  17. $panel.find('.btn-info').remove();
  18. var $code = $textarea.val();
  19. $textarea.remove();
  20. $pre.text($code).fadeIn();
  21. $label.text('This code will be executed');
  22. $buttonStart = $('<button>')
  23. .addClass('btn btn-success')
  24. .text('Start')
  25. .appendTo($panelBody)
  26. .one('click', function(event) {
  27. $('<script>')
  28. .text($code)
  29. .appendTo($place);
  30. });
  31. });
  32. var $buttonDelete = $('<button>').attr('id', 'delete-code').addClass('btn btn-danger pull-right').text('Delete').appendTo($panelBody)
  33. .one('click', function(event){
  34. $panel.remove();
  35. });
  36. }
  37. $saveCode.on('click', function(event){
  38. $buttonPlace.find('.btn-info').remove();
  39. var $code = $('#code').val();
  40. $pre.text($code).fadeIn();
  41. $form.find('.form-control').remove();
  42. $('label').text('This code will be executed');
  43. $buttonStart = $('<button>')
  44. .addClass('btn btn-success')
  45. .text('Start')
  46. .appendTo($buttonPlace)
  47. .one('click', function(event) {
  48. $('<script>')
  49. .text($code)
  50. .appendTo($place);
  51. })
  52. })
  53. $addPlace.on('click', function(event){
  54. crateTextArea();
  55. })