Skip to content

Commit

Permalink
V403.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Jan 18, 2024
1 parent 6eb5c74 commit acf0f28
Show file tree
Hide file tree
Showing 44 changed files with 2,180 additions and 1,150 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}
IGNORE_PATHS: 'templates/mod_assign,node_modules'
IGNORE_NAMES: '*.txt,behat_*.php,fallback.css,activity_navigation.mustache,message_drawer.mustache,overlaymenu.mustache,overlaymenuitem.mustache,savediscard.mustache,tabs.mustache,tourstep.mustache,admin_settingspage_tabs.php,secondarynav.mustache,overflow.mustache'
IGNORE_NAMES: '*.txt,behat_*.php,fallback.css,activity_navigation.mustache,message_drawer.mustache,overlaymenu.mustache,overlaymenuitem.mustache,savediscard.mustache,tabs.mustache,tourstep.mustache,admin_settingspage_tabs.php,secondarynav.mustache,overflow.mustache,head.mustache,footer.mustache,nofooter.mustache'

- name: PHP Lint
if: ${{ always() }}
Expand Down
12 changes: 12 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
Change Log in version 403.0.2 (2023111801)
===========================================
1. Fix 'Grade report scrolling', ref: https://moodle.org/mod/forum/discuss.php?d=453194#p1821224.
2. Tidy up header logic in relation to titles.
3. Navbar and breadcrumb tidy.
4. Fix 'error: class constructors must be invoked with 'new'' - ref: https://moodle.org/mod/forum/discuss.php?d=453804.
5. Add 'buttontexthovercolor' setting to fix button hovers.
6. Fix header search icon.
7. Add 'headerbgimagetextcolour' and 'headertextcolor2' to fix lower header text colours.
8. Fix position of '#savediscardsection'.
9. Refactored layouts as a progressional aim towards use of templating to a greater extent.

Change Log in version 403.0.1 (2023111800)
===========================================
1. Release candidate for Moodle 4.3.
Expand Down
11 changes: 1 addition & 10 deletions amd/build/icon_system_fontawesome.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

