Показать сообщение отдельно
  #2 (permalink)  
Старый 15.08.2014, 16:51
Интересующийся
Отправить личное сообщение для arsen97 Посмотреть профиль Найти все сообщения от arsen97
 
Регистрация: 02.08.2014
Сообщений: 15

function createWrapper(source) {
        var wrapperElement = document.createElement('iframe');
        wrapperElement.src = source;
        wrapperElement.style.border = '0px';
        wrapperElement.style.margin = '0px';
        wrapperElement.style.width = width + 'px';
        wrapperElement.style.height = height + 'px';
        wrapperElement.style.overflow = 'hidden';
        wrapperElement.scrolling = 'no';
        wrapperElement.frameBorder = '0';
        wrapperElement.marginWidth = '0';
        wrapperElement.marginHeight = '0';
        return wrapperElement;
    }
    
    switch (type) {
        case "iframe":
            if (typeof lrCompanionClickThru === 'function') {
                wrapper = createWrapper(content);
            } else {
                companion_html += '<iframe src="' + content + '" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="width: ' + width + 'px; height: ' + height + 'px; border: 0px; margin: 0px;"></iframe>';
            }
            break;
        case "image":
            if (typeof clickthru === 'string' && clickthru.match(/^http(s)?:\/\/t4\.liverail\.com/) !== null) {
                var clickthruRedirect = clickthru.split(/&redirect=/)[1];
                if (typeof clickthruRedirect !== 'string' || clickthruRedirect.length <= 0) {
                    clickthru = null;
                }
            }
            companion_html += (clickthru ? '<a href="' + clickthru + '" target="_blank">' : '') + '<img src="' + content + '" border="0" style="width: ' + width + 'px; height: ' + height + 'px; border: 0px; margin: 0px;" />' + (clickthru ? '</a>' : '');
            break;
        case "flash":
            delimiter = content.indexOf("?") == -1 ? "?" : "&";
            clickTag = (clickthru && content.indexOf("cdn.liverail.com") != -1) ? delimiter + "clickTAG=" + encodeURIComponent(clickthru) : delimiter;
            companion_html += '<object width="' + width + '" height="' + height + '"><param name="movie" value="' + content + clickTag + '"><param name="wmode" value="opaque"><param name="allowScriptAccess" value="always"><embed src="' + content + clickTag + '" type="application/x-shockwave-flash" allowScriptAccess="always" wmode="opaque" width="' + width + '" height="' + height + '"></embed></object>';
            break;
        case "js":
            if (typeof lrCompanionClickThru === 'function') {
                wrapper = createWrapper((window.location.protocol === 'https:' ? 'https://cdn-static-secure' : 'http://cdn-static') + '.liverail.com/js/companion_iframe.html?type=js&content=' + encodeURIComponent(content));
            } else {
                companion_html += '<iframe src="' + (window.location.protocol === 'https:' ? 'https://cdn-static-secure' : 'http://cdn-static') + '.liverail.com/js/companion_iframe.html?type=js&content=' + encodeURIComponent(content) + '" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="width: ' + width + 'px; height: ' + height + 'px; border: 0px; margin: 0px;"></iframe>';
            }
            break;
        default:
            companion_html += content;
    }
    
    fingerprint = {
        type: type,
        width: width,
        height: height,
        companionElement: div_companion
    };

    // Add click event wrapper companion element
    if (typeof lrCompanionClickThru === 'function') {
        if (!wrapper) {
            wrapper = document.createElement('div');
            wrapper.onmouseup = function(event) {
                if (!event) {
                    event = window.event;
                }
                // ingore right-click
                if (event.which === 3 || event.button === 2) {
                    return;
                }
                lrHandleClick(fingerprint);
            };
            wrapper.innerHTML = companion_html;
            div_companion.innerHTML = '';
        } else {
            // Attach click handler to iframes
            function onWrapperLoad() {
                uniqueId = (new Date()).getTime().toString();
                if (wrapper.contentWindow && wrapper.contentWindow.postMessage) {
                    if (content.substr(0, 30) === 'http://cdn-static.liverail.com') {
                        wrapper.contentWindow.postMessage(uniqueId, 'http://cdn-static.liverail.com');
                    } else if (content.substr(0, 38) === 'https://cdn-static-secure.liverail.com') {
                        wrapper.contentWindow.postMessage(uniqueId, 'https://cdn-static-secure.liverail.com');
                    }
                }
            }
            wrapper.onload = function() {
                onWrapperLoad();
            };
            if (typeof wrapper.onload !== 'function') {
                wrapper.onreadystatechange = function() {
                    if (this.readyState === 'loaded' || this.readyState === 'complete') {
                        onWrapperLoad();
                    }
                };
            }
            function handleMessage(event) {
                if (!event) {
                    event = window.event;
                }
                
                if (event.data === uniqueId) {
                    lrHandleClick(fingerprint);
                }
            }
            if (window.addEventListener) {
                window.addEventListener('message', handleMessage, false);
            } else if (window.attachEvent) {
                window.attachEvent('onmessage', handleMessage);
            }
            div_companion.innerHTML = companion_html;
        }
        div_companion.appendChild(wrapper);
    } else {
        div_companion.innerHTML = companion_html;
    }
    
    if (div_default)
        div_default.style.display = "none";
    div_companion.style.display = "block";
    
    lrCompanionDisplayed[size] = true;
    
    return true;
}

