Index: branches/wmf/1.17wmf1/extensions/MobileFrontend/javascripts/application.js |
— | — | @@ -1,5 +1,34 @@ |
2 | | -// I don't think this makes sense. Loading this here means that this button |
3 | | -// won't function until the page is loaded. It would probably be an |
| 2 | +var search = document.getElementById( 'search' ); |
| 3 | +var clearSearch = document.getElementById( 'clearsearch' ); |
| 4 | + |
| 5 | +initClearSearchLink(); |
| 6 | + |
| 7 | +function initClearSearchLink() { |
| 8 | + clearSearch.setAttribute( 'title','Clear' ); |
| 9 | + clearSearch.addEventListener( 'mousedown', clearSearchBox, true ); |
| 10 | + search.addEventListener( 'keyup', _handleClearSearchLink, false ); |
| 11 | +} |
| 12 | + |
| 13 | +function _handleClearSearchLink() { |
| 14 | + if ( clearSearch ) { |
| 15 | + if ( search.value.length > 0 ) { |
| 16 | + clearSearch.style.display = 'block'; |
| 17 | + } else { |
| 18 | + clearSearch.style.display = 'none'; |
| 19 | + } |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +function clearSearchBox( event ) { |
| 24 | + search.value = ''; |
| 25 | + clearSearch.style.display = 'none'; |
| 26 | + if ( event ) { |
| 27 | + event.preventDefault(); |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +// I don't think this makes sense. Loading this here means that this button |
| 32 | +// won't function until the page is loaded. It would probably be an |
4 | 33 | // improvement to just attach an onclick straight into the html. |
5 | 34 | document.getElementById( 'logo' ).onclick = function() { |
6 | 35 | var n = document.getElementById( 'nav' ).style; |
— | — | @@ -35,7 +64,7 @@ |
36 | 65 | window.scrollTo( 0, 1 ); |
37 | 66 | |
38 | 67 | // This is a global. I don't know why. |
39 | | -decode = document.getElementById( 'searchField' ); |
| 68 | +decode = document.getElementById( 'search' ); |
40 | 69 | decode.value = unescape( decode.value ); |
41 | 70 | decode = document.getElementsByTagName( 'title' )[0]; |
42 | 71 | decode.innerHTML = unescape( decode.innerHTML ); |
— | — | @@ -83,4 +112,4 @@ |
84 | 113 | var s = document.getElementById( d[i] + section_id ).style; |
85 | 114 | s.display = s.display == 'block' ? 'none' : 'block'; |
86 | 115 | } |
87 | | -} |
| 116 | +} |
\ No newline at end of file |