From 6702f44f92e9c74fe6d2dd1c69c5418a15af178c Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 31 Mar 2016 13:53:00 +0100 Subject: [fixmystreet.com] Move country lookup client side. There's no need for the IP->country lookup, only used in JavaScript to display a banner, to require a call to the FixMyStreet server. --- web/cobrands/fixmystreet.com/js.js | 26 ++++++++++++++++++++++++++ web/cobrands/fixmystreet/fixmystreet.js | 19 ------------------- 2 files changed, 26 insertions(+), 19 deletions(-) (limited to 'web') diff --git a/web/cobrands/fixmystreet.com/js.js b/web/cobrands/fixmystreet.com/js.js index 3abba8e33..9dbd11f2c 100644 --- a/web/cobrands/fixmystreet.com/js.js +++ b/web/cobrands/fixmystreet.com/js.js @@ -1,3 +1,29 @@ jQuery.validator.addMethod('validName', function(value, element) { var validNamePat = /\ba\s*n+on+((y|o)mo?u?s)?(ly)?\b/i; return this.optional(element) || value.length > 5 && value.match( /\S/ ) && value.match( /\s/ ) && !value.match( validNamePat ); }, translation_strings.category ); + +$(function(){ + + /* Front page banner for other countries */ + + $('.top_banner__close').live('click', function() { + $('.top_banner--country').hide(); + $.cookie('has_seen_country_message', 1, {expires: 365, path: '/'}); + }); + + if ( $('body.frontpage').length ) { + if (!$.cookie('has_seen_country_message')) { + $.ajax({ + url: 'https://gaze.mysociety.org/gaze-rest?f=get_country_from_ip', + success: function(data) { + if ( data && data != 'GB\n' ) { + var banner = '
Close

This site is for reporting problems in the UK. There are FixMyStreet sites all over the world, or you could set up your own using the FixMyStreet Platform.

'; + $('body').prepend(banner); + $('.top_banner--country').slideDown('slow'); + } + } + }); + } + } + +}); diff --git a/web/cobrands/fixmystreet/fixmystreet.js b/web/cobrands/fixmystreet/fixmystreet.js index f01c5142d..4de18be9a 100644 --- a/web/cobrands/fixmystreet/fixmystreet.js +++ b/web/cobrands/fixmystreet/fixmystreet.js @@ -532,25 +532,6 @@ $.fn.drawer = function(id, ajax) { }).fadeOut(500); }); - $('.top_banner__close').live('click', function() { - $('.top_banner--country').hide(); - $.cookie('has_seen_country_message', 1, {expires: 365, path: '/'}); - }); - - if ( cobrand == 'fixmystreet' && $('body.frontpage').length ) { - if (!$.cookie('has_seen_country_message')) { - $.ajax({ - url: '/country_message', - success: function(data) { - if ( data ) { - $('body').prepend(data); - $('.top_banner--country').slideDown('slow'); - } - } - }); - } - } - /* * Fancybox fullscreen images */ -- cgit v1.2.3