Index: trunk/extensions/MobileFrontend/tests/js/test_beta_opensearch.js |
— | — | @@ -0,0 +1,69 @@ |
| 2 | +var MFEOS = MobileFrontend.opensearch; |
| 3 | +var MFET = window.MobileFrontendTests; |
| 4 | + |
| 5 | +module("beta_opensearch.js - test highlight", { |
| 6 | + setup: function() { |
| 7 | + MFET.createFixtures(); |
| 8 | + MFEOS.init(); |
| 9 | + }, |
| 10 | + teardown: function() { |
| 11 | + $("#betaos").remove(); |
| 12 | + MFET.cleanFixtures(); |
| 13 | + } |
| 14 | +}); |
| 15 | + |
| 16 | +test("no results", function() { |
| 17 | + MFEOS.writeResults([]); |
| 18 | + strictEqual($("#results").text(), "No Results"); |
| 19 | +}); |
| 20 | + |
| 21 | +test("writeResults with highlighted text (case differs)", function() { |
| 22 | + var results = [ |
| 23 | + { label: "Hello world", value: "/HelloWorld" }, |
| 24 | + { label: "Hello kitty", value: "/HelloKitty" } |
| 25 | + ]; |
| 26 | + $("#search").val("el"); |
| 27 | + MFET.triggerEvent($("#search")[0], "keyup"); |
| 28 | + MFEOS.writeResults(results); |
| 29 | + var pageLink = $("#results .suggestions-result a.search-result-item")[0]; |
| 30 | + var pageLink2 = $("#results .suggestions-result a.search-result-item")[1]; |
| 31 | + strictEqual($(pageLink).text(), "Hello world", "check the label is correct"); |
| 32 | + strictEqual($(pageLink).html(), "H<strong>el</strong>lo world", "check the highlight is correct"); |
| 33 | + strictEqual($(pageLink2).html(), "H<strong>el</strong>lo kitty", "check the highlight is correct"); |
| 34 | +}); |
| 35 | + |
| 36 | +test("writeResults with highlighted text (case differs)", function() { |
| 37 | + var results = [ |
| 38 | + { label: "Hello world", value: "/HelloWorld" }, |
| 39 | + { label: "Hello kitty", value: "/HelloKitty" } |
| 40 | + ]; |
| 41 | + $("#search").val("hel"); |
| 42 | + MFET.triggerEvent($("#search")[0], "keyup"); |
| 43 | + MFEOS.writeResults(results); |
| 44 | + var pageLink = $("#results .suggestions-result a.search-result-item")[0]; |
| 45 | + strictEqual($(pageLink).html(), "<strong>Hel</strong>lo world", "check the highlight is correct"); |
| 46 | +}); |
| 47 | + |
| 48 | +test("writeResults with highlighted text (special character &)", function() { |
| 49 | + var results = [ |
| 50 | + { label: "Belle & Sebastian", value: "/B1" }, |
| 51 | + { label: "Belle & the Beast", value: "/B2" } |
| 52 | + ]; |
| 53 | + $("#search").val("Belle & S"); |
| 54 | + MFET.triggerEvent($("#search")[0], "keyup"); |
| 55 | + MFEOS.writeResults(results); |
| 56 | + var pageLink = $("#results .suggestions-result a.search-result-item")[0]; |
| 57 | + strictEqual($(pageLink).html(), "<strong>Belle & S</strong>ebastian", "check the highlight is correct"); |
| 58 | +}); |
| 59 | + |
| 60 | +test("writeResults with highlighted text (special character ?)", function() { |
| 61 | + var results = [ |
| 62 | + { label: "Title with ? in it", value: "/B1" } |
| 63 | + ]; |
| 64 | + $("#search").val("with ?"); |
| 65 | + MFET.triggerEvent($("#search")[0], "keyup"); |
| 66 | + MFEOS.writeResults(results); |
| 67 | + var pageLink = $("#results .suggestions-result a.search-result-item")[0]; |
| 68 | + strictEqual($(pageLink).html(), "Title <strong>with ?</strong> in it", "check the highlight is correct"); |
| 69 | +}); |
| 70 | + |
Index: trunk/extensions/MobileFrontend/MobileFrontend.body.php |
— | — | @@ -1302,6 +1302,13 @@ |
1303 | 1303 | 'localBasePath' => dirname( __FILE__ ), |
1304 | 1304 | 'remoteExtPath' => 'MobileFrontend', |
1305 | 1305 | ); |
| 1306 | + $testModules['qunit']['ext.mobilefrontend.tests.beta'] = array( |
| 1307 | + 'scripts' => array( 'tests/js/fixtures.js', 'javascripts/beta_application.js', |
| 1308 | + 'javascripts/beta_opensearch.js', 'tests/js/test_beta_opensearch.js' ), |
| 1309 | + 'dependencies' => array( ), |
| 1310 | + 'localBasePath' => dirname( __FILE__ ), |
| 1311 | + 'remoteExtPath' => 'MobileFrontend', |
| 1312 | + ); |
1306 | 1313 | return true; |
1307 | 1314 | } |
1308 | 1315 | |
Index: trunk/extensions/MobileFrontend/javascripts/beta_opensearch.js |
— | — | @@ -40,6 +40,10 @@ |
41 | 41 | search.onfocus = function() { |
42 | 42 | var pE, pT, pTT, rrd, rrdD, |
43 | 43 | removeResultsEl; |
| 44 | + sb = document.getElementById( 'searchbox' ); |
| 45 | + sq = document.getElementById( 'sq' ); |
| 46 | + content = document.getElementById( 'content' ); |
| 47 | + footer = document.getElementById( 'footer' ); |
44 | 48 | resetViewPort(); |
45 | 49 | |
46 | 50 | if ( zeroRatedBanner ) { |
— | — | @@ -305,7 +309,7 @@ |
306 | 310 | } |
307 | 311 | |
308 | 312 | function escapeJsString( str ) { |
309 | | - return String( str ).replace( /\\/g, '\\\\' ).replace( /'/g, "\\'" ).replace( /\n/g, '\\n' ); |
| 313 | + return str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); |
310 | 314 | } |
311 | 315 | |
312 | 316 | function writeResults( sections ) { |