[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-messages/js/autocomplete/ -> jquery.autocompletefb.js (source)

   1  /*!
   2   * jQuery plugin: autoCompletefb(AutoComplete Facebook)
   3   * @requires jQuery v1.2.2 or later
   4   * using plugin:jquery.autocomplete.js
   5   *
   6   * Credits:
   7   * - Idea: Facebook
   8   * - Guillermo Rauch: Original MooTools script
   9   * - InteRiders <http://interiders.com/>
  10   *
  11   * Copyright (c) 2008 Widi Harsojo <wharsojo@gmail.com>, http://wharsojo.wordpress.com/
  12   * Dual licensed under the MIT and GPL licenses:
  13   *   http://www.opensource.org/licenses/mit-license.php
  14   *   http://www.gnu.org/licenses/gpl.html
  15   */
  16  jQuery.fn.autoCompletefb = function(options)
  17  {
  18      var tmp = this;
  19      var settings =
  20      {
  21          ul         : tmp,
  22          urlLookup  : [""],
  23          acOptions  : {},
  24          foundClass : ".friend-tab",
  25          inputClass : ".send-to-input"
  26      }
  27  
  28      if(options) jQuery.extend(settings, options);
  29  
  30      var acfb =
  31      {
  32          params  : settings,
  33          removeFind : function(o){
  34              acfb.removeUsername(o);
  35              jQuery(o).unbind('click').parent().remove();
  36              jQuery(settings.inputClass,tmp).focus();
  37              return tmp.acfb;
  38          },
  39          removeUsername: function(o){
  40              var newID = o.parentNode.id.substr( o.parentNode.id.indexOf('-')+1 );
  41              jQuery('#send-to-usernames').removeClass(newID);
  42          }
  43      }
  44  
  45      jQuery(settings.foundClass+" img.p").click(function(){
  46          acfb.removeFind(this);
  47      });
  48  
  49      jQuery(settings.inputClass,tmp).autocompletebp(settings.urlLookup,settings.acOptions);
  50      jQuery(settings.inputClass,tmp).result(function(e,d,f){
  51          var f = settings.foundClass.replace(/\./,'');
  52          var d = String(d).split(' (');
  53          var un = d[1].substr(0, d[1].length-1);
  54  
  55          /* Don't add the same user multiple times */
  56          if( 0 === jQuery(settings.inputClass).siblings('#un-' + un).length ) {
  57              var ln = '#link-' + un;
  58              var l = jQuery(ln).attr('href');
  59              var v = '<li class="'+f+'" id="un-'+un+'"><span><a href="'+l+'">'+d[0]+'</a></span> <span class="p">X</span></li>';
  60  
  61              var x = jQuery(settings.inputClass,tmp).before(v);
  62              jQuery('#send-to-usernames').addClass(un);
  63  
  64              jQuery('.p',x[0].previousSibling).click(function(){
  65                  acfb.removeFind(this);
  66              });
  67          }
  68  
  69          jQuery(settings.inputClass,tmp).val('');
  70  
  71      });
  72  
  73      jQuery(settings.inputClass,tmp).focus();
  74      return acfb;
  75  }


Generated: Sat Nov 16 01:01:36 2019 Cross-referenced by PHPXref 0.7.1