r113830 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113829‎ | r113830 | r113831 >
Date:18:37, 14 March 2012
Author:jdlrobson
Status:resolved
Tags:
Comment:
allow search to be triggered on a blur and submit event

hitting enter in a search box should trigger a search
for javascript enabled browsers - not redirect to the
search results page

also some browsers (opera mini) do not support keyup
event so providing blur fallback
Modified paths:
  • /trunk/extensions/MobileFrontend/javascripts/beta_opensearch.js (modified) (history)
  • /trunk/extensions/MobileFrontend/templates/SearchTemplate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/javascripts/beta_opensearch.js
@@ -105,25 +105,28 @@
106106 }
107107 }
108108
109 - window.onload = function () {
110 - u( search ).bind( 'keyup',
111 - function() {
 109+ var performSearch = function(ev) {
 110+ ev.preventDefault();
112111 clearTimeout( timer );
113 - term = this.value;
 112+ term = search.value;
114113 if ( term.length < 1 ) {
115114 results.innerHTML = '';
116115 } else {
117116 term = encodeURIComponent( term );
118117 timer = setTimeout( function () { searchApi( term ); }, typingDelay );
119118 }
120 - } );
121119 };
 120+ u( search ).bind( 'keyup', performSearch );
 121+ u( document.getElementById( 'searchForm' ) ).bind( 'submit', performSearch );
 122+ u( search ).bind( 'blur', performSearch ); // for opera mini etc
122123
123124 function searchApi( term ) {
124125 url = apiUrl + '?action=opensearch&limit=' + numResults + '&namespace=0&format=xml&search=' + term;
125126 u.ajax( { url: url,
126127 success: function(xml) {
127 - writeResults( createObjectArray( xml ) );
 128+ if( u( document.body ).hasClass( 'full-screen-search' ) ) {
 129+ writeResults( createObjectArray( xml ) );
 130+ }
128131 }
129132 } );
130133 }
Index: trunk/extensions/MobileFrontend/templates/SearchTemplate.php
@@ -33,7 +33,7 @@
3434 <div id='header'>
3535 <div id='searchbox' {$logoDisplayNone}>
3636 <img width="35" height="22" alt='Logo' id='logo' src='{$this->data['wgMobileFrontendLogo']}' {$logoDisplayNone} />
37 - <form action='{$scriptUrl}' class='search_bar' method='get' {$searchBoxDisplayNone}>
 37+ <form id='searchForm' action='{$scriptUrl}' class='search_bar' method='get' {$searchBoxDisplayNone}>
3838 <input type="hidden" value="Special:Search" name="title" />
3939 <div id="sq" class="divclearable">
4040 <input type="search" name="search" id="search" size="22" value="{$searchField}" autocorrect="off" autocomplete="off" autocapitalize="off" maxlength="1024" class="search" placeholder="{$placeholder}" />

Follow-up revisions

RevisionCommit summaryAuthorDate
r113831follow up to r113830...jdlrobson18:38, 14 March 2012

Status & tagging log