Index: trunk/extensions/Narayam/resources/ext.narayam.core.js |
— | — | @@ -656,12 +656,36 @@ |
657 | 657 | var $li = $( '<li>' ).attr( 'id', 'pt-narayam' ).append( $link ); |
658 | 658 | |
659 | 659 | // 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 ); |
662 | 663 | $( 'body' ).prepend( $menu ); |
663 | 664 | $menu.hide(); |
664 | 665 | $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 | + |
666 | 690 | if( $menu.hasClass( 'open' ) ){ |
667 | 691 | $menu.removeClass( 'open' ); |
668 | 692 | $menu.hide(); |