mirror of
https://github.com/searxng/searxng.git
synced 2025-02-18 11:20:03 +00:00
Merge pull request #136 from pointhi/template_oscar_fix
[oscar_template] split up js-files, FIX #132
This commit is contained in:
commit
45734ee5f4
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,6 +9,7 @@ setup.cfg
|
||||
|
||||
*.pyc
|
||||
*/*.pyc
|
||||
*~
|
||||
|
||||
bin/
|
||||
build/
|
||||
|
@ -4,7 +4,8 @@ python:
|
||||
before_install:
|
||||
- "export DISPLAY=:99.0"
|
||||
- "sh -e /etc/init.d/xvfb start"
|
||||
- npm install -g less
|
||||
- npm install -g less grunt-cli
|
||||
- ( cd searx/static/oscar;npm install )
|
||||
install:
|
||||
- "make"
|
||||
- pip install coveralls
|
||||
@ -12,6 +13,7 @@ script:
|
||||
- "make tests"
|
||||
- "make robot"
|
||||
- "make styles"
|
||||
- "make grunt"
|
||||
- make coverage
|
||||
after_success:
|
||||
coveralls
|
||||
|
4
Makefile
4
Makefile
@ -20,6 +20,7 @@ $(python):
|
||||
|
||||
tests: .installed.cfg
|
||||
@bin/test
|
||||
@grunt test --gruntfile searx/static/oscar/gruntfile.js
|
||||
|
||||
robot: .installed.cfg
|
||||
@bin/robot
|
||||
@ -48,6 +49,9 @@ styles:
|
||||
@lessc -x searx/static/oscar/less/bootstrap/bootstrap.less > searx/static/oscar/css/bootstrap.min.css
|
||||
@lessc -x searx/static/oscar/less/oscar/oscar.less > searx/static/oscar/css/oscar.min.css
|
||||
|
||||
grunt:
|
||||
@grunt --gruntfile searx/static/oscar/gruntfile.js
|
||||
|
||||
locales:
|
||||
@pybabel compile -d searx/translations
|
||||
|
||||
|
1
searx/static/oscar/.gitignore
vendored
Normal file
1
searx/static/oscar/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
node_modules/
|
17
searx/static/oscar/README.rst
Normal file
17
searx/static/oscar/README.rst
Normal file
@ -0,0 +1,17 @@
|
||||
install dependencies
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
run this command in the directory ``searx/static/oscar``
|
||||
|
||||
``npm install``
|
||||
|
||||
compile sources
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
run this command in the directory ``searx/static/oscar``
|
||||
|
||||
``grunt``
|
||||
|
||||
or in the root directory:
|
||||
|
||||
``make grunt``
|
51
searx/static/oscar/gruntfile.js
Normal file
51
searx/static/oscar/gruntfile.js
Normal file
@ -0,0 +1,51 @@
|
||||
module.exports = function(grunt) {
|
||||
|
||||
grunt.initConfig({
|
||||
pkg: grunt.file.readJSON('package.json'),
|
||||
concat: {
|
||||
options: {
|
||||
separator: ';'
|
||||
},
|
||||
dist: {
|
||||
src: ['js/searx_src/*.js'],
|
||||
dest: 'js/searx.js'
|
||||
}
|
||||
},
|
||||
uglify: {
|
||||
options: {
|
||||
banner: '/*! oscar/searx.min.js | <%= grunt.template.today("dd-mm-yyyy") %> | https://github.com/asciimoo/searx */\n'
|
||||
},
|
||||
dist: {
|
||||
files: {
|
||||
'js/searx.min.js': ['<%= concat.dist.dest %>']
|
||||
}
|
||||
}
|
||||
},
|
||||
jshint: {
|
||||
files: ['gruntfile.js', 'js/searx_src/*.js'],
|
||||
options: {
|
||||
// options here to override JSHint defaults
|
||||
globals: {
|
||||
jQuery: true,
|
||||
console: true,
|
||||
module: true,
|
||||
document: true
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
files: ['<%= jshint.files %>'],
|
||||
tasks: ['jshint']
|
||||
}
|
||||
});
|
||||
|
||||
grunt.loadNpmTasks('grunt-contrib-uglify');
|
||||
grunt.loadNpmTasks('grunt-contrib-jshint');
|
||||
grunt.loadNpmTasks('grunt-contrib-watch');
|
||||
grunt.loadNpmTasks('grunt-contrib-concat');
|
||||
|
||||
grunt.registerTask('test', ['jshint']);
|
||||
|
||||
grunt.registerTask('default', ['jshint', 'concat', 'uglify']);
|
||||
|
||||
};
|
BIN
searx/static/oscar/js/searx.min.js
vendored
Normal file
BIN
searx/static/oscar/js/searx.min.js
vendored
Normal file
Binary file not shown.
23
searx/static/oscar/js/searx_src/00_requirejs_config.js
Normal file
23
searx/static/oscar/js/searx_src/00_requirejs_config.js
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* searx is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* searx is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with searx. If not, see < http://www.gnu.org/licenses/ >.
|
||||
*
|
||||
* (C) 2014 by Thomas Pointhuber, <thomas.pointhuber@gmx.at>
|
||||
*/
|
||||
|
||||
requirejs.config({
|
||||
baseUrl: '/static/oscar/js',
|
||||
paths: {
|
||||
app: '../app'
|
||||
}
|
||||
});
|
37
searx/static/oscar/js/searx_src/autocompleter.js
Normal file
37
searx/static/oscar/js/searx_src/autocompleter.js
Normal file
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* searx is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* searx is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with searx. If not, see < http://www.gnu.org/licenses/ >.
|
||||
*
|
||||
* (C) 2014 by Thomas Pointhuber, <thomas.pointhuber@gmx.at>
|
||||
*/
|
||||
|
||||
if(searx.autocompleter) {
|
||||
searx.searchResults = new Bloodhound({
|
||||
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
|
||||
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
||||
remote: '/autocompleter?q=%QUERY'
|
||||
});
|
||||
searx.searchResults.initialize();
|
||||
}
|
||||
|
||||
$(document).ready(function(){
|
||||
if(searx.autocompleter) {
|
||||
$('#q').typeahead(null, {
|
||||
name: 'search-results',
|
||||
displayKey: function(result) {
|
||||
return result;
|
||||
},
|
||||
source: searx.searchResults.ttAdapter()
|
||||
});
|
||||
}
|
||||
});
|
66
searx/static/oscar/js/searx_src/element_modifiers.js
Normal file
66
searx/static/oscar/js/searx_src/element_modifiers.js
Normal file
@ -0,0 +1,66 @@
|
||||
/**
|
||||
* searx is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* searx is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with searx. If not, see < http://www.gnu.org/licenses/ >.
|
||||
*
|
||||
* (C) 2014 by Thomas Pointhuber, <thomas.pointhuber@gmx.at>
|
||||
*/
|
||||
|
||||
$(document).ready(function(){
|
||||
/**
|
||||
* focus element if class="autofocus" and id="q"
|
||||
*/
|
||||
$('#q.autofocus').focus();
|
||||
|
||||
/**
|
||||
* select full content on click if class="select-all-on-click"
|
||||
*/
|
||||
$(".select-all-on-click").click(function () {
|
||||
$(this).select();
|
||||
});
|
||||
|
||||
/**
|
||||
* change text during btn-collapse click if possible
|
||||
*/
|
||||
$('.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')) {
|
||||
new_html = $(this).html().replace(btnTextCollapsed, btnTextNotCollapsed);
|
||||
} else {
|
||||
new_html = $(this).html().replace(btnTextNotCollapsed, btnTextCollapsed);
|
||||
}
|
||||
$(this).html(new_html);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* change text during btn-toggle click if possible
|
||||
*/
|
||||
$('.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');
|
||||
if(btnLabelToggled !== '') {
|
||||
if($(this).hasClass('btn-default')) {
|
||||
new_html = $(this).html().replace(btnLabelDefault, btnLabelToggled);
|
||||
} else {
|
||||
new_html = $(this).html().replace(btnLabelToggled, btnLabelDefault);
|
||||
}
|
||||
$(this).html(new_html);
|
||||
}
|
||||
$(this).toggleClass(btnClass);
|
||||
$(this).toggleClass('btn-default');
|
||||
});
|
||||
});
|
@ -1,74 +1,21 @@
|
||||
/**
|
||||
_ _ _
|
||||
| |__ ___ ___ | |_ ___| |_ _ __ __ ___ __
|
||||
| '_ \ / _ \ / _ \| __/ __| __| '__/ _` \ \/ /
|
||||
| |_) | (_) | (_) | |_\__ | |_| | | (_| |> <
|
||||
|_.__/ \___/ \___/ \__|___/\__|_| \__,_/_/\_\.js
|
||||
|
||||
*/
|
||||
|
||||
requirejs.config({
|
||||
baseUrl: '/static/oscar/js',
|
||||
paths: {
|
||||
app: '../app'
|
||||
}
|
||||
});
|
||||
|
||||
if(searx.autocompleter) {
|
||||
searx.searchResults = new Bloodhound({
|
||||
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
|
||||
queryTokenizer: Bloodhound.tokenizers.whitespace,
|
||||
remote: '/autocompleter?q=%QUERY'
|
||||
});
|
||||
searx.searchResults.initialize();
|
||||
}
|
||||
* searx is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* searx is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with searx. If not, see < http://www.gnu.org/licenses/ >.
|
||||
*
|
||||
* (C) 2014 by Thomas Pointhuber, <thomas.pointhuber@gmx.at>
|
||||
*/
|
||||
|
||||
$(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');
|
||||
if(btnLabelToggled != '') {
|
||||
if($(this).hasClass('btn-default')) {
|
||||
|
||||
var html = $(this).html().replace(btnLabelDefault, btnLabelToggled);
|
||||
} else {
|
||||
var html = $(this).html().replace(btnLabelToggled, btnLabelDefault);
|
||||
}
|
||||
$(this).html(html);
|
||||
}
|
||||
$(this).toggleClass(btnClass);
|
||||
$(this).toggleClass('btn-default');
|
||||
});
|
||||
|
||||
$('.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);
|
||||
}
|
||||
});
|
||||
|
||||
$(".select-all-on-click").click(function () {
|
||||
$(this).select();
|
||||
});
|
||||
|
||||
if(searx.autocompleter) {
|
||||
$('#q').typeahead(null, {
|
||||
name: 'search-results',
|
||||
displayKey: function(result) {
|
||||
return result;
|
||||
},
|
||||
source: searx.searchResults.ttAdapter()
|
||||
});
|
||||
}
|
||||
|
||||
$(".searx_overpass_request").on( "click", function( event ) {
|
||||
var overpass_url = "https://overpass-api.de/api/interpreter?data=";
|
||||
var query_start = overpass_url + "[out:json][timeout:25];(";
|
||||
@ -80,7 +27,7 @@ $(document).ready(function(){
|
||||
var result_table_loadicon = "#" + $(this).data('result-table-loadicon');
|
||||
|
||||
// tags which can be ignored
|
||||
var osm_ignore_tags = [ "addr:city", "addr:country", "addr:housenumber", "addr:postcode", "addr:street" ]
|
||||
var osm_ignore_tags = [ "addr:city", "addr:country", "addr:housenumber", "addr:postcode", "addr:street" ];
|
||||
|
||||
if(osm_id && osm_type && result_table) {
|
||||
result_table = "#" + result_table;
|
||||
@ -102,11 +49,11 @@ $(document).ready(function(){
|
||||
//alert(query);
|
||||
var ajaxRequest = $.ajax( query )
|
||||
.done(function( html) {
|
||||
if(html && html['elements'] && html['elements'][0]) {
|
||||
var element = html['elements'][0];
|
||||
if(html && html.elements && html.elements[0]) {
|
||||
var element = html.elements[0];
|
||||
var newHtml = $(result_table).html();
|
||||
for (var row in element.tags) {
|
||||
if(element.tags["name"] == null || osm_ignore_tags.indexOf(row) == -1) {
|
||||
if(element.tags.name === null || osm_ignore_tags.indexOf(row) == -1) {
|
||||
newHtml += "<tr><td>" + row + "</td><td>";
|
||||
switch(row) {
|
||||
case "phone":
|
||||
@ -125,11 +72,12 @@ $(document).ready(function(){
|
||||
break;
|
||||
case "wikipedia":
|
||||
if(element.tags[row].indexOf(":") != -1) {
|
||||
newHtml += "<a href=\"https://" + element.tags[row].substring(0,element.tags[row].indexOf(":")) + ".wikipedia.org/wiki/"
|
||||
+ element.tags[row].substring(element.tags[row].indexOf(":")+1) + "\">" + element.tags[row] + "</a>";
|
||||
newHtml += "<a href=\"https://" + element.tags[row].substring(0,element.tags[row].indexOf(":")) + ".wikipedia.org/wiki/" + element.tags[row].substring(element.tags[row].indexOf(":")+1) + "\">" + element.tags[row] + "</a>";
|
||||
break;
|
||||
}
|
||||
/* jshint ignore:start */
|
||||
default:
|
||||
/* jshint ignore:end */
|
||||
newHtml += element.tags[row];
|
||||
break;
|
||||
}
|
||||
@ -143,7 +91,7 @@ $(document).ready(function(){
|
||||
})
|
||||
.fail(function() {
|
||||
$(result_table_loadicon).html($(result_table_loadicon).html() + "<p class=\"text-muted\">could not load data!</p>");
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -161,9 +109,9 @@ $(document).ready(function(){
|
||||
|
||||
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);
|
||||
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
|
15
searx/static/oscar/package.json
Normal file
15
searx/static/oscar/package.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"devDependencies": {
|
||||
"grunt": "~0.4.5",
|
||||
"grunt-contrib-uglify": "~0.6.0",
|
||||
"grunt-contrib-watch" : "~0.6.1",
|
||||
"grunt-contrib-concat" : "~0.5.0",
|
||||
"grunt-contrib-jshint" : "~0.10.0"
|
||||
},
|
||||
|
||||
"scripts": {
|
||||
"build": "npm install && grunt",
|
||||
"start": "grunt watch",
|
||||
"test": "grunt"
|
||||
}
|
||||
}
|
@ -73,6 +73,6 @@
|
||||
<script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
|
||||
{% if autocomplete %}<script src="{{ url_for('static', filename='js/typeahead.bundle.min.js') }}"></script>{% endif %}
|
||||
<script src="{{ url_for('static', filename='js/require-2.1.15.min.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='js/scripts.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='js/searx.min.js') }}"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
<form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" id="search_form" role="search">
|
||||
<div class="input-group col-md-8 col-md-offset-2">
|
||||
<input type="search" name="q" class="form-control input-lg" id="q" placeholder="{{ _('Search for...') }}" autocomplete="off" value="{{ q }}">
|
||||
<input type="search" name="q" class="form-control input-lg autofocus" id="q" placeholder="{{ _('Search for...') }}" autocomplete="off" value="{{ q }}">
|
||||
<span class="input-group-btn">
|
||||
<button type="submit" class="btn btn-default input-lg">{{ icon('search') }}<span class="sr-only">{{ _('Start search') }}</span></button>
|
||||
</span>
|
||||
|
Loading…
Reference in New Issue
Block a user