app.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. $(function() {
  2. $("#page-jump-button").click(function(event) {
  3. let urlTemplate = $(this).data("url-template");
  4. let page = $("#page-jump-input").val();
  5. let url = urlTemplate.replace("PAGE", page);
  6. window.location = url;
  7. });
  8. $("#sort-dropdown").change(function(event) {
  9. let urlTemplate = $(this).data("url-template");
  10. let sort = $(this).val();
  11. let url = urlTemplate.replace("SORT", sort);
  12. window.location = url;
  13. });
  14. $("input[type=password]").keyup(function(event) {
  15. let formText = $(this).next(".form-text");
  16. let lengthSpan = $(formText).find("span[data-length-requirement]");
  17. let upperSpan = $(formText).find("span[data-uppercase-requirement]");
  18. let lowerSpan = $(formText).find("span[data-lowercase-requirement]");
  19. let numberSpan = $(formText).find("span[data-number-requirement]");
  20. let specialSpan = $(formText).find("span[data-special-requirement]");
  21. let upper = new RegExp("[A-Z]");
  22. let lower = new RegExp("[a-z]");
  23. let number = new RegExp("[0-9]");
  24. let special = new RegExp("[^A-Za-z0-9]");
  25. let value = $(this).val();
  26. let lengthClass = value.length >= 6 ? "text-success" : "text-danger";
  27. let upperClass = upper.test(value) ? "text-success" : "text-danger";
  28. let lowerClass = lower.test(value) ? "text-success" : "text-danger";
  29. let numberClass = number.test(value) ? "text-success" : "text-danger";
  30. let specialClass = special.test(value) ? "text-success" : "text-danger";
  31. lengthSpan.attr("class", lengthClass);
  32. upperSpan.attr("class", upperClass);
  33. lowerSpan.attr("class", lowerClass);
  34. numberSpan.attr("class", numberClass);
  35. specialSpan.attr("class", specialClass);
  36. });
  37. var clipboard = new ClipboardJS(".btn[data-clipboard-target]");
  38. });
  39. var maps = [];
  40. function initialiseTooltips() {
  41. $('[data-toggle="tooltip"]').tooltip();
  42. }
  43. function initialiseMaps() {
  44. $("div[data-maps]").each(function() {
  45. let position = {
  46. lat: $(this).data("lat"),
  47. lng: $(this).data("lng")
  48. };
  49. let options = {};
  50. options.center = position;
  51. options.zoom = $(this).data("zoom");
  52. options.gestureHandling = "greedy";
  53. options.scaleControl = true;
  54. let map = new google.maps.Map(this, options);
  55. if(this.id) {
  56. maps[this.id] = map;
  57. }
  58. // Plot marker
  59. let marker = $(this).data("marker");
  60. if(marker) {
  61. let options = {};
  62. options.position = position;
  63. options.map = map;
  64. options.draggable = $(this).data("marker-draggable");
  65. let marker = new google.maps.Marker(options);
  66. let markerDragendTarget = $(this).data("marker-dragend-target");
  67. if(markerDragendTarget) {
  68. marker.addListener("dragend", function() {
  69. let position = marker.getPosition();
  70. $(markerDragendTarget).find("input[data-latitude]").val(position.lat());
  71. $(markerDragendTarget).find("input[data-longitude]").val(position.lng());
  72. });
  73. }
  74. }
  75. // Plot basic markers
  76. let markers = $(this).data("markers");
  77. if(markers) {
  78. let bounds = new google.maps.LatLngBounds;
  79. for(let i in markers) {
  80. let options = {};
  81. options.position = {
  82. "lat": markers[i].latitude * 1,
  83. "lng": markers[i].longitude * 1
  84. };
  85. options.map = map;
  86. let marker = new google.maps.Marker(options);
  87. bounds.extend(options.position);
  88. }
  89. if(markers.length > 1) {
  90. maps[this.id].fitBounds(bounds, 32);
  91. }
  92. }
  93. let callback = $(this).data("callback");
  94. if(callback) {
  95. try {
  96. window[callback]();
  97. }
  98. catch(err) {
  99. console.log(err);
  100. }
  101. }
  102. });
  103. $("input[data-autocomplete]").each(function() {
  104. let mapId = $(this).data("autocomplete");
  105. let map = maps[mapId];
  106. let autocomplete = new google.maps.places.Autocomplete(this);
  107. autocomplete.bindTo("bounds", map);
  108. autocomplete.setFields(["address_components", "geometry", "icon", "name"]);
  109. autocomplete.addListener("place_changed", function() {
  110. let place = autocomplete.getPlace();
  111. if(place.geometry.viewport) {
  112. map.fitBounds(place.geometry.viewport);
  113. }
  114. else {
  115. map.setCenter(place.geometry.location);
  116. map.setZoom(17);
  117. }
  118. });
  119. });
  120. }