
var bm = bm || {}; // get the apps namespace

bm.replaceSvg = (function ($) {

    var collectSvg = function(){
        $('svg.js-svg-replace[data-src]').each(function(){
            var $self = $(this);
                $self.removeClass('js-svg-replace');
            var classes = $self.attr('class');
            var url = $(this).data('src');
            $.get(url)
                .done(function(data){
                    var content = $(data).find('svg');
                    $(content).attr('class', classes);
                    $self.replaceWith(content);
                });
        });
    }
    return {
        replace:collectSvg
    }


}(jQuery));


(function($){
    $(document).ready(function(){
        bm.replaceSvg.replace();
    });

    $(window).on('content.changed',function(){
        bm.replaceSvg.replace();
    });
    $('body').on('changedContent',function(){
        bm.replaceSvg.replace();
    });

    $('body').on('openLightbox', function () {
        bm.replaceSvg.replace();
    });
})(jQuery);
