From 0e97f9b3773585d8fb76659dc710726a888c4851 Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Fri, 6 Mar 2015 14:31:01 +0100 Subject: Make JOSM button work in https mode. The JOSM button now contacts JOSM on http://localhost:8111/ if the taginfo page is using http and https://localhost:8112/ if it is using https. This way we don't have a problem with mixed content. Also the way JOSM is called now works without the iframes which were a hack around the (then) missing CORS ability. --- web/public/js/taginfo.js | 20 ++++++++++++++++++++ web/views/key.erb | 1 - web/views/relation.erb | 1 - web/views/tag.erb | 1 - web/viewsjs/key.js.erb | 6 +----- web/viewsjs/relation.js.erb | 6 +----- web/viewsjs/tag.js.erb | 5 +---- 7 files changed, 23 insertions(+), 17 deletions(-) (limited to 'web') diff --git a/web/public/js/taginfo.js b/web/public/js/taginfo.js index 92e7f70..21a8563 100644 --- a/web/public/js/taginfo.js +++ b/web/public/js/taginfo.js @@ -743,6 +743,26 @@ function comparison_list_change(key, value) { /* ============================ */ +function activate_josm_button() { + if (window.location.protocol == "https:") { + var url = jQuery('#josm_button')[0].href.replace('http://localhost:8111/', 'https://localhost:8112/'); + jQuery('#josm_button')[0].href = url; + } + + jQuery('#josm_button').bind('click', function() { + var url = jQuery('#josm_button')[0].href; + jQuery.get(url, function(data) { + if (data.substring(0, 2) != 'OK') { + alert("Problem contacting JOSM. Is it running? Is remote control activated?"); + console.log("Answer from JOSM: [" + data + "]"); + } + }); + return false; + }); +} + +/* ============================ */ + function project_tag_desc(description, icon, url) { var out = ''; if (icon) { diff --git a/web/views/key.erb b/web/views/key.erb index ceb9928..42434d5 100644 --- a/web/views/key.erb +++ b/web/views/key.erb @@ -117,7 +117,6 @@ - <% javascript do JS.raw(<<"JAVASCRIPT") function redraw_chart() { diff --git a/web/views/relation.erb b/web/views/relation.erb index caca294..cbda1be 100644 --- a/web/views/relation.erb +++ b/web/views/relation.erb @@ -64,7 +64,6 @@ - <% javascript do JS.raw(<<"JAVASCRIPT") function page_init2() { diff --git a/web/views/tag.erb b/web/views/tag.erb index dda4594..0e87439 100644 --- a/web/views/tag.erb +++ b/web/views/tag.erb @@ -104,7 +104,6 @@ - <% javascript do JS.raw(<<"JAVASCRIPT") function page_init2() { diff --git a/web/viewsjs/key.js.erb b/web/viewsjs/key.js.erb index 8f19ab2..e9886f1 100644 --- a/web/viewsjs/key.js.erb +++ b/web/viewsjs/key.js.erb @@ -218,11 +218,7 @@ function create_chart(params) { function page_init() { up = function() { window.location = '/keys'; } - - jQuery('#josm_button').bind('click', function() { - jQuery('#josmiframe')[0].src = jQuery('#josm_button')[0].href; - return false; - }); + activate_josm_button(); jQuery('#filter').bind('change', function() { var value = this.value; diff --git a/web/viewsjs/relation.js.erb b/web/viewsjs/relation.js.erb index ad34fc3..2a23d57 100644 --- a/web/viewsjs/relation.js.erb +++ b/web/viewsjs/relation.js.erb @@ -259,11 +259,7 @@ function create_role_chart(data) { } function page_init() { - jQuery('#josm_button').bind('click', function() { - jQuery('#josmiframe')[0].src = jQuery('#josm_button')[0].href; - return false; - }); - up = function() { window.location = '/relations'; }; + activate_josm_button(); page_init2(); } diff --git a/web/viewsjs/tag.js.erb b/web/viewsjs/tag.js.erb index 4cf5908..ebefcc1 100644 --- a/web/viewsjs/tag.js.erb +++ b/web/viewsjs/tag.js.erb @@ -134,10 +134,7 @@ var create_flexigrid_for = { }; function page_init() { - jQuery('#josm_button').bind('click', function() { - jQuery('#josmiframe')[0].src = jQuery('#josm_button')[0].href; - return false; - }); + activate_josm_button(); jQuery('#filter').bind('change', function() { var value = this.value; -- cgit v1.2.3