r114157 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r114156‎ | r114157 | r114158 >
Date:17:17, 19 March 2012
Author:jdlrobson
Status:ok
Tags:
Comment:
provide different animations for references

provide a slide animation as well as one with no
animation

also clear the lastLink as otherwise a 3rd click on
a link will not re-reveal it
Modified paths:
  • /trunk/extensions/MobileFrontend/javascripts/references.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/javascripts/references.js
@@ -4,6 +4,8 @@
55
66 hashtest = window.location.hash.substr(1).match(/refspeed:([0-9]*)/);
77 options.animationSpeed = hashtest ? parseInt( hashtest[1], 10 ) : 500;
 8+ hashtest = window.location.hash.substr(1).match(/refanimation:([a-z]*)/);
 9+ options.animation = hashtest ? hashtest[1] : null;
810
911 function collect() {
1012 var references = {};
@@ -32,13 +34,23 @@
3335 function init() {
3436 $( '<div id="mf-references"><div></div></div>' ).hide().appendTo( document.body );
3537 var close = function() {
36 - $( '#mf-references' ).fadeOut( options.animationSpeed );
 38+ var top;
 39+ lastLink = null;
 40+ if( options.animation === 'none' ) {
 41+ $( '#mf-references' ).hide();
 42+ } else if( options.animation === 'slide' ){
 43+ top = window.innerHeight + window.pageYOffset;
 44+ $( '#mf-references' ).show().animate( { top: top }, options.animationSpeed );
 45+ } else {
 46+ $( '#mf-references' ).fadeOut( options.animationSpeed );
 47+ }
3748 }, lastLink;
3849 $( '<button>close</button>' ).click( close ).appendTo( '#mf-references' );
3950 $( '.mw-cite-backlink a' ).click( close );
4051
4152 var data, html, href, references = collect();
4253 $( 'sup a' ).click( function(ev) {
 54+ var top, oh;
4355 href = $(this).attr( 'href' );
4456 data = href && href.charAt(0) === '#' ?
4557 references[ href.substr( 1, href.length ) ] : null;
@@ -52,11 +64,20 @@
5365 attr( 'href', href ).appendTo('<div />').parent().html();
5466 }
5567 $( '#mf-references div' ).html( html );
56 - $( '#mf-references' ).fadeIn( options.animationSpeed );
 68+ calculatePosition();
 69+ if( options.animation === 'none' ) {
 70+ $( '#mf-references' ).show();
 71+ } else if( options.animation === 'slide' ){
 72+ top = window.innerHeight + window.pageYOffset;
 73+ oh = $( '#mf-references' ).outerHeight();
 74+ $( '#mf-references' ).show().css( { 'top': top } ).
 75+ animate( { top: top - oh }, options.animationSpeed );
 76+ } else {
 77+ $( '#mf-references' ).fadeIn( options.animationSpeed );
 78+ }
5779 } else {
5880 close();
5981 }
60 - calculatePosition();
6182 ev.preventDefault();
6283 });
6384 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r114206MFT r114134, r114136, r114144, r114145, r114150, r114152, r114157awjrichards22:26, 19 March 2012

Status & tagging log