diff --git a/public/javascripts/photo.js b/public/javascripts/photo.js index 2991903d7..b0f8e0729 100644 --- a/public/javascripts/photo.js +++ b/public/javascripts/photo.js @@ -8,18 +8,20 @@ $(document).keydown(function(e){ switch(e.keyCode) { case 37: if(!$("textarea").hasClass("hasfocus")){//prevent redirect if textarea has focus - window.location = $("#prev_photo").attr('href'); + window.location = document.getElementById("prev_photo").href; } break; case 39: if(!$("textarea").hasClass("hasfocus")){ - window.location = $("#next_photo").attr('href'); + window.location = document.getElementById("next_photo").href; } break; } }); $(document).ready(function(){ + var $edit_photo = $(".edit_photo"); + //add a clas to verify if a textarea has focus $("textarea").live('focus',function(){ $(this).addClass("hasfocus"); @@ -34,13 +36,13 @@ $(document).ready(function(){ }); //Add a description with ajax request - $("#photo_submit").click(function(evenet){ + $("#photo_submit").click(function(event){ event.preventDefault(); - var method = $(".edit_photo").attr("method"); - var url = $(".edit_photo").attr("action"); - var data = $(".edit_photo").serialize(); - $(".description").text($("#photo_caption").val()); - $(".edit_photo").toggle(); + var method = $edit_photo.attr("method"); + var url = $edit_photo.attr("action"); + var data = $edit_photo.serialize(); + $(".description").text(document.getElementById("photo_caption").value); + $edit_photo.toggle(); $.ajax({ type: method,