Skip to:
Content

BuddyPress.org

Ticket #6935: 6935.01.patch

File 6935.01.patch, 2.6 KB (added by r-a-y, 8 years ago)
  • src/bp-messages/js/autocomplete/jquery.autocompletefb.js

     
    1919        var settings =
    2020        {
    2121                ul         : tmp,
    22                 urlLookup  : [""],
     22                urlLookup  : [''],
    2323                acOptions  : {},
    24                 foundClass : ".friend-tab",
    25                 inputClass : ".send-to-input"
    26         }
     24                foundClass : '.friend-tab',
     25                inputClass : '.send-to-input'
     26        };
    2727
    28         if(options) jQuery.extend(settings, options);
     28        if (options) {
     29                jQuery.extend(settings, options);
     30        }
    2931
    3032        var acfb =
    3133        {
     
    4042                        var newID = o.parentNode.id.substr( o.parentNode.id.indexOf('-')+1 );
    4143                        jQuery('#send-to-usernames').removeClass(newID);
    4244                }
    43         }
     45        };
    4446
    45         jQuery(settings.foundClass+" img.p").click(function(){
     47        jQuery(settings.foundClass+' img.p').click(function(){
    4648                acfb.removeFind(this);
    4749        });
    4850
    4951        jQuery(settings.inputClass,tmp).autocomplete(settings.urlLookup,settings.acOptions);
    5052        jQuery(settings.inputClass,tmp).result(function(e,d,f){
    51                 var f = settings.foundClass.replace(/\./,'');
    52                 var d = String(d).split(' (');
     53                f = settings.foundClass.replace(/\./,'');
     54                d = String(d).split(' (');
    5355                var un = d[1].substr(0, d[1].length-1);
    5456
    5557                /* Don't add the same user multiple times */
    5658                if( 0 === jQuery(settings.inputClass).siblings('#un-' + un).length ) {
     59                        // Get URL parameter function.
     60                        // http://stackoverflow.com/a/21903119
     61                        var getUrlParameter = function getUrlParameter(sParam) {
     62                                var sPageURL = decodeURIComponent(window.location.search.substring(1)),
     63                                sURLVariables = sPageURL.split('&'),
     64                                sParameterName,
     65                                i;
     66
     67                                for (i = 0; i < sURLVariables.length; i++) {
     68                                        sParameterName = sURLVariables[i].split('=');
     69
     70                                        if (sParameterName[0] === sParam) {
     71                                                return sParameterName[1] === undefined ? true : sParameterName[1];
     72                                        }
     73                                }
     74                        };
     75
    5776                        var ln = '#link-' + un;
    5877                        var l = jQuery(ln).attr('href');
    5978                        var v = '<li class="'+f+'" id="un-'+un+'"><span><a href="'+l+'">'+d[0]+'</a></span> <span class="p">X</span></li>';
    6079
    61                         var x = jQuery(settings.inputClass,tmp).closest('li').before(v);
     80                        var x;
     81                        // Check if we are attempting to PM a user via URL querystring.
     82                        if ( getUrlParameter('r') ) {
     83                                x = jQuery(settings.inputClass,tmp).before(v);
     84                        } else {
     85                                x = jQuery(settings.inputClass,tmp).closest('li').before(v);
     86                        }
     87
    6288                        jQuery('#send-to-usernames').addClass(un);
    6389
    6490                        jQuery('.p',x[0].previousSibling).click(function(){
     
    7298
    7399        jQuery(settings.inputClass,tmp).focus();
    74100        return acfb;
    75 }
     101};