app.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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("[data-clipboard-target], [data-clipboard-text]");
  38. clipboard.on("success", function(e) {
  39. $(e.trigger).tooltip("hide").attr("data-original-title", "Copied!").tooltip("show");
  40. e.clearSelection();
  41. });
  42. let hasTooltips = $('[data-toggle="tooltip"]').length > 0;
  43. if(hasTooltips) {
  44. initialiseTooltips();
  45. }
  46. });
  47. var maps = [];
  48. function initialiseTooltips() {
  49. $('[data-toggle="tooltip"]').tooltip();
  50. }
  51. function initialiseMaps() {
  52. $("div[data-maps]").each(function() {
  53. let position = {
  54. lat: $(this).data("lat"),
  55. lng: $(this).data("lng")
  56. };
  57. let options = {};
  58. options.center = position;
  59. options.zoom = $(this).data("zoom");
  60. options.gestureHandling = "greedy";
  61. options.scaleControl = true;
  62. let map = new google.maps.Map(this, options);
  63. if(this.id) {
  64. maps[this.id] = map;
  65. }
  66. // Plot marker
  67. let marker = $(this).data("marker");
  68. if(marker) {
  69. let options = {};
  70. options.position = position;
  71. options.map = map;
  72. options.draggable = $(this).data("marker-draggable");
  73. let marker = new google.maps.Marker(options);
  74. let markerDragendTarget = $(this).data("marker-dragend-target");
  75. if(markerDragendTarget) {
  76. marker.addListener("dragend", function() {
  77. let position = marker.getPosition();
  78. $(markerDragendTarget).find("input[data-latitude]").val(position.lat());
  79. $(markerDragendTarget).find("input[data-longitude]").val(position.lng());
  80. });
  81. }
  82. }
  83. // Plot basic markers
  84. let markers = $(this).data("markers");
  85. if(markers) {
  86. let bounds = new google.maps.LatLngBounds;
  87. for(let i in markers) {
  88. let options = {};
  89. options.position = {
  90. "lat": markers[i].latitude * 1,
  91. "lng": markers[i].longitude * 1
  92. };
  93. options.map = map;
  94. let marker = new google.maps.Marker(options);
  95. bounds.extend(options.position);
  96. }
  97. if(markers.length > 1) {
  98. maps[this.id].fitBounds(bounds, 32);
  99. }
  100. }
  101. let callback = $(this).data("callback");
  102. if(callback) {
  103. try {
  104. window[callback]();
  105. }
  106. catch(err) {
  107. console.log(err);
  108. }
  109. }
  110. });
  111. $("input[data-autocomplete]").each(function() {
  112. let mapId = $(this).data("autocomplete");
  113. let map = maps[mapId];
  114. let autocomplete = new google.maps.places.Autocomplete(this);
  115. autocomplete.bindTo("bounds", map);
  116. autocomplete.setFields(["address_components", "geometry", "icon", "name"]);
  117. autocomplete.addListener("place_changed", function() {
  118. let place = autocomplete.getPlace();
  119. if(place.geometry.viewport) {
  120. map.fitBounds(place.geometry.viewport);
  121. }
  122. else {
  123. map.setCenter(place.geometry.location);
  124. map.setZoom(17);
  125. }
  126. });
  127. });
  128. }