Skip to content

Commit fe46c7e

Browse files
authored
New: Added favicon support (fixes #306) (#396)
1 parent 0748700 commit fe46c7e

File tree

4 files changed

+81
-1
lines changed

4 files changed

+81
-1
lines changed

example.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
// Available properties
22
// --------------------------------------------------
33

4+
// course.json
5+
"_vanilla": {
6+
"_favIcon": {
7+
"_src": ""
8+
}
9+
},
10+
411
// contentObjects.json
512
"_vanilla": {
613
"_backgroundImage": {

js/theme.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ class Theme extends Backbone.Controller {
1616

1717
onDataReady() {
1818
$('html').addClass(Adapt.course.get('_courseStyle'));
19+
this.addFavIcon();
20+
}
21+
22+
addFavIcon() {
23+
const theme = Adapt.course.get('_vanilla');
24+
if (!theme._favIcon._src) return;
25+
const $linkStandard = $(`<link rel="icon" href="${theme._favIcon._src}" size="192x192" />`);
26+
const $linkApple = $(`<link rel="apple-touch-icon" href="${theme._favIcon._src}" />`);
27+
$('head')
28+
.append($linkStandard)
29+
.append($linkApple);
1930
}
2031

2132
onPostRender(view) {

properties.schema

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,30 @@
698698
"type": "object"
699699
},
700700
"course": {
701-
"type": "object"
701+
"type": "object",
702+
"properties": {
703+
"_vanilla": {
704+
"type": "object",
705+
"required": false,
706+
"properties": {
707+
"_favIcon": {
708+
"type": "object",
709+
"required": false,
710+
"legend": "FavIcon",
711+
"properties": {
712+
"_src": {
713+
"type": "string",
714+
"required": false,
715+
"default": "",
716+
"inputType": "Asset:image",
717+
"validators": [],
718+
"help": "Select a favicon to improve user experience and enforce brand consistency. This will be displayed in places like your browser's address bar, page tabs and bookmarks menu. Usually, a favicon is 16 x 16 pixels in size and stored in the GIF, PNG, or ICO file format."
719+
}
720+
}
721+
}
722+
}
723+
}
724+
}
702725
},
703726
"contentobject": {
704727
"type": "object",

schema/course.schema.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"$anchor": "vanilla-course",
3+
"$schema": "https://json-schema.org/draft/2020-12/schema",
4+
"type": "object",
5+
"$patch": {
6+
"source": {
7+
"$ref": "course"
8+
},
9+
"with": {
10+
"properties": {
11+
"_vanilla": {
12+
"type": "object",
13+
"title": "Theme",
14+
"default": {},
15+
"properties": {
16+
"_favIcon": {
17+
"type": "object",
18+
"default": {},
19+
"title": "Favicon",
20+
"properties": {
21+
"_src": {
22+
"type": "string",
23+
"isObjectId": true,
24+
"title": "Image",
25+
"description": "Select a favicon to improve user experience and enforce brand consistency. This will be displayed in places like your browser's address bar, page tabs and bookmarks menu. Usually, a favicon is 16 x 16 pixels in size and stored in the GIF, PNG, or ICO file format.",
26+
"default": "",
27+
"_backboneForms": {
28+
"type": "Asset",
29+
"media": "image"
30+
}
31+
}
32+
}
33+
}
34+
}
35+
}
36+
}
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)