1let cnxDiscoveryPlayerInitialized = false; 2 3if ( ! window.cnx ) { 4 window.cnx = {}; 5 window.cnx.cmd = []; 6} 7 8/** 9 * Get Connatix Player type based on device. 10 * @returns {string} 11 */ 12function getCNXPlayerType() { 13 let playerType = 'none'; 14 const deviceType = document.documentElement.clientWidth <= 1023 ? 'mobile' : 'desktop'; 15 16 playerType = tmbiCNXSettings['cnx_' + deviceType + '_player_type'] || 'none'; 17 18 return playerType; 19} 20 21/** 22 * Check if recirc strip is sticky on mobile. 23 * @returns {boolean} 24 */ 25function cnxIsRecircStickyEnabled() { 26 const recircDiv = document.getElementById("recirc-strip"); 27 if ( null !== recircDiv && (recircDiv.classList.contains('tmbi-recirc-strip-sticky-mobile') || recircDiv.classList.contains('tmbi-recirc-strip-sticky-mobile-down'))) { 28 return true; 29 } 30 return false; 31} 32 33/** 34 * Check if promo strap is sticky on mobile. 35 * @returns {boolean} 36 */ 37function cnxIsPromoStickyEnabled() { 38 const promoStrap = document.getElementById("promo-strap"); 39 if ( null !== promoStrap && promoStrap.classList.contains('tmbi-promo-strap-sticky') ) { 40 return true; 41 } 42 return false; 43} 44 45/** 46 * Load Connatix Library script. 47 * @param {*} cnxPlayerID 48 */ 49function loadCNXLibrary( cnxPlayerID ) { 50 let cnxLibLoader = document.createElement('script'); 51 cnxLibLoader.type = 'text/javascript'; 52 cnxLibLoader.async = true; 53 cnxLibLoader.src = 'https://cd.connatix.com/connatix.player.js?cid=' + tmbiCNXSettings.cid; 54 cnxLibLoader.id = 'tmbi-connatix-discovery-js'; 55 56 document.body.appendChild( cnxLibLoader ); 57 58 (new Image()).src = 'https://capi.connatix.com/tr/si?token=' + cnxPlayerID + '&cid=' + tmbiCNXSettings.cid; 59} 60 61/** 62 * Insert Connatix placeholder script and trigger player render. 63 * @param {*} playerType 64 */ 65function cnxPlaceholderScript( playerType ) { 66 const cnxScriptPlaceholder = document.createElement('script'); 67 cnxScriptPlaceholder.type = 'text/javascript'; 68 cnxScriptPlaceholder.id = tmbiCNXSettings.script_id; 69 70 let cnxPlayerID = ''; 71 72 if ( 'inline' === playerType ) { 73 const playspaceEle = document.querySelector('.cnx-playspace'); 74 75 if ( ! playspaceEle ) { 76 console.warn( 'Connatix inline player: .cnx-playspace not found' ); 77 return; 78 } 79 80 playspaceEle.appendChild(cnxScriptPlaceholder); 81 82 cnxPlayerID = tmbiCNXSettings.cnx_inline_player_id; 83 84 cnxDiscoveryTriggerRender( playerType, cnxPlayerID ); 85 } else if ( 'floating' === playerType ) { // TODO: check allow_floating_player too 86 cnxPlayerID = tmbiCNXSettings.cnx_floating_player_id; 87 88 document.body.appendChild(cnxScriptPlaceholder); 89 90 const cnxScrollHandler = () => { 91 cnxDiscoveryTriggerRender( playerType, cnxPlayerID ); 92 if ( cnxDiscoveryPlayerInitialized ) { 93 window.removeEventListener( 'scroll', cnxScrollHandler ); 94 } 95 }; 96 97 window.addEventListener( "scroll", cnxScrollHandler ); 98 } 99} 100 101/** 102 * Trigger Connatix Discovery Player render. 103 * @param {*} playerType 104 * @param {*} cnxPlayerID 105 * @returns 106 */ 107function cnxDiscoveryTriggerRender( playerType, cnxPlayerID ) { 108 if ( cnxDiscoveryPlayerInitialized ) { 109 console.log( 'Connatix Discovery Player already initialized.' ); 110 return; 111 } 112 113 if ( "floating" === playerType ) { 114 let trigger = document.querySelector( "#prearticle" ); 115 116 if ( ! trigger) { 117 trigger = document.querySelector( "head" ); 118 } 119 120 let triggerBottom = trigger.getBoundingClientRect().bottom; 121 122 if ( 0 < triggerBottom ) { 123 console.log( 'Connatix Discovery Floating Player: Trigger not yet reached. Bottom:', triggerBottom ); 124 return; 125 } 126 } 127 128 let cnx_gutterY = 0; 129 130 // Add floatingGutterY property to video player based on recirc strip. 131 if ( cnxIsRecircStickyEnabled() ) { 132 cnx_gutterY = document.getElementById("recirc-strip").offsetHeight; 133 } 134 135 // Add floatingGutterY property to video player based on promo strap. 136 if ( cnxIsPromoStickyEnabled() ) { 137 cnx_gutterY = document.getElementById("promo-strap").offsetHeight; 138 } 139 140 loadCNXLibrary( cnxPlayerID ); 141 142 cnx.cmd.push(function() { 143 cnx({ 144 playerId: cnxPlayerID, 145 "settings": { 146 "customization": { 147 "floating": { 148 "floatingGutterY": cnx_gutterY 149 } 150 } 151 } 152 }).render( tmbiCNXSettings.script_id, function( err, api ) { 153 if ( err ) { 154 console.error( 'Connatix Discovery Player Error:', err ); 155 return; 156 } 157 158 window.connatixPlayerAPI = api; 159 160 connatixPlayerAPI.on( connatixPlayerAPI.configEvents.IsViewable, function () { 161 wp.hooks.doAction( 'tmbi_connatix_is_loaded', window.connatixPlayerAPI ); 162 }); 163 164 if ( 'inline' === playerType ) { 165 connatixPlayerAPI.on( connatixPlayerAPI.configEvents.CloseButtonClicked, function () { 166 wp.hooks.doAction( 'tmbi_connatix_closed' ); 167 }); 168 } 169 }); 170 }); 171 172 cnxDiscoveryPlayerInitialized = true; 173 174 console.log( 'Connatix Discovery Player initialized.' ); 175} 176 177/** 178 * Resize inline player when closed. 179 */ 180function resizeInlinePlayer() { 181 let rightRailEle = document.querySelector( '.right-rail.cnx-inline-player-active' ); 182 let rightRailCnxPlayspaceEle = document.querySelector( '.right-rail.cnx-inline-player-active .cnx-inline-player-wrapper .cnx-playspace' ); 183 184 if ( null === rightRailEle || null === rightRailCnxPlayspaceEle ) { 185 return; 186 } 187 188 rightRailEle.classList.remove( 'cnx-inline-player-active' ); 189 rightRailCnxPlayspaceEle.style.height = 'auto'; 190 rightRailCnxPlayspaceEle.style.margin = '0'; 191} 192wp.hooks.addAction( 'tmbi_connatix_closed', 'tmbi-connatix-native', resizeInlinePlayer ); 193 194/** 195 * Pause Connatix player when Bytes expanded. 196 * @param {object} connatixPlayerAPI The Connatix Player API object. 197 */ 198function tmbiPauseCNXPlayer( connatixPlayerAPI ) { 199 if ( 'undefined' === typeof tmbiBytesData || false === tmbiBytesData.isBytesExpanded ) { 200 return; 201 } 202 203 connatixPlayerAPI.pause(); 204}
205wp.hooks.addAction( 'tmbi_connatix_is_loaded', 'tmbi-connatix-native', tmbiPauseCNXPlayer ); 206 207/** 208 * Initialize Connatix Player. 209 * @return {void} 210 */ 211function initCNXPlayer() { 212 if ( ! window.cnx ) { 213 window.cnx = {}; 214 window.cnx.cmd = []; 215 } 216 217 let rightRail = document.querySelector( '.right-rail' ); 218 219 const playerType = getCNXPlayerType(); 220 221 if ( 'inline' === playerType && rightRail ) { 222 rightRail.classList.add( 'cnx-inline-player-active' ); 223 } else { 224 document.querySelector('.cnx-inline-player-wrapper')?.remove(); 225 } 226 227 if ( 'none' !== playerType ) { 228 cnxPlaceholderScript( playerType ); 229 } 230} 231 232// Initialize Connatix Player on dom load or ready. 233document.addEventListener( 'DOMContentLoaded', initCNXPlayer ); 234if ( 'complete' === document.readyState || 'interactive' === document.readyState ) { 235 initCNXPlayer(); 236}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.