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.

156 lines
5.4 KiB

  1. <div class="narrow">
  2. <?= partial('partials/header') ?>
  3. <form role="form" style="margin-top: 20px;" id="note_form" action="/post" method="post">
  4. <div id="entry-buttons">
  5. <?= partial('partials/entry-buttons', ['options'=>$this->default_options]) ?>
  6. </div>
  7. <div class="form-group">
  8. <h3>Location <input type="checkbox" id="note_location_chk" value=""><img src="/images/spinner.gif" id="note_location_loading" style="display: none;"></h3>
  9. <input type="text" id="note_location_msg" value="" class="form-control" placeholder="" readonly="readonly">
  10. <input type="hidden" id="note_location" name="location">
  11. <input type="hidden" id="location_enabled" value="<?= $this->location_enabled ?>">
  12. <div id="note_location_img" style="display: none;">
  13. <img src="" height="180" id="note_location_img_wide" class="img-responsive">
  14. <img src="" height="320" id="note_location_img_small" class="img-responsive">
  15. </div>
  16. </div>
  17. </form>
  18. <?php if($this->micropub_endpoint): ?>
  19. <div class="callout">
  20. <p>Clicking an item will post this note to your Micropub endpoint. Below is some information about the request that will be made.</p>
  21. <table class="table table-condensed">
  22. <tr>
  23. <td>me</td>
  24. <td><code><?= session('me') ?></code> (should be your URL)</td>
  25. </tr>
  26. <tr>
  27. <td>scope</td>
  28. <td><code><?= $this->token_scope ?></code> (should be a space-separated list of permissions including "post")</td>
  29. </tr>
  30. <tr>
  31. <td>micropub endpoint</td>
  32. <td><code><?= $this->micropub_endpoint ?></code> (should be a URL)</td>
  33. </tr>
  34. <tr>
  35. <td>access token</td>
  36. <td>String of length <b><?= strlen($this->access_token) ?></b><?= (strlen($this->access_token) > 0) ? (', ending in <code>' . substr($this->access_token, -7) . '</code>') : '' ?> (should be greater than length 0)</td>
  37. </tr>
  38. <tr>
  39. <td>p3k-food</td>
  40. <td>The button you tap (or your custom text) will be sent to your Micropub endpoint in a field named <code>p3k-food</code></td>
  41. </tr>
  42. <tr>
  43. <td>p3k-type</td>
  44. <td>Will be either <code>drink</code> or <code>eat</code> depending on the type of entry</td>
  45. </tr>
  46. </table>
  47. </div>
  48. <?php endif; ?>
  49. </div>
  50. <script>
  51. $(function(){
  52. function bind_keyboard_shortcuts() {
  53. $(".text-custom-eat").keydown(function(e){
  54. if(e.keyCode == 13) {
  55. $(".btn-custom-eat").click();
  56. return false;
  57. }
  58. });
  59. $(".text-custom-drink").keydown(function(e){
  60. if(e.keyCode == 13) {
  61. $(".btn-custom-drink").click();
  62. return false;
  63. }
  64. });
  65. }
  66. bind_keyboard_shortcuts();
  67. function location_error(msg) {
  68. $("#note_location_msg").val(msg);
  69. $("#note_location_chk").removeAttr("checked");
  70. $("#note_location_loading").hide();
  71. $("#note_location_img").hide();
  72. $("#note_location_msg").removeClass("img-visible");
  73. }
  74. var map_template_wide = "<?= static_map('{lat}', '{lng}', 180, 700, 15) ?>";
  75. var map_template_small = "<?= static_map('{lat}', '{lng}', 320, 480, 15) ?>";
  76. function fetch_location() {
  77. $("#note_location_loading").show();
  78. navigator.geolocation.getCurrentPosition(function(position){
  79. $.get('/new/options', {
  80. latitude: position.coords.latitude,
  81. longitude: position.coords.longitude
  82. }, function(response) {
  83. $("#entry-buttons").html(response);
  84. bind_keyboard_shortcuts();
  85. });
  86. $("#note_location_loading").hide();
  87. var geo = "geo:" + (Math.round(position.coords.latitude * 100000) / 100000) + "," + (Math.round(position.coords.longitude * 100000) / 100000) + ";u=" + position.coords.accuracy;
  88. $("#note_location_msg").val(geo);
  89. $("#note_location").val(geo);
  90. $("#note_location_img_small").attr("src", map_template_small.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  91. $("#note_location_img_wide").attr("src", map_template_wide.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  92. $("#note_location_img").show();
  93. $("#note_location_msg").addClass("img-visible");
  94. }, function(err){
  95. if(err.code == 1) {
  96. location_error("The website was not able to get permission");
  97. } else if(err.code == 2) {
  98. location_error("Location information was unavailable");
  99. } else if(err.code == 3) {
  100. location_error("Timed out getting location");
  101. }
  102. });
  103. }
  104. $("#note_location_chk").click(function(){
  105. if($(this).attr("checked") == "checked") {
  106. if(navigator.geolocation) {
  107. $.post("/prefs", {
  108. enabled: 1
  109. });
  110. fetch_location();
  111. } else {
  112. location_error("Browser location is not supported");
  113. }
  114. } else {
  115. $("#note_location_img").hide();
  116. $("#note_location_msg").removeClass("img-visible");
  117. $("#note_location_msg").val('');
  118. $("#note_location").val('');
  119. $.post("/prefs", {
  120. enabled: 0
  121. });
  122. }
  123. });
  124. if($("#location_enabled").val() == 1) {
  125. $("#note_location_chk").attr("checked","checked");
  126. fetch_location();
  127. }
  128. });
  129. </script>