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.

83 lines
2.3 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">
  9. <label for="tweet_url">Tweet to Import</label>
  10. <input type="text" id="tweet_url" value="<?= $this->tweet_url ?>" class="form-control">
  11. </div>
  12. <div style="float: right; margin-top: 6px;">
  13. <button class="btn btn-success" id="btn_post">Import</button>
  14. </div>
  15. <div style="float: right; margin-top: 6px; margin-right: 6px;">
  16. <button class="btn btn-default" id="btn_preview">Preview</button>
  17. </div>
  18. </form>
  19. <div style="clear: both;"></div>
  20. <div id="preview_data" class="hidden">
  21. <pre></pre>
  22. </div>
  23. </div>
  24. <script>
  25. $(function(){
  26. $("#btn_preview").click(function(e){
  27. $("#btn_preview").addClass("loading disabled");
  28. $.post("/twitter/preview", {
  29. tweet_url: $("#tweet_url").val(),
  30. }, function(response){
  31. $("#preview_data pre").text(response.json);
  32. $("#preview_data").removeClass("hidden");
  33. $("#btn_preview").removeClass("loading disabled");
  34. });
  35. return false;
  36. });
  37. $("#btn_post").click(function(){
  38. $("#btn_post").addClass("loading disabled");
  39. $.post("/twitter", {
  40. tweet_url: $("#tweet_url").val(),
  41. }, function(response){
  42. if(response.location != false) {
  43. $("#test_success").removeClass('hidden');
  44. $("#test_error").addClass('hidden');
  45. $("#post_href").attr("href", response.location);
  46. $("#note_form").addClass('hidden');
  47. window.location = response.location;
  48. } else {
  49. $("#test_success").addClass('hidden');
  50. $("#test_error").removeClass('hidden');
  51. if(response.error_details) {
  52. $("#test_error").text(response.error_details);
  53. }
  54. $("#btn_post").removeClass("loading disabled");
  55. }
  56. });
  57. return false;
  58. });
  59. });
  60. </script>