|
if (typeof jQuery === "undefined" || jQuery.fn.jquery !== '1.7.1') { |
|
var script_tag = document.createElement('script'); |
|
script_tag.setAttribute("type","text/javascript"); |
|
script_tag.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"); |
|
script_tag.onload = ml_load_libs; |
|
script_tag.onreadystatechange = function () { |
|
if (this.readyState == 'complete' || this.readyState == 'loaded') ml_load_libs(); |
|
} |
|
document.getElementsByTagName("head")[0].appendChild(script_tag); |
|
} else { |
|
ml_load_libs(); |
|
} |
|
|
|
function ml_load_libs() { |
|
var libs = false; |
|
|
|
if (libs) { |
|
for (var i in libs) |
|
{ |
|
var script_tag = document.createElement('script'); |
|
script_tag.setAttribute("type","text/javascript"); |
|
script_tag.setAttribute("src", libs[i]); |
|
|
|
if (i == libs.length-1) { |
|
script_tag.onload = ml_webform_button; |
|
script_tag.onreadystatechange = function () { |
|
if (this.readyState == 'complete' || this.readyState == 'loaded') ml_webform_button(); |
|
} |
|
} |
|
document.getElementsByTagName("head")[0].appendChild(script_tag); |
|
} |
|
} else { |
|
ml_webform_button(); |
|
} |
|
} |
|
|
|
|
|
function ml_webform_button() { |
|
|
|
// $(document).ready(function(){ |
|
|
|
|
|
jQuery('.ml-subscribe-button').each(function(){ |
|
|
|
var $button = jQuery(this); |
|
var $form = jQuery(this).closest('form'); |
|
|
|
//patikriname ar dar neuzbindintas submitas, jei kelis kartus itrauktas sitas JS |
|
if ($button.data('ml-click-bound') === undefined || !$button.data('ml-click-bound')) { |
|
$button.data('ml-click-bound', 1); |
|
|
|
var code = $form.data('code'); |
|
if ( !$('#ml-iframe-' + code).length ) { |
|
var iframe_src = $form.attr('action'); |
|
var $iframe = $('<iframe frameborder="0" allowtransparency="true" id="ml-iframe-' + code + '" class="ml-button-iframe" src="' + iframe_src + '">'); |
|
$iframe.appendTo('body'); |
|
} |
|
var $iframe = $('#ml-iframe-' + code); |
|
|
|
|
|
$button.bind('click', function(e){ |
|
e.preventDefault(); |
|
mlShowIframe($iframe); |
|
}); |
|
} |
|
|
|
}); |
|
// }); |
|
} |
|
|
|
window.addEventListener("message", receiveMessage, false); |
|
|
|
function receiveMessage(event) |
|
{ |
|
//TODO: check event.origin |
|
var message_parts = event.data.split('-'); |
|
if (message_parts.length > 1) { |
|
if (message_parts[0] == 'mlCloseIframe') { |
|
var code = message_parts[1]; |
|
mlHideIframe($('#ml-iframe-' + code)); |
|
} |
|
} |
|
} |
|
|
|
function mlShowIframe($iframe) { |
|
$iframe.fadeIn(200); |
|
} |
|
|
|
function mlHideIframe($iframe) { |
|
$iframe.fadeOut(200); |
|
} |