function uuid4() { var uuid = "", i, random; for (i = 0; i < 32; i++) { random = Math.random() * 16 | 0; if (i == 8 || i == 12 || i == 16 || i == 20) { uuid += "-"; } uuid += (i == 12 ? 4 : (i == 16 ? (random & 3 | 8) : random)).toString(16); } return uuid; } function get_id($el) { var id = $el.attr('id'); if (id == undefined) { id = uuid4(); $el.attr('id', id); } return id; } function get_data($el, name) { try { if (name == undefined) { name = 'data'; } if (!$el.data(name)){ $el.data(name, $.parseJSON(decodeURIComponent($el.data(name + '_')))); } return $el.data(name); } catch(e) { return undefined; } } function cropText(text, length, replaceby) { replaceby = typeof(replaceby) != undefined ? replaceby : '...'; if (text.length > length) { text = text.slice(0, length - replaceby.length); text += replaceby; } return text; } function textLimiter(field, countfield, limit) { if (field.val().length > limit) { field.val(field.val().substring(0, limit)); } else { countfield.html(limit - field.val().length); } } function init_formfields_richtext() { $('form.form .formfield-richtext textarea').tinymce({ script_url: '//' + cdnhost + '/libs/tinymce/current/tinymce.min.js', theme: 'modern', language: {'ger': 'de', 'eng': 'en', 'fra': 'fr', 'ita': 'it'}[lang], resize: 'both', tabfocus_elements: ':prev,:next', add_unload_trigger: true, entity_encoding: 'raw', plugins: [ "autolink lists link charmap preview hr searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking table contextmenu directionality paste" ], statusbar: true, menubar: false, toolbar1: 'undo redo | cut copy paste searchreplace | visualblocks visualchars | code preview fullscreen', toolbar2: 'styleselect | bullist numlist table | blockquote subscript superscript hr charmap', toolbar3: 'removeformat | bold italic underline strikethrough | alignleft aligncenter alignright alignjustify', fix_list_elements: true, visual: true, browser_spellcheck: true, convert_urls: false, relative_urls: false, object_resizing: false, style_formats: [ {title: 'Headers', items: [ {title: 'Header 1', format: 'h1'}, {title: 'Header 2', format: 'h2'}, {title: 'Header 3', format: 'h3'}, {title: 'Header 4', format: 'h4'}, {title: 'Header 5', format: 'h5'}, {title: 'Header 6', format: 'h6'} ]}, {title: 'Blocks', items: [ {title: 'Paragraph', format: 'p'}, {title: 'Blockquote', format: 'blockquote'}, {title: 'Div', format: 'div'}, {title: 'Pre', format: 'pre'} ]} ], formats: { alignleft: {selector: '*', classes: 'left'}, alignright: {selector: '*', classes: 'right'}, aligncenter: {selector: '*', classes: 'center'}, alignjustify: {selector: '*', classes: 'justify'}, underline: {inline: 'ins'}, strikethrough: {inline: 'del'} } }); } function init_formfields() { $('body').delegate('form.form input, form.form select, form.form textarea, form.form button', 'mouseenter', function() { $(this).addClass('hover'); }); $('body').delegate('form.form input, form.form select, form.form textarea, form.form button', 'mouseleave', function() { $(this).removeClass('hover'); }); $('body').delegate('form.form input, form.form select, form.form textarea, form.form button', 'focus', function() { $(this).addClass('focus'); }); $('body').delegate('form.form input, form.form select, form.form textarea, form.form button', 'blur', function() { $(this).removeClass('focus'); }); $('body').delegate('div.formfield-input-checkbox input', 'change', function() { var container = $(this).parentsUntil('div.formfield').parent(); if ($(this).is(':checked')) { container.addClass('active'); } else { container.removeClass('active'); } }); $('div.formfield-input-checkbox').each(function() { if ($('input', $(this)).is(':checked')) { $(this).addClass('active'); } else { $(this).removeClass('active'); } }); $('body').delegate('div.formfield-input-radio input', 'change', function() { $this = $(this); var $listcontainer = $this.parentsUntil('fieldset.formradiolist').parent(); $('div.formfield-input-radio', $listcontainer).removeClass('active'); if ($this.is(':checked')) { $this.parentsUntil('div.formfield').parent().addClass('active'); } }); $('fieldset.formradiolist').each(function() { $listcontainer = $(this); $formfields = $('div.formfield-input-radio', $listcontainer); $formfields.removeClass('active'); $formfields.each(function() { var $formfield = $(this); var $input = $('input', $formfield); if ($input.is(':checked')) { $formfield.addClass('active'); } }); }); $('fieldset.formfieldset.activate_fields_if').each(function() { var $fieldset = $(this); var conditions = get_data($fieldset)['activate_fields_if']; var $form = $fieldset.parents('form'); var form_name = $form.attr('name'); check_fieldset_conditions($fieldset); $.each(conditions, function(index, condition) { name = condition[0]; var $field = $('input, select, textarea', $form).filter('[name="' + form_name + '_' + name + '"]'); $field.on('change', function(event) { check_fieldset_conditions($fieldset); }); }); }); init_formfields_richtext(); } function check_fieldset_conditions($fieldset) { var conditions = get_data($fieldset)['activate_fields_if']; var $form = $fieldset.parents('form'); var form_name = $form.attr('name'); var $innercontent = $('> .innercontent', $fieldset); var show = true; $.each(conditions, function(index, condition) { name = condition[0]; value = condition[1]; var $field = $('input, select, textarea', $form).filter('[name="' + form_name + '_' + name + '"]'); if ($field.is(':radio')) { $field = $field.filter(':checked'); } if (value != $field.val()) { show = false; } }); if (show) { $innercontent.show(); } else { $innercontent.hide(); } } function init_formbuttons() { $('form.form button').click(function() { $(this).val($(this).attr('name')); }); } function init_gallery() { if ($.fancybox != undefined) { $('.ZMSCustom-gallery').each(function() { var $gallery = $(this); var $galleryItems = $('.ZMSCustom-gallery_item', $gallery).attr('data-fancybox', $gallery.data('id')); $galleryItems.fancybox({ buttons: ["zoom", "slideShow", "fullScreen", "thumbs", "close"], }); }); $('.ZMSCustom-graphic a.btn_zoom').fancybox(); } } function init_tooltip_links() { $('body').delegate('a.tooltip-link', 'click', function(event) { event.preventDefault(); }); $('body').delegate('a.tooltip-link', 'mouseenter', function() { $(this).qtip({ overwrite: true, content: { text: function() { var returnvalue = $($(this).attr('href')).clone(); returnvalue.removeClass('tooltip-target'); returnvalue.removeClass('ZMSCustom-contentbox-main-tooltip-target'); return returnvalue; } }, hide: { fixed: true }, show: { ready: true }, position: { target: 'mouse', adjust: { mouse: false, x: 10 } }, style: { classes: 'qtip--target' } }); }); } function init_form_cookification() { $.fn['cookifyFormfield'] = function(form_id) { form_cookie = Cookies.getJSON(form_id); if (!form_cookie) { form_cookie = {} } return this.each(function() { var $this = $(this), name = $this.attr('id'), value; if ($this.is( ':checkbox, :radio' )) { if($this.attr('checked')) { value = $this.val(); } } else if ($this.is(':input')) { value = $this.val(); } else { value = $this.html(); } if( typeof value !== 'string' || value === '' ) { value = null; } form_cookie[name] = value; Cookies.set(form_id, form_cookie); }); } cookieFillform = function(form_id) { form_cookie = Cookies.getJSON(form_id); if (form_cookie) { $.each(form_cookie, function(key, value) { $field = $('#' + key); if (value !== null) { if ($field.is(':checkbox, :radio')) { if ($field.val() === value) { $field.attr('checked', 'checked'); var container = $field.parentsUntil('div.formfield-input-checkbox').parent(); container.addClass('active'); } else { $field.removeAttr('checked'); } } else if ($field.is(':input')) { $field.val(value); } else { $field.html(value); } } }); } } } function init_extern_layout_urls() { var $links = $('a'); $.each(extern_layout_urls, function(index, value) { $links.filter('[href^="' + value + '"]').each(function() { var $this = $(this); $this.attr('href', ZMS_ROOT + '/extern_' + lang + '.html?src=' + encodeURIComponent($this.attr('href'))); }); }); } function handle_title_tooltips(selectors) { $('body').delegate(selectors, 'mouseenter', function(event) { event.preventDefault(); try { $(this).data('qtip').show(); } catch(e) { $(this).qtip({ overwrite: true, show: { ready: true }, position: { my: 'bottom left', at: 'top center', viewport: $(window) }, style: { classes: 'qtip-rounded qtip--title', tip: true } }); } }); } $(function() { location_uri = new URI(); location_hash = location_uri.hash(); location_fragment = location_uri.fragment(); $window = $(window); $document = $(document); $html = $('html'); $body = $('body'); if (bowser.msie) { $html.addClass('bowser-msie'); if (!$html.hasClass('msie')) { $html.addClass('msie'); } } init_form_cookification(); init_formfields(); init_formbuttons(); init_gallery(); init_tooltip_links(); init_extern_layout_urls(); }); function init_header_promotion() { var $header_promotion = $('#header_promotion'); if ($header_promotion.length > 0) { var data = get_data($header_promotion); var variant = data['variant']; if ($body.hasClass('header_promotion-below-navbar')) { var $navbar = $('#navbar'); $window.resize(function(event) { var navbar_height = $navbar.height(); $header_promotion.css({ 'top': -navbar_height, 'margin-bottom': -navbar_height }); }).resize(); } if (variant == 'carousel') { var $carousel = $('> .objects', $header_promotion); var $targets = $('.header_promotion_target', $carousel); var $first_target = $targets.first(); var $play = $('.carousel-play', $carousel); var $pause = $('.carousel-pause', $carousel); $play.on('click', function() { if (!$play.hasClass('active')) { $carousel.carousel('cycle'); $play.addClass('active'); $pause.removeClass('active'); } }); $pause.on('click', function() { if (!$pause.hasClass('active')) { $carousel.carousel('pause'); $play.removeClass('active'); $pause.addClass('active'); } }); var slid = function($target, first) { var $video = $('video', $target); $video.on('play', function(event) { $carousel.carousel('pause'); }); $video.on('pause', function(event) { $carousel.carousel('cycle'); }); if ($video.length > 0) { var video = $video[0]; video.muted = true; video.currentTime = 0; video.play(); } } $carousel.on('slide.bs.carousel', function (event) { $carousel.removeClass('active-' + event.from).removeClass('active-last').addClass('active-' + event.to); if ($(event.relatedTarget).is(':last-child')) { $carousel.addClass('active-last'); } $('video', $carousel).each(function() { var video = this; video.muted = true; video.currentTime = 0; video.pause(); }).off('play').off('pause'); }); $carousel.on('slid.bs.carousel', function (event) { slid($(event.relatedTarget)); }); slid($first_target, true); } if (variant == 'covers') { var $objects = $('> .objects', $header_promotion); var $targets = $('> .innercontent > *', $objects); $objects.on('click', '.control-prev', function(event) { event.preventDefault(); var $active = $targets.filter('.active'); var $prev = $active.prev(); if ($prev.length > 0) { var $prevAll = $active.prevAll(); if ($prevAll.filter(function() { var $this = $(this); if ($this.css('opacity') != 1) { return true; } }).length > 0) { $active.removeClass('active'); $prev.addClass('active'); } } }); $objects.on('click', '.control-next', function(event) { event.preventDefault(); var $active = $targets.filter('.active'); var $next = $active.next(); if ($next.length > 0) { var $nextAll = $active.nextAll(); if ($nextAll.filter(function() { var $this = $(this); if ($this.css('opacity') != 1) { return true; } }).length > 0) { $active.removeClass('active'); $next.addClass('active'); } } }); } $header_promotion.addClass('loaded'); } } $(function() { init_header_promotion(); });function init_contentbox() { $('body').delegate('a.btn_toggle_text_details', 'click', function(event) { event.preventDefault(); $(this).parentsUntil('.text_details').parent().toggleClass('active'); }); if (document.location.toString().match('#')) { try { var myAnchor = document.location.toString().split('#')[1]; var $myTarget = $('.ZMSCustom-contentbox-main[data-id="' + myAnchor + '"]'); if ($myTarget.length > 0) { $('a.btn_toggle_text_details', $myTarget).click(); $('html, body').scrollTop($myTarget.offset().top); } } catch(e) {} } } function init_container() { $('div.ZMSCustom-container-main.limit-contentbox-text').each(function() { try { var $container = $(this); var limit = parseInt($.grep($container.attr('class').split(' '), function(classname) {return classname.startsWith('limit-contentbox-text-')})[0].replace('limit-contentbox-text-', '')); $('div.ZMSCustom-contentbox-main > .text', $container).each(function() { var $this = $(this); var original_content = $this.html(); var ellipsis = '...'; $this.truncate({length: limit, words: true, ellipsis: ellipsis}); if ($this.html() != original_content) { $this.addClass('truncated'); } }); } catch(e) {} }); $('div.ZMSCustom-container-main.link-contentbox div.ZMSCustom-contentbox-main').each(function() { var $this = $(this); if ($('> .link', $this).length <= 0) { var url = $this.data('url'); var link_text = getLangStr('btn_contentbox_link_text', lang); $('> .title > *', $this).wrap(''); $('').appendTo($this); $('.ZMSCustom-graphic-main > *', $this).not('a, .legend').wrap(''); } }); $('div.ZMSCustom-container-main.collapse-content').each(function() { var $container = $(this); var $title = $('> .title', $container); var $collapsable = $('> .innercontent', $container); if ($collapsable.length > 0) { var id = $container.attr('id'); var collapsable_id = id + '-collapsable'; $collapsable.addClass('collapse').attr('id', collapsable_id).on('show.bs.collapse', function() { $container.addClass('collapse-content-active'); }).on('hide.bs.collapse', function() { $container.removeClass('collapse-content-active'); }); $title.attr({ 'data-toggle': 'collapse', 'aria-expanded': 'false', 'data-target': '#' + collapsable_id, 'aria-controls': collapsable_id }); if (location_fragment == id || $container.hasClass('collapse-content-active')) { $collapsable.addClass('show').attr('aria-expanded', 'true'); $title.attr('aria-expanded', 'true') } } }); $window.on('hashchange', function(event) { var location_uri = new URI(); var location_hash = location_uri.hash(); var location_fragment = location_uri.fragment(); var $target = $(location_hash); if ($target.length > 0) { if ($target.is('.ZMSCustom-container.collapse-content')) { $('> .innercontent', $target).collapse('show'); } } }); } function init_slideshow() { $('.ZMSCustom-slideshow-main').each(function() { var $slideshow = $(this); var id = $slideshow.attr('id'); var data = get_data($slideshow); var variant = data['variant']; if (variant == 'carousel') { var $carousel = $('> .objects', $slideshow).attr('id', id + '_carousel').addClass('carousel slide'); var $targets = $('> *', $carousel); $targets.wrapAll('