aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlouise <louise>2009-09-23 15:43:54 +0000
committerlouise <louise>2009-09-23 15:43:54 +0000
commita6e0574642c9b6aa0f4d3c43bba1f12b56bfdfa5 (patch)
tree032ff18eb49bd79884d559908d477726647bf545
parent1ed78ecb294d558b91739170c8e78bd3db8360ba (diff)
Ugly way of allowing the AJAX paths to change depending on what root path the pages are being served from
-rw-r--r--perllib/Cobrand.pm10
-rw-r--r--perllib/Page.pm6
-rwxr-xr-xt/Cobrand.t16
-rw-r--r--t/Cobrands/Mysite/Util.pm6
-rw-r--r--web/js.js20
5 files changed, 32 insertions, 26 deletions
diff --git a/perllib/Cobrand.pm b/perllib/Cobrand.pm
index 0030c2ccf..e170ec87d 100644
--- a/perllib/Cobrand.pm
+++ b/perllib/Cobrand.pm
@@ -7,7 +7,7 @@
# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
# Email: louise@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: Cobrand.pm,v 1.20 2009-09-23 11:31:31 louise Exp $
+# $Id: Cobrand.pm,v 1.21 2009-09-23 15:43:54 louise Exp $
package Cobrand;
use strict;
@@ -369,16 +369,16 @@ sub header_params {
=cut
-sub root_path_pattern {
+sub root_path_js {
my ($cobrand) = @_;
my $handle;
if ($cobrand){
$handle = cobrand_handle($cobrand);
}
- if ( !$cobrand || !$handle || !$handle->can('root_path_pattern')){
- return '//g';
+ if ( !$cobrand || !$handle || !$handle->can('root_path_js')){
+ return 'var root_path = "";';
} else{
- return $handle->root_path_pattern();
+ return $handle->root_path_js();
}
}
diff --git a/perllib/Page.pm b/perllib/Page.pm
index bc3999e9b..b4ca97f3a 100644
--- a/perllib/Page.pm
+++ b/perllib/Page.pm
@@ -6,7 +6,7 @@
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: Page.pm,v 1.182 2009-09-23 13:31:46 louise Exp $
+# $Id: Page.pm,v 1.183 2009-09-23 15:43:54 louise Exp $
#
package Page;
@@ -428,7 +428,7 @@ sub display_map {
my $out = '';
my $cobrand = Page::get_cobrand($q);
- my $root_path_pattern = Cobrand::root_path_pattern($cobrand);
+ my $root_path_js = Cobrand::root_path_js($cobrand);
my $img_type;
if ($params{type}) {
my $encoding = '';
@@ -452,7 +452,7 @@ EOF
<script type="text/javascript">
var fms_x = $x - 2; var fms_y = $y - 2;
var start_x = $px; var start_y = $py;
-var root_path = window.location.pathname.match($root_path_pattern) || '';
+$root_path_js
</script>
<div id="map_box">
$params{pre}
diff --git a/t/Cobrand.t b/t/Cobrand.t
index 28dbeaf6b..8a5c69c95 100755
--- a/t/Cobrand.t
+++ b/t/Cobrand.t
@@ -6,7 +6,7 @@
# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
# Email: louise@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: Cobrand.t,v 1.11 2009-09-23 11:31:32 louise Exp $
+# $Id: Cobrand.t,v 1.12 2009-09-23 15:43:54 louise Exp $
#
use strict;
@@ -164,17 +164,17 @@ sub test_header_params {
is_deeply($header_params, {}, 'header_params returns an empty hash ref if no cobrand module');
}
-sub test_root_path_pattern {
+sub test_root_path_js {
my $cobrand = 'mysite';
- my $root_path_pattern = Cobrand::root_path_pattern($cobrand);
+ my $root_path_js = Cobrand::root_path_js($cobrand);
- # should get the results of the root_path_pattern function in the cobrand module if one exists
- is($root_path_pattern, 'root path pattern', 'root_path_pattern returns output from cobrand module');
+ # should get the results of the root_path_js function in the cobrand module if one exists
+ is($root_path_js, 'root path js', 'root_path_js returns output from cobrand module');
# should return an empty regex string otherwise
$cobrand = 'nosite';
- $root_path_pattern = Cobrand::root_path_pattern($cobrand);
- is($root_path_pattern, '//g', 'root_path_pattern returns an empty regex string if no cobrand module');
+ $root_path_js = Cobrand::root_path_js($cobrand);
+ is($root_path_js, 'var root_path = "";', 'root_path_pattern returns a string setting the root path to an empty string if no cobrand module');
}
ok(test_cobrand_handle() == 1, 'Ran all tests for the cobrand_handle function');
@@ -188,4 +188,4 @@ ok(test_extra_problem_data() == 1, 'Ran all tests for extra_problem_data');
ok(test_extra_update_data() == 1, 'Ran all tests for extra_update_data');
ok(test_extra_params() == 1, 'Ran all tests for extra_params');
ok(test_header_params() == 1, 'Ran all tests for header_params');
-ok(test_root_path_pattern() == 1, 'Ran all tests for root_path_pattern');
+ok(test_root_path_js() == 1, 'Ran all tests for root_js');
diff --git a/t/Cobrands/Mysite/Util.pm b/t/Cobrands/Mysite/Util.pm
index 9ddd4c01e..9cac84ca8 100644
--- a/t/Cobrands/Mysite/Util.pm
+++ b/t/Cobrands/Mysite/Util.pm
@@ -7,7 +7,7 @@
# Copyright (c) 2009 UK Citizens Online Democracy. All rights reserved.
# Email: louise@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: Util.pm,v 1.10 2009-09-23 11:31:32 louise Exp $
+# $Id: Util.pm,v 1.11 2009-09-23 15:43:54 louise Exp $
package Cobrands::Mysite::Util;
use Page;
@@ -67,7 +67,7 @@ sub header_params {
}
-sub root_path_pattern {
- return 'root path pattern';
+sub root_path_js {
+ return 'root path js';
}
1;
diff --git a/web/js.js b/web/js.js
index 7debab608..b3d61bdcc 100644
--- a/web/js.js
+++ b/web/js.js
@@ -42,7 +42,6 @@ YAHOO.util.Event.onContentReady('compass', function() {
YAHOO.util.Event.addListener(points[4], 'click', compass_pan, { home:1, orig_x:drag_x, orig_y:drag_y });
});
-
YAHOO.util.Event.onContentReady('map', function() {
var ua=navigator.userAgent.toLowerCase();
// if (document.getElementById('mapForm') && (/safari/.test(ua) || /Konqueror/.test(ua))) return;
@@ -295,8 +294,7 @@ function update_tiles(dx, dy, force) {
tile_x += horizontal;
fms_y -= vertical;
tile_y += vertical;
-
- var url = [ '/tilma/tileserver/10k-full/', fms_x, '-', (fms_x+5), ',', fms_y, '-', (fms_y+5), '/JSON' ].join('');
+ var url = [ root_path + '/tilma/tileserver/10k-full/', fms_x, '-', (fms_x+5), ',', fms_y, '-', (fms_y+5), '/JSON' ].join('');
YAHOO.util.Connect.asyncRequest('GET', url, {
success: urls_loaded, failure: urls_not_loaded,
argument: [tile_x, tile_y]
@@ -308,10 +306,18 @@ function update_tiles(dx, dy, force) {
function load_pins(x, y) {
if (document.getElementById('formX')) {
- url = [ '/ajax?sx=', document.getElementById('formX').value, ';sy=',
- document.getElementById('formY').value, ';x=', (x+2), ';y=', (y+2),
- ';all_pins=', document.getElementById('all_pins').value
- ].join('');
+ var ajax_params = [ 'sx=' + document.getElementById('formX').value,
+ 'sy=' + document.getElementById('formY').value,
+ 'x=' + (x+2),
+ 'y=' + (y+2),
+ 'all_pins=' + document.getElementById('all_pins').value ];
+ var separator;
+ if (window.Cobrand){
+ separator = window.Cobrand.param_separator();
+ }else{
+ separator = ';';
+ }
+ var url = [ root_path , '/ajax?', ajax_params.join(separator)].join('');
YAHOO.util.Connect.asyncRequest('GET', url, {
success: pins_loaded
});