Skip to:
Content

BuddyPress.org

Changeset 9248


Ignore:
Timestamp:
12/21/2014 11:55:47 AM (10 years ago)
Author:
djpaul
Message:

Messages: update autocomplete script to better handle long cookie values.

See #4606 for previous similiar fixes.

Fixes #5959, props psycleuk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/deprecated/js/autocomplete/jquery.autocomplete.js

    r6264 r9248  
    327327                    limit: options.max,
    328328                    action: 'messages_autocomplete_results',
    329                     'cookie': encodeURIComponent(document.cookie)
     329                    'cookie': getAutocompleteCookies()
    330330                }, extraParams),
    331331                success: function(data) {
     
    362362    };
    363363
     364    /* Returns a querystring of BP cookies (cookies beginning with 'bp-') */
     365    function getAutocompleteCookies() {
     366        var allCookies = document.cookie.split(';'),  // get all cookies and split into an array
     367            bpCookies      = {},
     368            cookiePrefix   = 'bp-',
     369            i, cookie, delimiter, name, value;
     370
     371        // loop through cookies
     372        for (i = 0; i < allCookies.length; i++) {
     373            cookie    = allCookies[i];
     374            delimiter = cookie.indexOf('=');
     375            name      = jq.trim( unescape( cookie.slice(0, delimiter) ) );
     376            value     = unescape( cookie.slice(delimiter + 1) );
     377
     378            // if BP cookie, store it
     379            if ( name.indexOf(cookiePrefix) === 0 ) {
     380                bpCookies[name] = value;
     381            }
     382        }
     383
     384        // returns BP cookies as querystring
     385        return encodeURIComponent( jq.param(bpCookies) );
     386    }
    364387};
    365388
Note: See TracChangeset for help on using the changeset viewer.