var webFontBar = function webFontBar() { var fonts = { 'Hattori' : [ 'HattoriHanzoLight' ], 'Ubuntu' : [ 'UbuntuBold', 'UbuntuCondensedRegular', 'UbuntuLightRegular', 'UbuntuLightBold', 'UbuntuRegular' ], 'Blagovest' : [ 'blagovest' ], 'PTSans' : [ 'PTSansCaptionBold', 'PTSansNarrowRegular', 'PTSansRegular' ], 'Cuprum' : [ 'CuprumRegular', 'CuprumBold' ], 'PTMono' : [ 'Pt_monoregular' ], 'PTSerif' : [ 'PTSerifRegular', 'PTSerifBold', 'PTSerifCaptionRegular' ] }, sizes = { 'Force' : [ '16pt', '18pt', '20pt', '22pt', '24pt', '26pt' ], 'Standard' : [ 'xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large' ], 'Percent' : [ '0.8em', '1.0em', '1.2em', '1.4em', '1.6em', '1.8em', '2.0em', '2.2em' ] }, selector = function selector(sel, text) { var name = ''; name += '<p>Choose ' + text + ': <select>'; jQuery.each(sel, function (key, val) { name += '<optgroup label="' + key + '">'; jQuery.each(val, function () { name += '<option>' + this + '</option>'; }); name += '</optgroup>'; }); name += '</select></p>'; return name; }, curFontGroup = '', curFont = '', curSize = '', myStyle = function myStyle(fntGrp) { return '<style id="myWebFont" type="text/css">@import "http://webfont.ru/font/import/' + fntGrp.toLowerCase() + '.css";</style>'; }, myContainer = ''; switch (window.location.hostname) { case 'flibusta.net' : myContainer = '#main'; break; case 'habrahabr.ru' : myContainer = '.content'; break; case 'www.proza.ru' : case 'proza.ru' : myContainer = '.text'; break; case 'lib.ru' : myContainer = 'pre'; break; default : myContainer = 'body'; break; } jQuery('#webfont').remove(); jQuery('<div></div>') .attr('id', 'webfont') .appendTo('body') .css({ 'position' : 'fixed', 'width' : '96%', 'top' : '0px', 'right' : '2%', 'display' : 'fixed', 'text-align' : 'center', 'background-color' : '#ffcc66', 'padding' : '0.1em 0.1em', 'font-family' : 'sans-serif', 'font-size' : '16px', 'overflow' : 'hidden', 'margin' : '0px 0px', 'box-shadow' : '0.1em 0.1em 0.3em 0.1em #333' }); jQuery('<span>[_]</span> ' + '<input type="text" value="' + myContainer + '" /> ' + '<p><a href="http://webfont.ru" target="_blank">webfont.ru</a> welcomes you! </p>' + selector(fonts, 'font') + ' ' + selector(sizes, 'size') ).appendTo('#webfont'); jQuery('#webfont').children().css({ 'margin' : '0px 0px', 'display' : 'inline' }); jQuery('#webfont span') .attr('title', 'Minimize') .css({ 'cursor' : 'pointer', 'font-weight' : 'bold', 'color' : '#36f' }) .toggle(function () { jQuery(this) .parent('#webfont') .width('2em') .children() .not('span') .css('display', 'none'); jQuery(this).attr('title', 'Maximize'); jQuery(this).text('[#]'); }, function () { jQuery(this) .parent('#webfont') .width('96%') .children() .css('display', 'inline'); jQuery(this).attr('title', 'Minimize'); jQuery(this).text('[_]'); }); jQuery('#webfont select') .change(function () { curFontGroup = jQuery('#webfont select:first option:selected').parent().attr('label'); curFont = jQuery('#webfont select:first option:selected').val(); curSize = jQuery('#webfont select:last option:selected').val(); var myPreviousStyle = jQuery('head style#myWebFont'); if(myPreviousStyle.text() !== '') { if(myPreviousStyle.text().match('.*import/(.*).css')[1] !== curFontGroup.toLowerCase()) { myPreviousStyle.remove(); jQuery(myStyle(curFontGroup)).appendTo('head'); } } else { jQuery(myStyle(curFontGroup)).appendTo('head'); } jQuery(jQuery('#webfont input').val()) .css({ 'font-family' : curFont, 'font-size' : curSize, 'line-height' : '1.4em' }); }); }, startMyFontSwitcher = function startMyFontSwitcher() { if (window.jQuery === undefined) { var jq = document.createElement('script'); jq.setAttribute('type', 'text/javascript'); jq.setAttribute('src', 'http://code.jquery.com/jquery.min.js'); document.head.appendChild(jq); jq.addEventListener('load', function () { webFontBar(); }, false); } else { webFontBar(); } }; startMyFontSwitcher();