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.

177 lines
5.9 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. // save and restore the value entered in the custom fields
  84. var custom_eat = $('#custom_eat').val();
  85. var custom_drink = $('#custom_drink').val();
  86. var selected = false;
  87. if($("#custom_drink:focus").length == 1) {
  88. selected = '#custom_drink';
  89. }
  90. if($("#custom_eat:focus").length == 1) {
  91. selected = '#custom_eat';
  92. }
  93. $("#entry-buttons").html(response);
  94. // restore the custom values entered
  95. $('#custom_eat').val(custom_eat);
  96. $('#custom_drink').val(custom_drink);
  97. if(selected) {
  98. $(selected).focus();
  99. }
  100. bind_keyboard_shortcuts();
  101. });
  102. $("#note_location_loading").hide();
  103. var geo = "geo:" + (Math.round(position.coords.latitude * 100000) / 100000) + "," + (Math.round(position.coords.longitude * 100000) / 100000) + ";u=" + position.coords.accuracy;
  104. $("#note_location_msg").val(geo);
  105. $("#note_location").val(geo);
  106. $("#note_location_img_small").attr("src", map_template_small.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  107. $("#note_location_img_wide").attr("src", map_template_wide.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  108. $("#note_location_img").show();
  109. $("#note_location_msg").addClass("img-visible");
  110. }, function(err){
  111. if(err.code == 1) {
  112. location_error("The website was not able to get permission");
  113. } else if(err.code == 2) {
  114. location_error("Location information was unavailable");
  115. } else if(err.code == 3) {
  116. location_error("Timed out getting location");
  117. }
  118. });
  119. }
  120. $("#note_location_chk").click(function(){
  121. if($(this).attr("checked") == "checked") {
  122. if(navigator.geolocation) {
  123. $.post("/prefs", {
  124. enabled: 1
  125. });
  126. fetch_location();
  127. } else {
  128. location_error("Browser location is not supported");
  129. }
  130. } else {
  131. $("#note_location_img").hide();
  132. $("#note_location_msg").removeClass("img-visible");
  133. $("#note_location_msg").val('');
  134. $("#note_location").val('');
  135. $.post("/prefs", {
  136. enabled: 0
  137. });
  138. }
  139. });
  140. if($("#location_enabled").val() == 1) {
  141. $("#note_location_chk").attr("checked","checked");
  142. fetch_location();
  143. }
  144. });
  145. </script>