Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- URL of the Script:
- http://mtnl.phozeca.com:3000/getjs?lib=false&nadipdata=%7B%22url%22%3A%22%2Fscripts%2Ftimespoints-main.js%3Fversion%3D1%22%2C%22referer%22%3A%22http%3A%2F%2Ftimesofindia.indiatimes.com%2Fworld%2Fus%2Flaptops-ipads-banned-on-us-bound-flights-from-8-countries%2Farticleshow%2F57745820.cms%22%2C%22subscriberId%22%3A%22XXXXXXXX%40mtnl%22%2C%22host%22%3A%22image.timespoints.iimg.in%22%2C%22categories%22%3A%5B1%5D%2C%22reputations%22%3A%5B1%5D%7D&screenheight=XXX&screenwidth=XXXX
- Script:
- var ns_ip = 'mtnl.phozeca.com';var ns_port = '3000';var subscriberId = 'XXXXXXXX@mtnl';var subscriberIP = 'XXX.XX.XXX.XX';var nadipdata = {"url":"/scripts/timespoints-main.js?version=1","referer":"http://timesofindia.indiatimes.com/world/us/laptops-ipads-banned-on-us-bound-flights-from-8-countries/articleshow/57745820.cms","subscriberId":"XXXXXXXX@mtnl","host":"image.timespoints.iimg.in","categories":[1],"reputations":[1]};var userAgent = "Mozilla/5.0%20(Windows%20NT%2010.0;%20Win64;%20x64)%20AppleWebKit/537.36%20(KHTML,%20like%20Gecko)%20Chrome/57.0.2987.110%20Safari/537.36";
- var AD_ID = "adMain";
- var AD_BACKGROUND_ID = "adBackground";
- var Z_INDEX_MAIN = 2147483647;
- var Z_INDEX_BACKGROUND = Z_INDEX_MAIN - 1;
- var MAIN_DISPLAY = "block"; // Para activar (none) o desactivar (block) fade in
- var injected_uuid = null;
- function loadAdsNADIP() {
- jQuery(document).ready(loadFirstAd());
- }
- function loadAd() {
- try {
- // console.log("jQuery('#'" + AD_ID + ").length: " + jQuery('#' + AD_ID).length + ". sarazasaraza: " + sarazasaraza);
- // Se fija que no exista un div con ese id
- if (jQuery('#' + AD_ID).length === 0 && matchedView !== undefined && matchedView !== null) {
- var adType = matchedView.type;
- console.log("Ad Type: " + adType);
- switch (adType) {
- case "BANNER":
- case "OVERSLIDE":
- loadVerticalAd(adType);
- break;
- case "TOP_AD":
- case "FLOORAD":
- loadHorizontalAd(adType);
- break;
- case "FIXED":
- loadFixed();
- break;
- case "repeat":
- loadRepeat();
- break;
- case "INTERSTITIAL":
- case "INTERSTITIAL_FLASH":
- loadInstertitialAd(adType);
- break;
- case "CUSTOMIZED":
- case "CUSTOMIZED_DYNAMIC":
- loadCustomizedAd(adType);
- break;
- case "IFRAME":
- loadIframeAd();
- loadListener();
- break;
- case "VAST":
- loadVastAd();
- loadListener();
- break;
- case "IMA":
- loadImaAd();
- loadListener();
- break;
- case "KOMLI_BANNER":
- loadKomliBannerAd();
- loadListener();
- break;
- case "INMOBI":
- loadInmobiAd();
- loadListener();
- break;
- case "MOBVISTA":
- loadMobvistaAd();
- loadListener();
- break;
- case "ADATHA":
- loadAdathaAd();
- loadListener();
- break;
- case "NONE":
- setTimeout(loadNextAdOnFallback, 0);
- break;
- default:
- console.log("Default type no configurado");
- break;
- }
- } else {
- logError("Existe div con id" + AD_ID, "loadAd");
- }
- } catch (err) {
- logError(err, "loadAd");
- }
- }
- // INICIO IFRAME AD ////////////////////////////////////////////////////////////
- function loadIframeAd() {
- try {
- // Arma la url del Ad
- var propSrc = matchedView.srcurl;
- if (propSrc.indexOf("?") >= 0) {
- propSrc += "&subscriberId=" + subscriberId;
- propSrc += "&subscriberIP=" + subscriberIP;
- propSrc += "&domainName=" + window.location.hostname;
- propSrc += "&adId=" + nadipad.adid;
- propSrc += "&viewKey=" + JSON.stringify(matchedView.viewKey);
- }
- // Obtiene las propiedades del Ad
- var propPosition = matchedView.position;
- var propWidth = matchedView.adwidth;
- var propHeight = matchedView.adheight;
- var removeScrollBody = (matchedView.removescrollbody === 'true');
- var fondoOscuro = (matchedView.backgroundblack === 'true');
- // Crea iframe y setea valores generales
- var ifrm = document.createElement("IFRAME");
- ifrm.setAttribute("src", propSrc);
- ifrm.setAttribute("id", AD_ID);
- ifrm.setAttribute("allowFullScreen", '');
- ifrm.style.width = getValue2(propWidth);
- ifrm.style.height = getValue2(propHeight);
- ifrm.style.position = 'fixed';
- ifrm.style.border = 'none';
- ifrm.style.overflow = 'hidden';
- ifrm.style.margin = '0 auto';
- ifrm.style.zIndex = Z_INDEX_MAIN;
- ifrm.style.display = 'block';
- ifrm.style.padding = '0px';
- if (propPosition === "FULLSCREEN") {
- ifrm.style.top = 0 + "px";
- ifrm.style.left = 0 + "px";
- ifrm.style.width = 100 + "%";
- ifrm.style.height = 100 + "%";
- } else {
- // Calcula y setea centrado horizontal
- var windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
- if (propWidth.indexOf("%") >= 0) {
- propWidth = windowWidth * (parseInt(propWidth) / 100);
- }
- var calculatedLeft = windowWidth / 2 - propWidth / 2;
- ifrm.style.left = calculatedLeft + "px";
- // Calcula y setea el centrado vertical de acuerdo a lo seleccionado
- if (propPosition === "TOP") {
- ifrm.style.top = 0 + "px";
- } else if (propPosition === "BOTTOM") {
- ifrm.style.bottom = 0 + "px";
- } else if (propPosition === "CENTERED") {
- // Calcula el centrado vertical
- var windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
- if (propHeight.indexOf("%") >= 0) {
- propHeight = windowHeight * (parseInt(propHeight) / 100);
- }
- var calculatedTop = windowHeight / 2 - propHeight / 2;
- ifrm.style.top = calculatedTop + "px";
- }
- }
- if (document.body !== null && document.body !== undefined) {
- // Inserta el iframe en el documento
- if (document.body.firstChild) {
- document.body.insertBefore(ifrm, document.body.firstChild);
- } else {
- document.body.appendChild(ifrm);
- }
- // Oculta el scroll segun corresponda
- if (removeScrollBody) {
- document.getElementsByTagName("body")[0].style.overflow = "hidden";
- }
- // Oscurece fondo o no segun corresponda
- if (fondoOscuro) {
- var divfondooscuro = document.createElement("div");
- divfondooscuro.id = AD_BACKGROUND_ID;
- document.body.appendChild(divfondooscuro);
- loadCssPropertiesInstertitialBackground();
- }
- // Setea accion final del Ad
- setFinalAction();
- } else {
- logError("(src=" + propSrc + "): document.body is " + document.body, "loadIframeAd");
- }
- } catch (err) {
- logError(err, "loadIframeAd");
- }
- }
- // FIN IFRAME AD ///////////////////////////////////////////////////////////////
- // INICIO VAST AD //////////////////////////////////////////////////////////////
- function loadVastAd() {
- try {
- var propPosition = matchedView.position;
- var propTop = parseInt(matchedView.top);
- var removeScrollBody = (matchedView.removescrollbody === 'true');
- var fondoOscuro = (matchedView.backgroundblack === 'true');
- var propWidth;
- var propHeight;
- var propLeft;
- if (propPosition === "FULLSCREEN") {
- propWidth = "100%";
- propHeight = "100%";
- propLeft = 0;
- } else {
- propWidth = matchedView.adwidth;
- propHeight = matchedView.adheight;
- propLeft = parseInt(matchedView.left);
- }
- if (propPosition === "CENTERED") {
- var windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
- var windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
- var popupHeight = propHeight;
- var popupWidth = propWidth;
- var elemTop = windowHeight / 2 - popupHeight / 2;
- var elemLeft = windowWidth / 2 - popupWidth / 2;
- propTop = elemTop;
- propLeft = elemLeft;
- }
- var adSizeWidth = calculateAdSize(matchedView.adwidth, window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth);
- var adSizeHeight = calculateAdSize(matchedView.adheight, window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight);
- var ifrm = document.createElement("IFRAME");
- var propsrc = "http://" + ns_ip + ":" + ns_port + "/nadip/iframevast?";
- propsrc += "subscriberId=" + subscriberId;
- propsrc += "&subscriberIP=" + subscriberIP;
- propsrc += "&adId=" + nadipad.adid;
- propsrc += "&viewKey=" + JSON.stringify(matchedView.viewKey);
- propsrc += "&refererURL=" + window.location.href;
- propsrc += "&domain=" + window.location.hostname.replace(/^www\./, "");
- propsrc += "&adSize=" + adSizeWidth + "x" + adSizeHeight;
- propsrc += "&userAgent=" + userAgent;
- ifrm.setAttribute("src", propsrc);
- ifrm.setAttribute("id", AD_ID);
- ifrm.setAttribute("allowFullScreen", '');
- ifrm.style.height = getValue2(propHeight);
- ifrm.style.position = 'fixed';
- ifrm.style.border = 'none';
- ifrm.style.overflow = 'hidden';
- ifrm.style.margin = '0 auto';
- ifrm.style.zIndex = Z_INDEX_MAIN;
- ifrm.style.display = 'block';
- ifrm.style.padding = '0px';
- ifrm.style.top = "auto";
- ifrm.style.left = "0px";
- if (propPosition === "CENTERED") {
- ifrm.style.top = propTop + "px";
- ifrm.style.left = propLeft + "px";
- } else if (propPosition === "TOP") {
- ifrm.style.top = "0px";
- }
- if (propPosition === "FULLSCREEN") {
- ifrm.style.width = "100%";
- ifrm.style.top = "0px";
- } else {
- ifrm.style.width = getValue2(propWidth);
- }
- if (document.body !== null && document.body !== undefined) {
- if (document.body.firstChild) {
- document.body.insertBefore(ifrm, document.body.firstChild);
- } else {
- document.body.appendChild(ifrm);
- }
- if (propPosition === "BOTTOM") {
- var div = document.getElementById(AD_ID);
- div.style.bottom = "0";
- if (div.getBoundingClientRect) {
- var rect = div.getBoundingClientRect();
- var cHeight = document.documentElement.clientHeight;
- var bottomOffset = (rect.bottom - cHeight);
- if (bottomOffset > 0) {
- div.style.bottom = bottomOffset + "px";
- }
- }
- }
- if (removeScrollBody) {
- document.getElementsByTagName("body")[0].style.overflow = "hidden";
- }
- if (fondoOscuro) {
- var divfondooscuro = document.createElement("div");
- divfondooscuro.id = AD_BACKGROUND_ID;
- document.body.appendChild(divfondooscuro);
- loadCssPropertiesInstertitialBackground();
- }
- setFinalAction();
- } else {
- logError("(src=" + propsrc + "): document.body is " + document.body, "loadVastAd");
- }
- } catch (err) {
- logError(err, "loadVastAd");
- }
- }
- function calculateAdSize(configuredSize, windowSize) {
- var adSize = configuredSize;
- if (configuredSize !== undefined && configuredSize.indexOf("%") > 0) {
- adSize = windowSize * (parseInt(configuredSize.replace("%", "")) / 100);
- }
- return adSize;
- }
- // FIN VAST AD /////////////////////////////////////////////////////////////////
- // INICIO IMA AD //////////////////////////////////////////////////////////////
- function loadImaAd() {
- try {
- // Obtiene las propiedades del Ad
- var propPosition = matchedView.position;
- var propHorizontalPosition = matchedView.horizontalposition;
- var removeScrollBody = (matchedView.removescrollbody === 'true');
- var fondoOscuro = (matchedView.backgroundblack === 'true');
- var adSizeWidth = calculateAdSize(matchedView.adwidth, window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth);
- var adSizeHeight = calculateAdSize(matchedView.adheight, window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight);
- var ifrm = document.createElement("IFRAME");
- var propSrc = "http://" + ns_ip + ":" + ns_port + "/nadip/iframeimasdk?";
- propSrc += "subscriberId=" + subscriberId;
- propSrc += "&subscriberIP=" + subscriberIP;
- propSrc += "&adId=" + nadipad.adid;
- propSrc += "&viewKey=" + JSON.stringify(matchedView.viewKey);
- propSrc += "&refererURL=" + window.location.href;
- propSrc += "&domain=" + window.location.hostname.replace(/^www\./, "");
- propSrc += "&adSize=" + adSizeWidth + "x" + adSizeHeight;
- propSrc += "&userAgent=" + userAgent;
- ifrm.setAttribute("src", propSrc);
- ifrm.setAttribute("id", AD_ID);
- ifrm.setAttribute("allowFullScreen", '');
- ifrm.style.width = adSizeWidth + "px";
- ifrm.style.height = adSizeHeight + "px";
- ifrm.style.position = 'fixed';
- ifrm.style.border = 'none';
- ifrm.style.overflow = 'hidden';
- ifrm.style.margin = '0 auto';
- ifrm.style.zIndex = Z_INDEX_MAIN;
- ifrm.style.display = 'block';
- ifrm.style.padding = '0px';
- if (propPosition === "FULLSCREEN") {
- ifrm.style.top = 0 + "px";
- ifrm.style.left = 0 + "px";
- ifrm.style.width = 100 + "%";
- ifrm.style.height = 100 + "%";
- } else {
- // Calcula y setea centrado horizontal
- if (propHorizontalPosition === undefined || propHorizontalPosition === null || propHorizontalPosition === "CENTERED") {
- // Calcula el centrado horizontal
- var windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
- var calculatedLeft = windowWidth / 2 - adSizeWidth / 2;
- ifrm.style.left = calculatedLeft + "px";
- } else if (propHorizontalPosition === "LEFT") {
- ifrm.style.left = 0 + "px";
- } else if (propHorizontalPosition === "RIGHT") {
- ifrm.style.right = 0 + "px";
- }
- // Calcula y setea el centrado vertical de acuerdo a lo seleccionado
- if (propPosition === undefined || propPosition === null || propPosition === "CENTERED") {
- // Calcula el centrado vertical
- var windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
- var calculatedTop = windowHeight / 2 - adSizeHeight / 2;
- ifrm.style.top = calculatedTop + "px";
- } else if (propPosition === "TOP") {
- ifrm.style.top = 0 + "px";
- } else if (propPosition === "BOTTOM") {
- ifrm.style.bottom = 0 + "px";
- }
- }
- if (document.body !== null && document.body !== undefined) {
- // Inserta el iframe en el documento
- if (document.body.firstChild) {
- document.body.insertBefore(ifrm, document.body.firstChild);
- } else {
- document.body.appendChild(ifrm);
- }
- // Oculta el scroll segun corresponda
- if (removeScrollBody) {
- document.getElementsByTagName("body")[0].style.overflow = "hidden";
- }
- // Oscurece fondo o no segun corresponda
- if (fondoOscuro) {
- var divfondooscuro = document.createElement("div");
- divfondooscuro.id = AD_BACKGROUND_ID;
- document.body.appendChild(divfondooscuro);
- loadCssPropertiesInstertitialBackground();
- }
- // Setea accion final del Ad
- setFinalAction();
- } else {
- logError("(src=" + propSrc + "): document.body is " + document.body, "loadImaAd");
- }
- } catch (err) {
- logError(err, "loadImaAd");
- }
- }
- // FIN IMA AD //////////////////////////////////////////////////////////////////
- // INICIO KOMLI BANNER AD //////////////////////////////////////////////////////
- function loadKomliBannerAd() {
- try {
- var propsrc = "http://" + ns_ip + ":" + ns_port + "/nadip/iframekomlibanner?";
- propsrc += "subscriberId=" + subscriberId;
- propsrc += "&subscriberIP=" + subscriberIP;
- propsrc += "&domainName=" + window.location.hostname;
- propsrc += "&adId=" + nadipad.adid;
- propsrc += "&viewKey=" + JSON.stringify(matchedView.viewKey);
- buildAdNetworkBanner(propsrc);
- } catch (err) {
- logError(err, "loadKomliBannerAd");
- }
- }
- // FIN KOMLI BANNER AD /////////////////////////////////////////////////////////
- // INICIO INMOBI AD ////////////////////////////////////////////////////////////
- function loadInmobiAd() {
- try {
- var propsrc = "http://" + ns_ip + ":" + ns_port + "/nadip/iframeinmobi?";
- propsrc += "subscriberId=" + subscriberId;
- propsrc += "&subscriberIP=" + subscriberIP;
- propsrc += "&adId=" + nadipad.adid;
- propsrc += "&viewKey=" + JSON.stringify(matchedView.viewKey);
- buildAdNetworkBanner(propsrc);
- } catch (err) {
- logError(err, "loadInmobiAd");
- }
- }
- // FIN INMOBI AD ///////////////////////////////////////////////////////////////
- // INICIO MOBVISTA AD //////////////////////////////////////////////////////////
- function loadMobvistaAd() {
- try {
- var propsrc = "http://" + ns_ip + ":" + ns_port + "/nadip/iframemobvista?";
- propsrc += "subscriberId=" + subscriberId;
- propsrc += "&subscriberIP=" + subscriberIP;
- propsrc += "&adId=" + nadipad.adid;
- propsrc += "&viewKey=" + JSON.stringify(matchedView.viewKey);
- buildAdNetworkBanner(propsrc);
- } catch (err) {
- logError(err, "loadMobvistaAd");
- }
- }
- // FIN MOBVISTA AD /////////////////////////////////////////////////////////////
- // INICIO ADATHA AD ////////////////////////////////////////////////////////////
- function loadAdathaAd() {
- try {
- var propsrc = "http://" + ns_ip + ":" + ns_port + "/nadip/iframeadatha?";
- propsrc += "subscriberId=" + subscriberId;
- propsrc += "&subscriberIP=" + subscriberIP;
- propsrc += "&adId=" + nadipad.adid;
- propsrc += "&viewKey=" + JSON.stringify(matchedView.viewKey);
- buildAdNetworkBanner(propsrc);
- } catch (err) {
- logError(err, "loadInmobiAd");
- }
- }
- // FIN INMOBI AD ///////////////////////////////////////////////////////////////
- // METODO AUXILIAR DE CREADOR DE AD NETWORK BANNER /////////////////////////////
- function buildAdNetworkBanner(adNetworkSource) {
- // Obtiene las propiedades del Ad
- var propPosition = matchedView.position;
- var propHorizontalPosition = matchedView.horizontalposition;
- var propWidth = matchedView.adwidth;
- var propHeight = matchedView.adheight;
- var removeScrollBody = (matchedView.removescrollbody === 'true');
- var fondoOscuro = (matchedView.backgroundblack === 'true');
- // Crea iframe y setea valores generales
- var ifrm = document.createElement("IFRAME");
- ifrm.setAttribute("src", adNetworkSource);
- ifrm.setAttribute("id", AD_ID);
- ifrm.setAttribute("allowFullScreen", '');
- ifrm.style.width = getValue2(propWidth);
- ifrm.style.height = getValue2(propHeight);
- ifrm.style.position = 'fixed';
- ifrm.style.border = 'none';
- ifrm.style.overflow = 'hidden';
- ifrm.style.margin = '0 auto';
- ifrm.style.zIndex = Z_INDEX_MAIN;
- ifrm.style.display = 'block';
- ifrm.style.padding = '0px';
- // Calcula y setea centrado horizontal
- if (propHorizontalPosition === undefined || propHorizontalPosition === null || propHorizontalPosition === "CENTERED") {
- // Calcula el centrado horizontal
- var windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
- var calculatedLeft = windowWidth / 2 - calculatePropValue(propWidth, windowWidth) / 2;
- ifrm.style.left = calculatedLeft + "px";
- } else if (propHorizontalPosition === "LEFT") {
- ifrm.style.left = 0 + "px";
- } else if (propHorizontalPosition === "RIGHT") {
- ifrm.style.right = 0 + "px";
- }
- // Calcula y setea el centrado vertical de acuerdo a lo seleccionado
- if (propPosition === undefined || propPosition === null || propPosition === "CENTERED") {
- // Calcula el centrado vertical
- var windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
- var calculatedTop = windowHeight / 2 - calculatePropValue(propHeight, windowHeight) / 2;
- ifrm.style.top = calculatedTop + "px";
- } else if (propPosition === "TOP") {
- ifrm.style.top = 0 + "px";
- } else if (propPosition === "BOTTOM") {
- ifrm.style.bottom = 0 + "px";
- }
- if (document.body !== null && document.body !== undefined) {
- // Inserta el iframe en el documento
- if (document.body.firstChild) {
- document.body.insertBefore(ifrm, document.body.firstChild);
- } else {
- document.body.appendChild(ifrm);
- }
- // Oculta el scroll segun corresponda
- if (removeScrollBody) {
- document.getElementsByTagName("body")[0].style.overflow = "hidden";
- }
- // Oscurece fondo o no segun corresponda
- if (fondoOscuro) {
- var divfondooscuro = document.createElement("div");
- divfondooscuro.id = AD_BACKGROUND_ID;
- document.body.appendChild(divfondooscuro);
- loadCssPropertiesInstertitialBackground();
- }
- // Setea accion final del Ad
- setFinalAction();
- } else {
- logError("(src=" + adNetworkSource + "): document.body is " + document.body, "buildAdNetworkBanner");
- }
- }
- function calculatePropValue(propWidth, windowWidth) {
- if (propWidth.indexOf("%") < 0) {
- try {
- return parseInt(propWidth);
- } catch (err) {
- return propWidth;
- }
- } else {
- return (parseInt(propWidth.replace("%", "")) * windowWidth) / 100;
- }
- }
- // INICIO VERTICAL AD //////////////////////////////////////////////////////////
- function loadVerticalAd(adType) {
- // console.log("loadAdsNADIP (" + adType + " - adid: " + nadipad.adid + ")");
- // Arma div
- var htmlDiv = "<div id='" + AD_ID + "' onclick='clickOnAdNADIPWithLink(this)'><a id='adButtonClose' onclick='closeAdNADIP()'>x</a></div>";
- // Agrega div al body segun corresponda
- switch (adType) {
- case "BANNER":
- jQuery("body").append(htmlDiv);
- break;
- case "OVERSLIDE":
- jQuery("body").prepend(htmlDiv);
- break;
- }
- // Carga propiedades de Main
- loadCssPropertiesVerticalMain();
- // Ubica horizontalmente segun corresponda
- switch (adType) {
- case "BANNER":
- var mainLeft = getValue(matchedView.left, "0px");
- jQuery("#" + AD_ID).css("left", mainLeft);
- break;
- case "OVERSLIDE":
- var mainRight = getValue(matchedView.right, "0px");
- jQuery("#" + AD_ID).css("right", mainRight);
- break;
- }
- // Carga propiedades de Boton X
- loadCssPropertiesButtonClose();
- // Indica si sirvio el Ad
- servedAdNADIP();
- // Setea la accion final a realizar
- setFinalAction();
- }
- function loadCssPropertiesVerticalMain() {
- // Prepara propiedades de div principal
- var mainZIndex = Z_INDEX_MAIN;
- var mainDisplay = MAIN_DISPLAY;
- var mainPosition = "fixed";
- var mainVerticalPosition = matchedView.position;
- var mainWidth = getValue(matchedView.adwidth, "200px");
- var mainHeight = getValue(matchedView.adheight, "600px");
- var mainBackgroundImage = matchedView.imgurl;
- var mainBackgroundRepeat = "round";
- var mainBackgroundSize = "cover";
- // Setea propiedades del div principal
- jQuery("#" + AD_ID).css("z-index", mainZIndex);
- jQuery("#" + AD_ID).css("display", mainDisplay);
- jQuery("#" + AD_ID).css("position", mainPosition);
- jQuery("#" + AD_ID).css("width", mainWidth);
- jQuery("#" + AD_ID).css("height", mainHeight);
- jQuery("#" + AD_ID).css("background-image", "url(" + mainBackgroundImage + ")");
- jQuery("#" + AD_ID).css("cursor", "pointer");
- jQuery("#" + AD_ID).fadeIn("slow");
- jQuery("#" + AD_ID).css("background-repeat", mainBackgroundRepeat);
- jQuery("#" + AD_ID).css("background-size", mainBackgroundSize);
- // Calcula y setea el centrado vertical de acuerdo a lo seleccionado
- if (mainVerticalPosition === undefined || mainVerticalPosition === null || mainVerticalPosition === "CENTERED") {
- var windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
- if (mainHeight.indexOf("%") >= 0) {
- mainHeight = windowHeight * (parseInt(mainHeight) / 100);
- }
- var calculatedTop = windowHeight / 2 - mainHeight / 2;
- jQuery("#" + AD_ID).css("top", calculatedTop + "px");
- } else if (mainVerticalPosition === "TOP") {
- jQuery("#" + AD_ID).css("top", 0 + "px");
- } else if (mainVerticalPosition === "BOTTOM") {
- jQuery("#" + AD_ID).css("bottom", 0 + "px");
- }
- }
- // FIN VERTICAL AD /////////////////////////////////////////////////////////////
- // INICIO HORIZONTAL AD ////////////////////////////////////////////////////////
- function loadHorizontalAd(adType) {
- // console.log("loadAdsNADIP (" + adType + " - adid: " + nadipad.adid + ")");
- // Arma div
- var htmlDiv = "<div id='" + AD_ID + "' onclick='clickOnAdNADIPWithLink(this)'><a id='adButtonClose' onclick='closeAdNADIP()'>x</a></div>";
- // Agrega div al body segun corresponda
- switch (adType) {
- case "TOP_AD":
- jQuery("body").append(htmlDiv);
- break;
- case "FLOORAD":
- jQuery("body").prepend(htmlDiv);
- break;
- }
- // Carga propiedades de Main
- loadCssPropertiesHorizontalMain();
- // Ubica horizontalmente segun corresponda
- switch (adType) {
- case "TOP_AD":
- var mainTop = getValue(matchedView.top, "0px");
- jQuery("#" + AD_ID).css("top", mainTop);
- break;
- case "FLOORAD":
- var mainBottom = getValue(matchedView.bottom, "0px");
- jQuery("#" + AD_ID).css("bottom", mainBottom);
- break;
- }
- // Carga propiedades de Boton X
- loadCssPropertiesButtonClose();
- // Indica si sirvio el Ad
- servedAdNADIP();
- // Setea la accion final a realizar
- setFinalAction();
- }
- function loadCssPropertiesHorizontalMain() {
- // Prepara propiedades de div principal
- var mainZIndex = Z_INDEX_MAIN;
- var mainDisplay = MAIN_DISPLAY;
- var mainPosition = "fixed";
- var mainHorizontalPosition = matchedView.horizontalposition;
- var mainWidth = getValue(matchedView.adwidth, "100%");
- var mainHeight = getValue(matchedView.adheight, "10%");
- var mainBackgroundImage = matchedView.imgurl;
- var mainBackgroundRepeat = "round";
- // var mainBackgroundPosition = "center center";
- var mainBackgroundSize = "cover";
- // Setea propiedades del div principal
- jQuery("#" + AD_ID).css("z-index", mainZIndex);
- jQuery("#" + AD_ID).css("display", mainDisplay);
- jQuery("#" + AD_ID).css("position", mainPosition);
- jQuery("#" + AD_ID).css("width", mainWidth);
- jQuery("#" + AD_ID).css("height", mainHeight);
- jQuery("#" + AD_ID).css("background-image", 'url(' + mainBackgroundImage + ')');
- // jQuery("#" + AD_ID).css("background-position", mainBackgroundPosition);
- jQuery("#" + AD_ID).css("background-repeat", mainBackgroundRepeat);
- jQuery("#" + AD_ID).css("background-size", mainBackgroundSize);
- jQuery("#" + AD_ID).css("cursor", "pointer");
- jQuery("#" + AD_ID).fadeIn("slow");
- // Calcula y setea centrado horizontal
- if (mainHorizontalPosition === undefined || mainHorizontalPosition === null || mainHorizontalPosition === "CENTERED") {
- var windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
- if (mainWidth.indexOf("%") >= 0) {
- mainWidth = windowWidth * (parseInt(mainWidth) / 100);
- }
- var calculatedLeft = windowWidth / 2 - mainWidth / 2;
- jQuery("#" + AD_ID).css("left", calculatedLeft + "px");
- } else if (mainHorizontalPosition === "LEFT") {
- jQuery("#" + AD_ID).css("left", 0 + "px");
- } else if (mainHorizontalPosition === "RIGHT") {
- jQuery("#" + AD_ID).css("right", 0 + "px");
- }
- }
- // FIN HORIZONTAL AD ///////////////////////////////////////////////////////////
- // INICIO FIXED ////////////////////////////////////////////////////////////////
- function loadFixed() {
- // console.log("loadAdsNADIP (FIXED - adid: " + nadipad.adid + ")");
- // Arma div
- var htmlDiv = "<div id='" + AD_ID + "' onclick='clickOnAdNADIPWithLink(this)'><a id='adButtonClose' onclick='closeAdNADIP()'>x</a></div>";
- // Agrega div al body segun corresponda
- jQuery("body").append(htmlDiv);
- // Carga propiedades de Main
- loadCssPropertiesFixedMain();
- // Carga propiedades de Boton X
- loadCssPropertiesButtonClose();
- // Indica si sirvio el Ad
- servedAdNADIP();
- // Setea la accion final a realizar
- setFinalAction();
- }
- function loadCssPropertiesFixedMain() {
- // Prepara propiedades de div principal
- var mainZIndex = Z_INDEX_MAIN;
- var mainDisplay = MAIN_DISPLAY;
- var mainPosition = "fixed";
- var mainTop = getValue(matchedView.top, "0px");
- var mainLeft = getValue(matchedView.left, "0px");
- var mainWidth = getValue(matchedView.adwidth, "200px");
- var mainHeight = getValue(matchedView.adheight, "200px");
- var mainBackgroundImage = matchedView.imgurl;
- var mainBackgroundRepeat = "round";
- var mainBackgroundSize = "cover";
- // Setea propiedades del div principal
- jQuery("#" + AD_ID).css("z-index", mainZIndex);
- jQuery("#" + AD_ID).css("display", mainDisplay);
- jQuery("#" + AD_ID).css("position", mainPosition);
- jQuery("#" + AD_ID).css("top", mainTop);
- jQuery("#" + AD_ID).css("left", mainLeft);
- jQuery("#" + AD_ID).css("width", mainWidth);
- jQuery("#" + AD_ID).css("height", mainHeight);
- jQuery("#" + AD_ID).css("background-image", 'url(' + mainBackgroundImage + ')');
- jQuery("#" + AD_ID).css("background-repeat", mainBackgroundRepeat);
- jQuery("#" + AD_ID).css("background-size", mainBackgroundSize);
- jQuery("#" + AD_ID).css("cursor", "pointer");
- jQuery("#" + AD_ID).fadeIn("slow");
- }
- // FIN FIXED ///////////////////////////////////////////////////////////////////
- // INICIO REPEAT ///////////////////////////////////////////////////////////////
- function loadRepeat() {
- // console.log("loadAdsNADIP (REPEAT - adid: " + nadipad.adid + ")");
- // Arma div
- var htmlDiv = "<div id='" + AD_ID + "' onclick='clickOnAdNADIP(this)'><a id='adButtonClose' onclick='closeAdNADIP()'>x</a></div>";
- // Agrega div al body
- jQuery("body").append(htmlDiv);
- // Carga propiedades de Main
- loadCssPropertiesRepeatMain();
- // Carga propiedades de Boton X
- loadCssPropertiesButtonClose();
- // Indica si sirvio el Ad
- servedAdNADIP();
- // Setea la accion final a realizar
- setFinalAction();
- }
- function loadCssPropertiesRepeatMain() {
- // Prepara propiedades del div principal
- var mainZIndex = Z_INDEX_MAIN;
- var mainDisplay = MAIN_DISPLAY;
- var mainPosition = "fixed";
- var mainTop = getValue(matchedView.top, "0px");
- var mainLeft = getValue(matchedView.left, "0px");
- var mainWidth = "100%";
- var mainHeight = getValue(matchedView.adheight, "200px");
- var mainBackgroundImage = matchedView.imgurl;
- // Setea propiedades del div principal
- jQuery("#" + AD_ID).css("z-index", mainZIndex);
- jQuery("#" + AD_ID).css("display", mainDisplay);
- jQuery("#" + AD_ID).css("position", mainPosition);
- jQuery("#" + AD_ID).css("top", mainTop);
- jQuery("#" + AD_ID).css("left", mainLeft);
- jQuery("#" + AD_ID).css("width", mainWidth);
- jQuery("#" + AD_ID).css("height", mainHeight);
- jQuery("#" + AD_ID).css("background-image", 'url(' + mainBackgroundImage + ')');
- jQuery("#" + AD_ID).fadeIn("slow");
- }
- // FIN REPEAT //////////////////////////////////////////////////////////////////
- // INICIO INTERSTITIAL | FLASH /////////////////////////////////////////////////
- function loadInstertitialAd(adType) {
- // console.log("loadAdsNADIP (" + adType + " - adid: " + nadipad.adid + ")");
- // Arma htmlDiv segun corresponda
- var htmlDiv;
- switch (adType) {
- case "INTERSTITIAL":
- htmlDiv = "<div id='" + AD_ID + "' onclick='clickOnAdNADIPWithLink(this)'><a id='adButtonClose' onclick='closeAdNADIP()'>x</a></div>";
- htmlDiv += "<div id='adBackground'></div>";
- break;
- case "INTERSTITIAL_FLASH":
- // Arma div
- htmlDiv = "<div id='" + AD_ID + "' onclick='clickOnAdNADIP(this)'><a id='adButtonClose' onclick='closeAdNADIP()'>x</a>";
- htmlDiv += "<embed id='flashElement' src='" + matchedView.imgurl + "'</embed>";
- htmlDiv += "</div><div id='adBackground'></div>";
- break;
- }
- // Agrega div al body segun corresponda
- jQuery("body").prepend(htmlDiv);
- // Carga propiedades de Main
- loadCssPropertiesInstertitialMain();
- // Carga propiedades de Boton X
- loadCssPropertiesButtonClose();
- // Carga propiedades de Background
- loadCssPropertiesInstertitialBackground();
- // Deshabilita el scroll de la pantalla
- enableBodyScroll(false);
- // Indica si sirvio el Ad
- servedAdNADIP();
- // Setea la accion final a realizar
- setFinalAction();
- }
- function loadCssPropertiesInstertitialMain() {
- // Prepara propiedades de div principal
- var mainZIndex = Z_INDEX_MAIN;
- var mainDisplay = "none";
- var mainPosition = "fixed";
- var main_position = "absolute"; /* hack for internet explorer 6 */
- var mainTop = "50%";
- var mainLeft = "50%";
- var mainWidth = getValue(matchedView.adwidth, "200px");
- var mainHeight = getValue(matchedView.adheight, "200px");
- var mainBorder = "1px solid #CCCCCC";
- var mainBackground = "#FFFFFF";
- var mainBackgroundSize = "cover";
- var mainBackgroundRepeat = "round";
- var mainBackgroundImage = matchedView.imgurl;
- // Setea propiedades del div principal
- jQuery("#" + AD_ID).css("z-index", mainZIndex);
- jQuery("#" + AD_ID).css("display", mainDisplay);
- jQuery("#" + AD_ID).css("position", mainPosition);
- jQuery("#" + AD_ID).css("_position", main_position);
- jQuery("#" + AD_ID).css("top", mainTop);
- jQuery("#" + AD_ID).css("left", mainLeft);
- jQuery("#" + AD_ID).css("width", mainWidth);
- jQuery("#" + AD_ID).css("height", mainHeight);
- jQuery("#" + AD_ID).css("border", mainBorder);
- jQuery("#" + AD_ID).css("background", mainBackground);
- jQuery("#" + AD_ID).css("background-size", mainBackgroundSize);
- jQuery("#" + AD_ID).css("background-repeat", mainBackgroundRepeat);
- jQuery("#" + AD_ID).css("background-image", 'url(' + mainBackgroundImage + ')');
- jQuery("#" + AD_ID).css("transform", "translate(-50%, -50%)");
- jQuery("#" + AD_ID).css("cursor", "pointer");
- jQuery("#" + AD_ID).fadeIn("slow");
- // FLASH
- if (document.getElementById("flashElement") !== null) {
- jQuery("#flashElement").attr('width', mainWidth);
- jQuery("#flashElement").attr('height', mainHeight);
- }
- }
- function loadCssPropertiesInstertitialBackground() {
- // Prepara propiedades de background
- var backgroundZIndex = Z_INDEX_BACKGROUND;
- var backgroundDisplay = "none";
- var backgroundPosition = "fixed";
- var background_position = "absolute"; /* hack for internet explorer 6 */
- var backgroundTop = "0px";
- var backgroundLeft = "0px";
- var backgroundWidth = "100%";
- var backgroundHeight = "100%";
- var backgroundBackground = "#000000";
- // Setea propiedades de background
- jQuery("#adBackground").css("z-index", backgroundZIndex);
- jQuery("#adBackground").css("display", backgroundDisplay);
- jQuery("#adBackground").css("position", backgroundPosition);
- jQuery("#adBackground").css("_position", background_position);
- jQuery("#adBackground").css("top", backgroundTop);
- jQuery("#adBackground").css("left", backgroundLeft);
- jQuery("#adBackground").css("width", backgroundWidth);
- jQuery("#adBackground").css("height", backgroundHeight);
- jQuery("#adBackground").css("background", backgroundBackground);
- jQuery("#adBackground").css({
- "opacity" : "0.7"
- });
- jQuery("#adBackground").fadeIn("fast");
- }
- // FIN INTERSTITIAL | FLASH ////////////////////////////////////////////////////
- // INICIO CUSTOMIZED ///////////////////////////////////////////////////////////
- function loadCustomizedAd(adType) {
- // console.log("loadAdsNADIP (" + adType + " - adid: " + nadipad.adid + ")");
- // Obtiene div custom
- var divCustomized = matchedView.divCustomized;
- // Agrega div al body
- jQuery("body").append(divCustomized);
- // Indica si sirvio el Ad
- servedAdNADIP();
- // Setea la accion final a realizar
- setFinalAction();
- }
- // FIN CUSTOMIZED //////////////////////////////////////////////////////////////
- // FUNCIONES AUXILIARES ////////////////////////////////////////////////////////
- function getValue(value, defaultValue) {
- return (value !== undefined && value !== null && value.length !== 0) ? value : defaultValue;
- }
- function getValue2(value) {
- if (value.indexOf("%") < 0) {
- try {
- return parseInt(value) + "px";
- } catch (err) {
- return value;
- }
- } else {
- return value;
- }
- }
- function loadCssPropertiesButtonClose() {
- // Prepara propiedades del div Close
- var closeDisplay = "block";
- var closeZIndex = Z_INDEX_MAIN;
- var closePosition = "absolute";
- var closeWidth = "10px";
- var closeHeight = "15px";
- var closeRight = "0px";
- var closeTop = "0px";
- var closeMarginTop = "-5px";
- var closeOverflow = "visible";
- var closeCursor = "pointer";
- var closeColor = "#CCCCCC";
- var closeFontFamily = "verdana";
- var closeFontSize = "14px";
- var closeFontWeight = "bold";
- // var backgroundColor = "black";
- // Setea propiedades del div de Close
- jQuery("#adButtonClose").css("float", "right");
- jQuery("#adButtonClose").css("display", closeDisplay);
- jQuery("#adButtonClose").css("z-index", closeZIndex);
- jQuery("#adButtonClose").css("position", closePosition);
- jQuery("#adButtonClose").css("width", closeWidth);
- jQuery("#adButtonClose").css("height", closeHeight);
- jQuery("#adButtonClose").css("right", closeRight);
- jQuery("#adButtonClose").css("top", closeTop);
- jQuery("#adButtonClose").css("margin-top", closeMarginTop);
- jQuery("#adButtonClose").css("overflow", closeOverflow);
- jQuery("#adButtonClose").css("cursor", closeCursor);
- jQuery("#adButtonClose").css("color", closeColor);
- jQuery("#adButtonClose").css("font-family", closeFontFamily);
- jQuery("#adButtonClose").css("font-size", closeFontSize);
- jQuery("#adButtonClose").css("font-weight", closeFontWeight);
- // jQuery("#adButtonClose").css("background-color", "black");
- }
- function enableBodyScroll(enabled) {
- if (enabled) {
- jQuery("body").css("overflow", "auto");
- } else {
- jQuery("body").css("overflow", "hidden");
- }
- }
- var autocloseTimeout;
- function setFinalAction() {
- try {
- var autocloseTime = parseInt(getValue(matchedView.autoClose, 0));
- if (autocloseTime > 0) {
- autocloseTimeout = setTimeout(function() {
- closeAdNADIP(true, false);
- }, autocloseTime * 1000);
- } else {
- // console.log("Autoclose disabled");
- var cycleTime = parseInt(getValue(matchedView.cycle, 0));
- if (cycleTime > 0) {
- setTimeout(function() {
- closeAdNADIP(true, false);
- loadNextAd();
- }, cycleTime * 1000);
- } else {
- // console.log("Cycle disabled");
- }
- }
- } catch (err) {
- logError(err, "setFinalAction");
- }
- }
- function setSleepTime() {
- try {
- var cycleTime = parseInt(getValue(matchedView.cycle, 0));
- if (cycleTime === 0) {
- var sleepTime = parseInt(getValue(matchedView.sleep, 0));
- if (sleepTime > 0) {
- setTimeout(function() {
- loadNextAd();
- }, sleepTime * 1000);
- } else {
- // console.log("Sleep disabled");
- }
- } else {
- // console.log("Cannot sleep because Cycle is enabled");
- }
- } catch (err) {
- logError(err, "setSleepTime");
- }
- }
- function nadipNextAdOnAdError() {
- closeAdNADIP(false, true);
- loadNextAdOnFallback();
- }
- function loadNextAdOnFallback() {
- if (firstad !== undefined && firstad !== null && firstad.adid !== undefined && firstad.adid !== null) {
- jQuery.ajax({
- type : "GET",
- url : "http://" + ns_ip + ":" + ns_port + "/api/getad",
- crossDomain : true,
- dataType : 'json',
- data : {
- "subscriberId" : subscriberId,
- "subscriberIP" : subscriberIP,
- "nadipdata" : JSON.stringify(nadipdata),
- "screenheight" : screen.height,
- "screenwidth" : screen.width,
- "firstad" : firstad.adid,
- "cycle" : false
- },
- cache : false,
- success : function(data) {
- console.log("loadNextAdOnFallback data: " + JSON.stringify(data));
- // Carga valores
- try {
- if (data !== null && data !== undefined && data.error !== null && data.error !== undefined && !data.error) {
- var oldnadipad = nadipad;
- nadipad = JSON.parse(data.nadipad);
- if (nadipad !== undefined && nadipad !== null && nadipad.adid !== undefined && nadipad.adid != null && nadipad.adid != firstad.adid) {
- matchedView = JSON.parse(data.matchedView);
- if (data.hasOwnProperty('nadipcategories') && data.nadipcategories) {
- nadipcategories = JSON.parse(data.nadipcategories);
- }
- if (data.hasOwnProperty('nadipadgroups')) {
- nadipadgroups = JSON.parse(data.nadipadgroups);
- }
- if (data.hasOwnProperty('nadipadcampaignid')) {
- nadipadcampaignid = JSON.parse(data.nadipadcampaignid);
- }
- injected_uuid = JSON.parse(data.injected_uuid);
- ns_ip = data.ns_ip;
- ns_port = data.ns_port;
- // Remueve el Ad existente
- jQuery('#' + AD_ID).remove();
- // Carga nuevo Ad
- loadAd();
- } else {
- nadipad = oldnadipad;
- logError("No view in session", "loadNextAdOnFallback: nadipdata: " + JSON.stringify(data));
- }
- } else {
- logError("No data in getad", "loadNextAdOnFallback: nadipdata: " + JSON.stringify(data));
- }
- } catch (err) {
- logError(err, "loadNextAdOnFallback: nadipdata: " + JSON.stringify(data));
- }
- }
- });
- } else {
- logError(err, "Firstad undefined or null on loadNextAdOnFallback()");
- }
- }
- function loadNextAd() {
- try {
- jQuery.ajax({
- type : "GET",
- url : "http://" + ns_ip + ":" + ns_port + "/api/getad",
- crossDomain : true,
- dataType : 'json',
- data : {
- "subscriberId" : subscriberId,
- "subscriberIP" : subscriberIP,
- "nadipdata" : JSON.stringify(nadipdata),
- "screenheight" : screen.height,
- "screenwidth" : screen.width,
- "preadid" : nadipad.adid,
- "cycle" : true
- },
- cache : false,
- success : function(data) {
- // console.log("getAdByCycle data: " + JSON.stringify(data));
- // Carga valores
- matchedView = JSON.parse(data.matchedView);
- nadipcategories = JSON.parse(data.nadipcategories);
- nadipad = JSON.parse(data.nadipad);
- if (data.hasOwnProperty('nadipadgroups')) {
- nadipadgroups = JSON.parse(data.nadipadgroups);
- }
- if (data.hasOwnProperty('nadipadcampaignid')) {
- nadipadcampaignid = JSON.parse(data.nadipadcampaignid);
- }
- ns_ip = data.ns_ip;
- ns_port = data.ns_port;
- // Remueve el Ad existente
- jQuery('#' + AD_ID).remove();
- // Carga nuevo Ad
- loadAd();
- }
- });
- } catch (err) {
- logError(err, "loadNextAd");
- }
- }
- function loadFirstAd() {
- console.log(typeof nadipdata.adid);
- jQuery.ajax({
- type : "GET",
- url : "http://" + ns_ip + ":" + ns_port + "/api/getad",
- crossDomain : true,
- dataType : 'json',
- data : {
- "subscriberId" : subscriberId,
- "subscriberIP" : subscriberIP,
- "nadipdata" : JSON.stringify(nadipdata),
- "screenheight" : screen.height,
- "screenwidth" : screen.width,
- "preadid" : -1,
- "cycle" : false
- },
- cache : false,
- success : function(data) {
- console.log("loadFirstAd data: " + JSON.stringify(data));
- // Carga valores
- try {
- if (data !== null && data !== undefined && data.error !== null && data.error !== undefined && !data.error) {
- matchedView = JSON.parse(data.matchedView);
- if (data.hasOwnProperty('nadipcategories') && data.nadipcategories) {
- nadipcategories = JSON.parse(data.nadipcategories);
- }
- nadipad = JSON.parse(data.nadipad);
- firstad = nadipad;
- if (data.hasOwnProperty('nadipadgroups')) {
- nadipadgroups = JSON.parse(data.nadipadgroups);
- }
- if (data.hasOwnProperty('nadipadcampaignid')) {
- nadipadcampaignid = JSON.parse(data.nadipadcampaignid);
- }
- injected_uuid = JSON.parse(data.injected_uuid);
- ns_ip = data.ns_ip;
- ns_port = data.ns_port;
- // Remueve el Ad existente
- jQuery('#' + AD_ID).remove();
- // Carga nuevo Ad
- loadAd();
- } else {
- logError("No data in getad", "loadFirstAd: nadipdata: " + JSON.stringify(data));
- }
- } catch (err) {
- logError(err, "loadFirstAd : nadipdata: " + JSON.stringify(data));
- }
- }
- });
- }
- function clickOnAdNADIPWithLink() {
- try {
- saveStatsNADIP("clicked");
- window.open(matchedView.link, '_blank');
- closeAdNADIP(false, true);
- } catch (err) {
- logError(err, "clickOnAdNADIPWithLink");
- }
- }
- function clickOnAdNADIP(element) {
- try {
- // console.log('clicked!');
- saveStatsNADIP("clicked");
- // window.open(matchedView.link, '_blank');
- } catch (err) {
- logError(err, "clickOnAdNADIP");
- }
- }
- function closeAdNADIP(isAutoclose, noStats, e) {
- try {
- if (!e) {
- var e = window.event;
- }
- if (typeof e !== 'undefined') {
- e.cancelBubble = true;
- if (e.stopPropagation)
- e.stopPropagation();
- }
- if (jQuery('#' + AD_ID).length !== 0) {
- var closeType;
- if (getValue(isAutoclose, false)) {
- closeType = "autoclosed";
- } else {
- closeType = "closed";
- clearTimeout(autocloseTimeout);
- }
- // Console.log('' + closeType + '!');
- if (!getValue(noStats, false)) {
- saveStatsNADIP(closeType);
- }
- jQuery("#" + AD_ID).remove();
- if (document.getElementById(AD_BACKGROUND_ID) !== null) {
- jQuery("#" + AD_BACKGROUND_ID).fadeOut("slow");
- }
- }
- // Activa Scroll nuevamente
- enableBodyScroll(true);
- // Sleep Time
- setSleepTime();
- } catch (err) {
- logError(err, "closeAdNADIP");
- }
- }
- function clearProperties() {
- matchedView = null;
- nadipcategories = null;
- nadipad = null;
- nadipadgroups = null;
- nadipadcampaignid = null;
- ns_ip = null;
- ns_port = null;
- mapaResult = null;
- }
- function servedAdNADIP(e) {
- try {
- if (!e) {
- var e = window.event;
- }
- if (typeof e !== 'undefined') {
- e.cancelBubble = true;
- if (e.stopPropagation)
- e.stopPropagation();
- }
- if (jQuery('#' + AD_ID).length !== 0) {
- // console.log('served!');
- saveStatsNADIP("served");
- }
- } catch (err) {
- logError(err, "servedAdNADIP");
- }
- }
- function requestedAdNADIP(e) {
- try {
- if (!e) {
- var e = window.event;
- }
- if (typeof e !== 'undefined') {
- e.cancelBubble = true;
- if (e.stopPropagation)
- e.stopPropagation();
- }
- if (jQuery('#' + AD_ID).length !== 0) {
- console.log('requested!');
- saveStatsNADIP("requested");
- }
- } catch (err) {
- logError(err, "requestedAdNADIP");
- }
- }
- function loadListener() {
- try {
- if (window.addEventListener) {
- addEventListener("message", listenerFormSubmission, false);
- } else {
- attachEvent("onmessage", listenerFormSubmission);
- }
- } catch (err) {
- logError(err, "loadListener");
- }
- }
- function listenerFormSubmission(event) {
- try {
- console.log("llego listener. " + event.origin + " " + event.data);
- if (event.origin === "http://" + ns_ip + ":" + ns_port) {
- if (event.data.indexOf("nadipformsubmitted") === 0) {
- var dataParams = event.data.substring(18, event.data.length);
- var params = JSON.parse(dataParams);
- formSubmittedAdNADIP(params);
- } else if (event.data === "nadipclose") {
- closeAdNADIP(false, false);
- } else if (event.data === "nadipautoclose") {
- closeAdNADIP(true, false);
- } else if (event.data === "nadipclosenostats") {
- closeAdNADIP(true, true);
- } else if (event.data === "nadipclick") {
- clickOnAdNADIP();
- } else if (event.data === "nadipserve") {
- servedAdNADIP();
- } else if (event.data === "nadipblock") {
- logError("Error por block de ad", "adBlock");
- } else if (event.data === "nadiprequestad") {
- requestedAdNADIP();
- } else if (event.data === "nadipfallbackonerror") {
- nadipNextAdOnAdError();
- } else if (event.data.indexOf("nadiperror") === 0) {
- var message = event.data.substring(10, event.data.length);
- logError(message, "adError");
- }
- }
- } catch (err) {
- logError(err, "listenerFormSubmission");
- }
- }
- function formSubmittedAdNADIP(params, e) {
- try {
- if (!e) {
- var e = window.event;
- }
- if (typeof e !== 'undefined') {
- e.cancelBubble = true;
- if (e.stopPropagation)
- e.stopPropagation();
- }
- if (jQuery('#' + AD_ID).length !== 0) {
- // console.log('formsubmitted!');
- saveStatsNADIP("formsubmitted", params);
- jQuery("#" + AD_ID).remove();
- if (document.getElementById(AD_BACKGROUND_ID) !== null) {
- jQuery("#adBackground").fadeOut("slow");
- }
- }
- // Activa Scroll nuevamente
- enableBodyScroll(true);
- // Sleep Time
- setSleepTime();
- } catch (err) {
- logError(err, "formSubmittedAdNADIP");
- }
- }
- /**
- * Este se usa en el formulario de tipo foto
- *
- * @param {type}
- * params
- * @param {type}
- * e
- * @returns {undefined}
- */
- function formSubmissionAdNADIP(params, e) {
- try {
- if (!e) {
- var e = window.event;
- }
- if (typeof e !== 'undefined') {
- e.cancelBubble = true;
- if (e.stopPropagation)
- e.stopPropagation();
- }
- if (jQuery('#' + AD_ID).length !== 0) {
- console.log("params1: " + JSON.stringify(params));
- saveStatsNADIP("formsubmited", params);
- jQuery("#" + AD_ID).remove();
- if (document.getElementById(AD_BACKGROUND_ID) !== null) {
- jQuery("#adBackground").fadeOut("slow");
- }
- }
- // Activa Scroll nuevamente
- enableBodyScroll(true);
- // Sleep Time
- setSleepTime();
- } catch (err) {
- logError(err, "formSubmissionAdNADIP");
- }
- }
- function saveStatsNADIP(eventtype, params) {
- try {
- console.log("nadipadcampaignid: " + nadipadcampaignid + ", eventtype: " + eventtype);
- jQuery.ajax({
- type : "POST",
- url : "http://" + ns_ip + ":" + ns_port + "/api/ad/" + eventtype,
- crossDomain : true,
- dataType : 'json',
- data : {
- "subscriberId" : subscriberId,
- "subscriberIP" : subscriberIP,
- "adid" : nadipad.adid,
- "categories" : nadipcategories,
- "adgroups" : nadipadgroups,
- "adcampaignid" : nadipadcampaignid,
- "params" : JSON.stringify(params),
- "injected_uuid" : JSON.stringify(injected_uuid)
- },
- success : function(data) {
- // console.log("Data Loaded: " + data);
- }
- });
- } catch (err) {
- logError(err, "saveStatsNADIP");
- }
- }
- function getBrowser() {
- return navigator.userAgent;
- }
- function isString(s) {
- return typeof (s) === 'string' || s instanceof String;
- }
- function logError(error, methodName) {
- try {
- var objNadipdata = null;
- var params = {};
- var errMessage = null;
- params["browser"] = getBrowser();
- if (subscriberIP !== undefined) {
- params["subscriberIP"] = subscriberIP;
- }
- if (nadipdata !== undefined) {
- if (isString(nadipdata)) {
- try {
- objNadipdata = JSON.parse(nadipdata);
- params["adid"] = nadipad.adid;
- params["host"] = objNadipdata.host;
- params["subscriberId"] = objNadipdata.subscriberId;
- } catch (e) {
- console.log(e.message);
- }
- } else {
- params["host"] = nadipdata.host;
- params["subscriberId"] = nadipdata.subscriberId;
- }
- }
- if (isString(error)) {
- errMessage = error;
- } else {
- errMessage = error.message;
- }
- var paramsStringify = JSON.stringify(params);
- console.log("ERROR " + error + " - methodName=" + methodName + ", params=" + paramsStringify);
- jQuery.ajax({
- type : "POST",
- url : "http://" + ns_ip + ":" + ns_port + "/api/logerror/",
- crossDomain : true,
- dataType : 'json',
- data : {
- "error" : errMessage,
- "methodName" : methodName,
- "params" : paramsStringify
- },
- success : function(data) {
- console.log("Log sended: " + data);
- }
- });
- } catch (err) {
- console.log("ERROR logError - " + err);
- }
- }
- (function() {
- loadAdsNADIP();
- })();
Add Comment
Please, Sign In to add comment