[POSSIBLE BREAKTHROUGH] Dock title font size

[POSSIBLE BREAKTHROUGH] Dock title font size

by Gareth J Barnard -
Number of replies: 21
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hello Themers,

I have long been frustrated by the font size of the dock title being fixed at 11px - too small.  So, I've decided to have a go at making the JS take into account the font size set in the CSS.  Now, this is not complete, but rather posted here as a 'challenge' to you as I'm not sure when I'll revisit the code but I wanted to share what I've done so far.

Thus with the CSS:

#dock, #dock .dockedtitle h2 {
    font-size: 24px;
}

#dock #dockeditempanel {
    font-size: 12px;
}

and the changed dock.js code:

M.core.dock.fixTitleOrientation = function(title, text) {
    var dock = M.core.dock.get(),
        fontsize = Y.one('#dock').getStyle('fontSize'),
        transform = 'rotate(-90deg)',
        test,
        width,
        height,
        top,
        container;
    title = Y.one(title);

/*
#dock, #dock .dockedtitle h2 {
font-size: 24px;
}

#dock #dockeditempanel {
font-size: 12px;
}
*/
    if (dock.get('orientation') !== 'vertical') {
        // If the dock isn't vertical don't adjust it!
        title.set('innerHTML', text);
        return title;
    }

    if (Y.UA.ie > 0 && Y.UA.ie < 8) {
        // IE 6/7 can't rotate text so force ver
        M.str.langconfig.thisdirectionvertical = 'ver';
    }

    switch (M.str.langconfig.thisdirectionvertical) {
        case 'ver':
            // Stacked is easy
            return title.set('innerHTML', text.split('').join('
')); case 'ttb': transform = 'rotate(90deg)'; break; case 'btt': // Nothing to do here. transform default is good. break; } if (Y.UA.ie === 8) { // IE8 can flip the text via CSS but not handle transform. IE9+ can handle the CSS3 transform attribute. title.set('innerHTML', text); title.setAttribute('style', 'writing-mode: tb-rl; filter: flipV flipH;display:inline;'); title.addClass('filterrotate'); return title; } // We need to fix a font-size - sorry theme designers. Y.log('Dock font size: ' + title.getStyle('fontSize')); Y.log('Dock font size: ' + title.getComputedStyle('fontSize')); Y.log('Dock attribute: ' + title.getAttribute('style')); //Y.log('Dock font size: ' + Y.one('#dock').getStyle('fontSize')); Y.log('Dock font size: ' + fontsize); Y.log('Dock font size int: ' + parseInt(fontsize)); //Y.log('Dock font siz4: ' + Y.one('#dock').getComputedStyle('fontSize')); test = Y.Node.create('

'+text+'

');
    //test = Y.Node.create('

style="font-size:'+title.getStyle('fontSize')+';">'+text+'

');
    BODY.insert(test, 0);
    width = test.one('span').get('offsetWidth') * 1.2;
    height = test.one('span').get('offsetHeight');
    test.remove();

    title.set('innerHTML', text);
    title.addClass('css3transform');

	Y.log('Test width: ' + width);
	Y.log('Test height: ' + height);

    // Move the title into position
    top = (width - height)/2;
    title.setStyles({
        'position' : 'relative',
        //'fontSize' : fontsize,
        'width' : width,
        //'top' : '0',
        //'transform-origin' : '100% 100%',
        'top' : top
    });

    // Positioning is different when in RTL mode.
	/*
    if (right_to_left()) {
        title.setStyle('left', width/2 - height);
    } else {
        title.setStyle('right', width/2 - height);
    }
    */
    if (right_to_left()) {
        title.setStyle('left', top - ((top/30) + (parseInt(fontsize)/3)));
    } else {
        title.setStyle('right', top - ((top/30) + (parseInt(fontsize)/3)));
    }

    // Rotate the text
    title.setStyles({
        'transform' : transform,
        '-ms-transform' : transform,
        '-moz-transform' : transform,
        '-webkit-transform' : transform,
        '-o-transform' : transform
    });

    container = Y.Node.create('
');
    container.append(title);
    container.setStyles({
        height : width + (width / 4),
        position : 'relative'
    });
    return container;
};

you can get titles like the attached image.  The key snag appears to be this calculation:

    if (right_to_left()) {
        title.setStyle('left', top - ((top/30) + (parseInt(fontsize)/3)));
    } else {
        title.setStyle('right', top - ((top/30) + (parseInt(fontsize)/3)));
    }

Where I think as the font size decreases so the difference between that value and top increases.  I've run out of time now to do any more.

More info to follow, cheers,

Gareth

(Edited by Mary Evans - original submission Friday, 30 January 2015, 7:19 PM)

Attachment 2015-01-30 19_07_19-Moo28_ Administration_ Appearance_ Themes_ Clean.jpg
Average of ratings: -
In reply to Gareth J Barnard

Re: Dock title font size

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Source dock.js file (which lives in '\lib\yui\src\dock') where you can see my 'experiments':

In reply to Gareth J Barnard

Re: Dock title font size

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

To build, see the Moodle documentation - https://docs.moodle.org/dev/YUI/Shifter - about installing and running 'shifter'.  After every build you will need to 'Purge all caches' even with TDM on.  It looks like this (errors still to remove):

Attachment 2015-01-30 19_10_07-Node.js command prompt_sm.jpg
In reply to Gareth J Barnard

Re: Dock title font size

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

I think Amy changed that font size (or was it Sam?) anyway just spotted a typo in original coding..

We used to be able to change the font sizes in CSS

/Y.log('Dock font siz4:

It should have read...

/Y.log('Dock font size:
In reply to Mary Evans

Re: Dock title font size

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
Y.log('Dock font siz4:

is not a coding fault but intentional to show the getComputedStyle rather than getStyle above on the console in line with the same number of characters.

As far as I'm aware with docking, the ability to set the font size in CSS has never happened.  So looking at: https://github.com/moodle/moodle/commits/master/lib/yui/src/dock/js/dock.js we have first commit: https://github.com/moodle/moodle/blob/84192d78363a26d99331d51eb7c428187844d469/lib/yui/src/dock/js/dock.js#L183 and last commit: https://github.com/moodle/moodle/blob/557f44d970b773228b839721f8350cd28d0af9ad/lib/yui/src/dock/js/dock.js#L179 - always a fixed font size of 11px.

In reply to Gareth J Barnard

Re: Dock title font size

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

In the rebuilt dock, maybe Gareth, but in the original docking before it got broken and rebuilt just about everything about the dock could be styled in css - There was a setting for the dock panel font size in my flexi_ii theme

https://github.com/roelmann/Flexi_ii/blob/master/settings.php#L695


R

In reply to Richard Oelmann

Re: Dock title font size

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Interesting Richard, does the setting actually work?

In reply to Gareth J Barnard

Re: Dock title font size

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers
It did at the time - TBH I haven't reviewed or looked at flexi for a long time. It was designed for 2.1/2.2 in the very early days of theme settings. I would think that now with the rebuilt dock and the fixed font size in that code that it doesn't work anymore.
In reply to Richard Oelmann

Re: Dock title font size

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

Hi Richard,

Thus in that case the problem I state here is a real problem still to be solved.

Kind regards,

Gareth

In reply to Gareth J Barnard

Re: Dock title font size

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

That setting does not work I tried it this afternoon. 

It may be an idea Gareth, if you report this as a bug in Moodle Tracker and insist we need to be able to adjust this font size in themes We may get a response, and a possible fix.

.

In reply to Mary Evans

Re: Dock title font size

by Danny Wahl -

here's a potentially related bug: MDL-26663

I filed that a few years back dealing with dock item positioning not being able to be changed.  I think we need more than font options, but for the dock to be a fully style-able component.

In reply to Danny Wahl

Re: Dock title font size

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi Danny,

I forgot all about that one. There were others too about odd things happening to the dock titles with some blocks but not others....really odd stuff which I think got fixed.

If you can check to see that the problem still exists for MDL-26663, we can reopen it and update the fix versions to M2.7 & M2.8 and master branches.

Cheers and thanks

Mary

In reply to Gareth J Barnard

Re: Dock title font size

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

Yes it is! - Sorry Gareth, never meant to imply it wasn't, just that I thought I remembered previously being able to style it with CSS as Mary had said.

BUT I tested in an old copy of 2.1 and Mary's right - I may have put the setting in there, but it didn't work (still not sure how I missed that in all the testing at the time - or with the number of people using it back then, how it never got reported as a bug!) and the font-size was fixed even then - just at 10 not 11 by the look of it.

In reply to Richard Oelmann

Re: Dock title font size

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers

No worries Richard.  Thanks for letting me know, I was going to see how the older code worked as a input here.

The snag with all of this is how the JS is creating the containers for the text by creating a 'dummy' DOM element, getting its size and then using that as a basis for creating the tiles.  Surely there must be a vertical way in pure HTML / CSS to do this with a relative list containing absolute text.

In reply to Gareth J Barnard

Re: Dock title font size

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

I have just implemented a setting based on a slightly modified version of Richard's code and got it to work.

The code is as follows:-

Add to settings.php...

    // Docked title font size.
    $name = 'theme_themename/dockedtitlefontsize';
    $title = get_string('dockedtitlefontsize', 'theme_themename');
    $description = get_string('dockedtitlefontsizedesc', 'theme_themename');
    $default = '100%';
    $choices = array(
        '100' => '100%',
        '101' => '101%',
        '102' => '102%',
        '103' => '103%',
        '104' => '104%',
        '105' => '105%',
    );
    $setting = new admin_setting_configselect($name, $title, $description, $default, $choices);
    $setting->set_updatedcallback('theme_reset_all_caches');
    $settings->add($setting);

Add to lib.php...

function theme_themename_process_css($css, $theme) {

    // Set font size for docked block title.
    if (!empty($theme->settings->dockedtitlefontsize)) {
    $dockedtitlefontsize = $theme->settings->dockedtitlefontsize;
    } else {
    $dockedtitlefontsize = '100'; // default;
    }
    $css = theme_themename_set_dockedtitlefontsize($css, $dockedtitlefontsize);

    return $css;
}

function theme_themename_set_dockedtitlefontsize($css, $dockedtitlefontsize) {
    $tag = 'setting:dockedtitlefontsize';
    $css = str_replace($tag, $dockedtitlefontsize . '%', $css);

    return $css;
}

Add to CSS file

.jsenabled.has_dock #dock .dockedtitle h2.css3transform {
    font-size: setting:dockedtitlefontsize !important;
    color: #f00; /* change colour here too */
    margin: 20px auto; /* adds some space top and bottom of title */
}

Add to lang/en/theme_themename.php

$string['dockedtitlefontsize'] ='Docked title font-size';
$string['dockedtitlefontsizedesc'] ='Choose the font-size for all docked block titles by selecting it from this drop-down list .';
In reply to Gareth J Barnard

Re: [POSSIBLE BREAKTHROUGH] Dock title font size

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

.jsenabled.has_dock #dock .dockedtitle h2.css3transform { font-size: 120%!important; }

WORKS IN ESSENTIALCUSTOM CSS

In reply to Mary Evans

Re: [POSSIBLE BREAKTHROUGH] Dock title font size

by Gareth J Barnard -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers
Nice idea, but... the size and height positions of the dock tabs are calculated as a factor of the contained content.  So, just changing the CSS is not a complete solution as with big sizes the text will overflow the box.
In reply to Gareth J Barnard

Re: [POSSIBLE BREAKTHROUGH] Dock title font size

by Dwight Hawley -

I was just coming to forums to see if I could adjust font and colors of the docking tabs. I guess this is the answer. It was, it is not, it might well be. After kicking the tires around coding I will happily wait on those who drive this thing. For what it's worth I would like to do a global font/sizing parameter and the ability to color tabs based on their class, or what they are, mostly so I can say "click on the blue tab" when the inevitable support calls come in.


Thanks to each of you for all you do.

In reply to Dwight Hawley

Re: [POSSIBLE BREAKTHROUGH] Dock title font size

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Do you mean something like this Dwight?

Click on the Blue Tab => Change Font Settings

In reply to Mary Evans

Re: [POSSIBLE BREAKTHROUGH] Dock title font size

by Dwight Hawley -

Hi Mary,


As an administrator it would be very nice to have the blue button, but this is more for the end user navigation.

A client would like to highlight certain things on the user page. These things would typically reside in a block so I started wondering how to color the blocks to match a wireframe I had been shone of their current site. Some of the things they want highlighted are a calendar/planner, upcoming events, a "My Grades" type of block etc.

Since I'm using the BCU theme I asked if docking had been disabled for some reason since I couldn't find a way to trigger it in the blocks themselves. Mike answered saying it had to do with 2.6 compatibility but told me where to change the code to make docking available. So that got me thinking about coloring the tabs to satisfy the highlight requirements for my clients, or if I decided to make the highlighted items regular blocks on the right, I could at least make the tabs stand out rather than fading into the background.

Attachment image002.jpg
In reply to Dwight Hawley

Re: [POSSIBLE BREAKTHROUGH] Dock title font size

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi,

Now that is an Interesting concept!

It should be possible to colourize the docked block titles but only in the order that they are docked as there is no current information as to which block it is.

So something like this should work...

#docked_item_0_title.firstdockitem {background-color: red}

#docked-item_1_title {background-color: green}

#docked-item_2_title {background-color: blue}

I'll look into this a bit more as there should be some indication as to which block is docked so they can be styled individually.

Cheers

Mary

In reply to Mary Evans

Re: [POSSIBLE BREAKTHROUGH] Dock title font size

by Richard Oelmann -
Picture of Core developers Picture of Plugin developers Picture of Testers

A tracker issue for an improvement (as opposed to bug) for the docking js, Mary? Such that the block name is added as a class, the way it is with the blocks themselves?