diff options
author | Matthew Somerville <matthew@mysociety.org> | 2011-08-17 19:35:03 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2011-08-17 19:35:03 +0100 |
commit | f38b8e985697c35a62374a2f02dce2d681ef58cd (patch) | |
tree | b7111c864e5d84caa7df547cc4e04ae7d9f1cb8a /web | |
parent | 6df503adf0926b67c88466913034ad1b84e57aba (diff) |
Stop back button breakage.
Diffstat (limited to 'web')
-rw-r--r-- | web/js/jquery.ba-hashchange.min.js | 9 | ||||
-rw-r--r-- | web/js/map-OpenLayers.js | 20 |
2 files changed, 25 insertions, 4 deletions
diff --git a/web/js/jquery.ba-hashchange.min.js b/web/js/jquery.ba-hashchange.min.js new file mode 100644 index 000000000..3c607bae3 --- /dev/null +++ b/web/js/jquery.ba-hashchange.min.js @@ -0,0 +1,9 @@ +/* + * jQuery hashchange event - v1.3 - 7/21/2010 + * http://benalman.com/projects/jquery-hashchange-plugin/ + * + * Copyright (c) 2010 "Cowboy" Ben Alman + * Dual licensed under the MIT and GPL licenses. + * http://benalman.com/about/license/ + */ +(function($,e,b){var c="hashchange",h=document,f,g=$.event.special,i=h.documentMode,d="on"+c in e&&(i===b||i>7);function a(j){j=j||location.href;return"#"+j.replace(/^[^#]*#?(.*)$/,"$1")}$.fn[c]=function(j){return j?this.bind(c,j):this.trigger(c)};$.fn[c].delay=50;g[c]=$.extend(g[c],{setup:function(){if(d){return false}$(f.start)},teardown:function(){if(d){return false}$(f.stop)}});f=(function(){var j={},p,m=a(),k=function(q){return q},l=k,o=k;j.start=function(){p||n()};j.stop=function(){p&&clearTimeout(p);p=b};function n(){var r=a(),q=o(m);if(r!==m){l(m=r,q);$(e).trigger(c)}else{if(q!==m){location.href=location.href.replace(/#.*/,"")+q}}p=setTimeout(n,$.fn[c].delay)}$.browser.msie&&!d&&(function(){var q,r;j.start=function(){if(!q){r=$.fn[c].src;r=r&&r+a();q=$('<iframe tabindex="-1" title="empty"/>').hide().one("load",function(){r||l(a());n()}).attr("src",r||"javascript:0").insertAfter("body")[0].contentWindow;h.onpropertychange=function(){try{if(event.propertyName==="title"){q.document.title=h.title}}catch(s){}}}};j.stop=k;o=function(){return a(q.location.href)};l=function(v,s){var u=q.document,t=$.fn[c].domain;if(v!==s){u.title=h.title;u.open();t&&u.write('<script>document.domain="'+t+'"<\/script>');u.close();q.location.hash=v}}})();return j})()})(jQuery,this);
\ No newline at end of file diff --git a/web/js/map-OpenLayers.js b/web/js/map-OpenLayers.js index 2e6c77f12..d3914a128 100644 --- a/web/js/map-OpenLayers.js +++ b/web/js/map-OpenLayers.js @@ -41,6 +41,17 @@ $(function(){ return false; }); + $(window).hashchange(function(){ + if (location.hash) return; + // Okay, back to around view. + fixmystreet.bbox_strategy.activate(); + fixmystreet.markers.refresh( { force: true } ); + fixmystreet.drag.deactivate(); + $('#side-form').hide(); + $('#side').show(); + fixmystreet.page = 'around'; + }); + // Vector layers must be added onload as IE sucks if ($.browser.msie) { $(window).load(fixmystreet_onload); @@ -288,10 +299,10 @@ OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { fixmystreet.markers.features[0].move(lonlat); } else { var markers = fms_markers_list( [ [ lonlat.lat, lonlat.lon, 'purple' ] ], false ); + fixmystreet.bbox_strategy.deactivate(); fixmystreet.markers.removeAllFeatures(); fixmystreet.markers.addFeatures( markers ); fixmystreet_activate_drag(); - fixmystreet.bbox_strategy.deactivate(); } fixmystreet_update_pin(lonlat); if (fixmystreet.page == 'new') { @@ -307,6 +318,7 @@ OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, { $('#side-form').show(); $('#side').hide(); fixmystreet.page = 'new'; + location.hash = 'report'; } }); @@ -322,12 +334,12 @@ function fixmystreet_update_pin(lonlat) { } function fixmystreet_activate_drag() { - var drag = new OpenLayers.Control.DragFeature( fixmystreet.markers, { + fixmystreet.drag = new OpenLayers.Control.DragFeature( fixmystreet.markers, { onComplete: function(feature, e) { fixmystreet_update_pin( feature.geometry.clone() ); } } ); - fixmystreet.map.addControl( drag ); - drag.activate(); + fixmystreet.map.addControl( fixmystreet.drag ); + fixmystreet.drag.activate(); } |