
jQuery(document).ready(function(){

    var $modal = jQuery('#iframeModal');
    var $iframe = jQuery('#iframeModalIframe');

    $modal.on('hidden.bs.modal', function (e) {
        $iframe.attr('src', '');
    });

    $iframe.iFrameResize({
        //log: true,
        onMessage: function(data){
            if(data.message === 'iframeModal.close'){
                $modal.modal('hide');
            }
            if(data.message === 'iframeModal.reload'){
                //location.reload(true);
                window.location.href = window.location.href;
            }
            if(data.message === 'iframeModal.contentLoaded'){
                $modal.animate({ scrollTop: 0 }, 'slow');
                $modal.modal('handleUpdate');
            }
        }
    });

    jQuery('.link-iframemodal-open').each(function(){
        jQuery(this).click(function(){
            var $self = jQuery(this);
            var src = $self.attr('href');
            $iframe.attr('src', src);
            $modal.modal('show');
            return false;
        });
    });

});