219 changes: 148 additions & 71 deletions amd/src/icon_system_fontawesome.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,112 +14,189 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Adaptable theme.
* Foundation theme.
*
* @module theme_adaptable/icon_system_fontawesome
* @copyright 2023 G J Barnard
* An Icon System implementation for FontAwesome based on core/icon_system_fontawesome by
* Damyon Wiese.
*
* @module theme_adaptable/icon_system_fontawesome
* @copyright 2017 Damyon Wiese
* @copyright 2023 G J Barnard.
* @author G J Barnard -
* {@link https://moodle.org/user/profile.php?id=442195}
* {@link https://gjbarnard.co.uk}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/

define(['core/icon_system', 'jquery', 'core/ajax', 'core/mustache', 'core/localstorage', 'core/url'],
function(IconSystem, $, Ajax, Mustache, LocalStorage, Url) {
import {call as fetchMany} from 'core/ajax';
import LocalStorage from 'core/localstorage';
import IconSystem from 'core/icon_system';
import * as Mustache from 'core/mustache';
import * as Config from 'core/config';
import * as Url from 'core/url';

/**
* An set of properties for an icon.
* @typedef {object} IconProperties
* @property {array} attributes
* @private
*/

var staticMap = null;
var fetchMap = null;
/**
* The FontAwesome icon system.
*/
export default class IconSystemFontawesome extends IconSystem {
/**
* @var {Map} staticMap A map of icon names to FA Icon.
* @private
*/
static staticMap = null;

/**
* @var {Promise} fetchPromise The promise used when fetching the result
* @private
*/
static fetchPromise = null;

/**
* IconSystemFontawesome
* @var {string} cacheKey The key used to store the icon map in LocalStorage.
* @private
*/
var IconSystemFontawesome = function() {
IconSystem.apply(this, arguments);
};
IconSystemFontawesome.prototype = Object.create(IconSystem.prototype);
static cacheKey = `core_iconsystem/theme/${Config.theme}/core/iconmap-fontawesome`;

/**
* Prefetch resources so later calls to renderIcon can be resolved synchronously.
*
* @method init
* @return {Promise}
* @returns {Promise<IconSystemFontawesome>}
*/
IconSystemFontawesome.prototype.init = function() {
if (staticMap) {
return $.when(this);
init() {
if (IconSystemFontawesome.staticMap) {
return Promise.resolve(this);
}

var map = LocalStorage.get('theme_adaptable/iconmap-fontawesome');
if (map) {
map = JSON.parse(map);
if (this.getMapFromCache()) {
return Promise.resolve(this);
}

if (map) {
staticMap = map;
return $.when(this);
if (IconSystemFontawesome.fetchPromise) {
return IconSystemFontawesome.fetchPromise;
}

if (fetchMap === null) {
fetchMap = Ajax.call([{
methodname: 'theme_adaptable_output_load_fontawesome_icon_map',
args: []
}], true, false)[0];
return this.fetchMapFromServer();
}

/**
* Get the icon map from LocalStorage.
*
* @private
* @returns {Map}
*/
getMapFromCache() {
const map = LocalStorage.get(IconSystemFontawesome.cacheKey);
if (map) {
IconSystemFontawesome.staticMap = new Map(JSON.parse(map));
}
return IconSystemFontawesome.staticMap;
}

/**
* Fetch the map data from the server.
*
* @private
* @returns {Promise}
*/
_fetchMapFromServer() {
return fetchMany([{
methodname: 'theme_foundation_output_load_fontawesome_icon_map',
args: {
},
}], true, false, false, 0, Config.themerev)[0];
}

/**
* Fetch the map data from the server.
*
* @returns {Promise<IconSystemFontawesome>}
* @private
*/
async fetchMapFromServer() {
IconSystemFontawesome.fetchPromise = (async () => {
const mapData = await this._fetchMapFromServer();

IconSystemFontawesome.staticMap = new Map(Object.entries(mapData).map(([, value]) => ([
`${value.component}/${value.pix}`,
value.to,
])));
LocalStorage.set(
IconSystemFontawesome.cacheKey,
JSON.stringify(Array.from(IconSystemFontawesome.staticMap.entries())),
);

return fetchMap.then(function(map) {
staticMap = {};
$.each(map, function(index, value) {
staticMap[value.component + '/' + value.pix] = value.to;
});
LocalStorage.set('theme_adaptable/iconmap-fontawesome', JSON.stringify(staticMap));
return this;
}.bind(this));
};
})();

return IconSystemFontawesome.fetchPromise;
}

/**
* Render an icon.
*
* @param {String} key
* @param {String} component
* @param {String} title
* @param {String} template
* @return {String}
* @method renderIcon
* @param {string} key
* @param {string} component
* @param {string} title
* @param {string} template
* @return {string} The rendered HTML content
*/
IconSystemFontawesome.prototype.renderIcon = function(key, component, title, template) {
var mappedIcon = staticMap[component + '/' + key];
var unmappedIcon = false;
if (typeof mappedIcon === "undefined") {
var url = Url.imageUrl(key, component);

unmappedIcon = {
attributes: [
{name: 'src', value: url},
{name: 'alt', value: title},
{name: 'title', value: title}
]
};
}

var context = {
key: mappedIcon,
title: title,
renderIcon(key, component, title, template) {
const iconKey = `${component}/${key}`;
const mappedIcon = IconSystemFontawesome.staticMap.get(iconKey);
const unmappedIcon = this.getUnmappedIcon(mappedIcon, key, component, title);

const context = {
title,
unmappedIcon,
alt: title,
unmappedIcon: unmappedIcon
key: mappedIcon,
};

return Mustache.render(template, context);
};
if (typeof title === "undefined" || title === '') {
context['aria-hidden'] = true;
}

return Mustache.render(template, context).trim();
}

/**
* Get the unmapped icon content, if the icon is not mapped.
*
* @param {IconProperties} mappedIcon
* @param {string} key
* @param {string} component
* @param {string} title
* @returns {IconProperties|null}
* @private
*/
getUnmappedIcon(mappedIcon, key, component, title) {
if (mappedIcon) {
return null;
}

return {
attributes: [
{name: 'src', value: Url.imageUrl(key, component)},
{name: 'alt', value: title},
{name: 'title', value: title}
],
};
}

/**
* Get the name of the template to pre-cache for this icon system.
*
* @return {String}
* @return {string}
* @method getTemplateName
*/
IconSystemFontawesome.prototype.getTemplateName = function() {
getTemplateName() {
return 'theme_adaptable/pix_icon_fontawesome';
};

return IconSystemFontawesome; // @alias module:theme_adaptable/icon_system_fontawesome

});
}
}
2 changes: 1 addition & 1 deletion classes/output/core_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
* Core Renderer
*/
class core_renderer extends core_renderer_base {
use core_renderer_toolbox;
use core_renderer_toolbox, core_renderer_layout;
}
Loading

0 comments on commit acf0f28

Please sign in to comment.