2014-09-26 20:43:54 +00:00
|
|
|
/**
|
|
|
|
_ _ _
|
|
|
|
| |__ ___ ___ | |_ ___| |_ _ __ __ ___ __
|
|
|
|
| '_ \ / _ \ / _ \| __/ __| __| '__/ _` \ \/ /
|
|
|
|
| |_) | (_) | (_) | |_\__ | |_| | | (_| |> <
|
|
|
|
|_.__/ \___/ \___/ \__|___/\__|_| \__,_/_/\_\.js
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2014-11-02 12:00:28 +00:00
|
|
|
requirejs.config({
|
|
|
|
baseUrl: '/static/oscar/js',
|
|
|
|
paths: {
|
|
|
|
app: '../app'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-09-29 07:44:29 +00:00
|
|
|
if(searx.autocompleter) {
|
|
|
|
searx.searchResults = new Bloodhound({
|
|
|
|
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
|
|
|
|
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
|
|
|
remote: '/autocompleter?q=%QUERY'
|
|
|
|
});
|
|
|
|
searx.searchResults.initialize();
|
|
|
|
}
|
|
|
|
|
2014-09-26 20:43:54 +00:00
|
|
|
$(document).ready(function(){
|
|
|
|
$('.btn-toggle .btn').click(function() {
|
|
|
|
var btnClass = 'btn-' + $(this).data('btn-class');
|
|
|
|
var btnLabelDefault = $(this).data('btn-label-default');
|
|
|
|
var btnLabelToggled = $(this).data('btn-label-toggled');
|
2014-09-27 08:23:05 +00:00
|
|
|
if(btnLabelToggled != '') {
|
|
|
|
if($(this).hasClass('btn-default')) {
|
2014-09-26 20:43:54 +00:00
|
|
|
|
|
|
|
var html = $(this).html().replace(btnLabelDefault, btnLabelToggled);
|
2014-09-27 08:23:05 +00:00
|
|
|
} else {
|
2014-09-26 20:43:54 +00:00
|
|
|
var html = $(this).html().replace(btnLabelToggled, btnLabelDefault);
|
|
|
|
}
|
|
|
|
$(this).html(html);
|
|
|
|
}
|
|
|
|
$(this).toggleClass(btnClass);
|
|
|
|
$(this).toggleClass('btn-default');
|
|
|
|
});
|
2014-09-27 08:23:05 +00:00
|
|
|
|
|
|
|
$('.btn-collapse').click(function() {
|
|
|
|
var btnTextCollapsed = $(this).data('btn-text-collapsed');
|
|
|
|
var btnTextNotCollapsed = $(this).data('btn-text-not-collapsed');
|
|
|
|
|
|
|
|
if(btnTextCollapsed != '' && btnTextNotCollapsed != '') {
|
|
|
|
if($(this).hasClass('collapsed')) {
|
|
|
|
var html = $(this).html().replace(btnTextCollapsed, btnTextNotCollapsed);
|
|
|
|
} else {
|
|
|
|
var html = $(this).html().replace(btnTextNotCollapsed, btnTextCollapsed);
|
|
|
|
}
|
|
|
|
$(this).html(html);
|
|
|
|
}
|
|
|
|
});
|
2014-09-27 13:46:57 +00:00
|
|
|
|
|
|
|
$(".select-all-on-click").click(function () {
|
|
|
|
$(this).select();
|
|
|
|
});
|
2014-09-29 07:44:29 +00:00
|
|
|
|
|
|
|
if(searx.autocompleter) {
|
|
|
|
$('#q').typeahead(null, {
|
|
|
|
name: 'search-results',
|
|
|
|
displayKey: function(result) {
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
source: searx.searchResults.ttAdapter()
|
|
|
|
});
|
|
|
|
}
|
2014-11-02 12:00:28 +00:00
|
|
|
|
|
|
|
$(".searx_init_map").on( "click", function( event ) {
|
|
|
|
var leaflet_target = $(this).data('leaflet-target');
|
|
|
|
var map_lon = $(this).data('map-lon');
|
|
|
|
var map_lat = $(this).data('map-lat');
|
|
|
|
var map_zoom = $(this).data('map-zoom');
|
|
|
|
var map_boundingbox = $(this).data('map-boundingbox');
|
|
|
|
var map_geojson = $(this).data('map-geojson');
|
|
|
|
|
|
|
|
require(['leaflet-0.7.3.min'], function(leaflet) {
|
|
|
|
if(map_boundingbox) {
|
|
|
|
var southWest = L.latLng(map_boundingbox[0], map_boundingbox[2]),
|
|
|
|
northEast = L.latLng(map_boundingbox[1], map_boundingbox[3]),
|
|
|
|
map_bounds = L.latLngBounds(southWest, northEast);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO hack
|
|
|
|
// change default imagePath
|
|
|
|
L.Icon.Default.imagePath = "/static/oscar/img/map";
|
|
|
|
|
|
|
|
// init map
|
|
|
|
var map = L.map(leaflet_target);
|
|
|
|
|
|
|
|
// create the tile layer with correct attribution
|
|
|
|
var osmUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
|
|
|
|
var osmAttrib='Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors';
|
|
|
|
var osm = new L.TileLayer(osmUrl, {minZoom: 1, maxZoom: 19, attribution: osmAttrib});
|
|
|
|
|
|
|
|
// init map view
|
|
|
|
if(map_bounds) {
|
|
|
|
// TODO hack: https://github.com/Leaflet/Leaflet/issues/2021
|
|
|
|
setTimeout(function () {
|
2014-11-02 21:35:06 +00:00
|
|
|
map.fitBounds(map_bounds, {
|
|
|
|
maxZoom:17
|
|
|
|
});
|
2014-11-02 12:00:28 +00:00
|
|
|
}, 0);
|
|
|
|
} else if (map_lon && map_lat) {
|
|
|
|
if(map_zoom)
|
|
|
|
map.setView(new L.LatLng(map_lat, map_lon),map_zoom);
|
|
|
|
else
|
|
|
|
map.setView(new L.LatLng(map_lat, map_lon),8);
|
|
|
|
}
|
|
|
|
|
|
|
|
map.addLayer(osm);
|
|
|
|
|
|
|
|
if(map_geojson)
|
|
|
|
L.geoJson(map_geojson).addTo(map);
|
2014-11-02 21:35:06 +00:00
|
|
|
/*else if(map_bounds)
|
|
|
|
L.rectangle(map_bounds, {color: "#ff7800", weight: 3, fill:false}).addTo(map);*/
|
2014-11-02 12:00:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// this event occour only once per element
|
|
|
|
$( this ).off( event );
|
|
|
|
});
|
2014-09-29 07:44:29 +00:00
|
|
|
});
|