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.

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