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
This commit is contained in:
OhaiBBQ 2010-11-01 05:26:58 -07:00
parent fb13ff2212
commit c8e8ef06e7

View file

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