"use strict"; var rosma = (function() { var rosma = { app_domain: '//rosma.farmexim.ro', rosma_set_all: function() { setTimeout(function() { var sa_spans = document.querySelectorAll('[class="rosite_sa"]'); for (var i = 0; i < sa_spans.length; ++i) { rosma.rosite_sa_prepare_slot(sa_spans[i]); } }, 500); }, rosite_sa_prepare_slot: function(slot) { var slotId = slot.getAttribute("data-slot-id"); var xmlHttp = {}; var bimg = {}; var frame = {}; var alink = {}; var slotData = {}; xmlHttp = new XMLHttpRequest(); xmlHttp.onreadystatechange = function() { if(xmlHttp.readyState == 4 && xmlHttp.status == 200) { slot.innerHTML = ''; slotData.slotId = JSON.parse(xmlHttp.responseText); //console.log('Slot['+slotId+']', slotData); if(typeof slotData.slotId.slot_width !== 'undefined') { if(slotData.slotId.slot_type === 'insert') { if (slotData.slotId.ban_type === 'image') { console.log('Slot['+slotId+']', slotData); console.log('slot', slot); slot.style.display = 'inline-table'; slot.style.border = 'none'; slot.style.margin = 0; slot.style.padding = 0; slot.style.position = 'relative'; slot.style.visibility = 'visible'; slot.style.backgroundColor = 'transparent'; slot.style.width = slotData.slotId.slot_width; slot.style.height = slotData.slotId.slot_height; //slot.style.borderColor = 'red'; //slot.style.borderWidth = '1px'; //slot.style.borderStyle = 'solid'; frame.slotId = document.createElement('iframe'); //frame.slotId.style.borderColor = 'blue'; //frame.slotId.style.borderWidth = '1px'; //frame.slotId.style.borderStyle = 'solid'; frame.slotId.width = slotData.slotId.slot_width; frame.slotId.height = slotData.slotId.slot_height; frame.slotId.style.width = slotData.slotId.slot_width + 'px'; frame.slotId.style.height = slotData.slotId.slot_height + 'px'; //frame.slotId.style.verticalAlign = 'bottom'; // frame.slotId.style.position = 'absolute'; frame.slotId.style.top = 0; frame.slotId.style.left = 0; // frame.slotId.style.marginLeft = Math.round(slotData.slot_width/2) + 'px'; // frame.slotId.style.left = 0; frame.slotId.style.top = 0; frame.slotId.frameBorder = 0; frame.slotId.marginWidth = 0; frame.slotId.marginHeight = 0; frame.slotId.vspace = 0; frame.slotId.hspace = 0; frame.slotId.allowTransparency = true; frame.slotId.scrolling = 'no'; // frame.slotId.src = '//ads.farmexim.ro/badisplay/getbdata/' + slotId; frame.slotId.src = 'about:blank'; alink.slotId = document.createElement('a'); if (slotData.slotId.ban_have_link == '1') { alink.slotId.target = '_blank'; alink.slotId.href = rosma.app_domain + '/badisplay/getblnk/' + slotData.slotId.ban_id; } bimg.slotId = document.createElement('img'); bimg.slotId.style.margin = 0; bimg.slotId.style.padding = 0; bimg.slotId.width = slotData.slotId.slot_width; bimg.slotId.height = slotData.slotId.slot_height; bimg.slotId.style.width = slotData.slotId.slot_width; bimg.slotId.style.height = slotData.slotId.slot_height; alink.slotId.appendChild(bimg.slotId); slot.appendChild(frame.slotId); frame.slotId.addEventListener('load', function (e) { console.log('slotData', slotData.slotId); console.log('bimg.slotId:' + slotId + '; ban_id: ' + slotData.slotId.ban_id + ' - ', bimg.slotId); bimg.slotId.src = rosma.app_domain + '/badisplay/getbimg/' + slotData.slotId.ban_id; frame.slotId.contentWindow.document.getElementsByTagName("body")[0].appendChild(alink.slotId); }); } else if (slotData.slotId.ban_type === 'iframe') { slot.style.display = 'inline-table'; slot.style.border = 'none'; slot.style.margin = 0; slot.style.padding = 0; slot.style.position = 'relative'; slot.style.visibility = 'visible'; slot.style.backgroundColor = 'transparent'; slot.style.width = slotData.slotId.slot_width; slot.style.height = slotData.slotId.slot_height; //slot.style.borderColor = 'red'; //slot.style.borderWidth = '1px'; //slot.style.borderStyle = 'solid'; frame.slotId = document.createElement('iframe'); //frame.slotId.style.borderColor = 'blue'; //frame.slotId.style.borderWidth = '1px'; //frame.slotId.style.borderStyle = 'solid'; //console.log(slotData.slotId); frame.slotId.width = slotData.slotId.slot_width; frame.slotId.height = slotData.slotId.slot_height; frame.slotId.style.width = slotData.slotId.slot_width + 'px'; frame.slotId.style.height = slotData.slotId.slot_height + 'px'; //frame.slotId.style.verticalAlign = 'bottom'; // frame.slotId.style.position = 'absolute'; frame.slotId.style.top = 0; frame.slotId.style.left = 0; // frame.slotId.style.marginLeft = Math.round(slotData.slot_width/2) + 'px'; // frame.slotId.style.left = 0; frame.slotId.style.top = 0; frame.slotId.frameBorder = 0; frame.slotId.marginWidth = 0; frame.slotId.marginHeight = 0; frame.slotId.vspace = 0; frame.slotId.hspace = 0; frame.slotId.allowTransparency = true; frame.slotId.scrolling = 'no'; // frame.slotId.src = '//ads.farmexim.ro/badisplay/getbdata/' + slotId; frame.slotId.src = rosma.app_domain + '/badisplay/getbifr/' + slotData.slotId.ban_id; slot.appendChild(frame.slotId); } } else if(slotData.slotId.slot_type === 'popup') { //console.log('popup; slot_id:' + slotData.slot_id + "; ban_id:" + slotData.ban_id); divModal = document.createElement('div'); divModal.style.position = 'fixed'; divModal.style.top = 0; divModal.style.left = 0; divModal.style.bottom = 0; divModal.style.right = 0; divModal.style.display = 'none'; divModal.style.overflow = 'auto'; try { divModal.style.backgroundColor = 'rgba(0, 0, 0, 0.7)'; } catch (e) { divModal.style.backgroundColor = '#cccccc'; } //divModal.style.fillStyle = "rgba(0, 0, 0, 0.7)"; divModal.style.zIndex = 9999; //divModal.classList.add('rosma_modal'); divModal.className += ' rosma_modal_background'; //divModal.style.opacity = "0.5"; divModalWindow = document.createElement('div'); divModalWindow.style.position = 'relative'; //divModalWindow.style.backgroundColor = '#FFFFFF'; divModalWindow.style.backgroundColor = '#cccccc'; //divModalWindow.style.width = '50%'; if(slotData.slotId.slot_width > 0) { divModalWindow.width = slotData.slotId.slot_width; divModalWindow.style.width = slotData.slotId.slot_width; } else { divModalWindow.style.width = '0'; } if(slotData.slotId.slot_height > 0) { divModalWindow.height = slotData.slotId.slot_height; divModalWindow.style.height = slotData.slotId.slot_height; } else { divModalWindow.style.height = '0'; } //divModalWindow.style.margin = '10% auto'; divModalWindow.style.marginTop = '5%'; divModalWindow.style.marginBottom = '5%'; divModalWindow.style.marginLeft = 'auto'; divModalWindow.style.marginRight = 'auto'; divModalWindow.style.padding = '0px'; //divModalWindow.classList.add('rosma_modal_window'); divModalWindow.className += ' rosma_modal_window'; btnClose = document.createElement('span'); btnClose.style.position = 'absolute'; btnClose.style.top = 0; btnClose.style.right = 0; btnClose.style.color = '#666666'; btnClose.style.width = '30px'; btnClose.style.height = '30px'; btnClose.style.fontSize = '30px'; btnClose.style.lineHeight = '30px'; btnClose.style.textAlign = 'center'; btnClose.style.cursor = 'pointer'; btnClose.className += ' rosma_modal_button'; btnClose.innerHTML = '×'; bimg.slotId = document.createElement('img'); bimg.slotId.src = app_domain + '/badisplay/getbimg/' + slotData.slotId.ban_id; //console.log('bimg.src', bimg.slotId.src); bimg.slotId.style.margin = 0; bimg.slotId.style.padding = 0; if(slotData.slotId.slot_width > 0) { bimg.slotId.width = slotData.slotId.slot_width; bimg.slotId.style.width = slotData.slotId.slot_width; } if(slotData.slotId.slot_height > 0) { bimg.slotId.height = slotData.slotId.slot_height; bimg.slotId.style.height = slotData.slotId.slot_height; } bimg.slotId.className += ' rosma_modal_image'; bimg.slotId.onload = function() { divModalWindow.width = bimg.slotId.width; divModalWindow.style.width = bimg.slotId.width; divModalWindow.height = bimg.slotId.height; divModalWindow.style.height = bimg.slotId.height; }; alink.slotId = document.createElement('a'); if (slotData.slotId.ban_have_link == '1') { alink.slotId.target = '_blank'; alink.slotId.href = app_domain + '/badisplay/getblnk/' + slotData.slotId.ban_id; } alink.slotId.appendChild(bimg.slotId); divModalWindow.appendChild(alink.slotId); divModal.onclick = function(event) { event = event || window.event; event.target = event.target || event.srcElement; if(event.target.className !='' && ' rosma_modal_background rosma_modal_button '.indexOf(event.target.className) > -1) { divModal.style.display = 'none'; } }; divModalWindow.appendChild(btnClose); divModal.appendChild(divModalWindow); slot.appendChild(divModal); divModal.style.display = 'block'; } } } }; xmlHttp.open("get", rosma.app_domain + '/badisplay/getsbdata/' + slotId + '/?rand=' + Math.random()); xmlHttp.send([]); } }; //export { rosma }; // console.log('innerROSMA', rosma); return rosma; rosma.rosma_set_all(); })(); module.export = rosma;