Index: trunk/extensions/WebFonts/resources/ext.webfonts.preview.js |
— | — | @@ -1,64 +1,64 @@ |
2 | 2 | /** |
3 | 3 | * Preview page script |
4 | 4 | */ |
5 | | -jQuery( function( $ ) { |
| 5 | +(function( $, mw ) { |
| 6 | + "use strict"; |
6 | 7 | |
7 | | - var showPreview = function( ) { |
8 | | - var $font = $( 'select#webfonts-font-chooser' ).val(); |
| 8 | + var showPreview = function () { |
| 9 | + var font = $( 'select#webfonts-font-chooser' ).val(); |
9 | 10 | var $downloadLink = $( 'a#webfonts-preview-download' ); |
10 | 11 | var $previewBox = $( 'div#webfonts-preview-area' ); |
11 | | - mw.webfonts.addFont( $font ); |
12 | | - $previewBox.css( 'font-family', $font ).addClass( 'webfonts-lang-attr' ); |
13 | | - $previewBox.css( 'font-size', parseInt( $( 'select#webfonts-size-chooser' ).val ( ) ) ); |
14 | | - var fontconfig = mw.webfonts.config.fonts[$font]; |
| 12 | + mw.webfonts.addFont( font ); |
| 13 | + $previewBox.css( 'font-family', font ).addClass( 'webfonts-lang-attr' ); |
| 14 | + $previewBox.css( 'font-size', parseInt( $( 'select#webfonts-size-chooser' ).val(), 10 ) ); |
| 15 | + var fontconfig = mw.webfonts.config.fonts[font]; |
15 | 16 | var base = mw.config.get( 'wgExtensionAssetsPath' ) + '/WebFonts/fonts/'; |
16 | | - $downloadLink.prop( 'href' , base + fontconfig.ttf ).removeClass( 'disabled' ); |
| 17 | + $downloadLink.prop( 'href', base + 'fontconfig.ttf' ).removeClass( 'disabled' ); |
17 | 18 | return true; |
18 | | - } |
| 19 | + }; |
19 | 20 | |
20 | | - var getFontsForLang = function( language ) { |
| 21 | + var getFontsForLang = function ( language ) { |
21 | 22 | var $fontSelecter = $( 'select#webfonts-font-chooser' ); |
22 | 23 | var $downloadLink = $( 'a#webfonts-preview-download' ); |
23 | 24 | $fontSelecter.empty(); |
24 | 25 | var languages = mw.webfonts.config.languages; |
25 | 26 | var fonts = languages[language]; |
26 | | - if(!fonts) { |
| 27 | + if( !fonts ) { |
27 | 28 | $downloadLink.removeAttr( 'href' ).addClass( 'disabled' ); |
28 | 29 | return false; |
29 | 30 | } |
30 | | - $.each(fonts, function(key, value) { |
31 | | - $fontSelecter.append( $('<option>', { value : value } ) |
32 | | - .text( value ) ); |
| 31 | + $.each( fonts, function( key, value ) { |
| 32 | + $fontSelecter.append( $( '<option>', { value: value } ) |
| 33 | + .text( value ) ); |
33 | 34 | } ); |
34 | 35 | showPreview(); |
35 | 36 | return true; |
36 | | - } |
| 37 | + }; |
| 38 | + |
| 39 | + $( document ).ready( function () { |
| 40 | + $( 'select#wpUserLanguage' ).change( function () { |
| 41 | + var language = $( 'select#wpUserLanguage' ).val(); |
| 42 | + getFontsForLang( language ); |
| 43 | + } ); |
37 | 44 | |
38 | | - $( 'select#wpUserLanguage' ).change( function () { |
39 | | - var language = $( 'select#wpUserLanguage' ).val(); |
40 | | - getFontsForLang( language ); |
41 | | - } ); |
| 45 | + $( 'select#webfonts-font-chooser, select#webfonts-size-chooser' ).change( function () { |
| 46 | + showPreview(); |
| 47 | + } ); |
42 | 48 | |
43 | | - $( 'select#webfonts-font-chooser' ).change( function () { |
44 | | - showPreview(); |
45 | | - } ); |
| 49 | + $( 'button#webfonts-preview-bold' ).click( function () { |
| 50 | + document.execCommand( 'bold', false, null ); |
| 51 | + } ); |
| 52 | + |
| 53 | + $( 'button#webfonts-preview-italic' ).click( function () { |
| 54 | + document.execCommand( 'italic', false, null ); |
| 55 | + } ); |
46 | 56 | |
47 | | - $( 'select#webfonts-size-chooser' ).change( function () { |
| 57 | + $( 'button#webfonts-preview-underline' ).click( function () { |
| 58 | + document.execCommand( 'underline', false, null ); |
| 59 | + } ); |
| 60 | + |
| 61 | + getFontsForLang( $( 'select#wpUserLanguage' ).val() ); |
48 | 62 | showPreview(); |
49 | 63 | } ); |
50 | | - |
51 | | - $( 'button#webfonts-preview-bold' ).click( function () { |
52 | | - document.execCommand( 'bold', false, null ); |
53 | | - } ); |
54 | 64 | |
55 | | - $( 'button#webfonts-preview-italic' ).click( function () { |
56 | | - document.execCommand( 'italic', false, null ); |
57 | | - } ); |
58 | | - |
59 | | - $( 'button#webfonts-preview-underline' ).click( function () { |
60 | | - document.execCommand( 'underline', false, null ); |
61 | | - } ); |
62 | | - |
63 | | - getFontsForLang( $( 'select#wpUserLanguage' ).val() ); |
64 | | - showPreview(); |
65 | | -} ); |
| 65 | +} )( jQuery, mediaWiki ); |
Index: trunk/extensions/WebFonts/resources/ext.webfonts.preview.css |
— | — | @@ -1,18 +1,19 @@ |
2 | 2 | select#wpUserLanguage, |
3 | 3 | select#webfonts-font-chooser, |
4 | | -select#webfonts-size-chooser{ |
| 4 | +select#webfonts-size-chooser { |
5 | 5 | width: 200px; |
6 | 6 | height: 25px; |
7 | 7 | vertical-align: middle; |
8 | 8 | } |
9 | 9 | |
10 | | -select#webfonts-size-chooser{ |
| 10 | +select#webfonts-size-chooser { |
11 | 11 | width: 50px; |
12 | 12 | } |
13 | 13 | |
14 | | -div#webfonts-preview-area{ |
| 14 | +div#webfonts-preview-area { |
15 | 15 | height: 300px; |
16 | 16 | border: 1px solid #cccccc; |
| 17 | + border-radius: 0 0 4px 4px; |
17 | 18 | -webkit-border-radius: 0 0 4px 4px; |
18 | 19 | -moz-border-radius: 0 0 4px 4px; |
19 | 20 | text-align: left; |
— | — | @@ -23,30 +24,30 @@ |
24 | 25 | button#webfonts-preview-bold, |
25 | 26 | button#webfonts-preview-italic, |
26 | 27 | button#webfonts-preview-underline, |
27 | | -a#webfonts-preview-download{ |
| 28 | +a#webfonts-preview-download { |
28 | 29 | height: 25px; |
29 | 30 | vertical-align: middle; |
30 | 31 | font-weight: bold; |
31 | 32 | text-shadow: 0 1px 0 rgba(255,255,255,0.4); |
32 | 33 | } |
33 | 34 | |
34 | | -a#webfonts-preview-download.disabled{ |
| 35 | +a#webfonts-preview-download.disabled { |
35 | 36 | color: #808080; |
36 | 37 | } |
37 | 38 | |
38 | | -div#webfonts-preview-toolbar button{ |
| 39 | +div#webfonts-preview-toolbar button { |
39 | 40 | width: 30px; |
40 | 41 | } |
41 | 42 | |
42 | | -button#webfonts-preview-italic{ |
| 43 | +button#webfonts-preview-italic { |
43 | 44 | font-style: italic; |
44 | 45 | } |
45 | 46 | |
46 | | -button#webfonts-preview-underline{ |
| 47 | +button#webfonts-preview-underline { |
47 | 48 | text-decoration: underline; |
48 | 49 | } |
49 | 50 | |
50 | | -a#webfonts-preview-download{ |
| 51 | +a#webfonts-preview-download { |
51 | 52 | padding-right: 10px; |
52 | 53 | padding-left: 10px; |
53 | 54 | padding-top: 3px; |
— | — | @@ -54,10 +55,11 @@ |
55 | 56 | text-decoration: none; |
56 | 57 | } |
57 | 58 | |
58 | | -div#webfonts-preview-toolbar{ |
| 59 | +div#webfonts-preview-toolbar { |
59 | 60 | overflow: hidden; |
60 | 61 | background-color: #F9F9F9; |
61 | 62 | border: 1px solid #CCCCCC; |
| 63 | + border-radius: 4px 4px 0 0; |
62 | 64 | -webkit-border-radius: 4px 4px 0 0; |
63 | 65 | -moz-border-radius: 4px 4px 0 0; |
64 | 66 | position: relative; |