diff options
Diffstat (limited to 'web')
-rw-r--r-- | web/cobrands/fixmystreet.com/front.js | 38 | ||||
-rw-r--r-- | web/cobrands/fixmystreet.com/js.js | 27 |
2 files changed, 38 insertions, 27 deletions
diff --git a/web/cobrands/fixmystreet.com/front.js b/web/cobrands/fixmystreet.com/front.js new file mode 100644 index 000000000..f544fb657 --- /dev/null +++ b/web/cobrands/fixmystreet.com/front.js @@ -0,0 +1,38 @@ +(function(){ + if (!document.querySelector) { return; } + if ( -1 !== navigator.userAgent.indexOf('Google Page Speed')) { return; } + if (document.cookie.indexOf('has_seen_country_message') !== -1) { return; } + + /* Front page banner for other countries */ + var request = new XMLHttpRequest(); + request.open('GET', 'https://gaze.mysociety.org/gaze-rest?f=get_country_from_ip', true); + request.onreadystatechange = function() { + if (this.readyState === 4) { + if (this.status >= 200 && this.status < 400) { + var data = this.responseText; + if ( data && data != 'GB\n' ) { + var banner = document.createElement('div'); + banner.className = 'top_banner top_banner--country'; + var close = document.createElement('a'); + close.className = 'top_banner__close'; + close.innerHTML = 'Close'; + close.href = '#'; + close.onclick = function(e) { + document.querySelector('.top_banner--country').style.display = 'none'; + var t = new Date(); t.setFullYear(t.getFullYear() + 1); + document.cookie = 'has_seen_country_message=1; path=/; expires=' + t.toUTCString(); + }; + var p = document.createElement('p'); + p.innerHTML = 'This site is for reporting <strong>problems in the UK</strong>. There are FixMyStreet sites <a href="http://fixmystreet.org/sites/">all over the world</a>, or you could set up your own using the <a href="http://fixmystreet.org/">FixMyStreet Platform</a>.'; + banner.appendChild(close); + banner.appendChild(p); + document.body.insertBefore(banner, document.body.firstChild); + document.querySelector('.top_banner--country').style.display = 'block'; + } + } + } + }; + request.send(); + request = null; + +})(); diff --git a/web/cobrands/fixmystreet.com/js.js b/web/cobrands/fixmystreet.com/js.js index 087d5d15f..9ecb8b8c2 100644 --- a/web/cobrands/fixmystreet.com/js.js +++ b/web/cobrands/fixmystreet.com/js.js @@ -11,30 +11,3 @@ jQuery.validator.addMethod('validName', valid_name_factory(0), translation_strings.name.required); jQuery.validator.addMethod('validNameU', valid_name_factory(1), translation_strings.name.required); })(); - -$(function(){ - - /* Front page banner for other countries */ - - $('.top_banner__close').live('click', function() { - $('.top_banner--country').hide(); - var t = new Date(); t.setFullYear(t.getFullYear() + 1); - document.cookie = 'has_seen_country_message=1; path=/; expires=' + t.toUTCString(); - }); - - if ( $('body.frontpage').length && -1 == navigator.userAgent.indexOf('Google Page Speed')) { - if (document.cookie.indexOf('has_seen_country_message') === -1) { - $.ajax({ - url: 'https://gaze.mysociety.org/gaze-rest?f=get_country_from_ip', - success: function(data) { - if ( data && data != 'GB\n' ) { - var banner = '<div class="top_banner top_banner--country"><a href="#" class="top_banner__close">Close</a> <p>This site is for reporting <strong>problems in the UK</strong>. There are FixMyStreet sites <a href="http://www.fixmystreet.org/sites/">all over the world</a>, or you could set up your own using the <a href="http://www.fixmystreet.org/">FixMyStreet Platform</a>.</p></div>'; - $('body').prepend(banner); - $('.top_banner--country').slideDown('slow'); - } - } - }); - } - } - -}); |