(function ($) { "use strict"; window.azexo = $.extend({}, window.azexo); var $window = $(window); var $body = $('body'); var $document = $(document); var $page = $('#page').css('visibility', 'hidden'); var $status = $("#status").css('display', 'block'); var $preloader = $("#preloader").css('display', 'block'); $(function () { $preloader.trigger('before-hide'); $page.css('visibility', 'visible'); $status.fadeOut("slow"); $preloader.fadeOut("slow"); }); var windowHeight = $window.height(); $window.on('resize', function () { windowHeight = $window.height(); }); $.fn.parallax = function (xpos, speedFactor, outerHeight) { var $this = $(this); var getHeight; var firstTop; var paddingTop = 0; $this.each(function () { firstTop = $this.offset().top; }); if (outerHeight) { getHeight = function (jqo) { return jqo.outerHeight(true); }; } else { getHeight = function (jqo) { return jqo.height(); }; } if (arguments.length < 1 || xpos === null) { xpos = "50%"; } if (arguments.length < 2 || speedFactor === null) { speedFactor = 0.1; } if (arguments.length < 3 || outerHeight === null) { outerHeight = true; } function update() { var pos = $window.scrollTop(); $this.each(function () { var $element = $(this); var top = $element.offset().top; var height = getHeight($element); if (top + height < pos || top > pos + windowHeight) { return; } $this.css('backgroundPosition', xpos + " " + Math.round((firstTop - pos) * speedFactor) + "px"); }); } $window.on('scroll', update); $window.on('resize', update); update(); }; $.fn.equalizeHeights = function () { var max = Math.max.apply(this, $(this).map(function (i, e) { return $(e).height(); }).get()); if (max > 0) this.height(max); return max; }; $.fn.equalizeWidths = function () { var max = Math.max.apply(this, $(this).map(function (i, e) { return $(e).width(); }).get()); if (max > 0) this.width(max); return max; }; $.fn.marginBackground = function () { var $this = $(this); var $bg = $this.find('> .background'); if ($bg.length === 0) { $bg = $('
').prependTo(this); $this.css('position', 'relative'); $bg.css('position', 'absolute'); $bg.css('top', '0'); $bg.css('bottom', '0'); $bg.css('background-color', $this.css('background-color')); $this.css('background-color', ''); $bg.css('background-image', $this.css('background-image')); $this.css('background-image', ''); } var m = ($this.parent().width() - $this.width()) / 2; $bg.css('left', '-' + m + 'px'); $bg.css('right', '-' + m + 'px'); }; $.fn.hierarchicalSelect = function () { $(this).each(function () { function create_select(before, node, level) { if (node) { $base_select.val(node.value); } else { $base_select.val(''); return false; } if (node.children.length === 0) return false; var $select = $('').insertAfter(before); if (placeholders) $select.append(''); $(node.children).each(function () { $('').appendTo($select).data('node', this); }); $select.data('after', false); $select.on('change', function () { var $this = $(this); function remove_after(after) { if (after) { remove_after($(after).data('after')); if ('select2' in $.fn && $base_select.is('.select2')) { $(after).select2('destroy'); } $(after).remove(); } } remove_after($this.data('after')); var after = create_select($this, $this.find(":selected").data('node'), level + 1); $this.data('after', after); }); if ('select2' in $.fn && $base_select.is('.select2')) { $select.select2(); } return $select; } var $base_select = $(this); $base_select.hide(); var placeholders = false; if ($base_select.data('placeholders')) { placeholders = $base_select.data('placeholders').split('|'); } else { if ($base_select.find('option[value=""]')) placeholders = $base_select.find('option[value=""]').text().split('|'); } var tree = {value: '', label: '', children: []}; var path = [tree]; var selected_path = false; var current_level = 0; $base_select.find('option').each(function () { var $this = $(this); if ($this.val() !== '') { var level = 0; if (($this.text().match(/^-+/g) || []).length) { level = ($this.text().match(/^-+/g) || [])[0].length; } var node = {value: $this.val(), label: $this.text().replace(/^-+/g, ''), children: []}; if (level > current_level) { path.push(path[current_level].children[path[current_level].children.length - 1]); current_level = level; } if (level < current_level) { path.pop(); current_level = level; } path[current_level].children.push(node); if ($this.is(':selected')) { selected_path = path.slice(0); selected_path.push(selected_path[current_level].children[selected_path[current_level].children.length - 1]); selected_path.shift(); } } }); var root_select = create_select($base_select, tree, 0); if (selected_path) { var $select = root_select; $(selected_path).each(function () { if ($select) { $select.val(this.value).change(); } $select = $select.data('after'); }); } }); }; window.azexo.getParameterByName = function (name, url) { if (!url) url = window.location.href; name = name.replace(/[\[\]]/g, "\\$&"); var regex = new RegExp("[?&]" + name + "(=([^]*)|&|#|$)"), results = regex.exec(url); if (!results) return null; if (!results[2]) return ''; return decodeURIComponent(results[2].replace(/\+/g, " ")); }; function common_ancestor(jq) { var prnt = $(jq[0]); jq.each(function () { prnt = prnt.parents().add(prnt).has(this).last(); }); return prnt; } $.fn.horizontal_menu_more = function (step) { var from = 0; var $items = $(this); if ($items.length > step) { var $ca = common_ancestor($items); var $more_button = $ca.children().last().clone(); if ($more_button.text()) { $more_button.html(''); } $more_button.find('*').each(function () { var $this = $(this); if ($this.text()) { $this.html(''); return false; } }); $more_button.addClass('horizontal-menu-more'); $ca.children().last().after($more_button); $more_button.find('span.fa-bars').on('click', function () { if (from >= $items.length) { from = 0; } var to = from + step; if (to > $items.length) { to = $items.length; } var $visible_items = $($items.slice(from, to)); if ($visible_items.length) { var $hidden_items = $items.not($visible_items); $ca.children().each(function () { var $this = $(this); if ($this.has($visible_items).length || $visible_items.filter($this).length) { $this.show(); } }); $ca.children().each(function () { var $this = $(this); if ($this.has($hidden_items).length || $hidden_items.filter($this).length) { $this.hide(); } }); from = from + step; } return false; }).trigger('click'); } }; function makeid() { var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for (var i = 0; i < 5; i++) text += possible.charAt(Math.floor(Math.random() * possible.length)); return text; } function initGallery() { if ('magnificPopup' in $) { $('.gallery').each(function () { var $gallery = $(this); $gallery.find('.gallery-item a').on('click', function (event) { event.preventDefault(); }); $gallery.find('.gallery-item').on('click', function () { var gallery_items = $.makeArray($gallery.find('.gallery-item').map(function () { return {src: $(this).find('img').attr('src')}; })); if (gallery_items.length > 0) { $.magnificPopup.open({ items: gallery_items, gallery: { enabled: true }, type: 'image' }, $(this).closest('.gallery-item').index()); } else { $.magnificPopup.open({ items: { src: $(this).find('img').attr('src') }, type: 'image' }); } }); }); } } function initEntryGallery() { if ('flexslider' in $.fn) { $('.entry-gallery .images:not(.carousel):not(.thumbnails), .header-gallery .images:not(.carousel):not(.thumbnails)').each(function () { var $gallery = $(this); if ($gallery.data('flexslider') === undefined) { if ($gallery.find('.image').length > 1) { $gallery.flexslider({ selector: '.image', smoothHeight: true, prevText: '', nextText: '', touch: true, pauseOnHover: true, mousewheel: false, controlNav: false }).show(); } } }); $('.entry-gallery .images:not(.carousel).thumbnails, .header-gallery .images:not(.carousel).thumbnails').each(function () { function unique_id() { return Math.round(new Date().getTime() + (Math.random() * 100)); } var $gallery = $(this); if ($gallery.data('flexslider') === undefined) { if ($gallery.find('.image').length > 1) { $gallery.attr('id', unique_id()); var $thumbnails = $('').append('').insertAfter($gallery); $gallery.find('.image').each(function () { $(this).clone().removeClass('zoom').appendTo($('').appendTo($thumbnails.find('.slides'))); }); var itemWidth = parseInt($thumbnails.find('ul.slides li').css('width'), 10); if (!itemWidth) { itemWidth = 150; } var itemHeight = parseInt($thumbnails.find('ul.slides li').css('height'), 10); if (!itemHeight) { itemHeight = 150; } $thumbnails.flexslider({ prevText: '', nextText: '', animation: "slide", controlNav: false, animationLoop: false, pauseOnHover: true, slideshow: false, itemWidth: itemWidth, itemHeight: itemHeight, direction: $gallery.data('vertical') ? 'vertical' : 'horizontal', touch: true, mousewheel: false, asNavFor: '#' + $gallery.attr('id') }); $gallery.flexslider({ selector: '.image', smoothHeight: true, prevText: '', nextText: '', touch: true, pauseOnHover: true, mousewheel: false, controlNav: false, sync: '#' + $gallery.attr('id') + '-thumbnails' }).show(); } } }); } if ('owlCarousel' in $.fn) { $('.entry-gallery .images.carousel, .header-gallery .images.carousel').each(function () { var $carousel = $(this); $carousel.data('center', 'yes'); $carousel.data('loop', 'yes'); initCarousel($carousel); if ('magnificPopup' in $) { var isDragging = false; $carousel.find('.image[data-popup]:not([data-popup=""])').on('mousedown', function () { $window.on('mousemove.popup', function () { isDragging = true; $window.off('mousemove.popup'); }); }).on('mouseup', function () { var wasDragging = isDragging; isDragging = false; $window.off('mousemove.popup'); if (!wasDragging) { var gallery = $.makeArray($carousel.find('.owl-item:not(.cloned) .image[data-popup]:not([data-popup=""])').map(function () { return {src: $(this).data('popup')}; })); if (gallery.length > 0) { var owlCarousel = $carousel.data('owlCarousel'); $.magnificPopup.open({ items: gallery, gallery: { enabled: true }, type: 'image' }, owlCarousel.relative($(this).closest('.owl-item').index())); } else { $.magnificPopup.open({ items: { src: $(this).data('popup') }, type: 'image' }); } } }); } }); } } function initCarousel($carousel) { function show($carousel) { if ($carousel.data('owlCarousel') === undefined) { while ($carousel.find('> div:not(.item)').length) { $carousel.find('> div:not(.item)').slice(0, contents_per_item).wrapAll(''); } $carousel.show(); if (width === '') width = $carousel.width(); var items = Math.round(($carousel.width() + margin) / (width + margin)); if (items === 0 || full_width) { items = 1; } if (lazy && (contents_per_item === 1) && ($carousel.find('.item').length >= items)) { $carousel.find('.item .image.lazy').each(function () { $(this).removeClass('lazy'); $(this).addClass('owl-lazy'); }); } var options = { items: items, dotsEach: items, responsive: {}, smartSpeed: 500, center: ($carousel.data('center') === 'yes'), loop: ($carousel.data('loop') === 'yes') && ($carousel.find('.item').length > items), autoplay: true, autoplayTimeout: 8000, lazyLoad: lazy && (contents_per_item === 1) && ($carousel.find('.item').length >= items), autoplayHoverPause: true, nav: true, dots: true, navText: ['', ''] }; if (margin > 0) { options.margin = margin; } if (stagePadding > 0) { options.stagePadding = stagePadding; } try { $carousel.owlCarousel(options).on('translated.owl.carousel', function (event) { try { BackgroundCheck.refresh($carousel.find('.owl-controls .owl-prev, .owl-controls .owl-next')); } catch (e) { } }); } catch (e) { } $carousel.find('.item').equalizeHeights(); var height = $carousel.find('.owl-item').height(); $carousel.find('.owl-stage').css('height', height + 'px'); try { BackgroundCheck.init({ targets: $carousel.find('.owl-controls .owl-prev, .owl-controls .owl-next'), images: $carousel.find('.item .image') }); } catch (e) { } } } function is_visible($carousel) { var visible = true; $carousel.parents().each(function () { var parent = this; if ($(parent).css('display') === 'none' && visible) { visible = false; } }); return visible; } if ($carousel.find('> div').length > 0) { var width = $carousel.data('width') ? $carousel.data('width') : ''; var height = $carousel.data('height') ? $carousel.data('height') : ''; var margin = isNaN(parseInt($carousel.data('margin'), 10)) ? 0 : parseInt($carousel.data('margin'), 10); var stagePadding = isNaN(parseInt($carousel.data('stagePadding'), 10)) ? 0 : parseInt($carousel.data('stagePadding'), 10); var full_width = $carousel.data('full-width') === 'yes'; var contents_per_item = $carousel.data('contents-per-item') ? $carousel.data('contents-per-item') : 1; if (!$carousel.data('entries')) { $carousel.data('entries', $carousel.find('> div')); } var lazy = ($carousel.find('.image.lazy').length > 0); if (typeof width !== typeof undefined && width !== false && typeof height !== typeof undefined && height !== false) { if (height !== '') { $carousel.find('.item .image').each(function () { $(this).height(height); }); } if (is_visible($carousel)) { show($carousel); } else { $document.on('click.azexo', function () { if ($carousel.data('owlCarousel') === undefined) { if (is_visible($carousel)) { show($carousel); } } }); } } return show; } return false; } function initAZEXOPostList() { if ('owlCarousel' in $.fn) { $window.on('resize', function () { $('.owl-carousel.posts-list').each(function () { var $carousel = $(this); if ($carousel.data('owlCarousel') !== undefined) { var owl = $carousel.data('owlCarousel'); var width = $carousel.data('width') ? $carousel.data('width') : ''; var full_width = $carousel.data('full-width') === 'yes'; if (width === '') width = $carousel.width(); var responsive = (owl.options.responsive ? owl.options.responsive : {}); var items = Math.round(($carousel.width() + owl.options.margin) / (width + owl.options.margin)); if (items === 0 || full_width) { items = 1; } responsive[$window.width()] = { items: items }; owl.options.responsive = responsive; $carousel.find('.item').css('height', ''); $carousel.find('.owl-stage').css('height', ''); owl.refresh(); setTimeout(function () { owl.refresh(); $carousel.find('.item').equalizeHeights(); owl.refresh(); }); } }); }); $('.owl-carousel.posts-list').each(function () { var $carousel = $(this); var show = initCarousel($carousel); if (show !== false) { $carousel.closest('.posts-list-wrapper').find('> .list-header > .list-filter > .filter-term').off('click.posts-list-carousel').on('click.posts-list-carousel', function () { if ($carousel.data('owlCarousel') !== undefined) { $carousel.data('owlCarousel').destroy(); $($carousel.data('entries')).detach(); $carousel.empty(); $carousel.append($carousel.data('entries')); if ($(this).data('term')) { $carousel.find('.filterable:not(.' + $(this).data('term') + ')').detach(); } show($carousel); } }); } }); } $('.posts-list-wrapper .list-filter .filter-term').each(function () { var $this = $(this); $this.data('posts-list-wrapper', $this.closest('.posts-list-wrapper')); $this.off('click.posts-list').on('click.posts-list', function () { var $this = $(this); $this.closest('.list-filter').find('.filter-term').removeClass('active'); $this.addClass('active'); if ($this.data('term')) { $this.data('posts-list-wrapper').find('> .posts-list .filterable.' + $this.data('term')).addClass('showed'); $this.data('posts-list-wrapper').find('> .posts-list .filterable:not(.' + $this.data('term') + ')').removeClass('showed'); } else { $this.data('posts-list-wrapper').find('> .posts-list .filterable').addClass('showed'); } $this.data('posts-list-wrapper').find('> .posts-list .filterable').removeClass('even').removeClass('odd'); $this.data('posts-list-wrapper').find('> .posts-list .filterable.showed:even').addClass('even'); $this.data('posts-list-wrapper').find('> .posts-list .filterable.showed:odd').addClass('odd'); }); }); $('.posts-list-wrapper .list-filter').addClass('filtering'); $('.posts-list-wrapper > .posts-list .filterable').addClass('showed'); $('.posts-list-wrapper > .posts-list .filterable:even').addClass('even'); $('.posts-list-wrapper > .posts-list .filterable:odd').addClass('odd'); $('.azexo-posts-list-filters').each(function () { var $this = $(this); var filters = $('.posts-list-wrapper .list-filter'); if (filters.length > 0 && $this.children().length === 0) { filters.detach(); $this.append(filters); } }); $('.azexo-posts-list-groups').each(function () { $(this).empty(); var groups_menu = $('').appendTo(this); $('.posts-list-wrapper .list-group').each(function () { var $this = $(this); var id = $this.find('[type="checkbox"]').attr('id'); var header = $this.find('.group-header h4').text(); $('