Index: trunk/extensions/Configure/Configure.page.php |
— | — | @@ -703,6 +703,7 @@ |
704 | 704 | 'id' => 'configure-form' ) ) . "\n" : |
705 | 705 | Xml::openElement( 'div', array( 'id' => 'configure-form' ) ) |
706 | 706 | ) . |
| 707 | + $this->buildSearchForm() . "\n" . |
707 | 708 | Xml::openElement( 'div', array( 'id' => 'configure' ) ) . "\n" . |
708 | 709 | $this->buildAllSettings() . "\n" . |
709 | 710 | ( $this->mCanEdit ? |
— | — | @@ -727,6 +728,14 @@ |
728 | 729 | ); |
729 | 730 | $this->injectScriptsAndStyles(); |
730 | 731 | } |
| 732 | + |
| 733 | + /** Show a hidden-by-default search form */ |
| 734 | + protected function buildSearchForm() { |
| 735 | + $form = wfMsgExt( 'configure-js-search-prompt', 'parseinline' ) . ' ' . Xml::element( 'input', array( 'id' => 'configure-search-input', 'size' => 45 ) ); |
| 736 | + $form = Xml::tags( 'p', null, $form ) . "\n" . Xml::element( 'ul', array( 'id' => 'configure-search-results' ) ); |
| 737 | + $form = Xml::fieldset( wfMsg( 'configure-js-search-legend' ), $form, array( 'style' => 'display: none;', 'id' => 'configure-search-form' ) ); |
| 738 | + return $form; |
| 739 | + } |
731 | 740 | |
732 | 741 | /** |
733 | 742 | * Inject JavaScripts and Stylesheets in page output |
Index: trunk/extensions/Configure/Configure.i18n.php |
— | — | @@ -50,6 +50,8 @@ |
51 | 51 | 'configure-js-biglist-show' => '[show details]', |
52 | 52 | 'configure-js-biglist-hide' => '[hide details]', |
53 | 53 | 'configure-js-summary-none' => 'No settings', |
| 54 | + 'configure-js-search-legend' => 'Search settings', |
| 55 | + 'configure-js-search-prompt' => 'Query: ', |
54 | 56 | 'configure-no-diff' => 'There are no changes between selected versions.', |
55 | 57 | 'configure-no-directory' => 'The directory used to store the settings, <tt>$1</tt>, does not exist. |
56 | 58 | Please create it or change it to use this extension.', |
Index: trunk/extensions/Configure/Configure.js |
— | — | @@ -3,6 +3,8 @@ |
4 | 4 | * create JavaScript buttons to allow to modify the form to have more |
5 | 5 | * flexibility |
6 | 6 | */ |
| 7 | + |
| 8 | + var allSettings = undefined; |
7 | 9 | |
8 | 10 | function setupConfigure(){ |
9 | 11 | |
— | — | @@ -262,7 +264,87 @@ |
263 | 265 | summariseSetting( list, summary ); |
264 | 266 | list.parentNode.insertBefore( summary, list ); |
265 | 267 | } |
| 268 | + |
| 269 | + /** Search box initialise */ |
| 270 | + buildSearchIndex(); |
| 271 | + |
| 272 | + // Insert a little search form just before the configuration form |
| 273 | + document.getElementById( 'configure-search-form' ).style.display = 'block'; |
| 274 | + addHandler( document.getElementById( 'configure-search-input' ), 'keyup', function() { doSearch( this.value ); } ) |
266 | 275 | } |
| 276 | + |
| 277 | +function doSearch( query ) { |
| 278 | + query = query.toLowerCase(); |
| 279 | + |
| 280 | + var results = document.getElementById( 'configure-search-results' ); |
| 281 | + |
| 282 | + // Empty the existing results |
| 283 | + while(results.firstChild) { |
| 284 | + results.removeChild(results.firstChild); |
| 285 | + } |
| 286 | + |
| 287 | + if (query == '') { |
| 288 | + return; |
| 289 | + } |
| 290 | + |
| 291 | + var isMatch = function(element) { return element.description.indexOf( query ) !== -1; } |
| 292 | + for( var i=0;i<allSettings.length;++i ) { |
| 293 | + var data = allSettings[i]; |
| 294 | + if (isMatch( data )) { |
| 295 | + var a = document.createElement( 'a' ); |
| 296 | + var li = document.createElement( 'li' ); |
| 297 | + |
| 298 | + a.href = '#config-head-'+data.fid+'-'+data.sid; |
| 299 | + addHandler( a, 'click', configToggle ); |
| 300 | + a.confSec = data.fid; |
| 301 | + a.confSub = data.sid; |
| 302 | + a.appendChild( document.createTextNode( data.displayDescription ) ); |
| 303 | + li.appendChild( a ); |
| 304 | + |
| 305 | + results.appendChild( li ); |
| 306 | + } |
| 307 | + } |
| 308 | +} |
| 309 | + |
| 310 | +function buildSearchIndex() { |
| 311 | + allSettings = []; |
| 312 | + |
| 313 | + // For each section... |
| 314 | + var rootElement = document.getElementById( 'configure' ); |
| 315 | + var fieldsets = rootElement.getElementsByTagName( 'fieldset' ); |
| 316 | + for( var fid=0;fid<fieldsets.length;++fid ) { |
| 317 | + // For each subsection... |
| 318 | + var fieldset = fieldsets[fid]; |
| 319 | + var fieldset_title = getInnerText( fieldset.getElementsByTagName( 'legend' )[0] ); |
| 320 | + var subsections = getElementsByClassName( fieldset, 'table', 'configure-table' ); |
| 321 | + for( var sid=0;sid<subsections.length;++sid ) { |
| 322 | + var subsection = subsections[sid].getElementsByTagName( 'tbody' )[0]; |
| 323 | + var heading = document.getElementById( subsection.parentNode.id.replace( 'config-table', 'config-head' ) ); |
| 324 | + |
| 325 | + // For each setting... |
| 326 | + for( var i=0; i<subsection.childNodes.length;++i ) { |
| 327 | + var row = subsection.childNodes[i]; |
| 328 | + if ( row.nodeType != row.ELEMENT_NODE || row.tagName != 'TR' ) { |
| 329 | + continue; |
| 330 | + } |
| 331 | + |
| 332 | + var desc_cell = getElementsByClassName( row, 'td', 'configure-left-column' )[0]; |
| 333 | + |
| 334 | + |
| 335 | + var description; |
| 336 | + |
| 337 | + if (desc_cell.getElementsByTagName( 'p' ).length) { // Ward off comments like "This setting has been customised" |
| 338 | + description = getInnerText( desc_cell.getElementsByTagName( 'p' )[0] ); |
| 339 | + } else { |
| 340 | + description = getInnerText( desc_cell ); |
| 341 | + } |
| 342 | + |
| 343 | + allSettings.push( { 'description': description.toLowerCase(), 'fid':fid+1, 'sid':sid, 'displayDescription': description } ); |
| 344 | + } |
| 345 | + } |
| 346 | + } |
| 347 | +} |
| 348 | + |
267 | 349 | // Summarise the setting contained in 'div' to the summary field 'summary'. |
268 | 350 | function summariseSetting( div, summary ) { |
269 | 351 | // Empty the existing summary |
— | — | @@ -592,11 +674,7 @@ |
593 | 675 | var oldsecid = this.parentNode.parentNode.selectedid; |
594 | 676 | var confSec = this.confSec; |
595 | 677 | var confSub = this.confSub; |
596 | | - if( confSub == -1 ){ |
597 | | - var toc = this.parentNode.parentNode; |
598 | | - } else { |
599 | | - var toc = this.parentNode.parentNode.parentNode.parentNode; |
600 | | - } |
| 678 | + var toc = document.getElementById( 'configtoc' ); |
601 | 679 | var oldSec = toc.confSec; |
602 | 680 | var oldId = 'config-section-' + oldSec; |
603 | 681 | document.getElementById( oldId ).style.display = "none"; |