Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Orion » Editor Font Size(How to change orion's font size dynamically)
Editor Font Size [message #839692] Mon, 09 April 2012 00:10 Go to next message
Joe Ertaba is currently offline Joe Ertaba
Messages: 17
Registered: April 2012
Junior Member
I am aware font size can be changed by modifying its value from "textviewContainer" CSS class. What I am interested in is changing font-size dynamically from JavaScript.

Is there any method for that?
Re: Editor Font Size [message #840056 is a reply to message #839692] Mon, 09 April 2012 12:04 Go to previous messageGo to next message
Anton McConville is currently offline Anton McConville
Messages: 1
Registered: April 2012
Junior Member
Hi Joe,

The short answer is that you can use JavaScript, although there is no API specific for setting the font at the moment. A JavaScript call would modify the style sheet and alter the settings for that class.

If you check the settings page, you can use a user interface to change the size and color of the font. The programming behind that is in textStylerOptions.js

[ org.eclipse.orion.client >> bundles >> org.eclipse.orion.client.editor >> web >> examples >> textview >> textStylerOptions.js ]

Anton
Re: Editor Font Size [message #840231 is a reply to message #840056] Mon, 09 April 2012 16:59 Go to previous message
Joe Ertaba is currently offline Joe Ertaba
Messages: 17
Registered: April 2012
Junior Member
Hi Anton,

Thanks for your reply.

Here is my snippet for those who may need change each setting separately.

var setSetting = (function(){
    var indexArray = [];
    var styleSheet = function (path) {
        for(var i = 0; i < doc.styleSheets.length; i++) {
            var sheet = doc.styleSheets[i];
            if(path.test(sheet.href)) 
                return sheet;
        }
        return null;
    }(/textview\.css/);
    if (!styleSheet) return false;

    const css = ".textviewContainer{%s}";
    return function(type, value) {
        if (indexArray[type])
            styleSheet.deleteRule(indexArray[type]);
        else
            indexArray[type] = styleSheet.cssRules.length;
            
        styleSheet.insertRule(css.replace("%s",  type + ": " + value + " !important"), indexArray[type]);
        textView.update(true);
        
        return true;
    }
})();

setSetting("font-family", "monospace");
setSetting("background-color", "white");
setSetting("font-size", "12pt");


"doc" and "textView" must be set before execution.

P.S:
The code has been just tested in Firefox browser.

[Updated on: Mon, 09 April 2012 17:05]

Report message to a moderator

Previous Topic:Editor problem with FF10.0.2
Next Topic:Key words auto suggestion
Goto Forum:
  


Current Time: Mon Jul 28 04:19:37 EDT 2014

Powered by FUDForum. Page generated in 0.01711 seconds