Index: trunk/extensions/WebFonts/tests/qunit/ext.webfonts.tests.js |
— | — | @@ -82,7 +82,7 @@ |
83 | 83 | } ); |
84 | 84 | |
85 | 85 | test( '-- Dynamic font loading based on font-family style attribute', function() { |
86 | | - expect( 14 ) |
| 86 | + expect( 14 ); |
87 | 87 | |
88 | 88 | mw.webfonts.fonts = []; |
89 | 89 | ok( $( 'body' ).append( "<p class='webfonts-testing-font-family-style'>Some content</p>" ), 'An element for testing font-family loading was appended to body' ); |
— | — | @@ -113,6 +113,25 @@ |
114 | 114 | ok( $testElement.remove() ); |
115 | 115 | } ); |
116 | 116 | |
| 117 | +test( '-- Build the menu', function() { |
| 118 | + expect( 8 ); |
| 119 | + var oldFonts = mw.webfonts.fonts; |
| 120 | + var fonts = []; |
| 121 | + assertFalse( mw.webfonts.buildMenu( fonts ) , 'Build the menu with empty fonts list' ); |
| 122 | + fonts = mw.webfonts.config.languages.hi; |
| 123 | + ok( mw.webfonts.buildMenu( fonts ) , 'Build the menu with hindi fonts list' ); |
| 124 | + equals( $( 'li#pt-webfont' ).length , 1, 'There should be one and only one menu at any time' ); |
| 125 | + ok( mw.webfonts.buildMenu( fonts ) , 'Build the menu with hindi fonts list again' ); |
| 126 | + equals( $( 'li#pt-webfont' ).length , 1, 'There should be one and only one menu at any time' ); |
| 127 | + equals( $( 'ul#webfonts-fontsmenu li' ).length , fonts.length + 2 , 'Number of menu items is number of availables fonts, a help link and reset item' ); |
| 128 | + equals ( $( 'li.webfont-help-item').length , 1, 'Help link exists' ); |
| 129 | + if (oldFonts.length) |
| 130 | + assertTrue( mw.webfonts.buildMenu( oldFonts ) , 'Restore the menu' ); |
| 131 | + else { |
| 132 | + assertFalse( mw.webfonts.buildMenu( oldFonts ) , 'Restore the menu' ); |
| 133 | + } |
| 134 | +} ); |
| 135 | + |
117 | 136 | isFontFaceLoaded = function( fontFamilyName ) { |
118 | 137 | var lastStyleIndex = document.styleSheets.length - 1; |
119 | 138 | |
Index: trunk/extensions/WebFonts/resources/ext.webfonts.js |
— | — | @@ -363,8 +363,14 @@ |
364 | 364 | buildMenu: function( fonts ) { |
365 | 365 | var $menuItemsDiv = mw.webfonts.buildMenuItems( fonts ); |
366 | 366 | if( $menuItemsDiv === null ) { |
367 | | - return; |
| 367 | + return false; |
368 | 368 | } |
| 369 | + |
| 370 | + if( $( 'li#pt-webfont' ).length > 0 ) { |
| 371 | + $( 'li#pt-webfont' ).remove(); |
| 372 | + $( 'div#webfonts-menu' ).remove(); |
| 373 | + } |
| 374 | + |
369 | 375 | var $menu = $( '<div>' ) |
370 | 376 | .attr( 'id', 'webfonts-menu' ) |
371 | 377 | .addClass( 'webfontMenu' ) |
— | — | @@ -435,6 +441,7 @@ |
436 | 442 | $( '#searchform' ).css( { visibility: 'visible' } ); |
437 | 443 | } ); |
438 | 444 | } |
| 445 | + return true; |
439 | 446 | } |
440 | 447 | }; |
441 | 448 | |