some JS refactoring

This commit is contained in:
Laurent 2010-12-15 19:25:35 -05:00
parent b22398951e
commit 4515ba631f
7 changed files with 58 additions and 56 deletions

View file

@ -3,16 +3,15 @@
* the COPYRIGHT file.
*/
$("#edit_aspect_trigger").live("click",
function(){
$("#edit_aspect_trigger").live("click", function() {
EditPane.toggle();
}
);
});
var EditPane = {
setTranslations: function(translations) {
EditPane.translations = translations;
},
toggle: function() {
if( $("#edit_aspect_pane").hasClass("active") ) {
EditPane.fadeOut();
@ -21,22 +20,22 @@ var EditPane = {
}
},
fadeIn: function(){
fadeIn: function() {
var trigger = $("#edit_aspect_trigger");
$("#edit_aspect_pane").addClass("active");
$(".contact_pictures").fadeOut(200, function(){
$(".contact_pictures").fadeOut(200, function() {
$("#edit_aspect_pane").fadeIn(200);
trigger.html(EditPane.translations.doneEditing);
});
},
fadeOut: function(){
fadeOut: function() {
var trigger = $("#edit_aspect_trigger");
trigger.html(EditPane.translations.editAspect);
$("#edit_aspect_pane").removeClass("active");
$("#edit_aspect_pane").fadeOut(200, function(){
$("#edit_aspect_pane").fadeOut(200, function() {
$(".contact_pictures").fadeIn(200);
});
}

View file

@ -49,8 +49,13 @@ var AspectEdit = {
$.ajax({
type: "DELETE",
url: "/requests/" + person.attr('data-guid'),
data: {"accept" : true, "aspect_id" : dropzone.attr('data-aspect_id') },
success: function() { AspectEdit.onDeleteRequestSuccess(person, dropzone); }
data: {
"accept": true,
"aspect_id": dropzone.attr('data-aspect_id')
},
success: function() {
AspectEdit.onDeleteRequestSuccess(person, dropzone);
}
});
}
@ -59,11 +64,15 @@ var AspectEdit = {
$.ajax({
url: "/aspects/move_contact/",
data: {
"person_id" : person.attr('data-guid'),
"from" : person.attr('data-aspect_id'),
"to" : { "to" : dropzone.attr('data-aspect_id') }
"person_id": person.attr('data-guid'),
"from": person.attr('data-aspect_id'),
"to": {
"to": dropzone.attr('data-aspect_id')
}
},
success: function() { AspectEdit.onMovePersonSuccess(person, dropzone); }
success: function() {
AspectEdit.onMovePersonSuccess(person, dropzone);
}
});
}
@ -86,8 +95,7 @@ var AspectEdit = {
if( $(".person[data-guid='"+ person_id +"']").length == 1) {
AspectEdit.alertUser("You cannot remove the person from the last aspect");
}
else {
} else {
if (!person.hasClass('request')) {
$.ajax({
@ -118,7 +126,11 @@ var AspectEdit = {
$.ajax({
type: "PUT",
url: link,
data: {"aspect" : {"name" : $this.text() }}
data: {
"aspect": {
"name" : $this.text()
}
}
});
}
//update all other aspect links
@ -159,13 +171,9 @@ var AspectEdit = {
var old_request_count = request_html.match(/\d+/);
if (old_request_count == 1) {
$new_requests.html(
request_html.replace(/ \(\d+\)/, '')
);
$new_requests.html( request_html.replace(/ \(\d+\)/, '') );
} else {
$new_requests.html(
request_html.replace(/\d+/, old_request_count - 1)
);
$new_requests.html( request_html.replace(/\d+/, old_request_count - 1) );
}
},

View file

@ -4,10 +4,10 @@
*/
$(document).ready( function(){
$(document).ready(function() {
var List = {
initialize: function(){
$(".contact_list_search").keyup(function(e){
initialize: function() {
$(".contact_list_search").keyup(function(e) {
var search = $(this);
var list = $(this).siblings("ul").first();
var query = new RegExp(search.val(),'i');
@ -65,10 +65,10 @@ $(document).ready( function(){
$(this).fadeTo(200,1);
});
$('.added').live('mouseover', function(){
$('.added').live('mouseover', function() {
$(this).addClass("remove");
$(this).children("img").attr("src","/images/icons/monotone_close_exit_delete.png");
}).live('mouseout', function(){
}).live('mouseout', function() {
$(this).removeClass("remove");
$(this).children("img").attr("src","/images/icons/monotone_check_yes.png");
});

View file

@ -3,8 +3,8 @@
* the COPYRIGHT file.
*/
$(document).bind("mobileinit", function(){
$.extend( $.mobile , {
$(document).bind("mobileinit", function() {
$.extend($.mobile, {
ajaxLinksEnabled : false,
ajaxFormsEnabled : false
});

View file

@ -4,16 +4,16 @@
*/
var Mobile = {
initialize : function(){
initialize: function() {
$('#aspect_picker').change(Mobile.changeAspect);
},
changeAspect : function() {
changeAspect: function() {
Mobile.windowLocation('/aspects/' + $('#aspect_picker option:selected').val());
},
windowLocation : function(url) {
windowLocation: function(url) {
window.location = url;
},
}
};

View file

@ -3,7 +3,7 @@
* the COPYRIGHT file.
*/
$(document).ready( function(){
$(document).ready(function() {
//edit photo
$("#edit_photo_toggle").bind('click', function(evt) {
@ -36,26 +36,19 @@ $(document).ready( function(){
$('.make_profile_photo').bind('ajax:loading', function(data, json, xhr) {
var person_id = $(this).closest(".photo_options").attr('data-actor_person');
$("img[data-person_id='"+ person_id +"']").each( function() {
$(this).fadeTo(200,0.3);
});
$("img[data-person_id='" + person_id + "']").fadeTo(200, 0.3);
});
$('.make_profile_photo').bind('ajax:success', function(data, json, xhr) {
json = $.parseJSON(json);
$("img[data-person_id='"+ json['person_id'] +"']").each( function() {
$(this).fadeTo(200,1);
this.src = json['image_url_small'];
});
$("img[data-person_id='" + json['person_id'] + "']").fadeTo(200, 1).attr('src', json.image_url_small);
});
$('.make_profile_photo').bind('ajax:failure', function(data, json, xhr) {
var person_id = $(this).closest(".photo_options").attr('data-actor_person');
alert("Failed to update profile photo!");
$("img[data-person_id='"+ person_id +"']").each( function() {
$(this).fadeTo(200,1);
});
$("img[data-person_id='" + person_id + "']").fadeTo(200, 1);
});
});

View file

@ -1,17 +1,19 @@
/* Clear form plugin - called using $("elem").clearForm(); */
$.fn.clearForm = function() {
return this.each(function() {
var type = this.type, tag = this.tagName.toLowerCase();
if (tag == 'form')
return $(':input',this).clearForm();
if (type == 'text' || type == 'password' || tag == 'textarea')
this.value = '';
else if (type == 'checkbox' || type == 'radio')
this.checked = false;
else if (tag == 'select')
this.selectedIndex = -1;
else if (this.name == 'photos[]')
this.value = '';
var type = this.type, tag = this.tagName.toLowerCase();
if (tag == 'form') {
return $(':input',this).clearForm();
}
if (type == 'text' || type == 'password' || tag == 'textarea') {
this.value = '';
} else if (type == 'checkbox' || type == 'radio') {
this.checked = false;
} else if (tag == 'select') {
this.selectedIndex = -1;
} else if (this.name == 'photos[]') {
this.value = '';
}
$(this).blur();
});
};