Index: trunk/extensions/WebFonts/resources/ext.webfonts.preview.js |
— | — | @@ -0,0 +1,64 @@ |
| 2 | +/** |
| 3 | + * Preview page script |
| 4 | + */ |
| 5 | +jQuery( function( $ ) { |
| 6 | + |
| 7 | + var showPreview = function( ) { |
| 8 | + var $font = $( 'select#webfonts-font-chooser' ).val(); |
| 9 | + var $downloadLink = $( 'a#webfonts-preview-download' ); |
| 10 | + 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]; |
| 15 | + var base = mw.config.get( 'wgExtensionAssetsPath' ) + '/WebFonts/fonts/'; |
| 16 | + $downloadLink.prop( 'href' , base + fontconfig.ttf ).removeClass( 'disabled' ); |
| 17 | + return true; |
| 18 | + } |
| 19 | + |
| 20 | + var getFontsForLang = function( language ) { |
| 21 | + var $fontSelecter = $( 'select#webfonts-font-chooser' ); |
| 22 | + var $downloadLink = $( 'a#webfonts-preview-download' ); |
| 23 | + $fontSelecter.empty(); |
| 24 | + var languages = mw.webfonts.config.languages; |
| 25 | + var fonts = languages[language]; |
| 26 | + if(!fonts) { |
| 27 | + $downloadLink.removeAttr( 'href' ).addClass( 'disabled' ); |
| 28 | + return false; |
| 29 | + } |
| 30 | + $.each(fonts, function(key, value) { |
| 31 | + $fontSelecter.append( $('<option>', { value : value } ) |
| 32 | + .text( value ) ); |
| 33 | + } ); |
| 34 | + showPreview(); |
| 35 | + return true; |
| 36 | + } |
| 37 | + |
| 38 | + $( 'select#wpUserLanguage' ).change( function () { |
| 39 | + var language = $( 'select#wpUserLanguage' ).val(); |
| 40 | + getFontsForLang( language ); |
| 41 | + } ); |
| 42 | + |
| 43 | + $( 'select#webfonts-font-chooser' ).change( function () { |
| 44 | + showPreview(); |
| 45 | + } ); |
| 46 | + |
| 47 | + $( 'select#webfonts-size-chooser' ).change( function () { |
| 48 | + showPreview(); |
| 49 | + } ); |
| 50 | + |
| 51 | + $( 'button#webfonts-preview-bold' ).click( function () { |
| 52 | + document.execCommand( 'bold', false, null ); |
| 53 | + } ); |
| 54 | + |
| 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 | +} ); |
Property changes on: trunk/extensions/WebFonts/resources/ext.webfonts.preview.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 66 | + native |
Index: trunk/extensions/WebFonts/resources/ext.webfonts.preview.css |
— | — | @@ -0,0 +1,65 @@ |
| 2 | +select#wpUserLanguage, |
| 3 | +select#webfonts-font-chooser, |
| 4 | +select#webfonts-size-chooser{ |
| 5 | + width: 200px; |
| 6 | + height: 25px; |
| 7 | + vertical-align: middle; |
| 8 | +} |
| 9 | + |
| 10 | +select#webfonts-size-chooser{ |
| 11 | + width: 50px; |
| 12 | +} |
| 13 | + |
| 14 | +div#webfonts-preview-area{ |
| 15 | + height: 300px; |
| 16 | + border: 1px solid #cccccc; |
| 17 | + -webkit-border-radius: 0 0 4px 4px; |
| 18 | + -moz-border-radius: 0 0 4px 4px; |
| 19 | + text-align: left; |
| 20 | + padding: 5px; |
| 21 | + overflow: auto; |
| 22 | +} |
| 23 | + |
| 24 | +button#webfonts-preview-bold, |
| 25 | +button#webfonts-preview-italic, |
| 26 | +button#webfonts-preview-underline, |
| 27 | +a#webfonts-preview-download{ |
| 28 | + height: 25px; |
| 29 | + vertical-align: middle; |
| 30 | + font-weight: bold; |
| 31 | + text-shadow: 0 1px 0 rgba(255,255,255,0.4); |
| 32 | +} |
| 33 | + |
| 34 | +a#webfonts-preview-download.disabled{ |
| 35 | + color: #808080; |
| 36 | +} |
| 37 | + |
| 38 | +div#webfonts-preview-toolbar button{ |
| 39 | + width: 30px; |
| 40 | +} |
| 41 | + |
| 42 | +button#webfonts-preview-italic{ |
| 43 | + font-style: italic; |
| 44 | +} |
| 45 | + |
| 46 | +button#webfonts-preview-underline{ |
| 47 | + text-decoration: underline; |
| 48 | +} |
| 49 | + |
| 50 | +a#webfonts-preview-download{ |
| 51 | + padding-right: 10px; |
| 52 | + padding-left: 10px; |
| 53 | + padding-top: 3px; |
| 54 | + float: right; |
| 55 | + text-decoration: none; |
| 56 | +} |
| 57 | + |
| 58 | +div#webfonts-preview-toolbar{ |
| 59 | + overflow: hidden; |
| 60 | + background-color: #F9F9F9; |
| 61 | + border: 1px solid #CCCCCC; |
| 62 | + -webkit-border-radius: 4px 4px 0 0; |
| 63 | + -moz-border-radius: 4px 4px 0 0; |
| 64 | + position: relative; |
| 65 | + padding: 2px; |
| 66 | +} |
Property changes on: trunk/extensions/WebFonts/resources/ext.webfonts.preview.css |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 67 | + native |
Index: trunk/extensions/WebFonts/WebFonts.php |
— | — | @@ -30,9 +30,11 @@ |
31 | 31 | |
32 | 32 | // Internationalization |
33 | 33 | $wgExtensionMessagesFiles['WebFonts'] = "$dir/WebFonts.i18n.php"; |
| 34 | +$wgExtensionMessagesFiles['SpecialWebFonts'] = "$dir/SpecialWebFonts.i18n.php"; |
34 | 35 | |
35 | 36 | // Register auto load for the page class |
36 | 37 | $wgAutoloadClasses['WebFontsHooks'] = "$dir/WebFonts.hooks.php"; |
| 38 | +$wgAutoloadClasses['SpecialWebFonts'] = "$dir/SpecialWebFonts.php"; |
37 | 39 | |
38 | 40 | $wgHooks['BeforePageDisplay'][] = 'WebFontsHooks::addModules'; |
39 | 41 | $wgHooks['GetPreferences'][] = 'WebFontsHooks::addPreference'; |
— | — | @@ -41,6 +43,8 @@ |
42 | 44 | |
43 | 45 | $wgWebFontsEnabledByDefault = true; |
44 | 46 | |
| 47 | +$wgSpecialPages['WebFonts'] = 'SpecialWebFonts'; |
| 48 | + |
45 | 49 | $wgResourceModules['ext.webfonts.init'] = array( |
46 | 50 | 'scripts' => 'resources/ext.webfonts.init.js', |
47 | 51 | 'localBasePath' => $dir, |
— | — | @@ -70,3 +74,12 @@ |
71 | 75 | ), |
72 | 76 | 'position' => 'top', |
73 | 77 | ); |
| 78 | + |
| 79 | +$wgResourceModules['ext.webfonts.preview'] = array( |
| 80 | + 'scripts' => 'resources/ext.webfonts.preview.js', |
| 81 | + 'styles' => 'resources/ext.webfonts.preview.css', |
| 82 | + 'localBasePath' => $dir, |
| 83 | + 'remoteExtPath' => 'WebFonts', |
| 84 | + 'dependencies' => 'ext.webfonts.core', |
| 85 | + 'position' => 'top', |
| 86 | +); |
Index: trunk/extensions/WebFonts/SpecialWebFonts.php |
— | — | @@ -0,0 +1,83 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Contains logic for special page Special:WebFonts |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @author Santhosh Thottingal |
| 8 | + * @copyright Copyright © 2012 Santhosh Thottingal |
| 9 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 10 | + */ |
| 11 | + |
| 12 | +class SpecialWebFonts extends SpecialPage { |
| 13 | + public function __construct() { |
| 14 | + parent::__construct( 'WebFonts' ); |
| 15 | + } |
| 16 | + |
| 17 | + public function execute( $params ) { |
| 18 | + global $wgOut, $wgLang; |
| 19 | + $this->out = $wgOut; |
| 20 | + $this->lang = $wgLang->getCode(); |
| 21 | + if ( isset( $params ) ) { |
| 22 | + $this->lang = $params; |
| 23 | + } |
| 24 | + $wgOut->addModules( 'ext.webfonts.preview' ); |
| 25 | + $this->setHeaders(); |
| 26 | + $this->out->setPageTitle( wfMsg( 'webfonts' ) ); |
| 27 | + $this->out->addWikiMsg( 'webfonts-preview-intro' ); |
| 28 | + $this->showPreviewForm(); |
| 29 | + } |
| 30 | + |
| 31 | + protected function showPreviewForm() { |
| 32 | + $this->out->addHtml( Html::openElement( 'h2' ) |
| 33 | + . wfMsg( 'webfonts-preview-title' ) |
| 34 | + . Html::closeElement( 'h2' ) ); |
| 35 | + |
| 36 | + $this->out->addHtml( $this->showToolbar() ); |
| 37 | + |
| 38 | + $editArea = Html::openElement( 'div', array( 'id' => 'webfonts-preview-area' , 'contenteditable' => 'true' ) ) |
| 39 | + . wfMsg( 'webfonts-preview-sampltext' ) |
| 40 | + . Html::closeElement( 'div' ); |
| 41 | + $this->out->addHtml( $editArea ); |
| 42 | + |
| 43 | + $this->out->addHtml( Html::openElement( 'h2' ) |
| 44 | + . wfMsg( 'webfonts-preview-installing-fonts-title' ) |
| 45 | + . Html::closeElement( 'h2' ) ); |
| 46 | + $this->out->addWikiMsg( 'webfonts-preview-installing-fonts-text' ); |
| 47 | + } |
| 48 | + |
| 49 | + protected function showToolbar() { |
| 50 | + $langSelector = Xml::languageSelector( $this->lang ); |
| 51 | + |
| 52 | + $fontSelector = new XmlSelect(); |
| 53 | + $fontSelector->setAttribute( 'id', 'webfonts-font-chooser' ); |
| 54 | + |
| 55 | + $sizeSelector = new XmlSelect(); |
| 56 | + $sizeSelector->setAttribute( 'id', 'webfonts-size-chooser' ); |
| 57 | + for ( $size = 8; $size <= 28; $size += 2 ) { |
| 58 | + $sizeSelector->addOption( $size , $size ); |
| 59 | + } |
| 60 | + $sizeSelector->setDefault( 16 ); |
| 61 | + |
| 62 | + $bold = Html::openElement( 'button', array( 'id' => 'webfonts-preview-bold' ) ) . 'B' |
| 63 | + . Html::closeElement( 'button' ); |
| 64 | + |
| 65 | + $italic = Html::openElement( 'button', array( 'id' => 'webfonts-preview-italic' ) ) . 'I' |
| 66 | + . Html::closeElement( 'button' ); |
| 67 | + |
| 68 | + $underline = Html::openElement( 'button', array( 'id' => 'webfonts-preview-underline' ) ) . 'U' |
| 69 | + . Html::closeElement( 'button' ); |
| 70 | + |
| 71 | + $download = Html::openElement( 'a', array( 'id' => 'webfonts-preview-download', 'href' => '#' ) ) |
| 72 | + . wfMsg( 'webfonts-preview-download' ) . Html::closeElement( 'a' ); |
| 73 | + |
| 74 | + return Html::openElement( 'div', array( 'id' => 'webfonts-preview-toolbar' ) ) |
| 75 | + . $langSelector[1] |
| 76 | + . $fontSelector->getHtml() |
| 77 | + . $sizeSelector->getHtml() |
| 78 | + . $bold |
| 79 | + . $italic |
| 80 | + . $underline |
| 81 | + . $download |
| 82 | + . Html::closeElement( 'div' ); |
| 83 | + } |
| 84 | +} |
Property changes on: trunk/extensions/WebFonts/SpecialWebFonts.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 85 | + native |