function bcsInject(options) { options.onReady = options.onReady || null; options.idPrefix = options.idPrefix || ''; options.scripts = options.scripts || []; var loadChain = options.onReady; var sources = options.scripts.slice().reverse(); sources.map(function (description) { if (!(window.jQuery && description.type === 'jquery')) { // skip existing jquery loadChain = (function (description, loadChain) { return function () { bcsInject.importJS(description.source, options.idPrefix + description.id, loadChain); } })(description, loadChain); } }) function onDomReady() { loadChain(); } var DOMContentLoaded; if (document.addEventListener) { DOMContentLoaded = function () { document.removeEventListener("DOMContentLoaded", DOMContentLoaded, false); onDomReady(); }; } else if (document.attachEvent) { DOMContentLoaded = function () { // Make sure body exists, at least, in case IE gets a little overzealous if (document.readyState === "complete") { document.detachEvent("onreadystatechange", DOMContentLoaded); onDomReady(); } }; } if (document.readyState === "complete") { setTimeout(onDomReady, 1); } if (document.addEventListener) { document.addEventListener("DOMContentLoaded", DOMContentLoaded, false); } else if (document.attachEvent) { document.attachEvent("onreadystatechange", DOMContentLoaded); window.attachEvent("onload", onDomReady); } } bcsInject.importJS = function (source, id, onload) { if (!document.getElementById(id)) { var JS = document.createElement("SCRIPT"); JS.type = "text/javascript"; JS.src = source; JS.id = id; if (undefined != onload) JS.onload = onload; document.getElementsByTagName("head")[0].appendChild(JS); } } bcsInject({ onReady: bcchInit, idPrefix: 'bcch', scripts: [{source: 'https://i.bngprm.com/chat_head/jquery-1.4.4.min.js', id: 'tooljquery', type: 'jquery'}, {source: 'https://i.bngprm.com/chat_head/jquery.cookie.min.js', id: 'toolcookie'}, {source: 'https://i.bngprm.com/chat_head/jquery.image_player_001.js', id: 'toolimplayer'}] }) function bcchInit() { // php vars -> js var $ = jQuery; var iframeSrcTmpl = 'https://bongacams.com/chat-popup/%model_username%?fullwindow=1&classic=on&amute=1&lsp_style=chathead&hit_url=https%3A%2F%2Fbongacams.com%2Ftrack%3Fc%3D310158%26ps%3Dchat_head&landing_url=https://bongacams.com%3Fclassic%3Doff'; var trackingUrlTmpl = 'https://bongacams.com/track?c=310158&ps=chat_head&csurl=https://bongacams.com%3Fclassic%3Doff'; var vsUrlRootTmpl = 'https://db.bngpt.com/stream_%model_username%'; var isAdult = false; var originalPosition = {left: '0.02', top: '0.02'}; var originalPositionPC = {left: '2%', top: '2%'}; var $boundary, $float, $popup, $iframe, video, $fallback, closeTimer, isPopupOpened; var lockCookieName = 'bcchtool'; var isTouch = 'ontouchstart' in window || navigator.maxTouchPoints || navigator.msMaxTouchPoints; var isAndroid = /android/i.test(navigator.userAgent); var frequency = '21600000'; var modelData = { avatarUrl: '//i.wlicdn.com/0b2/0ad/209/9f3e254cbd49a2e9383613c8878ced62_thumb_medium.jpg', username: 'maddybloomx', displayname: 'maddybloomx', vsUrlRoot: 'https://db.bngpt.com/stream_maddybloomx', trackingUrl: '', iframeSrc: '' } bcchInit.open = function () { if (!isPopupOpened) { $boundary.addClass('__bcch_open'); isPopupOpened = true; if (isAdult) { setTimeout(function() { if (isPopupOpened) { $iframe.attr('src', modelData.iframeSrc) } }, 600); $iframe.css('visibility', 'hidden'); // wait for loading } else { videoEmbed(); } } onResize(); } bcchInit.close = function () { $boundary.removeClass('__bcch_open __hide_ch'); isPopupOpened = false; $iframe.removeAttr('src'); var $newIframe = $iframe.clone(); $iframe.replaceWith($newIframe); $iframe = $newIframe; $fallback.data('ImagePlayer') && $fallback.data('ImagePlayer').destroy(); $('#bcch_tool .js-stream_fallback').html(''); video && video.pause(); $float.css(originalPositionPC); } bcchInit.enforceClose = function () { bcchInit.close(true); $boundary.remove(); setLockCookie(); } function videoEmbed() { var url = modelData.vsUrlRoot; if (video) { $(video).unbind('error').bind('error', function () { $('#bcch_tool .js-stream_fallback').imagePlayer(url) }); $(video).attr('src', url + '.mp4') video.load(); video.play(); } } function openPromoUrl() { bcchInit.enforceClose(); window.open(modelData.trackingUrl, '_blank'); } function detectEdge() { var east = originalPosition.left < 0.5; var south = originalPosition.top < 0.5; $boundary.removeClass('bcch_edge_nw bcch_edge_sw bcch_edge_ne bcch_edge_se').addClass('bcch_edge_' + (south ? 's' : 'n') + (east ? 'e' : 'w')); } function onModelDataChange(data) { if (data.username && data.username !== modelData.username) { modelData.avatarUrl = data.avatarUrl ? data.avatarUrl : vsUrlRootTmpl.replace('%model_username%', data.username) + '/1.jpg'; } modelData.username = data.username; modelData.iframeSrc = iframeSrcTmpl.replace('%model_username%', modelData.username); modelData.trackingUrl = trackingUrlTmpl.replace('%model_username%', modelData.username); updateTemplate(); } function updateTemplate() { $('#bcch_tool .bcch_avatar, #bcch_tool .bcch_stream_wrapper') .css('background-image', 'url("' + modelData.avatarUrl + '")'); $('#bcch_tool a.js-promo').attr('href', modelData.trackingUrl); $('#bcch_tool .bcch_displayname').text(modelData.displayname); if (video) { video.setAttribute('src', modelData.vsUrlRoot + '.mp4'); video.load(); } } function onResize() { updateVHUnit(); fitTextFontSize('#bcch_tool .bcch_btn', $boundary.get(0)); reposition(); } onResizeDebounced = debounce(onResize, 100); function reposition() { $boundary.removeClass('__hide_ch') $float.css(originalPositionPC); if (isPopupOpened) { var deltaX, deltaY, newX = originalPositionPC.left, newY = originalPositionPC.top; var origLeftPx = originalPosition.left * $boundary.width(); var origTopPx = originalPosition.top * $boundary.height(); if ($boundary.hasClass('bcch_edge_ne') || $boundary.hasClass('bcch_edge_se')) { deltaX = window.innerWidth - ($popup.outerWidth(true) + origLeftPx); if (deltaX < 0) { newX = +origLeftPx + deltaX } } else { deltaX = $popup.outerWidth(true) - (origLeftPx + $float.width()); if (deltaX > 0) { newX = +origLeftPx + deltaX } } if ($boundary.hasClass('bcch_edge_sw') || $boundary.hasClass('bcch_edge_se')) { deltaY = window.innerHeight - ($popup.outerHeight(true) + origTopPx + $float.height()); if (deltaY < 0) { newY = +origTopPx + deltaY } } else { deltaY = $popup.outerHeight(true) - origTopPx; if (deltaY > 0) { newY = +origTopPx + deltaY } } if (newY < 0 || newY > window.innerHeight - $float.height()) { $boundary.addClass('__hide_ch'); } $float.css({left: newX, top: newY}); } } function fitTextFontSize(selector, parent, options) { parent = parent ? parent : document.body; options = $.extend({}, options); function forEach(array, callback) { for (var i = 0; i < array.length; i++) { callback.call(null, array[i]); // passes back stuff we need } } function isFit(el) { return el.scrollWidth <= el.offsetWidth && el.scrollHeight <= el.offsetHeight; } function dichotomy(min, max, el) { if (max - min < 1) { el.style.fontSize = min + 'px'; return min; } else { var mid = (max + min) / 2; el.style.fontSize = mid + 'px'; if (isFit(el)) { return dichotomy(mid, max, el); } else { return dichotomy(min, mid, el); } } } var commonMinFS = Infinity; var elements = parent.querySelectorAll(selector); forEach(elements, function (el) { el.style.fontSize = ''; var fsize = parseInt(window.getComputedStyle(el)['font-size'], 10); commonMinFS = Math.min(commonMinFS, isFit(el) ? fsize : dichotomy(1, fsize, el)); }) if (options.syncSize) { forEach(elements, function (el) { el.style.fontSize = commonMinFS + 'px'; }) } } function debounce(func, wait, immediate) { var timeout; return function () { var context = this; var later = function () { timeout = 0; if (!immediate) { func.apply(context, arguments); } }; var callNow = immediate && !timeout; clearTimeout(timeout); timeout = window.setTimeout(later, wait); if (callNow) { func.apply(context, argsuments); } }; } function onMessage(e) { var data = null; if (e.data) { try { data = JSON.parse(e.data); } catch (e) { //console.warn(e) } if (data) { switch (data.type) { case 'modelchange': onModelDataChange(data.data); $iframe.css('visibility', ''); break; case 'tracking_click': setTimeout(bcchInit.enforceClose, 100); break; } } } } function setLockCookie() { var date = new Date(); date.setTime(date.getTime() + Number(frequency)); $.cookie(lockCookieName, 1, {path: '/', expires: date}); } function attachHandlers() { $(document).bind('keyup', function (event) { var code = event.key || event.keyCode || event.which; if (isPopupOpened && code === 27) { event.preventDefault(); event.stopPropagation(); bcchInit.close() } }) $('a.js-promo, a.bcch_logo').bind('click', bcchInit.enforceClose); var $fab = $('#bcch_tool .bcch_fab'); $fab.bind('click', function (event) { isPopupOpened ? openPromoUrl() : bcchInit.open() }); $('#bcch_tool .bcch_overlay').bind('click', bcchInit.close); if (!isTouch) { $fab.add($popup).bind('mouseenter', function () { clearTimeout(closeTimer); $fab.add($popup).unbind('mouseleave'); setTimeout(function () { $fab.add($popup).bind('mouseleave', function () { closeTimer = setTimeout(function () { bcchInit.close() }, 200); }) }, isPopupOpened ? 0 : 200); // skip mouseleave due to chathead moved bcchInit.open(); }); } if (document.addEventListener) { window.addEventListener("message", onMessage, false); } else if (document.attachEvent) { window.attachEvent("onmessage", onMessage); } document.addEventListener("visibilitychange", function() { document.visibilityState !== 'visible' && isPopupOpened && bcchInit.close(); }); window.addEventListener('resize', onResizeDebounced); window.addEventListener('orientationchange', onResizeDebounced); } function updateVHUnit() { // css variable, for mobile chrome if (isAndroid) { var vh = window.innerHeight * 0.01; document.documentElement.style.setProperty('--vh', vh + 'px'); } } function onCssLoad() { var lockCookie = $.cookie(lockCookieName); if (lockCookie && !window['isPromoToolPreview']) { return; } if (!$('meta[name="viewport"]').length) { $('head').append(''); } // common elements $boundary = $('#bcch_tool'); $float = $('#bcch_tool .bcch_float'); $popup = $('#bcch_tool .bcch_popup'); $iframe = $('#bcch_tool iframe'); video = $('#bcch_tool video').get(0); $fallback = $('#bcch_tool .js-stream_fallback'); $float.css(originalPositionPC); detectEdge(); attachHandlers(); onModelDataChange(modelData); // initialize modelData updateVHUnit(); $boundary.show(); } // ------- entry point $('head').append(''); $('body').append('
'); var waitCssLoopCounter = 0; function checkCSSLoaded() { if (window.getComputedStyle(document.getElementById('bcch_tool'))['position'] === 'fixed') { onCssLoad(); } else if (waitCssLoopCounter < 100) { waitCssLoopCounter++; setTimeout(checkCSSLoaded, 200); } } checkCSSLoaded(); }