Index: trunk/extensions/WebFonts/resources/ext.webfonts.js |
— | — | @@ -346,36 +346,54 @@ |
347 | 347 | .prop( 'href', '#' ) |
348 | 348 | .text( mw.msg( 'webfonts-load' ) ) |
349 | 349 | .attr( 'title', mw.msg( 'webfonts-menu-tooltip' ) ); |
| 350 | + |
350 | 351 | // This is the fonts link |
351 | 352 | var $li = $( '<li>' ).attr( 'id', 'pt-webfont' ).append( $link ); |
352 | | - var positionFunction, menuSide; |
| 353 | + var positionFunction; |
353 | 354 | if ( $( 'body' ).hasClass( 'rtl' ) ) { |
354 | 355 | positionFunction = 'append'; |
355 | | - menuSide = 'left'; |
356 | 356 | } |
357 | 357 | else { |
358 | 358 | positionFunction = 'prepend'; |
359 | | - menuSide = 'right'; |
360 | 359 | } |
361 | 360 | // If RTL, add to the right of top personal links. Else, to the left |
362 | 361 | $( '#p-personal ul:first' )[positionFunction]( $li ); |
363 | 362 | |
364 | 363 | $( 'body' ).prepend( $menu ); |
365 | 364 | $li.click( function( event ) { |
366 | | - var menuOffset; |
| 365 | + var menuSide, menuOffset, distanceToEdge; |
| 366 | + |
367 | 367 | 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 | + } |
369 | 377 | } |
370 | 378 | 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 | + } |
372 | 388 | } |
| 389 | + |
373 | 390 | $menuItemsDiv.css( menuSide, menuOffset ); |
374 | 391 | |
375 | | - if( $menu.hasClass( 'open' ) ) { |
| 392 | + if ( $menu.hasClass( 'open' ) ) { |
376 | 393 | $menu.removeClass( 'open' ); |
377 | | - } else { |
| 394 | + } |
| 395 | + else { |
378 | 396 | $( 'div.open' ).removeClass( 'open' ); |
379 | | - $menu.addClass( 'open' ); |
| 397 | + $menu.addClass( 'open' ); |
380 | 398 | event.stopPropagation(); |
381 | 399 | } |
382 | 400 | } ); |