UNPKG

1.61 kBJavaScriptView Raw
1/**
2 * This does a replace to animateTemplate to insert in the Animate Template functions
3 * @param {[type]} blinkData [description]
4 * @param {[type]} animateTemplate [description]
5 * @param {Function} callback [description]
6 * @return {[type]} [description]
7 */
8module.exports = (tomlData, animateTemplate, skPkg) => {
9 const manifest = {}
10 const trackableEvents = tomlData.tvEvents.trackableEvents || tomlData.tvEvents.thirdPartyPixels || []
11 const clickThruEvents = tomlData.tvEvents.uri || []
12 const allConfigurables = new Set(trackableEvents.concat(clickThruEvents))
13 manifest.tvCustomEvents = [...allConfigurables].map((k) => {
14 const parts = k.split('_')
15 const configurable = {
16 name: k,
17 kind: parts[0] || '',
18 context: parts[1] || '',
19 args: parts.slice(2),
20 uri: clickThruEvents.includes(k)
21 }
22 return configurable
23 })
24
25 const videosJson = JSON.stringify(tomlData.videos, null, 2)
26 .split('\n')
27 .map((line) => ` ${line}`)
28 .join('\n')
29 .slice(4)
30 const mraidInitScript = `function adInit() {
31 var mraidBanner = new window.MraidBanner({
32 tvCustomEvents:${JSON.stringify(manifest.tvCustomEvents)},
33 width:$WT,
34 height:$HT,
35 fromAnimate:true,
36 videos:${videosJson},
37 bridgeId:'${tomlData.general.bridgeId}',
38 adParameters: {geoInfo: ${JSON.stringify(tomlData.geoInfo)}}
39 })
40}`
41 let newTemplate = animateTemplate.replace(/(<script>)function[\d\s\w|&_\(\)\{\}=<>`'"#:\+\*\.\/,-\[\]\\$]+?(<\/script>)/i, `$1${mraidInitScript}$2`) // eslint-disable-line
42 return newTemplate
43}