| 1 |
wp.domReady(function () { |
| 2 |
|
| 3 |
function typoCssVarsForEl(typo, prefix, el) { |
| 4 |
if (!typo || typeof typo !== 'object') return; |
| 5 |
var m = { family:'font-family', weight:'font-weight', transform:'text-transform', style:'font-style', decoration:'text-decoration', |
| 6 |
sizeDesktop:'font-size-d', sizeTablet:'font-size-t', sizeMobile:'font-size-m', |
| 7 |
lineHeightDesktop:'line-height-d', lineHeightTablet:'line-height-t', lineHeightMobile:'line-height-m', |
| 8 |
letterSpacingDesktop:'letter-spacing-d', letterSpacingTablet:'letter-spacing-t', letterSpacingMobile:'letter-spacing-m', |
| 9 |
wordSpacingDesktop:'word-spacing-d', wordSpacingTablet:'word-spacing-t', wordSpacingMobile:'word-spacing-m' }; |
| 10 |
Object.keys(m).forEach(function (k) { |
| 11 |
if (typo[k] !== undefined && typo[k] !== '') { |
| 12 |
var v = typo[k], u = typo[k + 'Unit'] || ''; |
| 13 |
if (/Desktop|Tablet|Mobile/.test(k) && typeof v === 'number') v = v + (u || 'px'); |
| 14 |
el.style.setProperty(prefix + m[k], '' + v); |
| 15 |
} |
| 16 |
}); |
| 17 |
} |
| 18 |
|
| 19 |
document.querySelectorAll('.bkbg-dual-heading-app').forEach(function (app) { |
| 20 |
var opts = {}; |
| 21 |
try { opts = JSON.parse(app.getAttribute('data-opts') || '{}'); } catch (e) {} |
| 22 |
|
| 23 |
var tag = opts.tag || 'h2'; |
| 24 |
var layout = opts.layout || 'stacked'; |
| 25 |
var align = opts.textAlign || 'center'; |
| 26 |
|
| 27 |
var wrap = document.createElement('div'); |
| 28 |
wrap.className = 'bkbg-dh-wrap'; |
| 29 |
if (opts.bgColor) wrap.style.background = opts.bgColor; |
| 30 |
wrap.style.paddingTop = (opts.paddingTop || 16) + 'px'; |
| 31 |
wrap.style.paddingBottom = (opts.paddingBottom || 16) + 'px'; |
| 32 |
wrap.style.setProperty('--bkbg-dh-l1-fs', (opts.line1Size || 52) + 'px'); |
| 33 |
wrap.style.setProperty('--bkbg-dh-l2-fs', (opts.line2Size || 52) + 'px'); |
| 34 |
wrap.style.setProperty('--bkbg-dh-sub-fs', (opts.subtextSize || 18) + 'px'); |
| 35 |
typoCssVarsForEl(opts.typoLine1, '--bkbg-dh-l1-', wrap); |
| 36 |
typoCssVarsForEl(opts.typoLine2, '--bkbg-dh-l2-', wrap); |
| 37 |
typoCssVarsForEl(opts.typoSubtext, '--bkbg-dh-sub-', wrap); |
| 38 |
|
| 39 |
var inner = document.createElement('div'); |
| 40 |
inner.className = 'bkbg-dh-inner'; |
| 41 |
inner.style.maxWidth = (opts.maxWidth || 900) + 'px'; |
| 42 |
inner.style.textAlign = align; |
| 43 |
|
| 44 |
var heading = document.createElement(tag); |
| 45 |
heading.className = 'bkbg-dh-heading'; |
| 46 |
heading.style.margin = '0'; |
| 47 |
|
| 48 |
var linesWrap = document.createElement('span'); |
| 49 |
linesWrap.className = 'bkbg-dh-lines-wrap bkbg-dh--' + layout; |
| 50 |
if (layout === 'stacked') { |
| 51 |
linesWrap.style.gap = (opts.lineGap || 4) + 'px'; |
| 52 |
} else { |
| 53 |
linesWrap.style.gap = '0 12px'; |
| 54 |
linesWrap.style.justifyContent = align === 'center' ? 'center' : (align === 'right' ? 'flex-end' : 'flex-start'); |
| 55 |
} |
| 56 |
|
| 57 |
function buildLine(text, color, effect, effectColor, effectColor2, strokeColor, strokeWidth, lineNum) { |
| 58 |
var span = document.createElement('span'); |
| 59 |
span.className = 'bkbg-dh-line bkbg-dh-line-' + lineNum; |
| 60 |
span.innerHTML = text || ''; |
| 61 |
|
| 62 |
if (effect === 'gradient') { |
| 63 |
span.classList.add('bkbg-dh-line--gradient'); |
| 64 |
span.style.setProperty('--bkbg-dh-grad', 'linear-gradient(90deg, ' + effectColor + ', ' + effectColor2 + ')'); |
| 65 |
} else if (effect === 'highlight') { |
| 66 |
span.classList.add('bkbg-dh-line--highlight'); |
| 67 |
span.style.setProperty('--bkbg-dh-hl', effectColor); |
| 68 |
} else if (effect === 'marker') { |
| 69 |
span.classList.add('bkbg-dh-line--marker'); |
| 70 |
span.style.setProperty('--bkbg-dh-hl', effectColor); |
| 71 |
} else if (effect === 'stroke') { |
| 72 |
span.classList.add('bkbg-dh-line--stroke'); |
| 73 |
span.style.setProperty('--bkbg-dh-stroke-w', (strokeWidth || 1) + 'px'); |
| 74 |
span.style.setProperty('--bkbg-dh-stroke-c', strokeColor || '#7c3aed'); |
| 75 |
} else { |
| 76 |
span.style.color = color; |
| 77 |
} |
| 78 |
return span; |
| 79 |
} |
| 80 |
|
| 81 |
var l1 = buildLine( |
| 82 |
opts.line1, opts.line1Color || '#111827', |
| 83 |
opts.line1Effect || 'none', |
| 84 |
opts.effectColor || '#fef08a', opts.effectColor2 || '#f97316', |
| 85 |
opts.strokeColor || '#7c3aed', opts.strokeWidth || 1, 1 |
| 86 |
); |
| 87 |
|
| 88 |
var l2 = buildLine( |
| 89 |
opts.line2, opts.line2Color || '#7c3aed', |
| 90 |
opts.line2Effect || 'none', |
| 91 |
opts.effectColor || '#fef08a', opts.effectColor2 || '#f97316', |
| 92 |
opts.strokeColor || '#7c3aed', opts.strokeWidth || 1, 2 |
| 93 |
); |
| 94 |
|
| 95 |
linesWrap.appendChild(l1); |
| 96 |
if (layout === 'inline') { |
| 97 |
var sp = document.createTextNode(' '); |
| 98 |
linesWrap.appendChild(sp); |
| 99 |
} |
| 100 |
linesWrap.appendChild(l2); |
| 101 |
heading.appendChild(linesWrap); |
| 102 |
inner.appendChild(heading); |
| 103 |
|
| 104 |
if (opts.showSubtext && opts.subtext) { |
| 105 |
var p = document.createElement('p'); |
| 106 |
p.className = 'bkbg-dh-subtext'; |
| 107 |
p.style.color = opts.subtextColor || '#6b7280'; |
| 108 |
p.innerHTML = opts.subtext; |
| 109 |
inner.appendChild(p); |
| 110 |
} |
| 111 |
|
| 112 |
wrap.appendChild(inner); |
| 113 |
app.parentNode.replaceChild(wrap, app); |
| 114 |
}); |
| 115 |
}); |
| 116 |
|