Jdlrobson has submitted this change and it was merged.

Change subject: Move modules from MobileFrontend into ZeroRatedMobileAccess
......................................................................


Move modules from MobileFrontend into ZeroRatedMobileAccess

TODO: Make tests run (requires RL changes in MobileFrontend extension)
Depends on: https://gerrit.wikimedia.org/r/#/c/57554/

Change-Id: I04e0c37af78bd16754aa2fff734a02b9abf00b0f
---
M ZeroRatedMobileAccess.body.php
M ZeroRatedMobileAccess.php
A javascripts/banner.js
A stylesheets/banner.css
4 files changed, 153 insertions(+), 0 deletions(-)

Approvals:
  Dr0ptp4kt: Checked; Looks good to me, but someone else must approve
  Jdlrobson: Verified; Looks good to me, approved
  jenkins-bot: Checked



diff --git a/ZeroRatedMobileAccess.body.php b/ZeroRatedMobileAccess.body.php
index 7c575e8..746a4ae 100644
--- a/ZeroRatedMobileAccess.body.php
+++ b/ZeroRatedMobileAccess.body.php
@@ -49,6 +49,8 @@
         * @return bool
         */
        public static function onBeforePageDisplay( &$out, &$options ) {
+               $out->addModuleStyles( 'mobile.zero.styles' );
+               $out->addModules( 'mobile.zero.scripts' );
                $ext = new ExtZeroRatedMobileAccess();
                return $ext->beforePageDisplayHTML( $out, $options );
        }
@@ -357,6 +359,29 @@
        }
 
        /**
+        * ResourceLoaderTestModules hook handler
+        * @see 
https://www.mediawiki.org/wiki/Manual:Hooks/ResourceLoaderTestModules
+        *
+        * @param array $testModules
+        * @param ResourceLoader $resourceLoader
+        * @return bool
+        */
+       public static function onResourceLoaderTestModules( array 
&$testModules, ResourceLoader &$resourceLoader ) {
+               $testModules['qunit']['ext.zeroratedmobileaccess.tests'] = 
array(
+                       'dependencies' => array(
+                               'mobile.zero.scripts'
+                       ),
+                       'targets' => array( 'mobile' ),
+                       'localBasePath' => dirname( dirname( __FILE__ ) ),
+                       'remoteExtPath' => 'ZeroRatedMobileAccess',
+                       'scripts' => array(
+                               'tests/js/test_banner.js',
+                       ),
+               );
+               return true;
+       }
+
+       /**
         * @return Array
         */
        private function mergeCarrierData() {
diff --git a/ZeroRatedMobileAccess.php b/ZeroRatedMobileAccess.php
index 11b478e..9e42f31 100644
--- a/ZeroRatedMobileAccess.php
+++ b/ZeroRatedMobileAccess.php
@@ -40,8 +40,31 @@
        $wgAutoloadClasses[$className] = $cwd . $classFilename . '.php';
 }
 
+$localBasePath = dirname( __FILE__ );
+$remoteExtPath = 'ZeroRatedMobileAccess';
+
+$wgResourceModules['mobile.zero.styles'] = array(
+       'localBasePath' => $localBasePath,
+       'remoteExtPath' => $remoteExtPath,
+       'targets' => array( 'mobile' ),
+       'styles' => array(
+               'stylesheets/banner.css',
+       ),
+);
+
+$wgResourceModules['mobile.zero.scripts'] = array(
+       'dependencies' => array( 'mobile.startup' ),
+       'localBasePath' => $localBasePath,
+       'remoteExtPath' => $remoteExtPath,
+       'targets' => array( 'mobile' ),
+       'scripts' => array(
+               'javascripts/banner.js',
+       ),
+);
+
 $wgEnableZeroRatedMobileAccessTesting = false;
 
+$wgHooks['ResourceLoaderTestModules'][] = 
'ExtZeroRatedMobileAccess::onResourceLoaderTestModules';
 $wgHooks['BeforePageDisplayMobile'][] = 
'ExtZeroRatedMobileAccess::onBeforePageDisplay';
 $wgHooks['GetMobileUrl'][] = 'ExtZeroRatedMobileAccess::getMobileUrl';
 $wgSpecialPages['ZeroRatedMobileAccess'] = 'ZeroRatedMobileAccess';
