Index: trunk/extensions/MobileFrontend/tests/js/test_opensearch.js |
— | — | @@ -1,5 +1,50 @@ |
2 | 2 | var MFEOS = MobileFrontend.opensearch; |
3 | 3 | var _ajax; |
| 4 | + |
| 5 | +module("MobileFrontend application.js: clear search", { |
| 6 | + setup: function() { |
| 7 | + $(['<div id="clearsearchtest"><div id="results"></div><input type="text" id="search">', |
| 8 | + '<button id="clearsearch" title="Clear" style="display:none;">clear</button></div>'].join("")).appendTo(document.body); |
| 9 | + MFEOS.initClearSearch(); |
| 10 | + }, |
| 11 | + teardown: function() { |
| 12 | + $("#clearsearchtest").remove(); |
| 13 | + } |
| 14 | +}); |
| 15 | + |
| 16 | +test("setup", function() { |
| 17 | + strictEqual($("#clearsearch").attr("title"), "Clear", "check clearsearch tooltip"); |
| 18 | +}); |
| 19 | + |
| 20 | +test("reveal clearsearch on text", function() { |
| 21 | + $("#search").val("hello"); |
| 22 | + var initialVisibility = $("#clearsearch").is(":visible"); |
| 23 | + MFET.triggerEvent($("#search")[0], "keyup") |
| 24 | + strictEqual(initialVisibility, false, "at start clear button should be hidden.") |
| 25 | + strictEqual($("#clearsearch").is(":visible"), true, "clear search is now visible"); |
| 26 | +}); |
| 27 | + |
| 28 | +test("hide clearsearch when no text", function() { |
| 29 | + $("#clearsearch").show(); |
| 30 | + $("#search").val(""); |
| 31 | + var initialVisibility = $("#clearsearch").is(":visible"); |
| 32 | + MFET.triggerEvent($("#search")[0], "keyup"); |
| 33 | + strictEqual(initialVisibility, true, "at start we made it visible") |
| 34 | + strictEqual($("#clearsearch").is("visible"), false, "now invisible due to lack of text in input"); |
| 35 | + strictEqual($("#results").is("visible"), false, "results also hidden"); |
| 36 | +}); |
| 37 | + |
| 38 | +test("click clearSearchBox", function() { |
| 39 | + $("#search").val("hello world"); |
| 40 | + $("#results,#clearsearch").show(); |
| 41 | + |
| 42 | + MFET.triggerEvent($("#clearsearch")[0], "mousedown") |
| 43 | + |
| 44 | + strictEqual($("#search").val(), "", "value reset"); |
| 45 | + strictEqual($("#results").is(":visible"), false, "results hidden"); |
| 46 | + strictEqual($("#clearsearch").is(":visible"), false, "clear search hidden"); |
| 47 | +}); |
| 48 | + |
4 | 49 | module("MobileFrontend opensearch.js - writeResults", { |
5 | 50 | setup: function() { |
6 | 51 | _ajax = MobileFrontend.utils.ajax; |
Index: trunk/extensions/MobileFrontend/tests/js/test_application.js |
— | — | @@ -75,50 +75,6 @@ |
76 | 76 | strictEqual(cookieEnd, "off", "banner now set for dismissal"); |
77 | 77 | }); |
78 | 78 | |
79 | | -module("MobileFrontend application.js: clear search", { |
80 | | - setup: function() { |
81 | | - MFET.createFixtures(); |
82 | | - MFE.init(); |
83 | | - $("#clearsearch").hide(); |
84 | | - }, |
85 | | - teardown: function() { |
86 | | - MFET.cleanFixtures(); |
87 | | - } |
88 | | -}); |
89 | | - |
90 | | -test("setup", function() { |
91 | | - strictEqual($("#clearsearch").attr("title"), "Clear", "check clearsearch tooltip"); |
92 | | -}); |
93 | | - |
94 | | -test("reveal clearsearch on text", function() { |
95 | | - $("#search").val("hello"); |
96 | | - var initialVisibility = $("#clearsearch").is(":visible"); |
97 | | - MFET.triggerEvent($("#search")[0], "keyup") |
98 | | - strictEqual(initialVisibility, false, "at start clear button should be hidden.") |
99 | | - strictEqual($("#clearsearch").is(":visible"), true, "clear search is now visible"); |
100 | | -}); |
101 | | - |
102 | | -test("hide clearsearch when no text", function() { |
103 | | - $("#clearsearch").show(); |
104 | | - $("#search").val(""); |
105 | | - var initialVisibility = $("#clearsearch").is(":visible"); |
106 | | - MFET.triggerEvent($("#search")[0], "keyup"); |
107 | | - strictEqual(initialVisibility, true, "at start we made it visible") |
108 | | - strictEqual($("#clearsearch").is("visible"), false, "now invisible due to lack of text in input"); |
109 | | - strictEqual($("#results").is("visible"), false, "results also hidden"); |
110 | | -}); |
111 | | - |
112 | | -test("click clearSearchBox", function() { |
113 | | - $("#search").val("hello world"); |
114 | | - $("#results,#clearsearch").show(); |
115 | | - |
116 | | - MFET.triggerEvent($("#clearsearch")[0], "mousedown") |
117 | | - |
118 | | - strictEqual($("#search").val(), "", "value reset"); |
119 | | - strictEqual($("#results").is(":visible"), false, "results hidden"); |
120 | | - strictEqual($("#clearsearch").is(":visible"), false, "clear search hidden"); |
121 | | -}); |
122 | | - |
123 | 79 | module("MobileFrontend application.js: logo click", { |
124 | 80 | setup: function() { |
125 | 81 | MFET.createFixtures(); |
Index: trunk/extensions/MobileFrontend/javascripts/opensearch.js |
— | — | @@ -136,6 +136,42 @@ |
137 | 137 | } |
138 | 138 | } |
139 | 139 | |
| 140 | + function initClearSearch() { |
| 141 | + var clearSearch = document.getElementById( 'clearsearch' ), |
| 142 | + search = document.getElementById( 'search' ), |
| 143 | + results = document.getElementById( 'results' ); |
| 144 | + function handleClearSearchLink() { |
| 145 | + if ( clearSearch ) { |
| 146 | + if ( search.value.length > 0 ) { |
| 147 | + clearSearch.style.display = 'block'; |
| 148 | + } else { |
| 149 | + clearSearch.style.display = 'none'; |
| 150 | + if ( results ) { |
| 151 | + results.style.display = 'none'; |
| 152 | + } |
| 153 | + } |
| 154 | + } |
| 155 | + } |
| 156 | + |
| 157 | + function clearSearchBox( event ) { |
| 158 | + search.value = ''; |
| 159 | + clearSearch.style.display = 'none'; |
| 160 | + if ( results ) { |
| 161 | + results.style.display = 'none'; |
| 162 | + } |
| 163 | + if ( event ) { |
| 164 | + event.preventDefault(); |
| 165 | + } |
| 166 | + } |
| 167 | + |
| 168 | + function onFocusHandler() { |
| 169 | + search.select(); |
| 170 | + } |
| 171 | + u( clearSearch ).bind( 'mousedown', clearSearchBox, true ); |
| 172 | + u( search ).bind( 'keyup', handleClearSearchLink, false ); |
| 173 | + u( search ).bind( 'click', onFocusHandler, true ); |
| 174 | + } |
| 175 | + |
140 | 176 | function init() { |
141 | 177 | var results = document.getElementById( 'results' ); |
142 | 178 | results.onmousedown = whichElement; |
— | — | @@ -144,9 +180,11 @@ |
145 | 181 | results.ontouchstart = whichElement; |
146 | 182 | } |
147 | 183 | init(); |
| 184 | + initClearSearch(); |
148 | 185 | |
149 | 186 | return { |
150 | 187 | init: init, |
| 188 | + initClearSearch: initClearSearch, |
151 | 189 | writeResults: writeResults, |
152 | 190 | createObjectArray: createObjectArray |
153 | 191 | }; |
Index: trunk/extensions/MobileFrontend/javascripts/beta_application.js |
— | — | @@ -32,24 +32,12 @@ |
33 | 33 | heading.insertBefore( createButton( false ), heading.firstChild ); |
34 | 34 | utilities( heading ).bind( 'click', openSectionHandler, false ); |
35 | 35 | } |
36 | | - search = document.getElementById( 'search' ); |
37 | | - clearSearch = document.getElementById( 'clearsearch' ); |
38 | 36 | results = document.getElementById( 'results' ); |
39 | 37 | languageSelection = document.getElementById( 'languageselection' ); |
40 | 38 | |
41 | 39 | zeroRatedBanner = document.getElementById( 'zero-rated-banner' ) || |
42 | 40 | document.getElementById( 'zero-rated-banner-red' ); |
43 | 41 | |
44 | | - function initClearSearchLink() { |
45 | | - function onFocusHandler() { |
46 | | - search.select(); |
47 | | - } |
48 | | - utilities( clearSearch ).bind( 'mousedown', clearSearchBox, true ); |
49 | | - utilities( search ).bind( 'keyup', handleClearSearchLink, false ); |
50 | | - utilities( search ).bind( 'keydown', handleDefaultText, false ); |
51 | | - utilities( search ).bind( 'click', onFocusHandler, true ); |
52 | | - } |
53 | | - |
54 | 42 | function navigateToLanguageSelection() { |
55 | 43 | var url; |
56 | 44 | if ( languageSelection ) { |
— | — | @@ -61,39 +49,10 @@ |
62 | 50 | } |
63 | 51 | utilities( languageSelection ).bind( 'change', navigateToLanguageSelection ); |
64 | 52 | |
65 | | - function handleDefaultText() { |
66 | | - var pE = document.getElementById( 'placeholder' ); |
67 | | - if ( pE ) { |
68 | | - pE.style.display = 'none'; |
69 | | - } |
70 | | - } |
71 | | - |
72 | | - function handleClearSearchLink() { |
73 | | - if ( clearSearch ) { |
74 | | - if ( search.value.length > 0 ) { |
75 | | - clearSearch.style.display = 'block'; |
76 | | - } else { |
77 | | - clearSearch.style.display = 'none'; |
78 | | - } |
79 | | - } |
80 | | - } |
81 | | - |
82 | | - function clearSearchBox( event ) { |
83 | | - search.value = ''; |
84 | | - clearSearch.style.display = 'none'; |
85 | | - if ( event ) { |
86 | | - event.preventDefault(); |
87 | | - } |
88 | | - } |
89 | | - |
90 | 53 | function logoClick() { |
91 | 54 | var n = document.getElementById( 'nav' ).style; |
92 | 55 | n.display = n.display === 'block' ? 'none' : 'block'; |
93 | 56 | } |
94 | | - initClearSearchLink(); |
95 | | - search.onpaste = function() { |
96 | | - handleDefaultText(); |
97 | | - }; |
98 | 57 | utilities( document.getElementById( 'logo' ) ).bind( 'click', logoClick ); |
99 | 58 | dismissNotification = document.getElementById( 'dismiss-notification' ); |
100 | 59 | |
Index: trunk/extensions/MobileFrontend/javascripts/beta_opensearch.js |
— | — | @@ -244,17 +244,58 @@ |
245 | 245 | } |
246 | 246 | } |
247 | 247 | |
| 248 | + function handleDefaultText() { |
| 249 | + var pE = document.getElementById( 'placeholder' ); |
| 250 | + if ( pE ) { |
| 251 | + pE.style.display = 'none'; |
| 252 | + } |
| 253 | + } |
| 254 | + |
| 255 | + function initClearSearch() { |
| 256 | + var clearSearch = document.getElementById( 'clearsearch' ), |
| 257 | + search = document.getElementById( 'search' ), |
| 258 | + results = document.getElementById( 'results' ); |
| 259 | + function handleClearSearchLink() { |
| 260 | + if ( clearSearch ) { |
| 261 | + if ( search.value.length > 0 ) { |
| 262 | + clearSearch.style.display = 'block'; |
| 263 | + } else { |
| 264 | + clearSearch.style.display = 'none'; |
| 265 | + } |
| 266 | + } |
| 267 | + } |
| 268 | + |
| 269 | + function clearSearchBox( event ) { |
| 270 | + search.value = ''; |
| 271 | + clearSearch.style.display = 'none'; |
| 272 | + if ( event ) { |
| 273 | + event.preventDefault(); |
| 274 | + } |
| 275 | + } |
| 276 | + |
| 277 | + function onFocusHandler() { |
| 278 | + search.select(); |
| 279 | + } |
| 280 | + u( clearSearch ).bind( 'mousedown', clearSearchBox, true ); |
| 281 | + u( search ).bind( 'keyup', handleClearSearchLink, false ); |
| 282 | + u( search ).bind( 'keydown', handleDefaultText, false ); |
| 283 | + u( search ).bind( 'click', onFocusHandler, true ); |
| 284 | + } |
| 285 | + |
248 | 286 | function init() { |
249 | 287 | var results = document.getElementById( 'results' ); |
250 | 288 | results.onmousedown = whichElement; |
251 | 289 | document.body.onmousedown = whichElement; |
252 | 290 | document.body.ontouchstart = whichElement; |
253 | 291 | results.ontouchstart = whichElement; |
| 292 | + search.onpaste = handleDefaultText; |
254 | 293 | } |
255 | 294 | init(); |
| 295 | + initClearSearch(); |
256 | 296 | |
257 | 297 | return { |
258 | 298 | init: init, |
| 299 | + initClearSearch: initClearSearch, |
259 | 300 | writeResults: writeResults, |
260 | 301 | createObjectArray: createObjectArray, |
261 | 302 | removeResults: removeResults |
Index: trunk/extensions/MobileFrontend/javascripts/application.js |
— | — | @@ -3,7 +3,7 @@ |
4 | 4 | MobileFrontend = (function() { |
5 | 5 | |
6 | 6 | function init() { |
7 | | - var i, search, clearSearch, results, languageSelection, a, heading, |
| 7 | + var i, results, languageSelection, a, heading, |
8 | 8 | sectionHeadings = document.getElementsByClassName( 'section_heading' ), |
9 | 9 | dismissNotification, cookieNameZeroVisibility, zeroRatedBanner, zeroRatedBannerVisibility; |
10 | 10 | utilities( document.body ).addClass( 'jsEnabled' ); |
— | — | @@ -28,20 +28,9 @@ |
29 | 29 | heading.insertBefore( createButton( false ), heading.firstChild ); |
30 | 30 | utilities( heading ).bind( 'click', openSectionHandler, false ); |
31 | 31 | } |
32 | | - search = document.getElementById( 'search' ); |
33 | | - clearSearch = document.getElementById( 'clearsearch' ); |
34 | 32 | results = document.getElementById( 'results' ); |
35 | 33 | languageSelection = document.getElementById( 'languageselection' ); |
36 | 34 | |
37 | | - function initClearSearchLink() { |
38 | | - function onFocusHandler() { |
39 | | - search.select(); |
40 | | - } |
41 | | - utilities( clearSearch ).bind( 'mousedown', clearSearchBox, true ); |
42 | | - utilities( search ).bind( 'keyup', handleClearSearchLink, false ); |
43 | | - utilities( search ).bind( 'click', onFocusHandler, true ); |
44 | | - } |
45 | | - |
46 | 35 | function navigateToLanguageSelection() { |
47 | 36 | var url; |
48 | 37 | if ( languageSelection ) { |
— | — | @@ -53,35 +42,10 @@ |
54 | 43 | } |
55 | 44 | utilities( languageSelection ).bind( 'change', navigateToLanguageSelection ); |
56 | 45 | |
57 | | - function handleClearSearchLink() { |
58 | | - if ( clearSearch ) { |
59 | | - if ( search.value.length > 0 ) { |
60 | | - clearSearch.style.display = 'block'; |
61 | | - } else { |
62 | | - clearSearch.style.display = 'none'; |
63 | | - if ( results ) { |
64 | | - results.style.display = 'none'; |
65 | | - } |
66 | | - } |
67 | | - } |
68 | | - } |
69 | | - |
70 | | - function clearSearchBox( event ) { |
71 | | - search.value = ''; |
72 | | - clearSearch.style.display = 'none'; |
73 | | - if ( results ) { |
74 | | - results.style.display = 'none'; |
75 | | - } |
76 | | - if ( event ) { |
77 | | - event.preventDefault(); |
78 | | - } |
79 | | - } |
80 | | - |
81 | 46 | function logoClick() { |
82 | 47 | var n = document.getElementById( 'nav' ).style; |
83 | 48 | n.display = n.display === 'block' ? 'none' : 'block'; |
84 | 49 | } |
85 | | - initClearSearchLink(); |
86 | 50 | utilities( document.getElementById( 'logo' ) ).bind( 'click', logoClick ); |
87 | 51 | dismissNotification = document.getElementById( 'dismiss-notification' ); |
88 | 52 | |