From c8e8ef06e7326c109fb86138ad3e2ea642b8bc92 Mon Sep 17 00:00:00 2001 From: OhaiBBQ Date: Mon, 1 Nov 2010 05:26:58 -0700 Subject: [PATCH] You don't need to make a new jQuery object to do that. Fixed typo in the click param Cache the .edit_photo jQuery object --- public/javascripts/photo.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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,