https://www.mediawiki.org/wiki/Special:Code/MediaWiki/112309
Revision: 112309
Author: jdlrobson
Date: 2012-02-24 10:19:34 +0000 (Fri, 24 Feb 2012)
Log Message:
-----------
separate banner code from search code and toggle code
this separates all the banner code into a separate banner
added test file test_banner and moved tests from test_application
here
this allows us more flexibility to do things such as not serve banner
code for certain devices which don't need it.
have avoided creating a beta_banner for current time since changes between
application and beta_application so minimal (essentially beta banner checks
for #zero-rated-banner-red in absence of #zero-rated-banner
Modified Paths:
--------------
trunk/extensions/MobileFrontend/MobileFrontend.body.php
trunk/extensions/MobileFrontend/javascripts/application.js
trunk/extensions/MobileFrontend/javascripts/beta_application.js
trunk/extensions/MobileFrontend/templates/ApplicationTemplate.php
trunk/extensions/MobileFrontend/tests/js/test_application.js
Added Paths:
-----------
trunk/extensions/MobileFrontend/javascripts/banner.js
trunk/extensions/MobileFrontend/tests/js/test_banner.js
Modified: trunk/extensions/MobileFrontend/MobileFrontend.body.php
===================================================================
--- trunk/extensions/MobileFrontend/MobileFrontend.body.php 2012-02-24
10:16:34 UTC (rev 112308)
+++ trunk/extensions/MobileFrontend/MobileFrontend.body.php 2012-02-24
10:19:34 UTC (rev 112309)
@@ -1304,8 +1304,8 @@
public function addTestModules( array &$testModules, ResourceLoader
&$resourceLoader ) {
$testModules['qunit']['ext.mobilefrontend.tests'] = array(
'scripts' => array( 'tests/js/fixtures.js',
'javascripts/application.js',
- 'javascripts/opensearch.js',
- 'tests/js/test_application.js',
'tests/js/test_opensearch.js' ),
+ 'javascripts/opensearch.js',
'javascripts/banner.js',
+ 'tests/js/test_application.js',
'tests/js/test_opensearch.js', 'tests/js/test_banner.js' ),
'dependencies' => array( ),
'localBasePath' => dirname( __FILE__ ),
'remoteExtPath' => 'MobileFrontend',
Modified: trunk/extensions/MobileFrontend/javascripts/application.js
===================================================================
--- trunk/extensions/MobileFrontend/javascripts/application.js 2012-02-24
10:16:34 UTC (rev 112308)
+++ trunk/extensions/MobileFrontend/javascripts/application.js 2012-02-24
10:19:34 UTC (rev 112309)
@@ -4,8 +4,7 @@
function init() {
var i, results, languageSelection, a, heading,
- sectionHeadings = document.getElementsByClassName(
'section_heading' ),
- dismissNotification, cookieNameZeroVisibility,
zeroRatedBanner, zeroRatedBannerVisibility;
+ sectionHeadings = document.getElementsByClassName(
'section_heading' );
utilities( document.body ).addClass( 'jsEnabled' );
function openSectionHandler() {
var sectionNumber = this.id ? this.id.split( '_' )[1] :
-1;
@@ -47,25 +46,7 @@
n.display = n.display === 'block' ? 'none' : 'block';
}
utilities( document.getElementById( 'logo' ) ).bind( 'click',
logoClick );
- dismissNotification = document.getElementById(
'dismiss-notification' );
- if ( dismissNotification ) {
- cookieNameZeroVisibility = 'zeroRatedBannerVisibility';
- zeroRatedBanner = document.getElementById(
'zero-rated-banner' );
- zeroRatedBannerVisibility = readCookie(
cookieNameZeroVisibility );
-
- if ( zeroRatedBannerVisibility === 'off' ) {
- zeroRatedBanner.style.display = 'none';
- }
-
- dismissNotification.onclick = function() {
- if ( zeroRatedBanner ) {
- zeroRatedBanner.style.display = 'none';
- writeCookie( cookieNameZeroVisibility,
'off', 1 );
- }
- };
- }
-
function checkHash() {
var hash = this.hash || document.location.hash;
if ( hash.indexOf( '#' ) === 0 ) {
@@ -113,39 +94,6 @@
}
}
- function writeCookie( name, value, days ) {
- var date, expires;
- if ( days ) {
- date = new Date();
- date.setTime( date.getTime() + ( days * 24 * 60 * 60
*1000 ) );
- expires = '; expires=' + date.toGMTString();
- } else {
- expires = '';
- }
- document.cookie = name + '=' + value + expires + '; path=/';
- }
-
- function readCookie( name ) {
- var nameVA = name + '=',
- ca = document.cookie.split( ';' ),
- c, i;
- for( i=0; i < ca.length; i++ ) {
- c = ca[i];
- while ( c.charAt(0) === ' ' ) {
- c = c.substring( 1, c.length );
- }
- if ( c.indexOf( nameVA ) === 0 ) {
- return c.substring( nameVA.length, c.length );
- }
- }
- return null;
- }
-
- function removeCookie( name ) {
- writeCookie( name, '', -1 );
- return null;
- }
-
function utilities( el ) {
function addClass( name ) {
var className = el.className,
@@ -193,9 +141,6 @@
};
return {
- readCookie: readCookie,
- writeCookie: writeCookie,
- removeCookie: removeCookie,
wm_reveal_for_hash: wm_reveal_for_hash,
wm_toggle_section: wm_toggle_section,
init: init,
Added: trunk/extensions/MobileFrontend/javascripts/banner.js
===================================================================
--- trunk/extensions/MobileFrontend/javascripts/banner.js
(rev 0)
+++ trunk/extensions/MobileFrontend/javascripts/banner.js 2012-02-24
10:19:34 UTC (rev 112309)
@@ -0,0 +1,64 @@
+MobileFrontend.banner = (function() {
+ function init() {
+ var dismissNotification, cookieNameZeroVisibility,
zeroRatedBanner, zeroRatedBannerVisibility;
+ dismissNotification = document.getElementById(
'dismiss-notification' );
+ if ( dismissNotification ) {
+ cookieNameZeroVisibility = 'zeroRatedBannerVisibility';
+ zeroRatedBanner = document.getElementById(
'zero-rated-banner' ) ||
+ document.getElementById(
'zero-rated-banner-red' );
+ zeroRatedBannerVisibility = readCookie(
cookieNameZeroVisibility );
+
+ if ( zeroRatedBannerVisibility === 'off' ) {
+ zeroRatedBanner.style.display = 'none';
+ }
+
+ dismissNotification.onclick = function() {
+ if ( zeroRatedBanner ) {
+ zeroRatedBanner.style.display = 'none';
+ writeCookie( cookieNameZeroVisibility,
'off', 1 );
+ }
+ };
+ }
+ }
+
+ function writeCookie( name, value, days ) {
+ var date, expires;
+ if ( days ) {
+ date = new Date();
+ date.setTime( date.getTime() + ( days * 24 * 60 * 60
*1000 ) );
+ expires = '; expires=' + date.toGMTString();
+ } else {
+ expires = '';
+ }
+ document.cookie = name + '=' + value + expires + '; path=/';
+ }
+
+ function readCookie( name ) {
+ var nameVA = name + '=',
+ ca = document.cookie.split( ';' ),
+ c, i;
+ for( i=0; i < ca.length; i++ ) {
+ c = ca[i];
+ while ( c.charAt(0) === ' ' ) {
+ c = c.substring( 1, c.length );
+ }
+ if ( c.indexOf( nameVA ) === 0 ) {
+ return c.substring( nameVA.length, c.length );
+ }
+ }
+ return null;
+ }
+
+ function removeCookie( name ) {
+ writeCookie( name, '', -1 );
+ return null;
+ }
+
+ init();
+ return {
+ init: init,
+ readCookie: readCookie,
+ writeCookie: writeCookie,
+ removeCookie: removeCookie
+ }
+})();
Modified: trunk/extensions/MobileFrontend/javascripts/beta_application.js
===================================================================
--- trunk/extensions/MobileFrontend/javascripts/beta_application.js
2012-02-24 10:16:34 UTC (rev 112308)
+++ trunk/extensions/MobileFrontend/javascripts/beta_application.js
2012-02-24 10:19:34 UTC (rev 112309)
@@ -8,8 +8,7 @@
function init() {
var i, search, clearSearch, results, languageSelection, a,
heading,
- sectionHeadings = document.getElementsByClassName(
'section_heading' ),
- dismissNotification, cookieNameZeroVisibility,
zeroRatedBanner, zeroRatedBannerVisibility;
+ sectionHeadings = document.getElementsByClassName(
'section_heading' );
utilities( document.body ).addClass( 'jsEnabled' );
function openSectionHandler() {
var sectionNumber = this.id ? this.id.split( '_' )[1] :
-1;
@@ -35,9 +34,6 @@
results = document.getElementById( 'results' );
languageSelection = document.getElementById(
'languageselection' );
- zeroRatedBanner = document.getElementById( 'zero-rated-banner'
) ||
- document.getElementById( 'zero-rated-banner-red' );
-
function navigateToLanguageSelection() {
var url;
if ( languageSelection ) {
@@ -54,25 +50,7 @@
n.display = n.display === 'block' ? 'none' : 'block';
}
utilities( document.getElementById( 'logo' ) ).bind( 'click',
logoClick );
- dismissNotification = document.getElementById(
'dismiss-notification' );
- if ( dismissNotification ) {
- cookieNameZeroVisibility = 'zeroRatedBannerVisibility';
- zeroRatedBanner = document.getElementById(
'zero-rated-banner' );
- zeroRatedBannerVisibility = readCookie(
cookieNameZeroVisibility );
-
- if ( zeroRatedBannerVisibility === 'off' ) {
- zeroRatedBanner.style.display = 'none';
- }
-
- dismissNotification.onclick = function() {
- if ( zeroRatedBanner ) {
- zeroRatedBanner.style.display = 'none';
- writeCookie( cookieNameZeroVisibility,
'off', 1 );
- }
- };
- }
-
function checkHash() {
var hash = this.hash || document.location.hash;
if ( hash.indexOf( '#' ) === 0 ) {
@@ -120,39 +98,6 @@
}
}
- function writeCookie( name, value, days ) {
- var date, expires;
- if ( days ) {
- date = new Date();
- date.setTime( date.getTime() + ( days * 24 * 60 * 60
*1000 ) );
- expires = '; expires=' + date.toGMTString();
- } else {
- expires = '';
- }
- document.cookie = name + '=' + value + expires + '; path=/';
- }
-
- function readCookie( name ) {
- var nameVA = name + '=',
- ca = document.cookie.split( ';' ),
- c, i;
- for( i=0; i < ca.length; i++ ) {
- c = ca[i];
- while ( c.charAt(0) === ' ' ) {
- c = c.substring( 1, c.length );
- }
- if ( c.indexOf( nameVA ) === 0 ) {
- return c.substring( nameVA.length, c.length );
- }
- }
- return null;
- }
-
- function removeCookie( name ) {
- writeCookie( name, '', -1 );
- return null;
- }
-
function utilities( el ) {
function addClass( name ) {
var className = el.className,
@@ -200,9 +145,6 @@
};
return {
- readCookie: readCookie,
- writeCookie: writeCookie,
- removeCookie: removeCookie,
wm_reveal_for_hash: wm_reveal_for_hash,
wm_toggle_section: wm_toggle_section,
init: init,
Modified: trunk/extensions/MobileFrontend/templates/ApplicationTemplate.php
===================================================================
--- trunk/extensions/MobileFrontend/templates/ApplicationTemplate.php
2012-02-24 10:16:34 UTC (rev 112308)
+++ trunk/extensions/MobileFrontend/templates/ApplicationTemplate.php
2012-02-24 10:19:34 UTC (rev 112309)
@@ -73,6 +73,7 @@
{$this->data['footerHtml']}
<!--[if gt IE 9]><!-->
{$startScriptTag}{$javaScriptPath}{$betaPrefix}application.js?version=01132011120915{$endScriptTag}
+
{$startScriptTag}{$javaScriptPath}banner.js{$endScriptTag}
{$openSearchScript}
{$filePageScript}
<!--[endif]-->
Modified: trunk/extensions/MobileFrontend/tests/js/test_application.js
===================================================================
--- trunk/extensions/MobileFrontend/tests/js/test_application.js
2012-02-24 10:16:34 UTC (rev 112308)
+++ trunk/extensions/MobileFrontend/tests/js/test_application.js
2012-02-24 10:19:34 UTC (rev 112309)
@@ -21,60 +21,6 @@
strictEqual($(el).hasClass("bar"), false);
});
-module("MobileFrontend application.js: cookies");
-
-test("read and write cookies", function() {
- var cookie_name = "test_cookies_module";
- MFE.writeCookie(cookie_name, "yes", 400);
- var cookieVal = MFE.readCookie(cookie_name);
- strictEqual(cookieVal, "yes",
- "Are you running off localhost?");
-});
-
-test("read and write cookies with spaces", function() {
- var cookie_name = "test_cookies_module";
- MFE.writeCookie(cookie_name, " yes this has spaces ", 400);
- MFE.writeCookie(cookie_name + "2", " yes this has spaces ", 400);
- var cookieVal = MFE.readCookie(cookie_name);
- strictEqual(cookieVal, "yes this has spaces",
- "spaces are kept and trailing whitespace is removed");
-});
-
-test("remove cookie via write", function() {
- var cookie_name = "test_cookies_module";
- MFE.writeCookie(cookie_name, "", -1);
- var cookieVal = MFE.readCookie(cookie_name);
- strictEqual(cookieVal, null, "Cookie deleted");
-});
-
-var BANNER_COOKIE_NAME = "zeroRatedBannerVisibility";
-module("MobileFrontend application.js: notifications", {
- setup: function() {
- MFET.cleanFixtures();
- MFE.removeCookie(BANNER_COOKIE_NAME);
- MFET.createFixtures();
- MFE.init();
- },
- teardown: function() {
- MFET.cleanFixtures();
- MFE.removeCookie(BANNER_COOKIE_NAME);
- }
-});
-
-test("dismiss notification", function() {
- var cookieStart = MFE.readCookie(BANNER_COOKIE_NAME);
- strictEqual(cookieStart, null, "no cookie set at start");
- strictEqual($("#zero-rated-banner").is(":visible"), true, "banner
should be on show");
-
- // trigger dismiss event
- $("#dismiss-notification").trigger("click");
-
- var cookieEnd = MFE.readCookie(BANNER_COOKIE_NAME);
- strictEqual(cookieStart, null, "no cookie set at start");
- strictEqual($("#zero-rated-banner").is(":visible"), false, "banner
should now be hidden");
- strictEqual(cookieEnd, "off", "banner now set for dismissal");
-});
-
module("MobileFrontend application.js: logo click", {
setup: function() {
MFET.createFixtures();
Added: trunk/extensions/MobileFrontend/tests/js/test_banner.js
===================================================================
--- trunk/extensions/MobileFrontend/tests/js/test_banner.js
(rev 0)
+++ trunk/extensions/MobileFrontend/tests/js/test_banner.js 2012-02-24
10:19:34 UTC (rev 112309)
@@ -0,0 +1,56 @@
+var MFEB = MobileFrontend.banner;
+var MFEBT = window.MobileFrontendTests;
+
+module("MobileFrontend banner.js: cookies");
+
+test("read and write cookies", function() {
+ var cookie_name = "test_cookies_module";
+ MFEB.writeCookie(cookie_name, "yes", 400);
+ var cookieVal = MFEB.readCookie(cookie_name);
+ strictEqual(cookieVal, "yes",
+ "Are you running off localhost?");
+});
+
+test("read and write cookies with spaces", function() {
+ var cookie_name = "test_cookies_module";
+ MFEB.writeCookie(cookie_name, " yes this has spaces ", 400);
+ MFEB.writeCookie(cookie_name + "2", " yes this has spaces ",
400);
+ var cookieVal = MFEB.readCookie(cookie_name);
+ strictEqual(cookieVal, "yes this has spaces",
+ "spaces are kept and trailing whitespace is removed");
+});
+
+test("remove cookie via write", function() {
+ var cookie_name = "test_cookies_module";
+ MFEB.writeCookie(cookie_name, "", -1);
+ var cookieVal = MFEB.readCookie(cookie_name);
+ strictEqual(cookieVal, null, "Cookie deleted");
+});
+
+var BANNER_COOKIE_NAME = "zeroRatedBannerVisibility";
+module("MobileFrontend application.js: notifications", {
+ setup: function() {
+ MFEBT.cleanFixtures();
+ MFEB.removeCookie(BANNER_COOKIE_NAME);
+ MFEBT.createFixtures();
+ MFEB.init();
+ },
+ teardown: function() {
+ MFEBT.cleanFixtures();
+ MFEB.removeCookie(BANNER_COOKIE_NAME);
+ }
+});
+
+test("MobileFrontend banner.js: dismiss notification", function() {
+ var cookieStart = MFEB.readCookie(BANNER_COOKIE_NAME);
+ strictEqual(cookieStart, null, "no cookie set at start");
+ strictEqual($("#zero-rated-banner").is(":visible"), true, "banner
should be on show");
+
+ // trigger dismiss event
+ $("#dismiss-notification").trigger("click");
+
+ var cookieEnd = MFEB.readCookie(BANNER_COOKIE_NAME);
+ strictEqual(cookieStart, null, "no cookie set at start");
+ strictEqual($("#zero-rated-banner").is(":visible"), false, "banner
should now be hidden");
+ strictEqual(cookieEnd, "off", "banner now set for dismissal");
+});
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs