jenkins-bot has submitted this change and it was merged.

Change subject: Introduce SchemaMobileWebSectionUsage
......................................................................


Introduce SchemaMobileWebSectionUsage

This schema logs activity in the page.
toggle event now emitted by Toggler class

Changes:
* section-id data attribute now on headings
* Introduce SchemaMobileWebSectionUsage

Bug: T114655
Change-Id: I24877d4bc414eaf03d02e485a3f1de1d1f427c44
---
M includes/MobileFrontend.hooks.php
A resources/mobile.loggingSchemas/SchemaMobileWebSectionUsage.js
M resources/mobile.toggle/toggle.js
M resources/skins.minerva.toggling/init.js
4 files changed, 93 insertions(+), 3 deletions(-)

Approvals:
  Bmansurov: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/MobileFrontend.hooks.php 
b/includes/MobileFrontend.hooks.php
index 4c17e4d..03e0df1 100644
--- a/includes/MobileFrontend.hooks.php
+++ b/includes/MobileFrontend.hooks.php
@@ -919,6 +919,7 @@
                        'MobileWebDiffClickTracking' => 10720373,
                        'MobileWebMainMenuClickTracking' => 11568715,
                        'MobileWebSearch' => 12054448,
+                       'MobileWebSectionUsage' => 14321266,
                        'MobileWebUIClickTracking' => 10742159,
                        'MobileWebWatching' => 11761466,
                        'MobileWebWatchlistClickTracking' => 10720361,
@@ -960,6 +961,7 @@
                        
'resources/mobile.loggingSchemas/SchemaMobileWebClickTracking.js',
                        
'resources/mobile.loggingSchemas/SchemaMobileWebWatching.js',
                        
'resources/mobile.loggingSchemas/SchemaMobileWebSearch.js',
+                       
'resources/mobile.loggingSchemas/SchemaMobileWebSectionUsage.js',
                );
 
                $schemaModules = array();
diff --git a/resources/mobile.loggingSchemas/SchemaMobileWebSectionUsage.js 
b/resources/mobile.loggingSchemas/SchemaMobileWebSectionUsage.js
new file mode 100644
index 0000000..0a11214
--- /dev/null
+++ b/resources/mobile.loggingSchemas/SchemaMobileWebSectionUsage.js
@@ -0,0 +1,52 @@
+( function ( M, $ ) {
+       var SchemaMobileWebSectionUsage,
+               Schema = M.require( 'mobile.startup/Schema' ),
+               user = M.require( 'mobile.user/user' ),
+               browser = M.require( 'mobile.browser/browser' );
+
+       /**
+        * @class SchemaMobileWebSectionUsage
+        * @extends Schema
+        */
+       SchemaMobileWebSectionUsage = Schema.extend( {
+               /**
+                * @inheritdoc
+                */
+               isSampled: true,
+               /**
+                * @inheritdoc
+                */
+               samplingRate: 0.01,
+               /** @inheritdoc **/
+               name: 'MobileWebSectionUsage',
+               /**
+                * @inheritdoc
+                *
+                * @cfg {Object} defaults Default options hash.
+                * @cfg {Boolean} defaults.isTablet whether the screen 
resolution is over 768px
+                * @cfg {String} defaults.sessionId unique session id for user
+                * @cfg {Boolean} defaults.hasServiceWorkerSupport whether the 
user is able to use service workers.
+                */
+               defaults: $.extend( {}, Schema.prototype.defaults, {
+                       isTablet: browser.isWideScreen(),
+                       sessionId: user.getSessionId(),
+                       hasServiceWorkerSupport: 'serviceWorker' in navigator
+               } ),
+               /**
+                * Enables the schema for the current page.
+                *
+                * @param {Page} page to enable the logger for
+                */
+               enable: function ( page ) {
+                       var defaults = {
+                               sectionCount: page.getSections().length,
+                               pageId: page.getId(),
+                               namespace: page.getNamespaceId()
+                       };
+                       $.extend( this.defaults, defaults );
+               }
+       } );
+
+       M.define( 'mobile.loggingSchemas/SchemaMobileWebSectionUsage', 
SchemaMobileWebSectionUsage );
+
+} )( mw.mobileFrontend, jQuery );
diff --git a/resources/mobile.toggle/toggle.js 
b/resources/mobile.toggle/toggle.js
index 1ed3abe..ccec446 100644
--- a/resources/mobile.toggle/toggle.js
+++ b/resources/mobile.toggle/toggle.js
@@ -20,10 +20,20 @@
         * @param {jQuery.Object} $container to apply toggling to
         * @param {String} prefix a prefix to use for the id.
         * @param {Page} [page] to allow storage of session for future visits
