Mirror of Quill
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
3.8 KiB

  1. <div class="narrow">
  2. <?= partial('partials/header') ?>
  3. <div style="clear: both;" class="notice-pad">
  4. <div class="alert alert-success hidden" id="test_success"><strong>Success! </strong><a href="" id="post_href">View your post</a></div>
  5. <div class="alert alert-danger hidden" id="test_error"><strong>Something went wrong!</strong><br>Your Micropub endpoint indicated that something went wrong creating the post.</div>
  6. </div>
  7. <form role="form" style="margin-top: 20px;" id="note_form">
  8. <div class="form-group" id="note-name">
  9. <label for="note_name">File Name (optional)</label>
  10. <input type="text" id="note_name" value="<?= htmlspecialchars($this->edit_data['name']) ?>" class="form-control" placeholder="">
  11. </div>
  12. <div class="form-group">
  13. <label for="note_content">Code</label>
  14. <textarea id="note_content" value="" class="form-control code-snippet" style="height: 12em;"><?= htmlspecialchars($this->edit_data['content']) ?></textarea>
  15. </div>
  16. <? if(!$this->url): ?>
  17. <label for="note_language">Language</label>
  18. <select class="form-control" id="note_language">
  19. <?php
  20. foreach($this->languages as $lang=>$exts):
  21. ?>
  22. <option value="<?= $lang ?>"<?= $lang == 'text' ? ' selected="selected"' : '' ?>><?= $lang ?></option>
  23. <?php
  24. endforeach;
  25. ?>
  26. </select>
  27. <? endif; ?>
  28. <div style="float: right; margin-top: 6px;">
  29. <button class="btn btn-success" id="btn_post"><?= $this->url ? 'Save' : 'Post' ?></button>
  30. </div>
  31. <input type="hidden" id="edit_url" value="<?= $this->url ?>">
  32. </form>
  33. <div style="clear: both;"></div>
  34. <hr>
  35. <div style="text-align: right;" id="bookmarklet">
  36. Bookmarklet: <a href="javascript:<?= js_bookmarklet('partials/code-bookmarklet', $this) ?>" class="btn btn-default btn-xs">code</a>
  37. </div>
  38. </div>
  39. <script>
  40. $(function(){
  41. var language_map = <?= json_encode($this->language_map) ?>;
  42. $("#note_name").on("keyup", function(){
  43. var name = $("#note_name").val();
  44. if(name && (m=name.match(/\.([a-z]+)$/))) {
  45. if(language_map[m[1]]) {
  46. $("#note_language").val(language_map[m[1]]);
  47. }
  48. }
  49. });
  50. $("#note_content").on('keyup', function(){
  51. var scrollHeight = document.getElementById("note_content").scrollHeight;
  52. var currentHeight = parseInt($("#note_content").css("height"));
  53. if(Math.abs(scrollHeight - currentHeight) > 20) {
  54. $("#note_content").css("height", (scrollHeight+30)+"px");
  55. }
  56. });
  57. $("#btn_post").click(function(){
  58. $("#btn_post").addClass("loading disabled");
  59. var syndications = [];
  60. $("#syndication-container button.btn-info").each(function(i,btn){
  61. syndications.push($(btn).data('syndication'));
  62. });
  63. var params = {
  64. content: $("#note_content").val(),
  65. };
  66. if($("#edit_url").val() != "") {
  67. params['edit'] = $("#edit_url").val();
  68. } else {
  69. params['language'] = $("#note_language").val();
  70. }
  71. if($("#note_name").val() != "") {
  72. params['name'] = $("#note_name").val();
  73. }
  74. $.post("/code", params, function(response){
  75. if(response.location != false) {
  76. $("#test_success").removeClass('hidden');
  77. $("#test_error").addClass('hidden');
  78. $("#post_href").attr("href", response.location);
  79. $("#note_form").addClass('hidden');
  80. window.location = response.location;
  81. } else {
  82. $("#test_success").addClass('hidden');
  83. $("#test_error").removeClass('hidden');
  84. if(response.error_details) {
  85. $("#test_error").text(response.error_details);
  86. }
  87. $("#btn_post").removeClass("loading disabled");
  88. }
  89. });
  90. return false;
  91. });
  92. });
  93. </script>