r106201 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106200‎ | r106201 | r106202 >
Date:14:39, 14 December 2011
Author:amire80
Status:ok
Tags:
Comment:
Copied the menu behavior from WebFonts.
Modified paths:
  • /trunk/extensions/Narayam/resources/ext.narayam.core.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Narayam/resources/ext.narayam.core.js
@@ -656,12 +656,36 @@
657657 var $li = $( '<li>' ).attr( 'id', 'pt-narayam' ).append( $link );
658658
659659 // If rtl, add to the right of top personal links. Else, to the left
660 - var fn = $( 'body' ).hasClass( 'rtl' ) ? "append" : "prepend";
661 - $( '#p-personal ul:first' )[fn]( $li );
 660+ var rtlEnv = $( 'body' ).hasClass( 'rtl' );
 661+ var positionFunction = rtlEnv ? "append" : "prepend";
 662+ $( '#p-personal ul:first' )[positionFunction]( $li );
662663 $( 'body' ).prepend( $menu );
663664 $menu.hide();
664665 $li.click( function( event ) {
665 - $menuItemsDiv.css( 'left', $li.offset().left );
 666+ var menuSide, menuOffset, distanceToEdge;
 667+
 668+ if ( rtlEnv ) {
 669+ distanceToEdge = $li.outerWidth() + $li.offset().left;
 670+ if ( $menuItemsDiv.outerWidth() > distanceToEdge ) {
 671+ menuSide = 'left';
 672+ menuOffset = $li.offset().left;
 673+ } else {
 674+ menuSide = 'right';
 675+ menuOffset = $(window).width() - distanceToEdge;
 676+ }
 677+ } else {
 678+ distanceToEdge = $(window).width() - $li.offset().left;
 679+ if ( $menuItemsDiv.outerWidth() > distanceToEdge ) {
 680+ menuSide = 'right';
 681+ menuOffset = distanceToEdge - $li.outerWidth();
 682+ } else {
 683+ menuSide = 'left';
 684+ menuOffset = $li.offset().left;
 685+ }
 686+ }
 687+
 688+ $menuItemsDiv.css( menuSide, menuOffset );
 689+
666690 if( $menu.hasClass( 'open' ) ){
667691 $menu.removeClass( 'open' );
668692 $menu.hide();

Status & tagging log