Gergő Tisza has uploaded a new change for review.

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


Change subject: Remove lightbox entries from history when closing
......................................................................

Remove lightbox entries from history when closing

Attempt to clean up history when closing the box, so that
the user does not need to navigate back through dozens of artificial
history entries when trying to go back to the previous page.

When the history entry in which the user opened the lightbox was not
the first entry in that document (e.g. the user navigated through the
TOC first), we can clean up perfectly. When it was the first entry,
an artificial future entry is left (i.e. the "forward" button of the
user's browser will be active, even though he never used the back
button). This could be confusing, but - as far as I can see -
impossible to avoid.

The patch is intended as a demonstration of the idea; if it is
accepted as the right way to go, the implementation needs to be fixed.

Change-Id: Ib247229e9da0df614239af72aa47772d8736772f
---
M resources/ext.multimediaViewer/ext.multimediaViewer.js
1 file changed, 33 insertions(+), 2 deletions(-)


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

diff --git a/resources/ext.multimediaViewer/ext.multimediaViewer.js 
b/resources/ext.multimediaViewer/ext.multimediaViewer.js
index 9b306e1..08a6814 100755
--- a/resources/ext.multimediaViewer/ext.multimediaViewer.js
+++ b/resources/ext.multimediaViewer/ext.multimediaViewer.js
@@ -53,7 +53,9 @@
                        'defullscreen-link-click': 'User clicked on button to 
return to normal lightbox view.',
                        'close-link-click': 'User clicked on the lightbox close 
button.',
                        'site-link-click': 'User clicked on the link to the 
file description page.'
-               };
+               },
+
+               historyStart = history.length;
 
        function MultimediaViewer() {
                var $thumbs = $( '.gallery .image img, a.image img' ),
@@ -127,7 +129,36 @@
                        this.$nextButton.add( this.$prevButton ).css( 'top', 
'-999px' );
                        $( document.body ).removeClass( 'mw-mlb-lightbox-open' 
);
                        if ( comingFromPopstate === false ) {
-                               history.pushState( {}, '', '#' );
+                               // go back to last state before opening the 
lightbox
+                               while ( history.state && history.state.mmv ) {
+                                       history.back();
+                               }
+
+                               // find out current history position compared 
to first entry of this document
+                               // this is only intended as a proof of contect 
and will probably not work
+                               // e.g. when arriving to the document by 
backnavigation, but could be made
+                               // more robust easily, e.g. by pushing a flag 
in the first state
+                               history.pushState( {}, null, '#' );
+                               var historyPosition = history.length - 1;
+                               history.back();
+
+                               // history.back does not remove entries from 
history;
+                               // if we can go back one more step wothout 
navigating away,
+                               // we can remove them by doing that and pushing 
the current state
+                               if ( historyPosition > historyStart ) {
+                                       var state = [
+                                               history.state, // might need to 
clone this... but at the moment nothing uses it anyway
+                                               document.title,
+                                               location.toString()
+                                       ];
+                                       history.back();
+                                       history.pushState.apply( history, state 
);
+                               } else {
+                                       // no way to drop all entries after 
this one :-(
+                                       // at least replace them with a single 
one
+                                       history.pushState( {}, null, '#' );
+                                       history.back();
+                               }
                        } else {
                                comingFromPopstate = false;
                        }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib247229e9da0df614239af72aa47772d8736772f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/MultimediaViewer
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <gti...@wikimedia.org>

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

Reply via email to