Jdlrobson has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/353546 )

Change subject: WIP: ReferencesController
......................................................................

WIP: ReferencesController

Bug: T130551
Change-Id: Id607067c9716cf7a4a74e6cd00ed0e8541d152bb
---
M extension.json
A resources/mobile.references/ReferencesController.js
M resources/skins.minerva.scripts/references.js
3 files changed, 87 insertions(+), 84 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MobileFrontend 
refs/changes/46/353546/1

diff --git a/extension.json b/extension.json
index ccb3781..ffbf0a2 100644
--- a/extension.json
+++ b/extension.json
@@ -898,6 +898,7 @@
                                "Drawer.hogan": 
"resources/mobile.references/ReferencesDrawer.hogan"
                        },
                        "scripts": [
+                               
"resources/mobile.references/ReferencesController.js",
                                
"resources/mobile.references/ReferencesDrawer.js"
                        ]
                },
diff --git a/resources/mobile.references/ReferencesController.js 
b/resources/mobile.references/ReferencesController.js
new file mode 100644
index 0000000..668de8c
--- /dev/null
+++ b/resources/mobile.references/ReferencesController.js
@@ -0,0 +1,77 @@
+( function ( M, $ ) {
+       /**
+        * Event handler to show reference when a reference link is clicked
+        * @ignore
+        * @param {jQuery.Event} ev Click event of the reference element
+        * @param {ReferencesDrawer} drawer to show the reference in
+        * @param {Page} page
+        */
+       function showReference( ev, drawer, page ) {
+               var urlComponents,
+                       $dest = $( ev.target ),
+                       href = $dest.attr( 'href' );
+
+               ev.preventDefault();
+
+               // If necessary strip the URL portion of the href so we are 
left with the
+               // fragment
+               urlComponents = href.split( '#' );
+               if ( urlComponents.length > 1 ) {
+                       href = '#' + urlComponents[1];
+               }
+               drawer.showReference( href, page, $dest.text() );
+
+               // don't hide drawer (stop propagation of click) if it is 
already shown
+               // (e.g. click another reference)
+               if ( drawer.isVisible() ) {
+                       ev.stopPropagation();
+               } else {
+                       // flush any existing reference information
+                       drawer.render( {
+                               text: undefined
+                       } );
+               }
+       }
+
+       /**
+        * Drawer for references
+        * @class ReferencesController
+        * @param {Page} page
+        * @param {ReferencesGateway} gateway
+        * @uses Icon
+        */
+       function ReferencesController( page, gateway ) {
+               var $refs = page.$( 'sup.reference a' );
+
+               if ( $refs.length ) {
+                       $refs
+                               .off( 'click' )
+                               .on( 'click', {
+                                       page: page
+                               }, $.proxy( this, 'onClickReference' ) );
+
+                       page.$( '.mw-cite-backlink a' )
+                               .off( 'click' );
+               }
+               this.gateway = gateway;
+       }
+       OO.initClass( ReferencesController );
+
+       /**
+        * Event handler to show reference when a reference link is clicked.
+        * Delegates to `showReference` once the references drawer is ready.
+        *
+        * @ignore
+        * @param {jQuery.Event} ev Click event of the reference element
+        */
+       ReferencesController.prototype.onReferenceClick = function ( ev ) {
+               if ( !this._drawer ) {
+                       this._drawer = new ReferencesDrawer( {
+                               gateway: this.gateway
+                       } );
+               }
+               showReference( ev, this._drawer, ev.data.page );
+       };
+
+       M.define( 'mobile.references/ReferencesController', 
ReferencesController );
+}( mw.mobileFrontend, jQuery ) );
diff --git a/resources/skins.minerva.scripts/references.js 
b/resources/skins.minerva.scripts/references.js
index 91d8233..66420b7 100644
--- a/resources/skins.minerva.scripts/references.js
+++ b/resources/skins.minerva.scripts/references.js
@@ -1,5 +1,5 @@
 ( function ( M, $ ) {
-       var drawer,
+       var ReferencesController = M.require( 
'mobile.references/ReferencesController' ),
                skin = M.require( 'skins.minerva.scripts/skin' ),
                page = M.getCurrentPage(),
                ReferencesMobileViewGateway = M.require(
@@ -8,100 +8,25 @@
                referencesMobileViewGateway = 
ReferencesMobileViewGateway.getSingleton(),
                ReferencesHtmlScraperGateway = M.require(
                        'mobile.references.gateway/ReferencesHtmlScraperGateway'
-               ),
-               ReferencesDrawer = M.require( 
'mobile.references/ReferencesDrawer' );
+               );
 
        /**
-        * Creates a ReferenceDrawer based on the currently available
-        * ReferenceGateway
+        * Creates a ReferenceGateway based on whether lazy loading references 
is enabled
         *
         * @ignore
-        * @return {ReferencesDrawer}
+        * @return {ReferencesGateway}
         */
-       function referenceDrawerFactory() {
-               var gateway = null;
-
+       function referenceGatewayFactory() {
                if ( mw.config.get( 'wgMFLazyLoadReferences', false ) ) {
-                       gateway = referencesMobileViewGateway;
+                       return referencesMobileViewGateway;
                } else {
-                       gateway = new ReferencesHtmlScraperGateway( new 
mw.Api() );
-               }
-
-               return new ReferencesDrawer( {
-                       gateway: gateway
-               } );
-       }
-
-       /**
-        * Event handler to show reference when a reference link is clicked
-        * @ignore
-        * @param {jQuery.Event} ev Click event of the reference element
-        * @param {ReferencesDrawer} drawer to show the reference in
-        * @param {Page} page
-        */
-       function showReference( ev, drawer, page ) {
-               var urlComponents,
-                       $dest = $( ev.target ),
-                       href = $dest.attr( 'href' );
-
-               ev.preventDefault();
-
-               // If necessary strip the URL portion of the href so we are 
left with the
-               // fragment
-               urlComponents = href.split( '#' );
-               if ( urlComponents.length > 1 ) {
-                       href = '#' + urlComponents[1];
-               }
-               drawer.showReference( href, page, $dest.text() );
-
-               // don't hide drawer (stop propagation of click) if it is 
already shown
-               // (e.g. click another reference)
-               if ( drawer.isVisible() ) {
-                       ev.stopPropagation();
-               } else {
-                       // flush any existing reference information
-                       drawer.render( {
-                               text: undefined
-                       } );
+                       return new ReferencesHtmlScraperGateway( new mw.Api() );
                }
        }
 
-       /**
-        * Event handler to show reference when a reference link is clicked.
-        * Delegates to `showReference` once the references drawer is ready.
-        *
-        * @ignore
-        * @param {jQuery.Event} ev Click event of the reference element
-        */
-       function onClickReference( ev ) {
-               if ( !drawer ) {
-                       drawer = referenceDrawerFactory();
-               }
-               showReference( ev, drawer, ev.data.page );
-       }
-
-       /**
-        * Make references clickable and show a drawer when clicked on.
-        * @ignore
-        * @param {Page} page
-        */
-       function setup( page ) {
-               var $refs = page.$( 'sup.reference a' );
-
-               if ( $refs.length ) {
-                       $refs
-                               .off( 'click' )
-                               .on( 'click', {
-                                       page: page
-                               }, onClickReference );
-                       page.$( '.mw-cite-backlink a' )
-                               .off( 'click' );
-               }
-       }
-
-       setup( page );
+       new ReferencesController( page );
        // When references are lazy loaded you'll want to take care of nested 
references
        skin.on( 'references-loaded', function ( page ) {
-               setup( page );
+               new ReferencesController( page, referenceGatewayFactory() );
        } );
 }( mw.mobileFrontend, jQuery ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id607067c9716cf7a4a74e6cd00ed0e8541d152bb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MobileFrontend
Gerrit-Branch: master
Gerrit-Owner: Jdlrobson <jrob...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to