var angellist = angellist || {}; angellist.company_selector = { // Plugin / JS version version: '1.2', // English labels for inserted text. Overridden with localized values through PHP output with special event trigger labels: { remove: "Delete", no_results: "No results found.", search: "Add a company:", search_placeholder: "Start typing..." }, // keep track of companies already on the page to prevent duplicates when adding company_ids: [], // create an ordered list to display companies and their input values create_company_list: function() { var results_div = jQuery( "#angellist-company-selector-results" ); if ( results_div.length === 0 ) { return; } results_div.html( "" ); angellist.company_selector.company_list = jQuery( "
    " ).attr( "id", "angellist-company-selector-companies" ); results_div.append( angellist.company_selector.company_list ); angellist.company_selector.enable_editable_company_list(); }, // add a company to the list add_company: function( company ) { // test for minimum properties if ( ! jQuery.isPlainObject( company ) || company.value === undefined || company.value === "" || company.label === undefined || jQuery.inArray( company.value, angellist.company_selector.company_ids ) > -1 ) { return; } if ( angellist.company_selector.company_list === undefined || angellist.company_selector.company_list.length === 0 ) { angellist.company_selector.create_company_list(); } var current_position = angellist.company_selector.company_ids.length; var li = jQuery( "
  1. " ).text( company.label ); li.append( jQuery( "" ).attr( { type:"hidden", name:"angellist-company[" + current_position + "][id]" } ).addClass( "angellist-company-id" ).val( company.value ) ); li.append( jQuery( "" ).attr( { type:"hidden", name:"angellist-company[" + current_position + "][name]" } ).val( company.label ) ); li.append( angellist.company_selector.company_delete_button() ); li.mouseenter( angellist.company_selector.company_mouseenter ).mouseleave( angellist.company_selector.company_mouseleave ); angellist.company_selector.company_list.append( li ); angellist.company_selector.company_ids.push( company.value ); if ( angellist.company_selector.company_ids.length == 2 ) { angellist.company_selector.enable_editable_company_list(); } }, // centralize the delete button HTML and events generation company_delete_button: function() { return jQuery( "