Index: trunk/extensions/MobileFrontend/templates/ApplicationTemplate.php |
— | — | @@ -73,6 +73,7 @@ |
74 | 74 | {$this->data['footerHtml']} |
75 | 75 | <!--[if gt IE 9]><!--> |
76 | 76 | {$startScriptTag}{$javaScriptPath}{$betaPrefix}application.js?version=01132011120915{$endScriptTag} |
| 77 | + {$startScriptTag}{$javaScriptPath}banner.js{$endScriptTag} |
77 | 78 | {$openSearchScript} |
78 | 79 | {$filePageScript} |
79 | 80 | <!--[endif]--> |
Index: trunk/extensions/MobileFrontend/tests/js/test_application.js |
— | — | @@ -21,60 +21,6 @@ |
22 | 22 | strictEqual($(el).hasClass("bar"), false); |
23 | 23 | }); |
24 | 24 | |
25 | | -module("MobileFrontend application.js: cookies"); |
26 | | - |
27 | | -test("read and write cookies", function() { |
28 | | - var cookie_name = "test_cookies_module"; |
29 | | - MFE.writeCookie(cookie_name, "yes", 400); |
30 | | - var cookieVal = MFE.readCookie(cookie_name); |
31 | | - strictEqual(cookieVal, "yes", |
32 | | - "Are you running off localhost?"); |
33 | | -}); |
34 | | - |
35 | | -test("read and write cookies with spaces", function() { |
36 | | - var cookie_name = "test_cookies_module"; |
37 | | - MFE.writeCookie(cookie_name, " yes this has spaces ", 400); |
38 | | - MFE.writeCookie(cookie_name + "2", " yes this has spaces ", 400); |
39 | | - var cookieVal = MFE.readCookie(cookie_name); |
40 | | - strictEqual(cookieVal, "yes this has spaces", |
41 | | - "spaces are kept and trailing whitespace is removed"); |
42 | | -}); |
43 | | - |
44 | | -test("remove cookie via write", function() { |
45 | | - var cookie_name = "test_cookies_module"; |
46 | | - MFE.writeCookie(cookie_name, "", -1); |
47 | | - var cookieVal = MFE.readCookie(cookie_name); |
48 | | - strictEqual(cookieVal, null, "Cookie deleted"); |
49 | | -}); |
50 | | - |
51 | | -var BANNER_COOKIE_NAME = "zeroRatedBannerVisibility"; |
52 | | -module("MobileFrontend application.js: notifications", { |
53 | | - setup: function() { |
54 | | - MFET.cleanFixtures(); |
55 | | - MFE.removeCookie(BANNER_COOKIE_NAME); |
56 | | - MFET.createFixtures(); |
57 | | - MFE.init(); |
58 | | - }, |
59 | | - teardown: function() { |
60 | | - MFET.cleanFixtures(); |
61 | | - MFE.removeCookie(BANNER_COOKIE_NAME); |
62 | | - } |
63 | | -}); |
64 | | - |
65 | | -test("dismiss notification", function() { |
66 | | - var cookieStart = MFE.readCookie(BANNER_COOKIE_NAME); |
67 | | - strictEqual(cookieStart, null, "no cookie set at start"); |
68 | | - strictEqual($("#zero-rated-banner").is(":visible"), true, "banner should be on show"); |
69 | | - |
70 | | - // trigger dismiss event |
71 | | - $("#dismiss-notification").trigger("click"); |
72 | | - |
73 | | - var cookieEnd = MFE.readCookie(BANNER_COOKIE_NAME); |
74 | | - strictEqual(cookieStart, null, "no cookie set at start"); |
75 | | - strictEqual($("#zero-rated-banner").is(":visible"), false, "banner should now be hidden"); |
76 | | - strictEqual(cookieEnd, "off", "banner now set for dismissal"); |
77 | | -}); |
78 | | - |
79 | 25 | module("MobileFrontend application.js: logo click", { |
80 | 26 | setup: function() { |
81 | 27 | MFET.createFixtures(); |
Index: trunk/extensions/MobileFrontend/tests/js/test_banner.js |
— | — | @@ -0,0 +1,56 @@ |
| 2 | +var MFEB = MobileFrontend.banner; |
| 3 | +var MFEBT = window.MobileFrontendTests; |
| 4 | + |
| 5 | +module("MobileFrontend banner.js: cookies"); |
| 6 | + |
| 7 | +test("read and write cookies", function() { |
| 8 | + var cookie_name = "test_cookies_module"; |
| 9 | + MFEB.writeCookie(cookie_name, "yes", 400); |
| 10 | + var cookieVal = MFEB.readCookie(cookie_name); |
| 11 | + strictEqual(cookieVal, "yes", |
| 12 | + "Are you running off localhost?"); |
| 13 | +}); |
| 14 | + |
| 15 | +test("read and write cookies with spaces", function() { |
| 16 | + var cookie_name = "test_cookies_module"; |
| 17 | + MFEB.writeCookie(cookie_name, " yes this has spaces ", 400); |
| 18 | + MFEB.writeCookie(cookie_name + "2", " yes this has spaces ", 400); |
| 19 | + var cookieVal = MFEB.readCookie(cookie_name); |
| 20 | + strictEqual(cookieVal, "yes this has spaces", |
| 21 | + "spaces are kept and trailing whitespace is removed"); |
| 22 | +}); |
| 23 | + |
| 24 | +test("remove cookie via write", function() { |
| 25 | + var cookie_name = "test_cookies_module"; |
| 26 | + MFEB.writeCookie(cookie_name, "", -1); |
| 27 | + var cookieVal = MFEB.readCookie(cookie_name); |
| 28 | + strictEqual(cookieVal, null, "Cookie deleted"); |
| 29 | +}); |
| 30 | + |
| 31 | +var BANNER_COOKIE_NAME = "zeroRatedBannerVisibility"; |
| 32 | +module("MobileFrontend application.js: notifications", { |
| 33 | + setup: function() { |
| 34 | + MFEBT.cleanFixtures(); |
| 35 | + MFEB.removeCookie(BANNER_COOKIE_NAME); |
| 36 | + MFEBT.createFixtures(); |
| 37 | + MFEB.init(); |
| 38 | + }, |
| 39 | + teardown: function() { |
| 40 | + MFEBT.cleanFixtures(); |
| 41 | + MFEB.removeCookie(BANNER_COOKIE_NAME); |
| 42 | + } |
| 43 | +}); |
| 44 | + |
| 45 | +test("MobileFrontend banner.js: dismiss notification", function() { |
| 46 | + var cookieStart = MFEB.readCookie(BANNER_COOKIE_NAME); |
| 47 | + strictEqual(cookieStart, null, "no cookie set at start"); |
| 48 | + strictEqual($("#zero-rated-banner").is(":visible"), true, "banner should be on show"); |
| 49 | + |
| 50 | + // trigger dismiss event |
| 51 | + $("#dismiss-notification").trigger("click"); |
| 52 | + |
| 53 | + var cookieEnd = MFEB.readCookie(BANNER_COOKIE_NAME); |
| 54 | + strictEqual(cookieStart, null, "no cookie set at start"); |
| 55 | + strictEqual($("#zero-rated-banner").is(":visible"), false, "banner should now be hidden"); |
| 56 | + strictEqual(cookieEnd, "off", "banner now set for dismissal"); |
| 57 | +}); |
Index: trunk/extensions/MobileFrontend/MobileFrontend.body.php |
— | — | @@ -1304,8 +1304,8 @@ |
1305 | 1305 | public function addTestModules( array &$testModules, ResourceLoader &$resourceLoader ) { |
1306 | 1306 | $testModules['qunit']['ext.mobilefrontend.tests'] = array( |
1307 | 1307 | 'scripts' => array( 'tests/js/fixtures.js', 'javascripts/application.js', |
1308 | | - 'javascripts/opensearch.js', |
1309 | | - 'tests/js/test_application.js', 'tests/js/test_opensearch.js' ), |
| 1308 | + 'javascripts/opensearch.js', 'javascripts/banner.js', |
| 1309 | + 'tests/js/test_application.js', 'tests/js/test_opensearch.js', 'tests/js/test_banner.js' ), |
1310 | 1310 | 'dependencies' => array( ), |
1311 | 1311 | 'localBasePath' => dirname( __FILE__ ), |
1312 | 1312 | 'remoteExtPath' => 'MobileFrontend', |
Index: trunk/extensions/MobileFrontend/javascripts/beta_application.js |
— | — | @@ -8,8 +8,7 @@ |
9 | 9 | |
10 | 10 | function init() { |
11 | 11 | var i, search, clearSearch, results, languageSelection, a, heading, |
12 | | - sectionHeadings = document.getElementsByClassName( 'section_heading' ), |
13 | | - dismissNotification, cookieNameZeroVisibility, zeroRatedBanner, zeroRatedBannerVisibility; |
| 12 | + sectionHeadings = document.getElementsByClassName( 'section_heading' ); |
14 | 13 | utilities( document.body ).addClass( 'jsEnabled' ); |
15 | 14 | function openSectionHandler() { |
16 | 15 | var sectionNumber = this.id ? this.id.split( '_' )[1] : -1; |
— | — | @@ -35,9 +34,6 @@ |
36 | 35 | results = document.getElementById( 'results' ); |
37 | 36 | languageSelection = document.getElementById( 'languageselection' ); |
38 | 37 | |
39 | | - zeroRatedBanner = document.getElementById( 'zero-rated-banner' ) || |
40 | | - document.getElementById( 'zero-rated-banner-red' ); |
41 | | - |
42 | 38 | function navigateToLanguageSelection() { |
43 | 39 | var url; |
44 | 40 | if ( languageSelection ) { |
— | — | @@ -54,25 +50,7 @@ |
55 | 51 | n.display = n.display === 'block' ? 'none' : 'block'; |
56 | 52 | } |
57 | 53 | utilities( document.getElementById( 'logo' ) ).bind( 'click', logoClick ); |
58 | | - dismissNotification = document.getElementById( 'dismiss-notification' ); |
59 | 54 | |
60 | | - if ( dismissNotification ) { |
61 | | - cookieNameZeroVisibility = 'zeroRatedBannerVisibility'; |
62 | | - zeroRatedBanner = document.getElementById( 'zero-rated-banner' ); |
63 | | - zeroRatedBannerVisibility = readCookie( cookieNameZeroVisibility ); |
64 | | - |
65 | | - if ( zeroRatedBannerVisibility === 'off' ) { |
66 | | - zeroRatedBanner.style.display = 'none'; |
67 | | - } |
68 | | - |
69 | | - dismissNotification.onclick = function() { |
70 | | - if ( zeroRatedBanner ) { |
71 | | - zeroRatedBanner.style.display = 'none'; |
72 | | - writeCookie( cookieNameZeroVisibility, 'off', 1 ); |
73 | | - } |
74 | | - }; |
75 | | - } |
76 | | - |
77 | 55 | function checkHash() { |
78 | 56 | var hash = this.hash || document.location.hash; |
79 | 57 | if ( hash.indexOf( '#' ) === 0 ) { |
— | — | @@ -120,39 +98,6 @@ |
121 | 99 | } |
122 | 100 | } |
123 | 101 | |
124 | | - function writeCookie( name, value, days ) { |
125 | | - var date, expires; |
126 | | - if ( days ) { |
127 | | - date = new Date(); |
128 | | - date.setTime( date.getTime() + ( days * 24 * 60 * 60 *1000 ) ); |
129 | | - expires = '; expires=' + date.toGMTString(); |
130 | | - } else { |
131 | | - expires = ''; |
132 | | - } |
133 | | - document.cookie = name + '=' + value + expires + '; path=/'; |
134 | | - } |
135 | | - |
136 | | - function readCookie( name ) { |
137 | | - var nameVA = name + '=', |
138 | | - ca = document.cookie.split( ';' ), |
139 | | - c, i; |
140 | | - for( i=0; i < ca.length; i++ ) { |
141 | | - c = ca[i]; |
142 | | - while ( c.charAt(0) === ' ' ) { |
143 | | - c = c.substring( 1, c.length ); |
144 | | - } |
145 | | - if ( c.indexOf( nameVA ) === 0 ) { |
146 | | - return c.substring( nameVA.length, c.length ); |
147 | | - } |
148 | | - } |
149 | | - return null; |
150 | | - } |
151 | | - |
152 | | - function removeCookie( name ) { |
153 | | - writeCookie( name, '', -1 ); |
154 | | - return null; |
155 | | - } |
156 | | - |
157 | 102 | function utilities( el ) { |
158 | 103 | function addClass( name ) { |
159 | 104 | var className = el.className, |
— | — | @@ -200,9 +145,6 @@ |
201 | 146 | }; |
202 | 147 | |
203 | 148 | return { |
204 | | - readCookie: readCookie, |
205 | | - writeCookie: writeCookie, |
206 | | - removeCookie: removeCookie, |
207 | 149 | wm_reveal_for_hash: wm_reveal_for_hash, |
208 | 150 | wm_toggle_section: wm_toggle_section, |
209 | 151 | init: init, |
Index: trunk/extensions/MobileFrontend/javascripts/application.js |
— | — | @@ -4,8 +4,7 @@ |
5 | 5 | |
6 | 6 | function init() { |
7 | 7 | var i, results, languageSelection, a, heading, |
8 | | - sectionHeadings = document.getElementsByClassName( 'section_heading' ), |
9 | | - dismissNotification, cookieNameZeroVisibility, zeroRatedBanner, zeroRatedBannerVisibility; |
| 8 | + sectionHeadings = document.getElementsByClassName( 'section_heading' ); |
10 | 9 | utilities( document.body ).addClass( 'jsEnabled' ); |
11 | 10 | function openSectionHandler() { |
12 | 11 | var sectionNumber = this.id ? this.id.split( '_' )[1] : -1; |
— | — | @@ -47,25 +46,7 @@ |
48 | 47 | n.display = n.display === 'block' ? 'none' : 'block'; |
49 | 48 | } |
50 | 49 | utilities( document.getElementById( 'logo' ) ).bind( 'click', logoClick ); |
51 | | - dismissNotification = document.getElementById( 'dismiss-notification' ); |
52 | 50 | |
53 | | - if ( dismissNotification ) { |
54 | | - cookieNameZeroVisibility = 'zeroRatedBannerVisibility'; |
55 | | - zeroRatedBanner = document.getElementById( 'zero-rated-banner' ); |
56 | | - zeroRatedBannerVisibility = readCookie( cookieNameZeroVisibility ); |
57 | | - |
58 | | - if ( zeroRatedBannerVisibility === 'off' ) { |
59 | | - zeroRatedBanner.style.display = 'none'; |
60 | | - } |
61 | | - |
62 | | - dismissNotification.onclick = function() { |
63 | | - if ( zeroRatedBanner ) { |
64 | | - zeroRatedBanner.style.display = 'none'; |
65 | | - writeCookie( cookieNameZeroVisibility, 'off', 1 ); |
66 | | - } |
67 | | - }; |
68 | | - } |
69 | | - |
70 | 51 | function checkHash() { |
71 | 52 | var hash = this.hash || document.location.hash; |
72 | 53 | if ( hash.indexOf( '#' ) === 0 ) { |
— | — | @@ -113,39 +94,6 @@ |
114 | 95 | } |
115 | 96 | } |
116 | 97 | |
117 | | - function writeCookie( name, value, days ) { |
118 | | - var date, expires; |
119 | | - if ( days ) { |
120 | | - date = new Date(); |
121 | | - date.setTime( date.getTime() + ( days * 24 * 60 * 60 *1000 ) ); |
122 | | - expires = '; expires=' + date.toGMTString(); |
123 | | - } else { |
124 | | - expires = ''; |
125 | | - } |
126 | | - document.cookie = name + '=' + value + expires + '; path=/'; |
127 | | - } |
128 | | - |
129 | | - function readCookie( name ) { |
130 | | - var nameVA = name + '=', |
131 | | - ca = document.cookie.split( ';' ), |
132 | | - c, i; |
133 | | - for( i=0; i < ca.length; i++ ) { |
134 | | - c = ca[i]; |
135 | | - while ( c.charAt(0) === ' ' ) { |
136 | | - c = c.substring( 1, c.length ); |
137 | | - } |
138 | | - if ( c.indexOf( nameVA ) === 0 ) { |
139 | | - return c.substring( nameVA.length, c.length ); |
140 | | - } |
141 | | - } |
142 | | - return null; |
143 | | - } |
144 | | - |
145 | | - function removeCookie( name ) { |
146 | | - writeCookie( name, '', -1 ); |
147 | | - return null; |
148 | | - } |
149 | | - |
150 | 98 | function utilities( el ) { |
151 | 99 | function addClass( name ) { |
152 | 100 | var className = el.className, |
— | — | @@ -193,9 +141,6 @@ |
194 | 142 | }; |
195 | 143 | |
196 | 144 | return { |
197 | | - readCookie: readCookie, |
198 | | - writeCookie: writeCookie, |
199 | | - removeCookie: removeCookie, |
200 | 145 | wm_reveal_for_hash: wm_reveal_for_hash, |
201 | 146 | wm_toggle_section: wm_toggle_section, |
202 | 147 | init: init, |
Index: trunk/extensions/MobileFrontend/javascripts/banner.js |
— | — | @@ -0,0 +1,64 @@ |
| 2 | +MobileFrontend.banner = (function() { |
| 3 | + function init() { |
| 4 | + var dismissNotification, cookieNameZeroVisibility, zeroRatedBanner, zeroRatedBannerVisibility; |
| 5 | + dismissNotification = document.getElementById( 'dismiss-notification' ); |
| 6 | + if ( dismissNotification ) { |
| 7 | + cookieNameZeroVisibility = 'zeroRatedBannerVisibility'; |
| 8 | + zeroRatedBanner = document.getElementById( 'zero-rated-banner' ) || |
| 9 | + document.getElementById( 'zero-rated-banner-red' ); |
| 10 | + zeroRatedBannerVisibility = readCookie( cookieNameZeroVisibility ); |
| 11 | + |
| 12 | + if ( zeroRatedBannerVisibility === 'off' ) { |
| 13 | + zeroRatedBanner.style.display = 'none'; |
| 14 | + } |
| 15 | + |
| 16 | + dismissNotification.onclick = function() { |
| 17 | + if ( zeroRatedBanner ) { |
| 18 | + zeroRatedBanner.style.display = 'none'; |
| 19 | + writeCookie( cookieNameZeroVisibility, 'off', 1 ); |
| 20 | + } |
| 21 | + }; |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + function writeCookie( name, value, days ) { |
| 26 | + var date, expires; |
| 27 | + if ( days ) { |
| 28 | + date = new Date(); |
| 29 | + date.setTime( date.getTime() + ( days * 24 * 60 * 60 *1000 ) ); |
| 30 | + expires = '; expires=' + date.toGMTString(); |
| 31 | + } else { |
| 32 | + expires = ''; |
| 33 | + } |
| 34 | + document.cookie = name + '=' + value + expires + '; path=/'; |
| 35 | + } |
| 36 | + |
| 37 | + function readCookie( name ) { |
| 38 | + var nameVA = name + '=', |
| 39 | + ca = document.cookie.split( ';' ), |
| 40 | + c, i; |
| 41 | + for( i=0; i < ca.length; i++ ) { |
| 42 | + c = ca[i]; |
| 43 | + while ( c.charAt(0) === ' ' ) { |
| 44 | + c = c.substring( 1, c.length ); |
| 45 | + } |
| 46 | + if ( c.indexOf( nameVA ) === 0 ) { |
| 47 | + return c.substring( nameVA.length, c.length ); |
| 48 | + } |
| 49 | + } |
| 50 | + return null; |
| 51 | + } |
| 52 | + |
| 53 | + function removeCookie( name ) { |
| 54 | + writeCookie( name, '', -1 ); |
| 55 | + return null; |
| 56 | + } |
| 57 | + |
| 58 | + init(); |
| 59 | + return { |
| 60 | + init: init, |
| 61 | + readCookie: readCookie, |
| 62 | + writeCookie: writeCookie, |
| 63 | + removeCookie: removeCookie |
| 64 | + } |
| 65 | +})(); |