r91734 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r91733‎ | r91734 | r91735 >
Date:17:07, 8 July 2011
Author:diebuche
Status:ok
Tags:
Comment:
Migrate skins/common/search.js functionality to mediawiki.special.search.js. Make JS unobtrusive.
Modified paths:
  • /trunk/phase3/includes/specials/SpecialSearch.php (modified) (history)
  • /trunk/phase3/resources/mediawiki.special/mediawiki.special.search.js (modified) (history)
  • /trunk/phase3/skins/common/search.js (deleted) (history)

Diff [purge]

Index: trunk/phase3/skins/common/search.js
@@ -1,50 +0,0 @@
2 -// JS specific to Special:Search
3 -
4 -// change the search link to what user entered
5 -window.mwSearchHeaderClick = function( obj ) {
6 - var searchbox = document.getElementById( 'searchText' );
7 - if( searchbox === null ) {
8 - searchbox = document.getElementById( 'powerSearchText' );
9 - }
10 - if( searchbox === null ) {
11 - return; // should always have either normal or advanced search
12 - }
13 -
14 - var searchterm = searchbox.value;
15 - var parts = obj.getAttribute( 'href', 2).split( 'search=' );
16 - var lastpart = '';
17 - var prefix = 'search=';
18 - if( parts.length > 1 && parts[1].indexOf('&') >= 0 ) {
19 - lastpart = parts[1].substring( parts[1].indexOf('&') );
20 - } else {
21 - prefix = '&search=';
22 - }
23 - obj.href = parts[0] + prefix + encodeURIComponent( searchterm ) + lastpart;
24 -};
25 -
26 -window.mwToggleSearchCheckboxes = function( btn ) {
27 - if( !document.getElementById ) {
28 - return;
29 - }
30 -
31 - var nsInputs = document.getElementById( 'powersearch' ).getElementsByTagName( 'input' );
32 - var isChecked = false;
33 -
34 - for ( var i = 0; i < nsInputs.length; i++ ) {
35 - var pattern = /^ns/;
36 - if ( ( nsInputs[i].type == 'checkbox' ) && ( pattern.test( nsInputs[i].name ) ) ) {
37 - switch ( btn ) {
38 - case 'none':
39 - if ( nsInputs[i].checked ) {
40 - nsInputs[i].checked = false;
41 - }
42 - break;
43 - case 'all':
44 - if ( !nsInputs[i].checked ) {
45 - nsInputs[i].checked = true;
46 - }
47 - break;
48 - }
49 - }
50 - }
51 -};
Index: trunk/phase3/includes/specials/SpecialSearch.php
@@ -863,7 +863,6 @@
864864 array(
865865 'type'=>'button',
866866 'id' => 'mw-search-toggleall',
867 - 'onclick' => 'mwToggleSearchCheckboxes("all");',
868867 'value' => wfMsg( 'powersearch-toggleall' )
869868 )
870869 ) .
@@ -872,7 +871,6 @@
873872 array(
874873 'type'=>'button',
875874 'id' => 'mw-search-togglenone',
876 - 'onclick' => 'mwToggleSearchCheckboxes("none");',
877875 'value' => wfMsg( 'powersearch-togglenone' )
878876 )
879877 )
@@ -1045,9 +1043,7 @@
10461044 'a',
10471045 array(
10481046 'href' => $this->getTitle()->getLocalURL( $stParams ),
1049 - 'title' => $tooltip,
1050 - 'onmousedown' => 'mwSearchHeaderClick(this);',
1051 - 'onkeydown' => 'mwSearchHeaderClick(this);'),
 1047+ 'title' => $tooltip),
10521048 $label
10531049 );
10541050 }
Index: trunk/phase3/resources/mediawiki.special/mediawiki.special.search.js
@@ -8,4 +8,30 @@
99 $( 'input[autofocus]:first' ).focus();
1010 }
1111
 12+// Bind check all/none button
 13+var $checkboxes = $('#powersearch input[id^=mw-search-ns]');
 14+$('#mw-search-toggleall').click( function() {
 15+ $checkboxes.prop("checked", true);
 16+} );
 17+$('#mw-search-togglenone').click( function() {
 18+ $checkboxes.prop("checked", false);
 19+} );
 20+
 21+// Change the header search links to what user entered
 22+var headerLinks = $('.search-types a');
 23+$('#searchText, #powerSearchText').change(function() {
 24+ var searchterm = $(this).val();
 25+ headerLinks.each( function() {
 26+ var parts = this.href.split( 'search=' );
 27+ var lastpart = '';
 28+ var prefix = 'search=';
 29+ if( parts.length > 1 && parts[1].indexOf('&') >= 0 ) {
 30+ lastpart = parts[1].substring( parts[1].indexOf('&') );
 31+ } else {
 32+ prefix = '&search=';
 33+ }
 34+ this.href = parts[0] + prefix + encodeURIComponent( searchterm ) + lastpart;
 35+ });
 36+}).trigger('change');
 37+
1238 } )( jQuery );
\ No newline at end of file

Follow-up revisions

RevisionCommit summaryAuthorDate
r91736r91734: Do the same for search.css and remove module from resources.phpdiebuche17:20, 8 July 2011

Status & tagging log