diff --git a/javascripts/banner.js b/javascripts/banner.js
new file mode 100644
index 0000000..75411ac
--- /dev/null
+++ b/javascripts/banner.js
@@ -0,0 +1,47 @@
+( function( M, $ ) {
+var m = ( function() {
+
+       function initBanner( banner ) {
+               var cookieNameZeroVisibility = banner.getAttribute( 'id' ),
+                       settings = M.settings,
+                       saveUserSetting = settings.saveUserSetting,
+                       getUserSetting = settings.getUserSetting,
+                       visibility,
+                       dismissNotification = banner.getElementsByTagName( 
'button' )[ 0 ];
+
+               if ( dismissNotification ) {
+                       visibility = getUserSetting( cookieNameZeroVisibility );
+
+                       if ( visibility === 'off' ) {
+                               banner.style.display = 'none';
+                       }
+
+                       dismissNotification.onclick = function() {
+                               banner.parentNode.removeChild( banner );
+                               saveUserSetting( cookieNameZeroVisibility, 
'off',
+                                       // FIXME: currently we only resort to 
cookie saving for the zero rated banners to avoid cache fragmentation
+                                       // (this has side effect that any 
banners shown on pages which do not support localStorage are not supported)
+                                       'zeroRatedBannerVisibility' === 
cookieNameZeroVisibility );
+                       };
+               }
+       }
+
+       function init() {
+               if ( $ ) {
+                       $( '.mw-mf-banner' ).each( function() {
+                               if ( $( this ).find( 'button.notify-close' 
).length === 0 &&
+                                       !$( this ).hasClass( 
'mw-mf-banner-undismissable' ) ) {
+                                       $( '<button class="notify-close">' 
).text( '×' ).appendTo( this );
+                               }
+                               initBanner( this );
+                       } );
+               }
+       }
+
+       return {
+               init: init,
+               initBanner: initBanner
+       };
+}() );
+M.define( 'banner', m );
+}( mw.mobileFrontend, jQuery ) );
diff --git a/stylesheets/banner.css b/stylesheets/banner.css
new file mode 100644
index 0000000..90fbdb6
--- /dev/null
+++ b/stylesheets/banner.css
@@ -0,0 +1,58 @@
+/* ZERO-RATED BANNERS
+moved from beta_common.css in
+Change-Id: Ia25126d950ee87cbc76f2e91d679cdd27405ee51
+*/
+.mw-mf-banner {
+  position: relative;
+  width: 100%;
+  z-index: 99;
+  background: #F4A83D;
+  display: block;
+  border-bottom: 1px solid #D6800C;
+  font-weight: bold;
+  padding: 0;
+  text-align: center;
+  color: #735005;
+  font-family: Tahoma, sans-serif;
+}
+.mw-mf-banner .mw-mf-message,
+.mw-mf-banner button {
+  padding-top: 10px;
+  padding-bottom: 10px;
+}
+.android.mw-mf-banner {
+  display: none;
+}
+html.android .android.mw-mf-banner {
+  display: block;
+}
+.mw-mf-banner a {
+  text-decoration: underline;
+  color: #735005;
+}
+.mw-mf-banner button.notify-close {
+  position: absolute;
+  right: 2px;
+  top: 2px;
+  background-color: #FAD163;
+  margin-right: 0;
+  border: 2px solid #735005;
+}
+.mw-mf-banner p {
+  line-height: normal;
+}
+.mw-mf-banner .mw-mf-message {
+  margin: 0;
+  color: #ffffff;
+  font-weight: bold;
+  text-align: center;
+  display: block;
+}
+.mw-mf-banner.mw-mf-banner-undismissable {
+  color: #ffffff;
+  background-color: red;
+}
+.mw-mf-banner.mw-mf-banner-undismissable a {
+  text-decoration: underline;
+  color: #ffffff;
+}

-- 
To view, visit https://gerrit.wikimedia.org/r/57553
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I04e0c37af78bd16754aa2fff734a02b9abf00b0f
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/ZeroRatedMobileAccess
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Dr0ptp4kt <[email protected]>
Gerrit-Reviewer: JGonera <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: Yurik <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to