r106197 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106196‎ | r106197 | r106198 >
Date:14:08, 14 December 2011
Author:amire80
Status:resolved
Tags:
Comment:
Better fix for bug 33095. Making the orientation of the drop-down menu conditional: it flips if it is too close to the edge.
Modified paths:
  • /trunk/extensions/WebFonts/resources/ext.webfonts.js (modified) (history)

Diff [purge]

Index: trunk/extensions/WebFonts/resources/ext.webfonts.js
@@ -346,36 +346,54 @@
347347 .prop( 'href', '#' )
348348 .text( mw.msg( 'webfonts-load' ) )
349349 .attr( 'title', mw.msg( 'webfonts-menu-tooltip' ) );
 350+
350351 // This is the fonts link
351352 var $li = $( '<li>' ).attr( 'id', 'pt-webfont' ).append( $link );
352 - var positionFunction, menuSide;
 353+ var positionFunction;
353354 if ( $( 'body' ).hasClass( 'rtl' ) ) {
354355 positionFunction = 'append';
355 - menuSide = 'left';
356356 }
357357 else {
358358 positionFunction = 'prepend';
359 - menuSide = 'right';
360359 }
361360 // If RTL, add to the right of top personal links. Else, to the left
362361 $( '#p-personal ul:first' )[positionFunction]( $li );
363362
364363 $( 'body' ).prepend( $menu );
365364 $li.click( function( event ) {
366 - var menuOffset;
 365+ var menuSide, menuOffset, distanceToEdge;
 366+
367367 if ( $( 'body' ).hasClass( 'rtl' ) ) {
368 - menuOffset = $li.offset().left;
 368+ distanceToEdge = $li.outerWidth() + $li.offset().left;
 369+ if ( $menuItemsDiv.outerWidth() > distanceToEdge ) {
 370+ menuSide = 'left';
 371+ menuOffset = $li.offset().left;
 372+ }
 373+ else {
 374+ menuSide = 'right';
 375+ menuOffset = $(window).width() - distanceToEdge;
 376+ }
369377 }
370378 else {
371 - menuOffset = $(window).width() - ( $li.offset().left + $li.outerWidth() );
 379+ distanceToEdge = $(window).width() - $li.offset().left;
 380+ if ( $menuItemsDiv.outerWidth() > distanceToEdge ) {
 381+ menuSide = 'right';
 382+ menuOffset = distanceToEdge - $li.outerWidth();
 383+ }
 384+ else {
 385+ menuSide = 'left';
 386+ menuOffset = $li.offset().left;
 387+ }
372388 }
 389+
373390 $menuItemsDiv.css( menuSide, menuOffset );
374391
375 - if( $menu.hasClass( 'open' ) ) {
 392+ if ( $menu.hasClass( 'open' ) ) {
376393 $menu.removeClass( 'open' );
377 - } else {
 394+ }
 395+ else {
378396 $( 'div.open' ).removeClass( 'open' );
379 - $menu.addClass( 'open' );
 397+ $menu.addClass( 'open' );
380398 event.stopPropagation();
381399 }
382400 } );

Follow-up revisions

RevisionCommit summaryAuthorDate
r106202Followup to r106197, whitespace cleanup.amire8014:39, 14 December 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r106186An initial fix for bug 33095. By default the right edge of the drop-down menu...amire8012:59, 14 December 2011

Status & tagging log