1
0

app.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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. $("canvas[data-chart]").each(function() {
  47. var object = $(this).data("chart");
  48. object.options.plugins.datalabels.display = function(context) {
  49. var dataset = context.dataset;
  50. return dataset.data[context.dataIndex];
  51. };
  52. if(object.datalabelFormatterCallback) {
  53. object.options.plugins.datalabels.formatter = window[object.datalabelFormatterCallback];
  54. }
  55. if(object.options.datalabelSuffixes) {
  56. object.options.plugins.datalabels.formatter = function(value, context) {
  57. let suffix = object.options.datalabelSuffixes[context.datasetIndex];
  58. if(suffix.length > 2 && parseInt(value) !== 1) {
  59. suffix += "s";
  60. }
  61. return value + suffix;
  62. }
  63. }
  64. new Chart(this, object);
  65. });
  66. $.fn.select2.defaults.set("theme", "bootstrap4");
  67. $("select[data-toggle='select2']").each((index, element) => {
  68. console.log(element);
  69. const $el = $(element);
  70. $el.select2();
  71. });
  72. });
  73. var maps = [];
  74. function initialiseTooltips() {
  75. $('[data-toggle="tooltip"]').tooltip();
  76. }
  77. function initialiseMaps() {
  78. $("div[data-maps]").each(function() {
  79. let position = {
  80. lat: $(this).data("lat"),
  81. lng: $(this).data("lng")
  82. };
  83. let options = {};
  84. options.center = position;
  85. options.zoom = $(this).data("zoom");
  86. options.gestureHandling = "greedy";
  87. options.scaleControl = true;
  88. options.styles = [
  89. {
  90. featureType: "poi",
  91. elementType: "labels",
  92. stylers: [
  93. {
  94. visibility: "off"
  95. }
  96. ]
  97. }
  98. ];
  99. let map = new google.maps.Map(this, options);
  100. if(this.id) {
  101. maps[this.id] = map;
  102. }
  103. // Plot marker
  104. let marker = $(this).data("marker");
  105. if(marker) {
  106. let options = {};
  107. options.position = position;
  108. options.map = map;
  109. options.draggable = $(this).data("marker-draggable");
  110. let marker = new google.maps.Marker(options);
  111. let markerDragendTarget = $(this).data("marker-dragend-target");
  112. if(markerDragendTarget) {
  113. marker.addListener("dragend", function() {
  114. let position = marker.getPosition();
  115. $(markerDragendTarget).find("input[data-latitude]").val(position.lat());
  116. $(markerDragendTarget).find("input[data-longitude]").val(position.lng());
  117. });
  118. }
  119. }
  120. // Plot basic markers
  121. let markers = $(this).data("markers");
  122. if(markers) {
  123. let bounds = new google.maps.LatLngBounds;
  124. for(let i in markers) {
  125. let options = {};
  126. options.position = {
  127. "lat": markers[i].latitude * 1,
  128. "lng": markers[i].longitude * 1
  129. };
  130. options.map = map;
  131. let marker = new google.maps.Marker(options);
  132. bounds.extend(options.position);
  133. }
  134. if(markers.length > 1) {
  135. maps[this.id].fitBounds(bounds, 32);
  136. }
  137. }
  138. let callback = $(this).data("callback");
  139. if(callback) {
  140. try {
  141. window[callback]();
  142. }
  143. catch(err) {
  144. console.log(err);
  145. }
  146. }
  147. });
  148. $("input[data-autocomplete]").each(function() {
  149. let mapId = $(this).data("autocomplete");
  150. let map = maps[mapId];
  151. let autocomplete = new google.maps.places.Autocomplete(this);
  152. autocomplete.bindTo("bounds", map);
  153. autocomplete.setFields(["address_components", "geometry", "icon", "name"]);
  154. autocomplete.addListener("place_changed", function() {
  155. let place = autocomplete.getPlace();
  156. if(place.geometry.viewport) {
  157. map.fitBounds(place.geometry.viewport);
  158. }
  159. else {
  160. map.setCenter(place.geometry.location);
  161. map.setZoom(17);
  162. }
  163. });
  164. });
  165. }