on master help sign in
[enh][oscar_template] split js-files and compile them together
commite687f5c290d30d32c9c32c4ae5c7b9085697ab87 authorThomas Pointhuber <thomas.pointhuber@gmx.at> dateSun 30 Nov 2014, 13:21 (12 years ago) parent08f4b7f
14 files changed+248−81
.gitignore+1 .travis.yml+2 Makefile+4 searx/static/oscar/.gitignore+1 searx/static/oscar/README.rst +17 searx/static/oscar/gruntfile.js+51 searx/static/oscar/js/searx.min.js+2 searx/static/oscar/js/searx_src/00_requirejs_config.js+23 searx/static/oscar/js/searx_src/autocompleter.js+37 searx/static/oscar/js/searx_src/element_modifiers.js+66 searx/static/oscar/js/scripts.js → searx/static/oscar/js/searx_src/leaflet_map.js+27−79 searx/static/oscar/package.json+15 searx/templates/oscar/base.html+1−1 searx/templates/oscar/search_full.html+1−1
.gitignore+1
@@ -9,6 +9,7 @@ setup.cfg
99
1010*.pyc
1111*/*.pyc
12+*~
1213
1314bin/
1415build/
.travis.yml+2
@@ -5,6 +5,7 @@ before_install:
55 - "export DISPLAY=:99.0"
66 - "sh -e /etc/init.d/xvfb start"
77 - npm install -g less
8+ - cd searx/static/oscar;npm install
89install:
910 - "make"
1011 - pip install coveralls
@@ -12,6 +13,7 @@ script:
1213 - "make tests"
1314 - "make robot"
1415 - "make styles"
16+ - "make grunt"
1517 - make coverage
1618after_success:
1719 coveralls
Makefile+4
@@ -20,6 +20,7 @@ $(python):
2020
2121tests: .installed.cfg
2222 @bin/test
23+ @grunt test --gruntfile searx/static/oscar/gruntfile.js
2324
2425robot: .installed.cfg
2526 @bin/robot
@@ -48,6 +49,9 @@ styles:
4849 @lessc -x searx/static/oscar/less/bootstrap/bootstrap.less > searx/static/oscar/css/bootstrap.min.css
4950 @lessc -x searx/static/oscar/less/oscar/oscar.less > searx/static/oscar/css/oscar.min.css
5051
52+grunt:
53+ @grunt --gruntfile searx/static/oscar/gruntfile.js
54+
5155locales:
5256 @pybabel compile -d searx/translations
5357
searx/static/oscar/.gitignorenew file+1
@@ -0,0 +1 @@
1+node_modules/
searx/static/oscar/README.rst new file+17
@@ -0,0 +1,17 @@
1+install dependencies
2+~~~~~~~~~~~~~~~~~~~~
3+
4+run this command in the directory ``searx/static/oscar``
5+
6+``npm install``
7+
8+compile sources
9+~~~~~~~~~~~~~~~
10+
11+run this command in the directory ``searx/static/oscar``
12+
13+``grunt``
14+
15+or in the root directory:
16+
17+``make grunt``
searx/static/oscar/gruntfile.jsnew file+51
@@ -0,0 +1,51 @@
1+module.exports = function(grunt) {
2+
3+ grunt.initConfig({
4+ pkg: grunt.file.readJSON('package.json'),
5+ concat: {
6+ options: {
7+ separator: ';'
8+ },
9+ dist: {
10+ src: ['js/searx_src/*.js'],
11+ dest: 'js/searx.js'
12+ }
13+ },
14+ uglify: {
15+ options: {
16+ banner: '/*! oscar/searx.min.js | <%= grunt.template.today("dd-mm-yyyy") %> | https://github.com/asciimoo/searx */\n'
17+ },
18+ dist: {
19+ files: {
20+ 'js/searx.min.js': ['<%= concat.dist.dest %>']
21+ }
22+ }
23+ },
24+ jshint: {
25+ files: ['gruntfile.js', 'js/searx_src/*.js'],
26+ options: {
27+ // options here to override JSHint defaults
28+ globals: {
29+ jQuery: true,
30+ console: true,
31+ module: true,
32+ document: true
33+ }
34+ }
35+ },
36+ watch: {
37+ files: ['<%= jshint.files %>'],
38+ tasks: ['jshint']
39+ }
40+ });
41+
42+ grunt.loadNpmTasks('grunt-contrib-uglify');
43+ grunt.loadNpmTasks('grunt-contrib-jshint');
44+ grunt.loadNpmTasks('grunt-contrib-watch');
45+ grunt.loadNpmTasks('grunt-contrib-concat');
46+
47+ grunt.registerTask('test', ['jshint']);
48+
49+ grunt.registerTask('default', ['jshint', 'concat', 'uglify']);
50+
51+};
searx/static/oscar/js/searx.min.jsnew file+2
@@ -0,0 +1,2 @@
1+/*! oscar/searx.min.js | 30-11-2014 | https://github.com/asciimoo/searx */
2+requirejs.config({baseUrl:"/static/oscar/js",paths:{app:"../app"}}),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(){searx.autocompleter&&$("#q").typeahead(null,{name:"search-results",displayKey:function(a){return a},source:searx.searchResults.ttAdapter()})}),$(document).ready(function(){$("#q.autofocus").focus(),$(".select-all-on-click").click(function(){$(this).select()}),$(".btn-collapse").click(function(){var a=$(this).data("btn-text-collapsed"),b=$(this).data("btn-text-not-collapsed");""!==a&&""!==b&&(new_html=$(this).hasClass("collapsed")?$(this).html().replace(a,b):$(this).html().replace(b,a),$(this).html(new_html))}),$(".btn-toggle .btn").click(function(){var a="btn-"+$(this).data("btn-class"),b=$(this).data("btn-label-default"),c=$(this).data("btn-label-toggled");""!==c&&(new_html=$(this).hasClass("btn-default")?$(this).html().replace(b,c):$(this).html().replace(c,b),$(this).html(new_html)),$(this).toggleClass(a),$(this).toggleClass("btn-default")})}),$(document).ready(function(){$(".searx_overpass_request").on("click",function(a){var b="https://overpass-api.de/api/interpreter?data=",c=b+"[out:json][timeout:25];(",d=");out meta;",e=$(this).data("osm-id"),f=$(this).data("osm-type"),g=$(this).data("result-table"),h="#"+$(this).data("result-table-loadicon"),i=["addr:city","addr:country","addr:housenumber","addr:postcode","addr:street"];if(e&&f&&g){g="#"+g;var j=null;switch(f){case"node":j=c+"node("+e+");"+d;break;case"way":j=c+"way("+e+");"+d;break;case"relation":j=c+"relation("+e+");"+d}if(j){$.ajax(j).done(function(a){if(a&&a.elements&&a.elements[0]){var b=a.elements[0],c=$(g).html();for(var d in b.tags)if(null===b.tags.name||-1==i.indexOf(d)){switch(c+="<tr><td>"+d+"</td><td>",d){case"phone":case"fax":c+='<a href="tel:'+b.tags[d].replace(/ /g,"")+'">'+b.tags[d]+"</a>";break;case"email":c+='<a href="mailto:'+b.tags[d]+'">'+b.tags[d]+"</a>";break;case"website":case"url":c+='<a href="'+b.tags[d]+'">'+b.tags[d]+"</a>";break;case"wikidata":c+='<a href="https://www.wikidata.org/wiki/'+b.tags[d]+'">'+b.tags[d]+"</a>";break;case"wikipedia":if(-1!=b.tags[d].indexOf(":")){c+='<a href="https://'+b.tags[d].substring(0,b.tags[d].indexOf(":"))+".wikipedia.org/wiki/"+b.tags[d].substring(b.tags[d].indexOf(":")+1)+'">'+b.tags[d]+"</a>";break}default:c+=b.tags[d]}c+="</td></tr>"}$(g).html(c),$(g).removeClass("hidden"),$(h).addClass("hidden")}}).fail(function(){$(h).html($(h).html()+'<p class="text-muted">could not load data!</p>')})}}$(this).off(a)}),$(".searx_init_map").on("click",function(a){var b=$(this).data("leaflet-target"),c=$(this).data("map-lon"),d=$(this).data("map-lat"),e=$(this).data("map-zoom"),f=$(this).data("map-boundingbox"),g=$(this).data("map-geojson");require(["leaflet-0.7.3.min"],function(){f&&(southWest=L.latLng(f[0],f[2]),northEast=L.latLng(f[1],f[3]),map_bounds=L.latLngBounds(southWest,northEast)),L.Icon.Default.imagePath="/static/oscar/img/map";{var a=L.map(b),h="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",i='Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors',j=new L.TileLayer(h,{minZoom:1,maxZoom:19,attribution:i}),k="http://otile{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.jpg",l='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">',m=new L.TileLayer(k,{minZoom:1,maxZoom:18,subdomains:"1234",attribution:l}),n="http://otile{s}.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg",o='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';new L.TileLayer(n,{minZoom:1,maxZoom:11,subdomains:"1234",attribution:o})}map_bounds?setTimeout(function(){a.fitBounds(map_bounds,{maxZoom:17})},0):c&&d&&(e?a.setView(new L.LatLng(d,c),e):a.setView(new L.LatLng(d,c),8)),a.addLayer(m);var p={"OSM Mapnik":j,MapQuest:m};L.control.layers(p).addTo(a),g&&L.geoJson(g).addTo(a)}),$(this).off(a)})});
searx/static/oscar/js/searx_src/00_requirejs_config.jsnew file+23
@@ -0,0 +1,23 @@
1+/**
2+ * searx is free software: you can redistribute it and/or modify
3+ * it under the terms of the GNU Affero General Public License as published by
4+ * the Free Software Foundation, either version 3 of the License, or
5+ * (at your option) any later version.
6+ *
7+ * searx is distributed in the hope that it will be useful,
8+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
9+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+ * GNU Affero General Public License for more details.
11+ *
12+ * You should have received a copy of the GNU Affero General Public License
13+ * along with searx. If not, see < http://www.gnu.org/licenses/ >.
14+ *
15+ * (C) 2014 by Thomas Pointhuber, <thomas.pointhuber@gmx.at>
16+ */
17+
18+requirejs.config({
19+ baseUrl: '/static/oscar/js',
20+ paths: {
21+ app: '../app'
22+ }
23+});
searx/static/oscar/js/searx_src/autocompleter.jsnew file+37
@@ -0,0 +1,37 @@
1+/**
2+ * searx is free software: you can redistribute it and/or modify
3+ * it under the terms of the GNU Affero General Public License as published by
4+ * the Free Software Foundation, either version 3 of the License, or
5+ * (at your option) any later version.
6+ *
7+ * searx is distributed in the hope that it will be useful,
8+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
9+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+ * GNU Affero General Public License for more details.
11+ *
12+ * You should have received a copy of the GNU Affero General Public License
13+ * along with searx. If not, see < http://www.gnu.org/licenses/ >.
14+ *
15+ * (C) 2014 by Thomas Pointhuber, <thomas.pointhuber@gmx.at>
16+ */
17+
18+if(searx.autocompleter) {
19+ searx.searchResults = new Bloodhound({
20+ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
21+ queryTokenizer: Bloodhound.tokenizers.whitespace,
22+ remote: '/autocompleter?q=%QUERY'
23+ });
24+ searx.searchResults.initialize();
25+}
26+
27+$(document).ready(function(){
28+ if(searx.autocompleter) {
29+ $('#q').typeahead(null, {
30+ name: 'search-results',
31+ displayKey: function(result) {
32+ return result;
33+ },
34+ source: searx.searchResults.ttAdapter()
35+ });
36+ }
37+});
searx/static/oscar/js/searx_src/element_modifiers.jsnew file+66
@@ -0,0 +1,66 @@
1+/**
2+ * searx is free software: you can redistribute it and/or modify
3+ * it under the terms of the GNU Affero General Public License as published by
4+ * the Free Software Foundation, either version 3 of the License, or
5+ * (at your option) any later version.
6+ *
7+ * searx is distributed in the hope that it will be useful,
8+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
9+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+ * GNU Affero General Public License for more details.
11+ *
12+ * You should have received a copy of the GNU Affero General Public License
13+ * along with searx. If not, see < http://www.gnu.org/licenses/ >.
14+ *
15+ * (C) 2014 by Thomas Pointhuber, <thomas.pointhuber@gmx.at>
16+ */
17+
18+$(document).ready(function(){
19+ /**
20+ * focus element if class="autofocus" and id="q"
21+ */
22+ $('#q.autofocus').focus();
23+
24+ /**
25+ * select full content on click if class="select-all-on-click"
26+ */
27+ $(".select-all-on-click").click(function () {
28+ $(this).select();
29+ });
30+
31+ /**
32+ * change text during btn-collapse click if possible
33+ */
34+ $('.btn-collapse').click(function() {
35+ var btnTextCollapsed = $(this).data('btn-text-collapsed');
36+ var btnTextNotCollapsed = $(this).data('btn-text-not-collapsed');
37+
38+ if(btnTextCollapsed !== '' && btnTextNotCollapsed !== '') {
39+ if($(this).hasClass('collapsed')) {
40+ new_html = $(this).html().replace(btnTextCollapsed, btnTextNotCollapsed);
41+ } else {
42+ new_html = $(this).html().replace(btnTextNotCollapsed, btnTextCollapsed);
43+ }
44+ $(this).html(new_html);
45+ }
46+ });
47+
48+ /**
49+ * change text during btn-toggle click if possible
50+ */
51+ $('.btn-toggle .btn').click(function() {
52+ var btnClass = 'btn-' + $(this).data('btn-class');
53+ var btnLabelDefault = $(this).data('btn-label-default');
54+ var btnLabelToggled = $(this).data('btn-label-toggled');
55+ if(btnLabelToggled !== '') {
56+ if($(this).hasClass('btn-default')) {
57+ new_html = $(this).html().replace(btnLabelDefault, btnLabelToggled);
58+ } else {
59+ new_html = $(this).html().replace(btnLabelToggled, btnLabelDefault);
60+ }
61+ $(this).html(new_html);
62+ }
63+ $(this).toggleClass(btnClass);
64+ $(this).toggleClass('btn-default');
65+ });
66+});
searx/static/oscar/js/scripts.js → searx/static/oscar/js/searx_src/leaflet_map.jsrenamed+27−79
@@ -1,74 +1,21 @@
11/**
2− _ _ _
3−| |__ ___ ___ | |_ ___| |_ _ __ __ ___ __
4−| '_ \ / _ \ / _ \| __/ __| __| '__/ _` \ \/ /
5−| |_) | (_) | (_) | |_\__ | |_| | | (_| |> <
6−|_.__/ \___/ \___/ \__|___/\__|_| \__,_/_/\_\.js
7−
8−*/
9−
10−requirejs.config({
11−baseUrl: '/static/oscar/js',
12−paths: {
13−app: '../app'
14−}
15−});
16−
17−if(searx.autocompleter) {
18− searx.searchResults = new Bloodhound({
19− datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
20− queryTokenizer: Bloodhound.tokenizers.whitespace,
21− remote: '/autocompleter?q=%QUERY'
22− });
23− searx.searchResults.initialize();
24−}
2+ * searx is free software: you can redistribute it and/or modify
3+ * it under the terms of the GNU Affero General Public License as published by
4+ * the Free Software Foundation, either version 3 of the License, or
5+ * (at your option) any later version.
6+ *
7+ * searx is distributed in the hope that it will be useful,
8+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
9+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10+ * GNU Affero General Public License for more details.
11+ *
12+ * You should have received a copy of the GNU Affero General Public License
13+ * along with searx. If not, see < http://www.gnu.org/licenses/ >.
14+ *
15+ * (C) 2014 by Thomas Pointhuber, <thomas.pointhuber@gmx.at>
16+ */
2517
2618$(document).ready(function(){
27− $('.btn-toggle .btn').click(function() {
28− var btnClass = 'btn-' + $(this).data('btn-class');
29− var btnLabelDefault = $(this).data('btn-label-default');
30− var btnLabelToggled = $(this).data('btn-label-toggled');
31− if(btnLabelToggled != '') {
32− if($(this).hasClass('btn-default')) {
33−
34− var html = $(this).html().replace(btnLabelDefault, btnLabelToggled);
35− } else {
36− var html = $(this).html().replace(btnLabelToggled, btnLabelDefault);
37− }
38− $(this).html(html);
39− }
40− $(this).toggleClass(btnClass);
41− $(this).toggleClass('btn-default');
42− });
43−
44− $('.btn-collapse').click(function() {
45− var btnTextCollapsed = $(this).data('btn-text-collapsed');
46− var btnTextNotCollapsed = $(this).data('btn-text-not-collapsed');
47−
48− if(btnTextCollapsed != '' && btnTextNotCollapsed != '') {
49− if($(this).hasClass('collapsed')) {
50− var html = $(this).html().replace(btnTextCollapsed, btnTextNotCollapsed);
51− } else {
52− var html = $(this).html().replace(btnTextNotCollapsed, btnTextCollapsed);
53− }
54− $(this).html(html);
55− }
56− });
57−
58− $(".select-all-on-click").click(function () {
59− $(this).select();
60− });
61−
62− if(searx.autocompleter) {
63− $('#q').typeahead(null, {
64− name: 'search-results',
65− displayKey: function(result) {
66− return result;
67− },
68− source: searx.searchResults.ttAdapter()
69− });
70− }
71−
7219 $(".searx_overpass_request").on( "click", function( event ) {
7320 var overpass_url = "https://overpass-api.de/api/interpreter?data=";
7421 var query_start = overpass_url + "[out:json][timeout:25];(";
@@ -80,7 +27,7 @@ $(document).ready(function(){
8027 var result_table_loadicon = "#" + $(this).data('result-table-loadicon');
8128
8229 // tags which can be ignored
83− var osm_ignore_tags = [ "addr:city", "addr:country", "addr:housenumber", "addr:postcode", "addr:street" ]
30+ var osm_ignore_tags = [ "addr:city", "addr:country", "addr:housenumber", "addr:postcode", "addr:street" ];
8431
8532 if(osm_id && osm_type && result_table) {
8633 result_table = "#" + result_table;
@@ -102,11 +49,11 @@ $(document).ready(function(){
10249 //alert(query);
10350 var ajaxRequest = $.ajax( query )
10451 .done(function( html) {
105− if(html && html['elements'] && html['elements'][0]) {
106− var element = html['elements'][0];
52+ if(html && html.elements && html.elements[0]) {
53+ var element = html.elements[0];
10754 var newHtml = $(result_table).html();
10855 for (var row in element.tags) {
109− if(element.tags["name"] == null || osm_ignore_tags.indexOf(row) == -1) {
56+ if(element.tags.name === null || osm_ignore_tags.indexOf(row) == -1) {
11057 newHtml += "<tr><td>" + row + "</td><td>";
11158 switch(row) {
11259 case "phone":
@@ -125,11 +72,12 @@ $(document).ready(function(){
12572 break;
12673 case "wikipedia":
12774 if(element.tags[row].indexOf(":") != -1) {
128− newHtml += "<a href=\"https://" + element.tags[row].substring(0,element.tags[row].indexOf(":")) + ".wikipedia.org/wiki/"
129− + element.tags[row].substring(element.tags[row].indexOf(":")+1) + "\">" + element.tags[row] + "</a>";
75+ 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>";
13076 break;
13177 }
78+ /* jshint ignore:start */
13279 default:
80+ /* jshint ignore:end */
13381 newHtml += element.tags[row];
13482 break;
13583 }
@@ -143,7 +91,7 @@ $(document).ready(function(){
14391 })
14492 .fail(function() {
14593 $(result_table_loadicon).html($(result_table_loadicon).html() + "<p class=\"text-muted\">could not load data!</p>");
146− })
94+ });
14795 }
14896 }
14997
@@ -158,12 +106,12 @@ $(document).ready(function(){
158106 var map_zoom = $(this).data('map-zoom');
159107 var map_boundingbox = $(this).data('map-boundingbox');
160108 var map_geojson = $(this).data('map-geojson');
161−
109+
162110 require(['leaflet-0.7.3.min'], function(leaflet) {
163111 if(map_boundingbox) {
164− var southWest = L.latLng(map_boundingbox[0], map_boundingbox[2]),
165− northEast = L.latLng(map_boundingbox[1], map_boundingbox[3]),
166− map_bounds = L.latLngBounds(southWest, northEast);
112+ southWest = L.latLng(map_boundingbox[0], map_boundingbox[2]);
113+ northEast = L.latLng(map_boundingbox[1], map_boundingbox[3]);
114+ map_bounds = L.latLngBounds(southWest, northEast);
167115 }
168116
169117 // TODO hack
searx/static/oscar/package.jsonnew file+15
@@ -0,0 +1,15 @@
1+{
2+ "devDependencies": {
3+ "grunt": "~0.4.5",
4+ "grunt-contrib-uglify": "~0.6.0",
5+ "grunt-contrib-watch" : "~0.6.1",
6+ "grunt-contrib-concat" : "~0.5.0",
7+ "grunt-contrib-jshint" : "~0.10.0"
8+ },
9+
10+ "scripts": {
11+ "build": "npm install && grunt",
12+ "start": "grunt watch",
13+ "test": "grunt"
14+ }
15+}
searx/templates/oscar/base.html+1−1
@@ -73,6 +73,6 @@
7373 <script src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
7474 {% if autocomplete %}<script src="{{ url_for('static', filename='js/typeahead.bundle.min.js') }}"></script>{% endif %}
7575 <script src="{{ url_for('static', filename='js/require-2.1.15.min.js') }}"></script>
76− <script src="{{ url_for('static', filename='js/scripts.js') }}"></script>
76+ <script src="{{ url_for('static', filename='js/searx.min.js') }}"></script>
7777</body>
7878</html>
searx/templates/oscar/search_full.html+1−1
@@ -2,7 +2,7 @@
22
33<form method="{{ method or 'POST' }}" action="{{ url_for('index') }}" id="search_form" role="search">
44 <div class="input-group col-md-8 col-md-offset-2">
5− <input type="search" name="q" class="form-control input-lg" id="q" placeholder="{{ _('Search for...') }}" autocomplete="off" value="{{ q }}">
5+ <input type="search" name="q" class="form-control input-lg autofocus" id="q" placeholder="{{ _('Search for...') }}" autocomplete="off" value="{{ q }}">
66 <span class="input-group-btn">
77 <button type="submit" class="btn btn-default input-lg">{{ icon('search') }}<span class="sr-only">{{ _('Start search') }}</span></button>
88 </span>