adopt-a-hydrant/public/assets/application.js

1 line
16 KiB
JavaScript
Raw Normal View History

2011-12-19 09:36:27 +00:00
$(function(){function j(a,b,c){var j=new google.maps.MarkerImage(c,new google.maps.Size(27,37),new google.maps.Point(0,0),new google.maps.Point(13,18)),k=new google.maps.MarkerImage("/assets/markers/shadow.png",new google.maps.Size(46,37),new google.maps.Point(0,0),new google.maps.Point(13,18)),l=new google.maps.Marker({animation:google.maps.Animation.DROP,icon:j,map:d,position:b,shadow:k});google.maps.event.addListener(l,"click",function(){g&&g.close();var b=new google.maps.InfoWindow({maxWidth:350});google.maps.event.addListener(b,"closeclick",function(){h=!1}),g=b,e=a,f=l,$.ajax({type:"GET",url:"/info_window",data:{thing_id:a},success:function(a){b==g&&(b.setContent(a),b.open(d,l),h=!0)}})}),i.push(a)}function k(b,c){$.ajax({type:"GET",url:"/things.json",data:{commit:$('#address_form input[type="submit"]').val(),utf8:"✓",authenticity_token:$('#address_form input[name="authenticity_token"]').val(),lat:b,lng:c,limit:$('#address_form input[name="limit"]').val()},success:function(e){if(e.errors)$("#address_label").addClass("error",500),$("#address").addClass("error",500),$("#address").focus();else{$("#address_label").removeClass("error",500),$("#address").removeClass("error",500);var f=-1;$(e).each(function(a,b){if($.inArray(b.id,i)==-1)f+=1;else return!0;setTimeout(function(){point=new google.maps.LatLng(b.lat,b.lng),b.user_id?image_path="/assets/markers/green.png":image_path="/assets/markers/red.png",j(b.id,point,image_path)},f*100)}),a=new google.maps.LatLng(b,c),d.setCenter(a),d.setZoom(18)}}})}var a=new google.maps.LatLng(42.358431,-71.059773),b=15,c={center:a,mapTypeControl:!1,mapTypeId:google.maps.MapTypeId.ROADMAP,panControl:!1,zoom:b},d=new google.maps.Map(document.getElementById("map_canvas"),c),e,f,g,h=!1,i=[];google.maps.event.addListener(d,"dragend",function(){if(h==1)return;a=d.getCenter(),k(a.lat(),a.lng())}),$("#address_form").submit(function(){var a=$("#address_form input[type='submit']");$(a).attr("disabled",!0);var b=$(a).attr("value");return $(a).attr("value","Please Wait..."),$("#address").val()===""?($(a).attr("disabled",!1),$(a).attr("value",b),$("#address_label").addClass("error",500),$("#address").addClass("error",500),$("#address").focus()):$.ajax({type:"GET",url:"/address.json",data:{commit:a.val(),utf8:"✓",authenticity_token:$('#address_form input[name="authenticity_token"]').val(),city_state:$("#city_state").val(),address:$("#address").val()},success:function(c){$(a).attr("disabled",!1),$(a).attr("value",b),c.errors?($("#address_label").addClass("error",500),$("#address").addClass("error",500),$("#address").focus()):k(c[0],c[1])}}),!1}),$('#combo_form input[type="radio"]').live("click",function(){var a=$(this);"new"==a.val()?($("#user_forgot_password_fields").slideUp(),$("#user_sign_in_fields").slideUp(),$("#user_sign_up_fields").slideDown(),$("#combo_form").data("state","user_sign_up")):"existing"==a.val()&&($("#user_sign_up_fields").slideUp(),$("#user_sign_in_fields").slideDown(function(){$("#combo_form").data("state","user_sign_in"),$("#user_forgot_password_link").click(function(){$("#user_sign_in_fields").slideUp(),$("#user_forgot_password_fields").slideDown(function(){$("#user_remembered_password_link").click(function(){$("#user_forgot_password_fields").slideUp(),$("#user_sign_in_fields").slideDown(),$("#combo_form").data("state","user_sign_in")})}),$("#combo_form").data("state","user_forgot_password")})}))}),$("#combo_form").live("submit",function(){var a=$("#combo_form input[type='submit']");$(a).attr("disabled",!0);var b=[];return/[\w\.%\+\]+@[\w\]+\.+[\w]{2,}/.test($("#user_email").val())?($("#user_email_label").removeClass("error"),$("#user_email").removeClass("error")):(b.push($("#user_email")),$("#user_email_label").addClass("error",500),$("#user_email").addClass("error",500)),!$(this).data("state")||$(this).data("state")==="user_sign_up"?($("#user_name").val()===""?(b.push($("#user_name")),$("#user_name_label").addClass("error",500),$("#user_name").addClass("error",500)):($("#user_name_label").removeClass("error"),$("#user_name").removeClass("error")),$("#user_password_confir