contact-js as its own file
This commit is contained in:
parent
5041a84882
commit
3ada121d0b
3 changed files with 89 additions and 87 deletions
|
|
@ -3,95 +3,8 @@
|
|||
-# the COPYRIGHT file.
|
||||
|
||||
|
||||
- content_for :head do
|
||||
:javascript
|
||||
$(document).ready( function(){
|
||||
|
||||
var ContactList = {
|
||||
initialize: function(){
|
||||
$(".contact_list_search").keyup(function(e){
|
||||
var search = $(this);
|
||||
var list = $(this).siblings("ul").first();
|
||||
var query = new RegExp(search.val(),'i');
|
||||
|
||||
$("li", list).each( function() {
|
||||
var element = $(this);
|
||||
if( !element.text().match(query) ){
|
||||
if( !element.hasClass('invis') ){
|
||||
element.addClass('invis').fadeOut(100);
|
||||
}
|
||||
} else {
|
||||
element.removeClass('invis').fadeIn(100);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
refreshContactCount: function(){
|
||||
var contactCountElement = $(".aspect_contact_count"),
|
||||
contactCount = $(".contact_pictures")[0].childElementCount,
|
||||
newHTML = contactCountElement.html().replace(/\d+/,contactCount);
|
||||
|
||||
contactCountElement.html(newHTML);
|
||||
}
|
||||
};
|
||||
|
||||
$('.added').live('ajax:loading', function(data, html, xhr) {
|
||||
$(this).fadeTo(200,0.4);
|
||||
});
|
||||
|
||||
$('.added').live('ajax:success', function(data, html, xhr) {
|
||||
var person_id = $(this).closest("li").find(".avatar").attr("data-person_id");
|
||||
$(".contact_pictures").find("img[data-person_id='"+person_id+"']").parent().remove();
|
||||
|
||||
$(this).parent().html(html);
|
||||
ContactList.refreshContactCount();
|
||||
|
||||
if( $(".contact_pictures")[0].childElementCount == 0 ) {
|
||||
$("#no_contacts").fadeIn(200);
|
||||
}
|
||||
|
||||
$(this).fadeTo(200,1);
|
||||
});
|
||||
|
||||
$('.added').live('ajax:failure', function(data, html, xhr) {
|
||||
alert("#{t('.cannot_remove')}");
|
||||
$(this).fadeTo(200,1);
|
||||
});
|
||||
|
||||
$('.add').live('ajax:loading', function(data, html, xhr) {
|
||||
$(this).fadeTo(200,0.4);
|
||||
});
|
||||
|
||||
$('.add').live('ajax:success', function(data, html, xhr) {
|
||||
var person_image = $(this).closest("li").find(".avatar")
|
||||
person_image.parent().clone().appendTo(".contact_pictures");
|
||||
|
||||
$(this).parent().html(html);
|
||||
ContactList.refreshContactCount();
|
||||
|
||||
if( $("#no_contacts").is(':visible') ) {
|
||||
$("#no_contacts").fadeOut(200);
|
||||
}
|
||||
|
||||
$(this).fadeTo(200,1);
|
||||
});
|
||||
|
||||
$('.added').live('mouseover', function(){
|
||||
$(this).addClass("remove");
|
||||
$(this).children("img").attr("src","/images/icons/monotone_close_exit_delete.png");
|
||||
}).live('mouseout', function(){
|
||||
$(this).removeClass("remove");
|
||||
$(this).children("img").attr("src","/images/icons/monotone_check_yes.png");
|
||||
});
|
||||
|
||||
ContactList.initialize();
|
||||
});
|
||||
|
||||
|
||||
.contact_list
|
||||
= search_field_tag :contact_search, "", :class => 'contact_list_search', :results => 5, :placeholder => t('.all_contacts')
|
||||
|
||||
%ul
|
||||
- for contact in contacts
|
||||
%li
|
||||
|
|
@ -99,3 +12,4 @@
|
|||
= link_to contact.person.real_name, contact.person
|
||||
.right
|
||||
= aspect_membership_button(aspect_id, contact)
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ javascripts:
|
|||
aspects:
|
||||
- public/javascripts/vendor/jquery-ui-1.8.6.custom.min.js
|
||||
- public/javascripts/aspect-edit.js
|
||||
- public/javascripts/contact-list.js
|
||||
|
||||
stylesheets:
|
||||
default:
|
||||
|
|
|
|||
87
public/javascripts/contact-list.js
Normal file
87
public/javascripts/contact-list.js
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/* Copyright (c) 2010, Diaspora Inc. This file is
|
||||
* licensed under the Affero General Public License version 3 or later. See
|
||||
* the COPYRIGHT file.
|
||||
*/
|
||||
|
||||
|
||||
$(document).ready( function(){
|
||||
var ContactList = {
|
||||
initialize: function(){
|
||||
$(".contact_list_search").keyup(function(e){
|
||||
var search = $(this);
|
||||
var list = $(this).siblings("ul").first();
|
||||
var query = new RegExp(search.val(),'i');
|
||||
|
||||
$("li", list).each( function() {
|
||||
var element = $(this);
|
||||
if( !element.text().match(query) ){
|
||||
if( !element.hasClass('invis') ){
|
||||
element.addClass('invis').fadeOut(100);
|
||||
}
|
||||
} else {
|
||||
element.removeClass('invis').fadeIn(100);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
refreshContactCount: function(){
|
||||
var contactCountElement = $(".aspect_contact_count"),
|
||||
contactCount = $(".contact_pictures")[0].childElementCount,
|
||||
newHTML = contactCountElement.html().replace(/\d+/,contactCount);
|
||||
|
||||
contactCountElement.html(newHTML);
|
||||
}
|
||||
};
|
||||
|
||||
$('.added').live('ajax:loading', function(data, html, xhr) {
|
||||
$(this).fadeTo(200,0.4);
|
||||
});
|
||||
|
||||
$('.added').live('ajax:success', function(data, html, xhr) {
|
||||
var person_id = $(this).closest("li").find(".avatar").attr("data-person_id");
|
||||
$(".contact_pictures").find("img[data-person_id='"+person_id+"']").parent().remove();
|
||||
|
||||
$(this).parent().html(html);
|
||||
ContactList.refreshContactCount();
|
||||
|
||||
if( $(".contact_pictures")[0].childElementCount == 0 ) {
|
||||
$("#no_contacts").fadeIn(200);
|
||||
}
|
||||
|
||||
$(this).fadeTo(200,1);
|
||||
});
|
||||
|
||||
$('.added').live('ajax:failure', function(data, html, xhr) {
|
||||
alert("#{t('.cannot_remove')}");
|
||||
$(this).fadeTo(200,1);
|
||||
});
|
||||
|
||||
$('.add').live('ajax:loading', function(data, html, xhr) {
|
||||
$(this).fadeTo(200,0.4);
|
||||
});
|
||||
|
||||
$('.add').live('ajax:success', function(data, html, xhr) {
|
||||
var person_image = $(this).closest("li").find(".avatar")
|
||||
person_image.parent().clone().appendTo(".contact_pictures");
|
||||
|
||||
$(this).parent().html(html);
|
||||
ContactList.refreshContactCount();
|
||||
|
||||
if( $("#no_contacts").is(':visible') ) {
|
||||
$("#no_contacts").fadeOut(200);
|
||||
}
|
||||
|
||||
$(this).fadeTo(200,1);
|
||||
});
|
||||
|
||||
$('.added').live('mouseover', function(){
|
||||
$(this).addClass("remove");
|
||||
$(this).children("img").attr("src","/images/icons/monotone_close_exit_delete.png");
|
||||
}).live('mouseout', function(){
|
||||
$(this).removeClass("remove");
|
||||
$(this).children("img").attr("src","/images/icons/monotone_check_yes.png");
|
||||
});
|
||||
|
||||
ContactList.initialize();
|
||||
});
|
||||
Loading…
Reference in a new issue