diff options
Diffstat (limited to 'www/js/fixmystreet.js')
-rw-r--r-- | www/js/fixmystreet.js | 141 |
1 files changed, 41 insertions, 100 deletions
diff --git a/www/js/fixmystreet.js b/www/js/fixmystreet.js index 9b8708f..71a4f96 100644 --- a/www/js/fixmystreet.js +++ b/www/js/fixmystreet.js @@ -77,21 +77,57 @@ function tabs(elem, indirect) { } -$(function(){ +$(document).delegate( '#front-page', 'pageshow', function(event, ui) { + // Geolocation + if (geo_position_js.init() && !$('#geolocate_link').length) { + console.log('adding thing'); + $('#postcodeForm').after('<a href="#" id="geolocate_link">… or locate me automatically</a>'); + $('#geolocate_link').click(getPosition); + } +}); + +$(document).bind('pageshow', function(){ var $html = $('html'); $html.removeClass('no-js').addClass('js'); - // Preload the new report pin document.createElement('img').src = '../i/pin-green.png'; var last_type; $(window).resize(function(){ + var footer = $("div[data-role='footer']:visible"), + content = $("div[data-role='content']:visible:visible"), + viewHeight = $(window).height(), + contentHeight = viewHeight - footer.outerHeight(); + $html.addClass('mobile'); + if (typeof fixmystreet !== 'undefined' && fixmystreet.page == 'around') { + // Immediately go full screen map if on around page + $('#map_box').css({ + position: 'absolute', + top: 0, left: 0, right: 0, bottom: 0, + height: contentHeight, + margin: 0 + }); + $('#fms_pan_zoom').css({ top: '2.75em !important' }); + } else { + $('#map_box').css({ + zIndex: '', position: '', + top: '', left: '', right: '', bottom: '', + width: '', height: '10em', + margin: '' + }); + } + + $('span.report-a-problem-btn').on('click.reportBtn', function(){ + $('html, body').animate({scrollTop:0}, 500); + }).css({ cursor:'pointer' }).on('hover.reportBtn', function(){ + $(this).toggleClass('hover'); + }); var crosshairsControls, i, markHere, newX, newY; - if (typeof fixmystreet.map !== "undefined") { + if (typeof fixmystreet !== 'undefined' && typeof fixmystreet.map !== "undefined") { // Update the position of any crosshairs controls: crosshairsControls = fixmystreet.map.getControlsByClass( "OpenLayers.Control.Crosshairs"); @@ -99,6 +135,7 @@ $(function(){ crosshairsControls[i].reposition(); } // Also reposition the "Tap here to mark this point" button: + console.log('reposition mark-here'); markHere = $('#mark-here'); newX = $(window).width() / 2 - markHere.width() / 2; newY = $(window).height() * 4 / 5 - markHere.height() / 2; @@ -106,87 +143,13 @@ $(function(){ left: newX + "px", top: newY + "px" }); + console.log( newX + ', ' + newY ); } - - var type = $('#site-header').css('borderTopWidth'); - if (type == '4px') { - type = 'mobile'; - } else if (type == '0px') { - type = 'desktop'; } - else { - return; - } - if (last_type == type) { - return; - } - if (type == 'mobile') { - $html.addClass('mobile'); - $('#map_box').prependTo('.content').css({ - zIndex: '', position: '', - top: '', left: '', right: '', bottom: '', - width: '', height: '10em', - margin: '' - }); - if (typeof fixmystreet !== 'undefined') { - fixmystreet.state_map = ''; // XXX - } - if (typeof fixmystreet !== 'undefined' && fixmystreet.page == 'around') { - // Immediately go full screen map if on around page - $('#site-header').hide(); - $('#map_box').prependTo('.wrapper').css({ - position: 'absolute', - top: 0, left: 0, right: 0, bottom: 0, - height: 'auto', - margin: 0 - }); - $('#fms_pan_zoom').css({ top: '2.75em !important' }); - $('.big-green-banner') - .addClass('mobile-map-banner') - .appendTo('#map_box') - .text('Place pin on map') - .prepend('<a href="index.html">home</a>'); - } - $('span.report-a-problem-btn').on('click.reportBtn', function(){ - $('html, body').animate({scrollTop:0}, 500); - }).css({ cursor:'pointer' }).on('hover.reportBtn', function(){ - $(this).toggleClass('hover'); - }); - } else { - // Make map full screen on non-mobile sizes. - $html.removeClass('mobile'); - var map_pos = 'fixed', map_height = '100%'; - if ($html.hasClass('ie6')) { - map_pos = 'absolute'; - map_height = $(window).height(); - } - $('#map_box').prependTo('.wrapper').css({ - zIndex: 0, position: map_pos, - top: 0, left: 0, right: 0, bottom: 0, - width: '100%', height: map_height, - margin: 0 - }); - if (typeof fixmystreet !== 'undefined') { - fixmystreet.state_map = 'full'; - } - if (typeof fixmystreet !== 'undefined' && fixmystreet.page == 'around') { - // Remove full-screen-ness - $('#site-header').show(); - $('#fms_pan_zoom').css({ top: '4.75em !important' }); - $('.big-green-banner') - .removeClass('mobile-map-banner') - .prependTo('#side') - .text('Click map to report a problem'); - } - $('span.report-a-problem-btn').css({ cursor:'' }).off('.reportBtn'); - } - last_type = type; }); //add mobile class if small screen $(window).resize(); - $('#pc').focus(); - $('input[type=submit]').removeAttr('disabled'); /* $('#mapForm').submit(function() { @@ -286,12 +249,6 @@ $(function(){ $('#form_category').change( form_category_onchange ); - // Geolocation - if (geo_position_js.init()) { - $('#postcodeForm').after('<a href="#" id="geolocate_link">… or locate me automatically</a>'); - $('#geolocate_link').click(getPosition); - } - /* * Report a problem page */ @@ -363,7 +320,6 @@ $(function(){ /* * Show stuff on input focus */ - $('.form-focus-hidden').hide(); $('.form-focus-trigger').on('focus', function(){ $('.form-focus-hidden').fadeIn(500); }); @@ -580,19 +536,4 @@ $.fn.drawer = function(id, ajax) { heightFix(window, '.content', -176); } } - -}); - -/* -XXX Disabled because jerky on Android and makes map URL bar height too small on iPhone. -// Hide URL bar -$(window).load(function(){ - window.setTimeout(function(){ - var s = window.pageYOffset || document.compatMode === "CSS1Compat" && document.documentElement.scrollTop || document.body.scrollTop || 0; - if (s < 20 && !location.hash) { - window.scrollTo(0, 1); - } - }, 0); }); -*/ - |