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.

167 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. <h3>Caffeine</h3>
  5. <ul class="caffeine entry-buttons">
  6. <?php foreach(caffeine_options() as $val): ?>
  7. <li><input type="submit" name="drank" class="btn btn-default" value="<?= $val ?>"></li>
  8. <?php endforeach; ?>
  9. </ul>
  10. <br>
  11. <h3>Alcohol</h3>
  12. <ul class="alcohol entry-buttons">
  13. <?php foreach(alcohol_options() as $val): ?>
  14. <li><input type="submit" name="drank" class="btn btn-default" value="<?= $val ?>"></li>
  15. <?php endforeach; ?>
  16. </ul>
  17. <br>
  18. <h3>Drank</h3>
  19. <ul class="other entry-buttons">
  20. <li>
  21. <input type="text" class="form-control text-custom-drank" name="custom_drank" placeholder="Custom" style="width: 72%; float: left; margin-right: 2px;">
  22. <input type="submit" class="btn btn-default btn-custom-drank" value="Post" style="width: 26%; float: right;">
  23. </li>
  24. </ul>
  25. <br><br>
  26. <h3>Ate</h3>
  27. <ul class="other entry-buttons">
  28. <li>
  29. <input type="text" class="form-control text-custom-ate" name="custom_ate" placeholder="Custom" style="width: 72%; float: left; margin-right: 2px;">
  30. <input type="submit" class="btn btn-default btn-custom-ate" value="Post" style="width: 26%; float: right;">
  31. </li>
  32. </ul>
  33. <br><br>
  34. <div class="form-group">
  35. <h3>Location <input type="checkbox" id="note_location_chk" value=""><img src="/images/spinner.gif" id="note_location_loading" style="display: none;"></h3>
  36. <input type="text" id="note_location_msg" value="" class="form-control" placeholder="" readonly="readonly">
  37. <input type="hidden" id="note_location" name="location">
  38. <input type="hidden" id="location_enabled" value="<?= $this->location_enabled ?>">
  39. <div id="note_location_img" style="display: none;">
  40. <img src="" height="180" id="note_location_img_wide" class="img-responsive">
  41. <img src="" height="320" id="note_location_img_small" class="img-responsive">
  42. </div>
  43. </div>
  44. </form>
  45. <?php if($this->micropub_endpoint): ?>
  46. <div class="callout">
  47. <p>Clicking an item will post this note to your Micropub endpoint. Below is some information about the request that will be made.</p>
  48. <table class="table table-condensed">
  49. <tr>
  50. <td>me</td>
  51. <td><code><?= session('me') ?></code> (should be your URL)</td>
  52. </tr>
  53. <tr>
  54. <td>scope</td>
  55. <td><code><?= $this->token_scope ?></code> (should be a space-separated list of permissions including "post")</td>
  56. </tr>
  57. <tr>
  58. <td>micropub endpoint</td>
  59. <td><code><?= $this->micropub_endpoint ?></code> (should be a URL)</td>
  60. </tr>
  61. <tr>
  62. <td>access token</td>
  63. <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>
  64. </tr>
  65. </table>
  66. </div>
  67. <?php endif; ?>
  68. </div>
  69. <script>
  70. $(function(){
  71. $(".text-custom-ate").keydown(function(e){
  72. if(e.keyCode == 13) {
  73. $(".btn-custom-ate").click();
  74. return false;
  75. }
  76. });
  77. $(".text-custom-drank").keydown(function(e){
  78. if(e.keyCode == 13) {
  79. $(".btn-custom-drank").click();
  80. return false;
  81. }
  82. });
  83. function location_error(msg) {
  84. $("#note_location_msg").val(msg);
  85. $("#note_location_chk").removeAttr("checked");
  86. $("#note_location_loading").hide();
  87. $("#note_location_img").hide();
  88. $("#note_location_msg").removeClass("img-visible");
  89. }
  90. var map_template_wide = "<?= static_map('{lat}', '{lng}', 180, 700, 15) ?>";
  91. var map_template_small = "<?= static_map('{lat}', '{lng}', 320, 480, 15) ?>";
  92. function fetch_location() {
  93. $("#note_location_loading").show();
  94. navigator.geolocation.getCurrentPosition(function(position){
  95. $("#note_location_loading").hide();
  96. var geo = "geo:" + (Math.round(position.coords.latitude * 100000) / 100000) + "," + (Math.round(position.coords.longitude * 100000) / 100000) + ";u=" + position.coords.accuracy;
  97. $("#note_location_msg").val(geo);
  98. $("#note_location").val(geo);
  99. $("#note_location_img_small").attr("src", map_template_small.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  100. $("#note_location_img_wide").attr("src", map_template_wide.replace('{lat}', position.coords.latitude).replace('{lng}', position.coords.longitude));
  101. $("#note_location_img").show();
  102. $("#note_location_msg").addClass("img-visible");
  103. }, function(err){
  104. if(err.code == 1) {
  105. location_error("The website was not able to get permission");
  106. } else if(err.code == 2) {
  107. location_error("Location information was unavailable");
  108. } else if(err.code == 3) {
  109. location_error("Timed out getting location");
  110. }
  111. });
  112. }
  113. $("#note_location_chk").click(function(){
  114. if($(this).attr("checked") == "checked") {
  115. if(navigator.geolocation) {
  116. $.post("/prefs", {
  117. enabled: 1
  118. });
  119. fetch_location();
  120. } else {
  121. location_error("Browser location is not supported");
  122. }
  123. } else {
  124. $("#note_location_img").hide();
  125. $("#note_location_msg").removeClass("img-visible");
  126. $("#note_location_msg").val('');
  127. $("#note_location").val('');
  128. $.post("/prefs", {
  129. enabled: 0
  130. });
  131. }
  132. });
  133. if($("#location_enabled").val() == 1) {
  134. $("#note_location_chk").attr("checked","checked");
  135. fetch_location();
  136. }
  137. });
  138. </script>