Ticket #33902: 33902.2.patch
| File 33902.2.patch, 7.9 KB (added by , 10 years ago) |
|---|
-
src/wp-admin/css/edit.css
1105 1105 } 1106 1106 1107 1107 .ac_results { 1108 display: none; 1109 margin: -1px 0 0; 1108 1110 padding: 0; 1109 margin: 0;1110 1111 list-style: none; 1111 1112 position: absolute; 1112 1113 z-index: 10000; 1113 display: none; 1114 border: 1px solid #808080; 1114 border: 1px solid #5b9dd9; 1115 1115 background-color: #fff; 1116 1116 } 1117 1117 … … 1120 1120 } 1121 1121 1122 1122 .ac_results li { 1123 padding: 2px 5px; 1123 margin: 0; 1124 padding: 5px 10px; 1124 1125 white-space: nowrap; 1125 color: #101010; 1126 text-align: left; 1126 cursor: pointer; 1127 1127 } 1128 1128 1129 .ac_over { 1130 background-color: #f0f0b8; 1131 cursor: pointer; 1129 .ac_results .ac_over, 1130 .ac_over .ac_match { 1131 background-color: #0073aa; 1132 color: #fff; 1132 1133 } 1133 1134 1134 1135 .ac_match { -
src/wp-includes/js/jquery/suggest.js
12 12 * 13 13 */ 14 14 15 (function($) { 15 window.wp = window.wp || {}; 16 16 17 ( function( $, wp ) { 18 19 var uid = 1, 20 l10n = window.suggestL10n; 21 17 22 $.suggest = function(input, options) { 18 23 var $input, $results, timeout, prevLength, cache, cacheSize; 19 24 20 $input = $(input).attr("autocomplete", "off"); 21 $results = $("<ul/>"); 25 $input = $( input ).attr({ 26 'autocomplete': 'off', 27 'autocorrect': 'off', 28 'autocapitalize': 'none', 29 'spellcheck': 'false', 30 'role': 'combobox', 31 'aria-owns': 'results-list-' + uid, 32 'aria-autocomplete': 'list', 33 'aria-expanded': 'false' 34 }); 22 35 23 timeout = false; // hold timeout ID for suggestion results to appear24 prevLength = 0; // last recorded length of $input.val()25 cache = []; // cache MRU list26 cacheSize = 0; // size of cache in chars (bytes?)36 $results = $("<ul/>").attr({ 37 'id': 'results-list-' + uid, 38 'role': 'listbox' 39 }); 27 40 41 // Increment the unique ID in case of multiple suggest on the same page. 42 uid++; 43 44 // Hold timeout ID for suggestion results to appear. 45 timeout = false; 46 // Last recorded length of $input.val(). 47 prevLength = 0; 48 // Cache MRU list 49 cache = []; 50 // Size of cache in chars (bytes?). 51 cacheSize = 0; 52 28 53 $results.addClass(options.resultsClass).appendTo('body'); 29 54 55 resetPosition(); 30 56 31 resetPosition();32 57 $(window) 33 58 .on( 'load', resetPosition ) // just in case user is changing size of page while loading 34 59 .on( 'resize', resetPosition ); 35 60 36 $input.blur(function() { 37 setTimeout(function() { $results.hide() }, 200); 38 }); 61 $input.blur( function() { 62 if ( timeout ) { 63 clearTimeout( timeout ); 64 } 39 65 66 setTimeout( function() { 67 hideItems(); 68 }, 200 ); 69 }); 70 40 71 $input.keydown(processKey); 41 72 42 73 function resetPosition() { … … 48 79 }); 49 80 } 50 81 51 52 82 function processKey(e) { 53 83 54 84 // handling up/down/escape requires results to be visible … … 80 110 break; 81 111 82 112 case 27: // escape 83 $results.hide();113 hideItems(); 84 114 break; 85 115 86 116 } … … 93 123 prevLength = $input.val().length; 94 124 95 125 } 96 97 98 126 } 99 127 100 101 128 function suggest() { 102 129 103 130 var q = $.trim($input.val()), multipleSepPos, items; … … 120 147 121 148 $.get(options.source, {q: q}, function(txt) { 122 149 123 $results.hide();150 hideItems(); 124 151 125 152 items = parseTxt(txt, q); 126 153 … … 133 160 134 161 } else { 135 162 136 $results.hide();163 hideItems(); 137 164 138 165 } 139 166 … … 170 197 } 171 198 172 199 function displayItems(items) { 173 var html = '', i ;200 var html = '', i, ariaLabel; 174 201 if (!items) 175 202 return; 176 203 177 204 if (!items.length) { 178 $results.hide();205 hideItems(); 179 206 return; 180 207 } 181 208 182 209 resetPosition(); // when the form moves after the page has loaded 183 210 184 for (i = 0; i < items.length; i++) 185 html += '<li>' + items[i] + '</li>'; 211 for ( i = 0; i < items.length; i++ ) { 212 uid++; 213 /* 214 * `aria-label` is used just to override the results text which 215 * is split in two parts, the highlighted term and other parts of the term. 216 */ 217 ariaLabel = '<span>' + items[i] + '</span>'; 218 ariaLabel = $( ariaLabel ).text(); 219 html += '<li role="option" id="suggestion-' + uid + '" aria-label="' + ariaLabel + '">' + items[i] + '</li>'; 220 } 186 221 187 222 $results.html(html).show(); 188 223 224 $input.attr( 'aria-expanded', 'true' ); 225 226 setTimeout( function() { 227 wp.a11y.speak( l10n.suggestionsFound.replace( '%d', items.length ) ); 228 }, 10 ); 229 189 230 $results 190 231 .children('li') 191 232 .mouseover(function() { … … 200 241 201 242 } 202 243 244 function hideItems() { 245 $results.hide(); 246 $input.attr( 'aria-expanded', 'false' ); 247 } 248 203 249 function parseTxt(txt, q) { 204 250 205 251 var items = [], tokens = txt.split(options.delimiter), i, token; … … 249 295 } else { 250 296 $input.val($currentResult.text()); 251 297 } 252 $results.hide(); 253 $input.trigger('change'); 298 hideItems(); 299 $input.trigger( 'change' ).removeAttr( 'aria-activedescendant' ); 300 wp.a11y.speak( l10n.selected + ' ' + $currentResult.text() ); 254 301 255 302 if (options.onSelect) 256 303 options.onSelect.apply($input[0]); … … 263 310 264 311 $currentResult = getCurrentResult(); 265 312 266 if ( $currentResult)313 if ( $currentResult ) { 267 314 $currentResult 268 315 .removeClass(options.selectClass) 269 316 .next() 270 317 .addClass(options.selectClass); 271 else 318 319 if ( $currentResult.next().length ) { 320 $input.attr( 'aria-activedescendant', $currentResult.next().attr( 'id' ) ); 321 } else { 322 $input.removeAttr( 'aria-activedescendant' ); 323 } 324 } else { 272 325 $results.children('li:first-child').addClass(options.selectClass); 273 326 $input.attr( 'aria-activedescendant', $results.children( 'li:first-child' ).attr( 'id' ) ); 327 } 274 328 } 275 329 276 330 function prevResult() { 277 331 var $currentResult = getCurrentResult(); 278 332 279 if ( $currentResult)333 if ( $currentResult ) { 280 334 $currentResult 281 335 .removeClass(options.selectClass) 282 336 .prev() 283 337 .addClass(options.selectClass); 284 else285 $results.children('li:last-child').addClass(options.selectClass);286 338 339 if ( $currentResult.prev().length ) { 340 $input.attr( 'aria-activedescendant', $currentResult.prev().attr( 'id' ) ); 341 } else { 342 $input.removeAttr( 'aria-activedescendant' ); 343 } 344 } else { 345 $results.children( 'li:last-child' ).addClass( options.selectClass ); 346 $input.attr( 'aria-activedescendant', $results.children( 'li:last-child' ).attr( 'id' ) ); 347 } 287 348 } 288 349 } 289 350 … … 313 374 314 375 }; 315 376 316 })( jQuery);377 })( jQuery, window.wp ); -
src/wp-includes/script-loader.php
235 235 // jQuery plugins 236 236 $scripts->add( 'jquery-color', "/wp-includes/js/jquery/jquery.color.min.js", array('jquery'), '2.1.1', 1 ); 237 237 $scripts->add( 'suggest', "/wp-includes/js/jquery/suggest$suffix.js", array('jquery'), '1.1-20110113', 1 ); 238 did_action( 'init' ) && $scripts->localize( 'suggest', 'suggestL10n', array( 239 'suggestionsFound' => __( 'Suggestions found: %d' ), 240 'selected' => __( 'Selected:' ), 241 ) ); 242 238 243 $scripts->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array('jquery'), '20m', 1 ); 239 244 $scripts->add( 'jquery-query', "/wp-includes/js/jquery/jquery.query.js", array('jquery'), '2.1.7', 1 ); 240 245 $scripts->add( 'jquery-serialize-object', "/wp-includes/js/jquery/jquery.serialize-object.js", array('jquery'), '0.2', 1 ); … … 499 504 'postBoxEmptyString' => __( 'Drag boxes here' ), 500 505 ) ); 501 506 502 $scripts->add( 'tags-box', "/wp-admin/js/tags-box$suffix.js", array( 'jquery', 'suggest' ), false, 1 );507 $scripts->add( 'tags-box', "/wp-admin/js/tags-box$suffix.js", array( 'jquery', 'suggest', 'wp-a11y' ), false, 1 ); 503 508 did_action( 'init' ) && $scripts->localize( 'tags-box', 'tagsBoxL10n', array( 504 509 'tagDelimiter' => _x( ',', 'tag delimiter' ), 505 510 ) );