1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| $().ready(function(){
var ajaxResponse = "#ajax_response";
var ids = new Array();
// initialization's
$("<div id='ajax_response'></div>").insertBefore(inputBox);
$(mainHolder).addClass("fb_holder");
if(ajaxFilePath == "")
alert("Please set value for 'ajaxFilePath'");
// on focus of textbox show friends list
$(inputBox).keyup(function(event){
var p = $(mainHolder);
var offset = p.offset();
// create ajax request and get all the friend names starting with name XXX
var keyword = $(inputBox).val();
// remove select-friend class
if(keyword.length)
{
if(event.keyCode != 40 && event.keyCode != 38 && event.keyCode != 13)
{
$(ajaxResponse).css("left",parseInt(offset.left));
$(ajaxResponse).css("top",parseInt(offset.top + $(mainHolder).height()));
$(ajaxResponse).css("opacity","0.9");
$(ajaxResponse).css("width",parseInt($(mainHolder).width()));
if(ajaxFilePath != "")
{
$.ajax({
type: "POST",
url: ajaxFilePath,
data: "data="+keyword,
success: function(rep){
if(rep != 0)
$(ajaxResponse).html(rep).css("display","block");
}
});
}
}
}
});
// on click of list item mark that friend as selected
$("#close").live("click",function(){
var found = "";
// remove selected friend
$(this).parent().css("display","none");
// get id of selected item
var index = $(this).parent(".added").attr("id");
// remove selected index
if(index != " " || index != "undefined")
ids.splice(parseInt(found),1);
// print updated ids
$("#selected_ids").val(ids);
});
$(".list li").live("mouseover",function () {
$("li[class='selected']").removeClass("selected");
$(this).addClass("selected");
});
$(".list li").live("mouseout",function () {
$("li .selected").removeClass("selected");
$(this).removeClass("selected");
});
$(".list li").live("click",function () {
var text = $(this).text();
var id = $(this).find("a").attr("id");
// mark friend as selected and add to selected ist
$(this).addFriend(text,id);
});
$(".added").live("mouseover",function(){
$(this).addClass("added-hover");
});
$(".added").live("mouseout",function(){
$(this).removeClass("added-hover");
$(this).addClass("added");
});
$(".added").live("click",function(){
$(mainHolder).find(".selected-friend").removeClass("selected-friend");
$(this).addClass("selected-friend");
$(this).find("#close").css("color","white");
});
jQuery.fn.addFriend = function(text,id) {
{
$("<div class='added' id='"+id+"'>"+text+"<span id='close'>x</span></div>").prependTo($(mainHolder));
// hide list
$(".list").css("display","none");
// clear textbox
$(inputBox).val("").focus();
}
// insert selected id to array
ids.push(id);
// print selected ids in textbox
$("#selected_ids").val(ids);
}
}); |
Partager