+        * @param {Schema} [schema] to log events on
+        * @extends OO.EventEmitter
         */
-       function Toggler( $container, prefix, page ) {
+       function Toggler( $container, prefix, page, schema ) {
+               OO.EventEmitter.call( this );
                this._enable( $container, prefix, page );
+               if ( schema ) {
+                       this.schema = schema;
+                       this.connect( this, {
+                               toggled: 'onToggle'
+                       } );
+               }
        }
+       OO.mixinClass( Toggler, OO.EventEmitter );
 
        /**
         * Using the settings module looks at what sections were previously 
expanded on
@@ -126,6 +136,19 @@
        }
 
        /**
+        * Event handler fired when a section is toggled open/closed
+        *
+        * @param {Boolean} isCollapsed whether the section is now collapsed 
(at end of toggle)
+        * @param {Number} sectionId that was open/closed
+        */
+       Toggler.prototype.onToggle = function ( isCollapsed, sectionId ) {
+               this.schema.log( {
+                       eventName: isCollapsed ? 'close-section' : 
'open-section',
+                       section: sectionId
+               } );
+       };
+
+       /**
         * Given a heading, toggle it and any of its children
         *
         * @param {jQuery.Object} $heading A heading belonging to a section
@@ -134,12 +157,17 @@
        Toggler.prototype.toggle = function ( $heading ) {
                var isCollapsed = $heading.is( '.open-block' ),
                        page = $heading.data( 'page' ),
+                       sectionId = $heading.data( 'section-number' ),
                        options, indicator;
 
                $heading.toggleClass( 'open-block' );
                $heading.data( 'indicator' ).remove();
 
                options = isCollapsed ? arrowUpOptions : arrowDownOptions;
+               /**
+                * @event toggled
+                */
+               this.emit( 'toggled', isCollapsed, sectionId );
                indicator = new Icon( options ).prependTo( $heading );
                $heading.data( 'indicator', indicator );
 
@@ -236,6 +264,7 @@
                        if ( $heading.next().is( 'div' ) ) {
                                $heading
                                        .addClass( 'collapsible-heading ' )
+                                       .data( 'section-number', i )
                                        .data( 'page', page )
                                        .attr( {
                                                tabindex: 0,
diff --git a/resources/skins.minerva.toggling/init.js 
b/resources/skins.minerva.toggling/init.js
index e79f230..ec24db4 100644
--- a/resources/skins.minerva.toggling/init.js
+++ b/resources/skins.minerva.toggling/init.js
@@ -1,5 +1,7 @@
 ( function ( M, $ ) {
-       var page = M.getCurrentPage(),
+       var schema,
+               page = M.getCurrentPage(),
+               SchemaMobileWebSectionUsage = M.require( 
'mobile.loggingSchemas/SchemaMobileWebSectionUsage' ),
                $contentContainer = $( '#content #bodyContent' ),
                Toggler = M.require( 'mobile.toggle/Toggler' );
 
@@ -15,7 +17,12 @@
        function init( $container, prefix, page ) {
                // distinguish headings in content from other headings
                $container.find( '> h1,> h2,> h3,> h4,> h5,> h6' ).addClass( 
'section-heading' );
-               new Toggler( $container, prefix, page );
+               schema = new SchemaMobileWebSectionUsage();
+               schema.enable( page );
+               schema.log( {
+                       eventName: 'entered'
+               } );
+               new Toggler( $container, prefix, page, schema );
        }
 
        // avoid this running on Watchlist

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I24877d4bc414eaf03d02e485a3f1de1d1f427c44
Gerrit-PatchSet: 11
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <[email protected]>
Gerrit-Reviewer: Bmansurov <[email protected]>
Gerrit-Reviewer: Jdlrobson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to