Skip to content

Commit d309183

Browse files
committed
Move assetConfig to ContentFeature class
1 parent eaa8be0 commit d309183

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

src/content-feature.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import { camelcase, matchHostname, processAttr } from './utils.js'
22
import { immutableJSONPatch } from 'immutable-json-patch'
33
import { PerformanceMonitor } from './performance.js'
44

5+
/**
6+
* @typedef {object} AssetConfig
7+
* @property {string} regularFontUrl
8+
* @property {string} boldFontUrl
9+
*/
10+
511
export default class ContentFeature {
612
constructor (featureName) {
713
this.name = featureName
@@ -21,6 +27,13 @@ export default class ContentFeature {
2127
return this._platform
2228
}
2329

30+
/**
31+
* @type {AssetConfig}
32+
*/
33+
get assetConfig () {
34+
return this._args?.assets || {}
35+
}
36+
2437
/**
2538
* Get the value of a config setting.
2639
* If the value is not set, return the default value.

src/features/click-to-load.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const titleID = 'DuckDuckGoPrivacyEssentialsCTLElementTitle'
2222
// @see {getConfig}
2323
let config = null
2424
let sharedStrings = null
25-
let styles = getStyles()
25+
let styles = null
2626

2727
// TODO: Remove these redundant data structures and refactor the related code.
2828
// There should be no need to have the entity configuration stored in two
@@ -894,10 +894,10 @@ function makeBaseStyleElement (mode = 'lightMode') {
894894
* Creates an anchor element with no destination. It is expected that a click
895895
* handler is added to the element later.
896896
* @param {string} linkText
897-
* @param {displayMode} [mode='lightMode']
897+
* @param {displayMode} mode
898898
* @returns {HTMLAnchorElement}
899899
*/
900-
function makeTextButton (linkText, mode) {
900+
function makeTextButton (linkText, mode = 'lightMode') {
901901
const linkElement = document.createElement('a')
902902
linkElement.style.cssText = styles.headerLink + styles[mode].linkFont
903903
linkElement.textContent = linkText
@@ -1617,9 +1617,7 @@ export default class ClickToLoad extends ContentFeature {
16171617
config = localizedConfig.config
16181618
sharedStrings = localizedConfig.sharedStrings
16191619
// update styles if asset config was sent
1620-
if (args?.assets) {
1621-
styles = getStyles(args.assets)
1622-
}
1620+
styles = getStyles(this.assetConfig)
16231621

16241622
for (const entity of Object.keys(config)) {
16251623
// Strip config entities that are first-party, or aren't enabled in the

src/features/click-to-load/ctl-config.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,10 @@ import localesJSON from '../../../build/locales/ctl-locales.js'
77
/*********************************************************
88
* Style Definitions
99
*********************************************************/
10-
/**
11-
* @typedef {object} AssetConfig
12-
* @property {string} regularFontUrl
13-
* @property {string} boldFontUrl
14-
*/
15-
1610
/**
1711
* Get CSS style defintions for CTL, using the provided AssetConfig for any non-embedded assets
1812
* (e.g. fonts.)
19-
* @param {AssetConfig} [assets]
13+
* @param {import('../../content-feature.js').AssetConfig} [assets]
2014
*/
2115
export function getStyles (assets) {
2216
let fontStyle = ''

0 commit comments

Comments
 (0)