scripts.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /**
  2. _ _ _
  3. | |__ ___ ___ | |_ ___| |_ _ __ __ ___ __
  4. | '_ \ / _ \ / _ \| __/ __| __| '__/ _` \ \/ /
  5. | |_) | (_) | (_) | |_\__ | |_| | | (_| |> <
  6. |_.__/ \___/ \___/ \__|___/\__|_| \__,_/_/\_\.js
  7. */
  8. requirejs.config({
  9. baseUrl: '/static/oscar/js',
  10. paths: {
  11. app: '../app'
  12. }
  13. });
  14. if(searx.autocompleter) {
  15. searx.searchResults = new Bloodhound({
  16. datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
  17. queryTokenizer: Bloodhound.tokenizers.whitespace,
  18. remote: '/autocompleter?q=%QUERY'
  19. });
  20. searx.searchResults.initialize();
  21. }
  22. $(document).ready(function(){
  23. $('.btn-toggle .btn').click(function() {
  24. var btnClass = 'btn-' + $(this).data('btn-class');
  25. var btnLabelDefault = $(this).data('btn-label-default');
  26. var btnLabelToggled = $(this).data('btn-label-toggled');
  27. if(btnLabelToggled != '') {
  28. if($(this).hasClass('btn-default')) {
  29. var html = $(this).html().replace(btnLabelDefault, btnLabelToggled);
  30. } else {
  31. var html = $(this).html().replace(btnLabelToggled, btnLabelDefault);
  32. }
  33. $(this).html(html);
  34. }
  35. $(this).toggleClass(btnClass);
  36. $(this).toggleClass('btn-default');
  37. });
  38. $('.btn-collapse').click(function() {
  39. var btnTextCollapsed = $(this).data('btn-text-collapsed');
  40. var btnTextNotCollapsed = $(this).data('btn-text-not-collapsed');
  41. if(btnTextCollapsed != '' && btnTextNotCollapsed != '') {
  42. if($(this).hasClass('collapsed')) {
  43. var html = $(this).html().replace(btnTextCollapsed, btnTextNotCollapsed);
  44. } else {
  45. var html = $(this).html().replace(btnTextNotCollapsed, btnTextCollapsed);
  46. }
  47. $(this).html(html);
  48. }
  49. });
  50. $(".select-all-on-click").click(function () {
  51. $(this).select();
  52. });
  53. if(searx.autocompleter) {
  54. $('#q').typeahead(null, {
  55. name: 'search-results',
  56. displayKey: function(result) {
  57. return result;
  58. },
  59. source: searx.searchResults.ttAdapter()
  60. });
  61. }
  62. $(".searx_init_map").on( "click", function( event ) {
  63. var leaflet_target = $(this).data('leaflet-target');
  64. var map_lon = $(this).data('map-lon');
  65. var map_lat = $(this).data('map-lat');
  66. var map_zoom = $(this).data('map-zoom');
  67. var map_boundingbox = $(this).data('map-boundingbox');
  68. var map_geojson = $(this).data('map-geojson');
  69. require(['leaflet-0.7.3.min'], function(leaflet) {
  70. if(map_boundingbox) {
  71. var southWest = L.latLng(map_boundingbox[0], map_boundingbox[2]),
  72. northEast = L.latLng(map_boundingbox[1], map_boundingbox[3]),
  73. map_bounds = L.latLngBounds(southWest, northEast);
  74. }
  75. // TODO hack
  76. // change default imagePath
  77. L.Icon.Default.imagePath = "/static/oscar/img/map";
  78. // init map
  79. var map = L.map(leaflet_target);
  80. // create the tile layer with correct attribution
  81. var osmMapnikUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
  82. var osmMapnikAttrib='Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors';
  83. var osmMapnik = new L.TileLayer(osmMapnikUrl, {minZoom: 1, maxZoom: 19, attribution: osmMapnikAttrib});
  84. var osmMapquestUrl='http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg';
  85. var osmMapquestAttrib='Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors | Tiles Courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a> <img src="http://developer.mapquest.com/content/osm/mq_logo.png">';
  86. var osmMapquest = new L.TileLayer(osmMapquestUrl, {minZoom: 1, maxZoom: 18, subdomains: '1234', attribution: osmMapquestAttrib});
  87. var osmMapquestOpenAerialUrl='http://otile{s}.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg';
  88. var osmMapquestOpenAerialAttrib='Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors | Tiles Courtesy of <a href="http://www.mapquest.com/" target="_blank">MapQuest</a> <img src="https://developer.mapquest.com/content/osm/mq_logo.png"> | Portions Courtesy NASA/JPL-Caltech and U.S. Depart. of Agriculture, Farm Service Agency';
  89. var osmMapquestOpenAerial = new L.TileLayer(osmMapquestOpenAerialUrl, {minZoom: 1, maxZoom: 11, subdomains: '1234', attribution: osmMapquestOpenAerialAttrib});
  90. // init map view
  91. if(map_bounds) {
  92. // TODO hack: https://github.com/Leaflet/Leaflet/issues/2021
  93. setTimeout(function () {
  94. map.fitBounds(map_bounds, {
  95. maxZoom:17
  96. });
  97. }, 0);
  98. } else if (map_lon && map_lat) {
  99. if(map_zoom)
  100. map.setView(new L.LatLng(map_lat, map_lon),map_zoom);
  101. else
  102. map.setView(new L.LatLng(map_lat, map_lon),8);
  103. }
  104. map.addLayer(osmMapnik);
  105. var baseLayers = {
  106. "OSM Mapnik": osmMapnik,
  107. "MapQuest": osmMapquest/*,
  108. "MapQuest Open Aerial": osmMapquestOpenAerial*/
  109. };
  110. L.control.layers(baseLayers).addTo(map);
  111. if(map_geojson)
  112. L.geoJson(map_geojson).addTo(map);
  113. /*else if(map_bounds)
  114. L.rectangle(map_bounds, {color: "#ff7800", weight: 3, fill:false}).addTo(map);*/
  115. });
  116. // this event occour only once per element
  117. $( this ).off( event );
  118. });
  119. });