Added strict equality operator to #publisher and #stream keydown event

Added caching of the $container jQuery object
Added caching of $controls and $this in the .make_profile_photo click event
changed the success callback to use this.src = photo_url; instead of creating a new jQuery object
This commit is contained in:
OhaiBBQ 2010-11-01 10:37:07 -07:00
parent 6474f5c5f3
commit 175e5bdc30

View file

@ -49,13 +49,13 @@ $(document).ready(function(){
); );
$("#publisher").find("textarea").keydown( function(e) { $("#publisher").find("textarea").keydown( function(e) {
if (e.keyCode == 13) { if (e.keyCode === 13) {
$(this).closest("form").submit(); $(this).closest("form").submit();
} }
}); });
$("#stream").delegate("textarea.comment_box", "keydown", function(e){ $("#stream").delegate("textarea.comment_box", "keydown", function(e){
if (e.keyCode == 13) { if (e.keyCode === 13) {
$(this).closest("form").submit(); $(this).closest("form").submit();
} }
}); });
@ -101,26 +101,29 @@ $.fn.clearForm = function() {
var video_active_container = null; var video_active_container = null;
function openVideo(type, videoid, link) { function openVideo(type, videoid, link) {
var container = document.createElement('div'); var container = document.createElement('div'),
$container = $(container);
if(type == 'youtube.com') { if(type == 'youtube.com') {
container.innerHTML = '<a href="http://www.youtube.com/watch?v='+videoid+'" target="_blank">Watch this video on Youtube</a><br><object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/'+videoid+'?fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+videoid+'?fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>'; $container.html('<a href="http://www.youtube.com/watch?v='+videoid+'" target="_blank">Watch this video on Youtube</a><br><object width="640" height="385"><param name="movie" value="http://www.youtube.com/v/'+videoid+'?fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/'+videoid+'?fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="385"></embed></object>');
} else { } else {
container.innerHTML = 'Invalid videotype <i>'+type+'</i> (ID: '+videoid+')'; $container.html('Invalid videotype <i>'+type+'</i> (ID: '+videoid+')');
} }
if(video_active_container != null) { if(video_active_container != null) {
video_active_container.parentNode.removeChild(video_active_container); video_active_container.parentNode.removeChild(video_active_container);
} }
video_active_container = container; video_active_container = container;
$(container).hide(); $container.hide();
link.parentNode.insertBefore(container, this.nextSibling); link.parentNode.insertBefore(container, this.nextSibling);
$(container).slideDown('fast', function() { }); $container.slideDown('fast', function() { });
link.onclick = function() { $(container).slideToggle('fast', function() { } ); } link.onclick = function() { $container.slideToggle('fast', function() { } ); }
} }
$(".make_profile_photo").live("click", function(){ $(".make_profile_photo").live("click", function(){
var user_id = $(this).closest(".controls").attr('data-actor'); var $this = $(this),
person_id = $(this).closest(".controls").attr('data-actor_person'); $controls = $this.closest(".controls"),
photo_url = $(this).closest(".controls").attr('data-image_url'); user_id = $controls.attr('data-actor');
person_id = $controls.attr('data-actor_person');
photo_url = $controls(".controls").attr('data-image_url');
$.ajax({ $.ajax({
type: "PUT", type: "PUT",
@ -128,7 +131,7 @@ $(".make_profile_photo").live("click", function(){
data: {"person":{"profile":{ "image_url": photo_url }}}, data: {"person":{"profile":{ "image_url": photo_url }}},
success: function(){ success: function(){
$("img[data-person_id='"+ person_id +"']").each( function() { $("img[data-person_id='"+ person_id +"']").each( function() {
$(this).attr('src', photo_url); this.src = photo_url;
}); });
} }
}); });