Gilles has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/173916

Change subject: Turn mmv-next/mmv-prev into OO events
......................................................................

Turn mmv-next/mmv-prev into OO events

More of those events sent to the document can be converted, but it's a start...

Change-Id: I6100ce303346ab9fa94332e91f5d730dc83f4e65
---
M resources/mmv/mmv.js
M resources/mmv/mmv.lightboxinterface.js
M resources/mmv/ui/mmv.ui.canvasButtons.js
M resources/mmv/ui/mmv.ui.js
4 files changed, 25 insertions(+), 11 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/MultimediaViewer 
refs/changes/16/173916/1

diff --git a/resources/mmv/mmv.js b/resources/mmv/mmv.js
index 46d440c..749c180 100644
--- a/resources/mmv/mmv.js
+++ b/resources/mmv/mmv.js
@@ -875,12 +875,14 @@
        MMVP.setupEventHandlers = function () {
                var viewer = this;
 
+               this.ui.on( 'mmv-next', function () {
+                       viewer.nextImage();
+               } ).on( 'mmv-prev', function () {
+                       viewer.prevImage();
+               } );
+
                $( document ).on( 'mmv-close.mmvp', function () {
                        viewer.close();
-               } ).on( 'mmv-next.mmvp', function () {
-                       viewer.nextImage();
-               } ).on( 'mmv-prev.mmvp', function () {
-                       viewer.prevImage();
                } ).on( 'mmv-resize-end.mmvp', function () {
                        viewer.resize( viewer.ui );
                } ).on( 'mmv-request-thumbnail.mmvp', function ( e, size ) {
@@ -900,7 +902,8 @@
        * Unregisters all event handlers. Currently only used in tests.
        */
        MMVP.cleanupEventHandlers = function () {
-               $( document ).off( 'mmv-close.mmvp mmv-next.mmvp mmv-prev.mmvp 
mmv-resize-end.mmvp' );
+               $( document ).off( 'mmv-close.mmvp mmv-resize-end.mmvp' );
+               this.ui.off( 'mmv-next' ).off( 'mmv-prev' );
        };
 
        /**
diff --git a/resources/mmv/mmv.lightboxinterface.js 
b/resources/mmv/mmv.lightboxinterface.js
index 2fb2c55..2ac2133 100644
--- a/resources/mmv/mmv.lightboxinterface.js
+++ b/resources/mmv/mmv.lightboxinterface.js
@@ -184,6 +184,9 @@
                this.handleEvent( 'mmv-faded-out', function ( e ) { 
ui.fadedOut( e ); } );
                this.handleEvent( 'mmv-fade-stopped', function ( e ) { 
ui.fadeStopped( e ); } );
 
+               this.buttons.on( 'mmv-next', function() { ui.emit( 'mmv-next' 
); } )
+                       .on( 'mmv-prev', function() { ui.emit( 'mmv-prev' ); } 
);
+
                $parent = $( parentId || document.body );
 
                // Clean up fullscreen data because hard-existing fullscreen 
might have left
@@ -242,6 +245,8 @@
 
                this.optionsDialog.unattach();
                this.optionsDialog.closeDialog();
+
+               this.buttons.off( 'mmv-next' ).off( 'mmv-prev' );
 
                this.clearEvents();
 
@@ -381,10 +386,11 @@
                                }
 
                                if ( forward ) {
-                                       $( document ).trigger( $.Event( 
'mmv-next' ) );
+                                       this.emit( 'mmv-next' );
                                } else {
-                                       $( document ).trigger( $.Event( 
'mmv-prev' ) );
+                                       this.emit( 'mmv-prev' );
                                }
+
                                e.preventDefault();
                                break;
                }
diff --git a/resources/mmv/ui/mmv.ui.canvasButtons.js 
b/resources/mmv/ui/mmv.ui.canvasButtons.js
index 414951b..861e243 100644
--- a/resources/mmv/ui/mmv.ui.canvasButtons.js
+++ b/resources/mmv/ui/mmv.ui.canvasButtons.js
@@ -94,11 +94,11 @@
                } );
 
                this.$next.click( function () {
-                       $container.trigger( $.Event( 'mmv-next' ) );
+                       buttons.emit( 'mmv-next' );
                } );
 
                this.$prev.click( function () {
-                       $container.trigger( $.Event( 'mmv-prev' ) );
+                       buttons.emit( 'mmv-prev' );
                } );
        }
        oo.inheritClass( CanvasButtons, mw.mmv.ui.Element );
diff --git a/resources/mmv/ui/mmv.ui.js b/resources/mmv/ui/mmv.ui.js
index 60a424f..5b5529b 100644
--- a/resources/mmv/ui/mmv.ui.js
+++ b/resources/mmv/ui/mmv.ui.js
@@ -15,7 +15,7 @@
  * along with MultimediaViewer.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-( function ( mw, $ ) {
+( function ( mw, $, oo ) {
        var EP,
                cachedRTL;
 
@@ -27,6 +27,8 @@
         * @param {jQuery} $container
         */
        function Element( $container ) {
+               oo.EventEmitter.call( this );
+
                /** @property {jQuery} $container The element that contains the 
UI element. */
                this.$container = $container;
 
@@ -46,6 +48,9 @@
                 */
                this.timers = {};
        }
+
+       oo.inheritClass( Element, oo.EventEmitter );
+
        EP = Element.prototype;
 
        /**
@@ -268,4 +273,4 @@
        mw.mmv.ui = {};
        mw.mmv.ui.reuse = {};
        mw.mmv.ui.Element = Element;
-}( mediaWiki, jQuery ) );
+}( mediaWiki, jQuery, OO ) );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6100ce303346ab9fa94332e91f5d730dc83f4e65
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MultimediaViewer
Gerrit-Branch: master
Gerrit-Owner: Gilles <gdu...@wikimedia.org>

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

Reply via email to