///////////////////////////////////////////////////////////////////////////////////////////

function lrClearCompanion(size, force) {
    //
    if (size == "LB")
        size = "728x90";
    if (size == "MR")
        size = "300x250";
    if (size == "SB")
        size = "300x60";
    if (size == "WS")
        size = "160x600";
    //
    
    if (!lrCompanionPurge[size] && !force)
        return false;
    
    var div_companion = document.getElementById("lr_comp_" + size);
    var div_default = document.getElementById("lr_comp_default_" + size);
    
    if (typeof lrCompanionIds[size] !== 'undefined') {
        if (typeof lrCompanionIds[size].companionElement === 'string') {
            div_companion = document.getElementById(lrCompanionIds[size].companionElement);
        }
        if (typeof lrCompanionIds[size].defaultElement === 'string') {
            div_default = document.getElementById(lrCompanionIds[size].defaultElement);
        }
    }
    
    if (!div_companion)
        return false;
    
    switch (typeof lrCompanionPurgeCallback[size]) {
        
        case 'function':
            
            lrCompanionPurgeCallback[size]();
            break;
        
        case 'string':
            
            eval(lrCompanionPurgeCallback[size]);
            break;
    }
    
    if (lrCompanionPurgeDelay[size] > 0) {
        setTimeout("div_companion.style.display = \"none\"; if(div_default) div_default.style.display = \"block\"; lrCompanionDisplayed[size] = false;", lrCompanionPurgeDelay[size] * 1000);
    } else {
        div_companion.style.display = "none";
        if (div_default)
            div_default.style.display = "block";
        
        lrCompanionDisplayed[size] = false;
    }
    
    return true;
}

(function() {
    
    var pageAdSlotStart = function() {
    };
    
    if (typeof window.lrAdSlotStart === 'function') {
        pageAdSlotStart = window.lrAdSlotStart;
    }
    
    window.lrAdSlotStart = function(type) {
        if (type === "ov")
            return false;
        for (size in lrCompanionPurgeNextBreak) {
            if (lrCompanionPurgeNextBreak.hasOwnProperty(size) && lrCompanionPurgeNextBreak[size] && lrCompanionDisplayed[size]) {
                lrClearCompanion(size, true);
            }
        }
        pageAdSlotStart(type);
        return true;
    };
}());

///////////////////////////////////////////////////////////////////////////////////////////

function lrTMACDisplayCompanion(banners) {
    var i, size, hasSize, div_companion;
    
    hasSize = {};
    
    for (i = 0; i < banners.length; i += 1) {
        
        size = banners[i]["size"];
        
        hasSize[size] = [
            banners[i]["width"], 
            banners[i]["height"]
        ];

        // Resolve companion id
        div_companion = "lr_comp_" + size;
        if (lrCompanionIds[size] !== undefined) {
            if (typeof lrCompanionIds[size].companionElement === 'string') {
                div_companion = lrCompanionIds[size].companionElement;
            }
        }
        
        lrDisplayCompanion(size, "plain", "", "", "");
        tmDisplayBanner(banners, div_companion, hasSize[size][0], hasSize[size][1]);
    }
    
    window.lrTMACClearCompanion = function() {
        
        for (size in hasSize) {
            if (hasSize.hasOwnProperty(size)) {
                lrClearCompanion(size);
            }
        }
    };
}

это продолжение..
Ответить с цитированием