Ticket #3278: autosuggest-41.patch
| File autosuggest-41.patch, 24.8 KB (added by , 15 years ago) |
|---|
-
bp-themes/bp-default/_inc/css/default.css
1058 1058 margin-left: 54px; 1059 1059 padding-left: 22px; 1060 1060 } 1061 form#whats-new-form #whats-new-textarea {1061 form#whats-new-form textarea { 1062 1062 background: #fff; 1063 1063 border: 1px inset #ccc; 1064 1064 -moz-border-radius: 3px; 1065 1065 -webkit-border-radius: 3px; 1066 1066 border-radius: 3px; 1067 margin-bottom: 10px;1068 padding: 8px;1069 }1070 form#whats-new-form textarea {1071 border: none;1072 1067 color: #555; 1073 1068 font-family: inherit; 1074 1069 font-size: 14px; 1075 1070 height: 50px; 1076 margin: 0; 1077 padding: 0; 1078 width: 100%; 1071 padding: 1%; 1072 width: 98%; 1079 1073 } 1080 1074 form#whats-new-form #whats-new-options select { 1081 1075 max-width: 200px; 1082 1076 } 1083 1077 form#whats-new-form #whats-new-submit { 1084 1078 float: right; 1085 margin : 0;1079 margin-top: 12px; 1086 1080 } 1087 1081 #whats-new-options { 1088 1082 margin-bottom: 18px; -
bp-themes/bp-default/_inc/global.js
1067 1067 jq.cookie('bp-' + objects[i] + '-extras', null, {path: '/'} ); 1068 1068 }); 1069 1069 }); 1070 1071 // @mentions autosuggest 1072 if (jQuery.fn.mentions) { 1073 jQuery('#comment').mentions(); // comments 1074 jQuery('#whats-new').mentions({ resultsbox : '#whats-new-options', resultsbox_position : 'prepend' }); // What's new / status update 1075 jQuery('#message_content').mentions({ resultsbox : '#message_content', resultsbox_position : 'after' }); // messaging (body) 1076 jQuery('#topic_text').mentions({ resultsbox : '#topic_text', resultsbox_position : 'after' }); // forums (bbPress standalone) 1077 jQuery('#reply_text').mentions({ resultsbox : '#reply_text', resultsbox_position : 'after' }); // forums (bbPress standalone) 1078 } 1070 1079 }); 1071 1080 1072 1081 /* Setup activity scope and filter based on the current cookie settings. */ -
bp-activity/bp-activity-actions.php
315 315 } 316 316 add_action( 'bp_actions', 'bp_activity_action_favorites_feed' ); 317 317 318 ?> 318 /** 319 * AJAX receiver for the @mention autosuggest jQuery library. Performs a search on the string provided and returns matches. 320 * 321 * @global object $bp BuddyPress global settings 322 * @return mixed Either HTML or JSON. If error, "-1" for missing parameters, "0" for no matches. 323 * @see bp-activity/js/jquery.mentions.js 324 * @since 1.3 325 */ 326 function bp_activity_mention_autosuggest() { 327 global $bp; 328 329 if ( empty( $_POST['limit'] ) || empty( $_POST['search'] ) ) 330 exit( '-1' ); 331 332 // Sanitise input 333 $search_query = implode( '', (array) preg_replace( array( '|^https?://|i', '|\*|', '|@|' ), '', $_POST['search'] ) ); 334 if ( empty( $search_query ) ) 335 exit( '-1' ); 336 337 $args = array( 338 'count_total' => false, 339 'number' => (int) $_POST['limit'], 340 'search' => "{$search_query}*" 341 ); 342 343 if ( !empty( $bp->loggedin_user->id ) ) 344 $args['exclude'] = array( $bp->loggedin_user->id ); 345 346 if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) ) { 347 $args['fields'] = array( 'ID', 'user_login' ); 348 $args['orderby'] = 'login'; 349 350 } else { 351 $args['fields'] = array( 'ID', 'user_nicename' ); 352 $args['orderby'] = 'nicename'; 353 } 354 355 $args = apply_filters( 'bp_activity_mention_autosuggest_args', $args ); 356 357 // Search users 358 $user_search_results = get_users( $args ); 359 if ( empty( $user_search_results ) ) { 360 361 // Return JSON 362 if ( !empty( $_POST['format'] ) && 'json' == $_POST['format'] ) { 363 exit( json_encode( false ) ); 364 365 // Return HTML 366 } else { 367 printf( '<li class="section error"><p><span>%s</span> %s</p></li>', _x( 'No matches found.', 'no search results', 'buddypress' ), _x( 'Please check your spelling.', 'no search results', 'buddypress' ) ); 368 exit(); 369 } 370 } 371 372 // If logged in, get user's friends 373 $friend_ids = array(); 374 if ( !empty( $bp->loggedin_user->id ) ) 375 $friend_ids = friends_get_friend_user_ids( $bp->loggedin_user->id ); 376 377 $search_results = array( 'friends' => array(), 'others' => array() ); 378 379 // Build results 380 foreach ( (array) $user_search_results as $user ) { 381 $result = new stdClass; 382 $result->avatar = bp_core_fetch_avatar( array( 'item_id' => $user->ID, 'width' => 30, 'height' => 30, 'type' => 'thumb', 'alt' => __( 'Profile picture of %s', 'buddypress' ) ) ); 383 $result->name = bp_core_get_user_displayname( $user->ID ); 384 385 if ( defined( 'BP_ENABLE_USERNAME_COMPATIBILITY_MODE' ) ) 386 $result->id = $user->user_login; 387 else 388 $result->id = $user->user_nicename; 389 390 if ( in_array( $user->ID, $friend_ids ) ) 391 $search_results['friends'][] = $result; 392 else 393 $search_results['others'][] = $result; 394 } 395 396 apply_filters_ref_array( 'bp_activity_mention_autosuggest', array( &$search_results, $args ) ); 397 398 // Return JSON 399 if ( !empty( $_POST['format'] ) && 'json' == $_POST['format'] ) { 400 exit( json_encode( $search_results ) ); 401 402 // Return HTML 403 } else { 404 $html = array(); 405 406 foreach ( $search_results as $section => $items ) { 407 if ( empty( $items ) ) 408 continue; 409 410 // Friends and other users 411 if ( 'friends' == $section || 'others' == $section ) { 412 if ( 'friends' == $section ) { 413 $html[] = sprintf( '<li class="section friends"><p>%s</p></li>', __( 'Your friends:', 'buddypress' ) ); 414 415 } elseif ( 'others' == $section ) { 416 if ( !empty( $search_results['friends'] ) ) 417 $html[] = sprintf( '<li class="section other"><p>%s</p></li>', sprintf( __( 'Other people on %s:', 'buddypress' ), get_bloginfo( 'name', 'display' ) ) ); 418 else 419 $html[] = sprintf( '<li class="section other"><p>%s</p></li>', sprintf( __( 'People on %s:', 'buddypress' ), get_bloginfo( 'name', 'display' ) ) ); 420 } 421 422 foreach ( $items as $item ) 423 $html[] = sprintf( '<li class=%s><p>%s</p></li>', esc_attr( $item->id ), $item->avatar . esc_html( $item->name ) ); 424 425 // For third-party extensions 426 } else { 427 $custom_section = apply_filters( 'bp_activity_mention_autosuggest_custom_section', false, $section, $items ); 428 429 if ( !empty( $custom_section ) ) 430 $html = array_merge( $html, (array) $custom_section ); 431 } 432 } 433 434 // Safety net 435 if ( empty( $html ) ) 436 $html[] = sprintf( '<li class="section error"><p><span>%s</span> %s</p></li>', _x( 'No matches found.', 'no search results', 'buddypress' ), _x( 'Please check your spelling.', 'no search results', 'buddypress' ) ); 437 438 exit( apply_filters( 'bp_activity_mention_autosuggest_html', implode( PHP_EOL, $html ), $html ) ); 439 } 440 } 441 add_action( 'wp_ajax_activity_mention_autosuggest', 'bp_activity_mention_autosuggest' ); 442 ?> 443 No newline at end of file -
bp-activity/bp-activity-loader.php
1 1 <?php 2 3 2 /** 4 3 * BuddyPress Activity Streams Loader 5 4 * … … 267 266 268 267 parent::_setup_title(); 269 268 } 269 270 /** 271 * Register the @mentions autosuggest stuff 272 * 273 * @since BuddyPress 1.3 274 * @access private 275 */ 276 function _setup_actions() { 277 parent::_setup_actions(); 278 279 if ( is_admin() ) 280 return; 281 282 if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) 283 wp_enqueue_script( 'bp-activity-mentions-js', BP_PLUGIN_URL . '/bp-activity/js/jquery.mentions.dev.js', array( 'jquery' ), '1.0' ); 284 else 285 wp_enqueue_script( 'bp-activity-mentions-js', BP_PLUGIN_URL . '/bp-activity/js/jquery.mentions.js', array( 'jquery' ), '1.0' ); 286 287 if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) 288 wp_enqueue_style( 'bp-activity-mentions', BP_PLUGIN_URL . '/bp-activity/css/jquery.mentions.dev.css', array(), '1.0' ); 289 else 290 wp_enqueue_style( 'bp-activity-mentions', BP_PLUGIN_URL . '/bp-activity/css/jquery.mentions.css', array(), '1.0' ); 291 292 wp_localize_script( 'bp-activity-mentions-js', 'BPMentions', array( 293 'error1' => __( 'Sorry, an error occurred.', 'buddypress' ), 294 'error2' => _x( 'Please try again.', 'an error occurred', 'buddypress' ), 295 'searching' => _x( 'Searching...', 'started a search', 'buddypress' ) 296 ) ); 297 } 270 298 } 271 299 // Create the activity component 272 300 $bp->activity = new BP_Activity_Component(); 273 274 ?> 301 ?> 302 No newline at end of file -
bp-activity/css/jquery.mentions.css
1 #mentions-autosuggest{background-color:#fafafa;background-color:rgba(250,250,250,0.8);border-bottom:1px solid #000;border-bottom:1px solid rgba(0,0,0,0.25);-moz-border-radius:0 0 6px 6px;-webkit-border-radius:0 0 6px 6px;border-radius:0 0 6px 6px;-moz-box-shadow:0 1px 3px rgba(0,0,0,0.5);-webkit-box-shadow:0 1px 3px rgba(0,0,0,0.5);box-shadow:0 1px 3px rgba(0,0,0,0.5);display:none;list-style:none;margin:0 2px;overflow:hidden;padding:7px 0;z-index:999;}#mentions-autosuggest img{margin:0 10px 0 0;}#mentions-autosuggest li{border-bottom:1px solid transparent;border-top:1px solid transparent;font-size:14px;margin:0;overflow:hidden;padding:2px 10px;top:9px;}#mentions-autosuggest li:not(.section):hover{background:#ebf4ff;background:-moz-linear-gradient(top,#f0f9ff 0,#ebf4ff 100%);background:-ms-linear-gradient(top,#f0f9ff 0,#ebf4ff 100%);background:-o-linear-gradient(top,#f0f9ff 0,#ebf4ff 100%);background:-webkit-gradient(linear,left top,left bottom,color-stop(0%,#f0f9ff),color-stop(100%,#ebf4ff));background:-webkit-linear-gradient(top,#f0f9ff 0,#ebf4ff 100%);background:linear-gradient(top,#f0f9ff 0,#ebf4ff 100%);border-bottom:1px solid #a1dcfa;border-top:1px solid #a1dcfa;cursor:pointer;filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#f0f9ff',endColorstr='#ebf4ff',GradientType=0);}#mentions-autosuggest li img{opacity:.8;}#mentions-autosuggest li:not(.section):hover img{opacity:1;}#mentions-autosuggest li:not(.section) p{line-height:35px;}#mentions-autosuggest .section{font-size:12px;margin-top:10px;}#mentions-autosuggest .section:first-child{margin-top:0;}#mentions-autosuggest .section.error span{font-weight:bold;} 2 No newline at end of file -
bp-activity/css/jquery.mentions.dev.css
1 #mentions-autosuggest { 2 background-color: rgb(250, 250, 250); /* IE7-8 */ 3 background-color: rgba(250, 250, 250, 0.8); 4 border-bottom: 1px solid rgb(0, 0, 0); /* IE7-8 */ 5 border-bottom: 1px solid rgba(0, 0, 0, 0.25); 6 -moz-border-radius: 0 0 6px 6px; 7 -webkit-border-radius: 0 0 6px 6px; 8 border-radius: 0 0 6px 6px; 9 -moz-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); 10 -webkit-box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); 11 box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); 12 display: none; 13 list-style: none; 14 margin: 0 2px; 15 overflow: hidden; 16 padding: 7px 0; 17 z-index: 999; 18 } 19 #mentions-autosuggest img { 20 margin: 0 10px 0 0; 21 } 22 #mentions-autosuggest li { 23 border-bottom: 1px solid transparent; 24 border-top: 1px solid transparent; 25 font-size: 14px; 26 margin: 0; 27 overflow: hidden; 28 padding: 2px 10px; 29 top: 9px; 30 } 31 #mentions-autosuggest li:not(.section):hover { 32 background: #ebf4ff; /* Fallback */ 33 background: -moz-linear-gradient(top, #f0f9ff 0%, #ebf4ff 100%); /* FF3.6+ */ 34 background: -ms-linear-gradient(top, #f0f9ff 0%, #ebf4ff 100%); /* IE10+ */ 35 background: -o-linear-gradient(top, #f0f9ff 0%, #ebf4ff 100%); /* Opera11.10+ */ 36 background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #f0f9ff), color-stop(100%, #ebf4ff)); /* Chrome,Safari4+ */ 37 background: -webkit-linear-gradient(top, #f0f9ff 0%, #ebf4ff 100%); /* Chrome10+,Safari5.1+ */ 38 background: linear-gradient(top, #f0f9ff 0%, #ebf4ff 100%); /* W3C */ 39 border-bottom: 1px solid #a1dcfa; 40 border-top: 1px solid #a1dcfa; 41 cursor: pointer; 42 filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#f0f9ff', endColorstr='#ebf4ff', GradientType=0); /* IE6-9 */ 43 } 44 #mentions-autosuggest li img { 45 opacity: 0.8; 46 } 47 #mentions-autosuggest li:not(.section):hover img { 48 opacity: 1; 49 } 50 #mentions-autosuggest li:not(.section) p { 51 line-height: 35px; 52 } 53 #mentions-autosuggest .section { 54 font-size: 12px; 55 margin-top: 10px; 56 } 57 #mentions-autosuggest .section:first-child { 58 margin-top: 0; 59 } 60 #mentions-autosuggest .section.error span { 61 font-weight: bold; 62 } 63 No newline at end of file -
bp-activity/js/jquery.mentions.dev.js
1 /*! 2 * jQuery @mentions plugin, v1.0 3 * 4 * Copyright 2011, Paul Gibbs <paul@byotos.com>. 5 * 6 * Licensed under GPL Version 2 and/or 3. 7 * http://www.gnu.org/licenses/gpl-2.0.html 8 * http://www.gnu.org/licenses/gpl-3.0.html 9 * 10 * Requires jQuery 1.6+ 11 */ 12 13 /* 14 * @todo Add keyboard up/down/return/tab support. 15 * @todo Use contentEditable. 16 */ 17 18 (function($) { 19 $.fn.mentions = function(options) { 20 options = $.extend({}, $.fn.mentions.defaults, options); 21 22 var key = { 23 up : 38, 24 down : 40, 25 enter : 13, 26 esc : 27, 27 at : 64 28 }; 29 30 return this.each(function() { 31 var input_obj = $(this), 32 found_at_token = false, 33 results = null, 34 results_started = false, 35 previous_query = '', 36 query = '', 37 timer = 0, 38 39 // Metadata plugin support - http://docs.jquery.com/Plugins/Metadata/metadata 40 o = $.meta ? $.extend({}, options, input_obj.data()) : options, 41 42 // Have fun parsing this regex. I had fun writing it. 43 at_regex = new RegExp("@[\\w\\\\\\.\\-]+\\s?(?:[\\w\\\\\\.\\-]+\\s?){0," + (o.max_name_parts - 1) + "}(?:[\\w\\\\\\.\\-]w+)?$"); 44 45 // Add results box 46 function add_panel() { 47 var html = '<ul id="mentions-autosuggest"></ul>'; 48 49 if (o.resultsbox) { 50 if ('string' == typeof o.resultsbox) { 51 if ('prepend' == o.resultsbox_position) { 52 $(o.resultsbox).prepend(html); 53 } else if ('append' == o.resultsbox_position) { 54 $(o.resultsbox).append(html); 55 } else if ('before' == o.resultsbox_position) { 56 $(o.resultsbox).before(html); 57 } else if ('after' == o.resultsbox_position) { 58 $(o.resultsbox).after(html); 59 } 60 61 // Assume jQuery object 62 } else if (o.resultsbox) { 63 if ('prepend' == o.resultsbox_position) { 64 o.resultsbox.prepend(html); 65 } else if ('append' == o.resultsbox_position) { 66 o.resultsbox.append(html); 67 } else if ('before' == o.resultsbox_position) { 68 o.resultsbox.before(html); 69 } else if ('after' == o.resultsbox_position) { 70 o.resultsbox.after(html); 71 } 72 } 73 74 // Fallback to parent's element 75 } else { 76 if ('prepend' == o.resultsbox_position) { 77 input_obj.parent().prepend(html); 78 } else if ('append' == o.resultsbox_position) { 79 input_obj.parent().append(html); 80 } else if ('before' == o.resultsbox_position) { 81 input_obj.parent().before(html); 82 } else if ('after' == o.resultsbox_position) { 83 input_obj.parent().after(html); 84 } 85 } 86 87 results = $('#mentions-autosuggest'); 88 } 89 90 // Close the results panel 91 function close_panel() { 92 clearTimeout(timer); 93 94 results.slideUp('slow', function() { 95 results.empty(); 96 97 // Move caret to end 98 input_obj[0].setSelectionRange(input_obj.val().length, input_obj.val().length); 99 input_obj.focus(); 100 }); 101 102 found_at_token = results_started = false; 103 previous_query = ''; 104 } 105 106 // Listen for input 107 function handle_input() { 108 if (!found_at_token) { 109 clearTimeout(timer); 110 return; 111 } 112 113 query = at_regex.exec(input_obj.val()); 114 if (!query) { 115 previous_query = query = ''; 116 return; 117 } 118 119 if (previous_query == query) { 120 return; 121 } 122 123 // New query is new 124 if ($.isFunction(o.start)) { 125 o.start.call(this, query); 126 } 127 128 if (!results_started) { 129 results.css('width', input_obj.outerWidth(false)-4).html('<li class="section ajaxloader"><p><span class="ajax-loader" style="display: inline"></span>' + BPMentions.searching + '</p></li>').show(); 130 } else { 131 // If panel is open, add spinner to top 132 results.css('width', input_obj.outerWidth(false)-4).prepend('<li class="section ajaxloader"><p><span class="ajax-loader" style="display: inline"></span>' + BPMentions.searching + '</p></li>').show(); 133 } 134 135 // Make ajax request 136 $.ajax({ 137 dataType : o.dataType, 138 type : 'POST', 139 url : ajaxurl, 140 data : { 141 'action' : 'activity_mention_autosuggest', 142 'cookie' : encodeURIComponent(document.cookie), 143 'format' : o.dataType, 144 'limit' : o.max_suggestions, 145 'search' : query 146 }, 147 148 // Callbacks 149 error : o.error, 150 success : receive_results 151 }); 152 153 previous_query = query; 154 } 155 156 // Data received from ajax request 157 function receive_results(response, textStatus, jqXHR) { 158 // If you've asked for JSON, handle that in the success callback. 159 if ($.isFunction(o.success)) { 160 o.success.call(response, textStatus, jqXHR); 161 } 162 163 if ('html' == o.dataType) { 164 // Fade out the loading spinner 165 results.find('li.ajaxloader').fadeOut('fast', function() { 166 $(this).remove(); 167 168 // Missing required parameter 169 if ('-1' == response) { 170 if ($.isFunction(o.error)) { 171 o.error.call(response, textStatus, jqXHR); 172 } 173 174 results.html('<li class="section error"><p><span>' + BPMentions.error1 + '</span> ' + BPMentions.error2 + '</p></li>'); 175 return; 176 177 // No results 178 } else if ( '0' == response ) { 179 results.html('<li class="section error"><p><span>' + BPMentions.noresults1 + '</span> ' + BPMentions.noresults2 + '</p></li>'); 180 181 // Insert results 182 } else { 183 results.css('width', input_obj.outerWidth(false)-4); 184 185 // Slide panel open if this is the first search 186 if (!results_started) { 187 results.slideUp('10000', function() { 188 results.html(response).slideDown('slow'); 189 }); 190 191 } else { 192 results.html(response); 193 } 194 } 195 196 results_started = true; 197 }); 198 199 if ($.isFunction(o.complete)) { 200 o.complete.call(response, textStatus, jqXHR); 201 } 202 } 203 } 204 205 // Put selected name into input_obj 206 function insert_name(name) { 207 input_obj.val(input_obj.val().substring(0, input_obj.val().lastIndexOf('@')) + '@' + name + ' '); 208 close_panel(); 209 } 210 211 $(function() { 212 add_panel(); 213 214 // Listen for input 215 input_obj.bind('keypress.mentions', function(event) { 216 if (key.at == event.which && !found_at_token) { 217 found_at_token = true; 218 219 // Start listening for input after "@" key 220 } else if (found_at_token) { 221 clearTimeout(timer); 222 223 if (results_started) { 224 timer = setTimeout(handle_input, 800); 225 } else { 226 // Do the first search very quickly 227 timer = setTimeout(handle_input, 350); 228 } 229 } 230 }); 231 232 // Escape / return (cancel) 233 input_obj.bind('keyup.mentions', function(event) { 234 if ((key.esc == event.keyCode || key.enter == event.keyCode) && results_started) { 235 event.preventDefault(); 236 close_panel(); 237 } 238 }); 239 240 // Defocus 241 input_obj.bind('focusout.mentions', function(event) { 242 if (results_started) { 243 close_panel(); 244 } 245 }); 246 247 // Click 248 results.delegate('li:not(.section)', 'click.mentions', function(event) { 249 event.preventDefault(); 250 insert_name($(this).attr('class')); 251 }); 252 }); 253 }); 254 }; 255 256 $.fn.mentions.defaults = { 257 // Options 258 'resultsbox_position' : 'append', // Used with resultsbox. How to glue the results panel to the results box; "append", "prepend", "after", "before". 259 'dataType' : 'html', // Type of data expected back from the server. Supports 'html' and 'json'. 260 'max_name_parts' : 3, // Number of word parts that are identified as a name; i.e. "Boone B Gorges." 261 'max_suggestions' : 6, // Max number of suggestions to return. 262 'resultsbox' : '', // Used if dataType=html. jQuery identifier or object to append the results' container box to. If not set, defaults to "this'" parent element. 263 264 // Callbacks 265 'start' : null, // After a pattern match, before anything else. 266 'success' : null, // When data received (before complete). 267 'complete' : null, // When we're finished (after success). 268 'error' : null // On any type of error. 269 }; 270 })(jQuery); 271 No newline at end of file -
bp-activity/js/jquery.mentions.js
1 /* 2 * jQuery @mentions plugin, v1.0 3 * 4 * Copyright 2011, Paul Gibbs <paul@byotos.com>. 5 * 6 * Licensed under GPL Version 2 and/or 3. 7 * http://www.gnu.org/licenses/gpl-2.0.html 8 * http://www.gnu.org/licenses/gpl-3.0.html 9 * 10 * Requires jQuery 1.6+ 11 */ 12 (function(a){a.fn.mentions=function(b){b=a.extend({},a.fn.mentions.defaults,b);var c={up:38,down:40,enter:13,esc:27,at:64};return this.each(function(){var q=a(this),l=false,i=null,p=false,f="",m="",d=0,e=a.meta?a.extend({},b,q.data()):b,g=new RegExp("@[\\w\\\\\\.\\-]+\\s?(?:[\\w\\\\\\.\\-]+\\s?){0,"+(e.max_name_parts-1)+"}(?:[\\w\\\\\\.\\-]w+)?$");function k(){var o='<ul id="mentions-autosuggest"></ul>';if(e.resultsbox){if("string"==typeof e.resultsbox){if("prepend"==e.resultsbox_position){a(e.resultsbox).prepend(o)}else{if("append"==e.resultsbox_position){a(e.resultsbox).append(o)}else{if("before"==e.resultsbox_position){a(e.resultsbox).before(o)}else{if("after"==e.resultsbox_position){a(e.resultsbox).after(o)}}}}}else{if(e.resultsbox){if("prepend"==e.resultsbox_position){e.resultsbox.prepend(o)}else{if("append"==e.resultsbox_position){e.resultsbox.append(o)}else{if("before"==e.resultsbox_position){e.resultsbox.before(o)}else{if("after"==e.resultsbox_position){e.resultsbox.after(o)}}}}}}}else{if("prepend"==e.resultsbox_position){q.parent().prepend(o)}else{if("append"==e.resultsbox_position){q.parent().append(o)}else{if("before"==e.resultsbox_position){q.parent().before(o)}else{if("after"==e.resultsbox_position){q.parent().after(o)}}}}}i=a("#mentions-autosuggest")}function r(){clearTimeout(d);i.slideUp("slow",function(){i.empty();q[0].setSelectionRange(q.val().length,q.val().length);q.focus()});l=p=false;f=""}function h(){if(!l){clearTimeout(d);return}m=g.exec(q.val());if(!m){f=m="";return}if(f==m){return}if(a.isFunction(e.start)){e.start.call(this,m)}if(!p){i.css("width",q.outerWidth(false)-4).html('<li class="section ajaxloader"><p><span class="ajax-loader" style="display: inline"></span>'+BPMentions.searching+"</p></li>").show()}else{i.css("width",q.outerWidth(false)-4).prepend('<li class="section ajaxloader"><p><span class="ajax-loader" style="display: inline"></span>'+BPMentions.searching+"</p></li>").show()}a.ajax({dataType:e.dataType,type:"POST",url:ajaxurl,data:{action:"activity_mention_autosuggest",cookie:encodeURIComponent(document.cookie),format:e.dataType,limit:e.max_suggestions,search:m},error:e.error,success:n});f=m}function n(o,t,s){if(a.isFunction(e.success)){e.success.call(o,t,s)}if("html"==e.dataType){i.find("li.ajaxloader").fadeOut("fast",function(){a(this).remove();if("-1"==o){if(a.isFunction(e.error)){e.error.call(o,t,s)}i.html('<li class="section error"><p><span>'+BPMentions.error1+"</span> "+BPMentions.error2+"</p></li>");return}else{if("0"==o){i.html('<li class="section error"><p><span>'+BPMentions.noresults1+"</span> "+BPMentions.noresults2+"</p></li>")}else{i.css("width",q.outerWidth(false)-4);if(!p){i.slideUp("10000",function(){i.html(o).slideDown("slow")})}else{i.html(o)}}}p=true});if(a.isFunction(e.complete)){e.complete.call(o,t,s)}}}function j(o){q.val(q.val().substring(0,q.val().lastIndexOf("@"))+"@"+o+" ");r()}a(function(){k();q.bind("keypress.mentions",function(o){if(c.at==o.which&&!l){l=true}else{if(l){clearTimeout(d);if(p){d=setTimeout(h,800)}else{d=setTimeout(h,350)}}}});q.bind("keyup.mentions",function(o){if((c.esc==o.keyCode||c.enter==o.keyCode)&&p){o.preventDefault();r()}});q.bind("focusout.mentions",function(o){if(p){r()}});i.delegate("li:not(.section)","click.mentions",function(o){o.preventDefault();j(a(this).attr("class"))})})})};a.fn.mentions.defaults={resultsbox_position:"append",dataType:"html",max_name_parts:3,max_suggestions:6,resultsbox:"",start:null,success:null,complete:null,error:null}})(jQuery); 13 No newline at end of file