/** * Global variables */ "use strict"; var userAgent = navigator.userAgent.toLowerCase(), initialDate = new Date(), $document = $(document), $window = $(window), $html = $("html"), isDesktop = $html.hasClass("desktop"), isIE = userAgent.indexOf("msie") != -1 ? parseInt(userAgent.split("msie")[1]) : userAgent.indexOf("trident") != -1 ? 11 : userAgent.indexOf("edge") != -1 ? 12 : false, isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent), isTouch = "ontouchstart" in window, plugins = { pointerEvents: isIE < 11 ? "js/pointer-events.min.js" : false, smoothScroll: $html.hasClass("use--smoothscroll") ? "js/smoothscroll.min.js" : false, bootstrapTooltip: $("[data-toggle='tooltip']"), bootstrapTabs: $(".tabs"), rdParallax: $(".rd-parallax"), rdAudioPlayer: $(".rd-audio"), rdVideoPlayer: $(".rd-video-player"), responsiveTabs: $(".responsive-tabs"), rdGoogleMaps: $(".rd-google-map"), rdNavbar: $(".rd-navbar"), rdVideoBG: $(".rd-video"), rdRange: $('.rd-range'), textRotator: $(".text-rotator"), owl: $(".owl-carousel"), swiper: $(".swiper-slider"), counter: $(".counter"), flickrfeed: $(".flickr"), twitterfeed: $(".twitter"), progressBar: $(".progress-bar-js"), progressLinear: $(".progress-linear"), isotope: $(".isotope"), countDown: $(".countdown"), calendar: $(".rd-calendar"), facebookfeed: $(".facebook"), instafeed: $(".instafeed"), facebookWidget: $('#fb-root'), materialTabs: $('.rd-material-tabs'), filePicker: $('.rd-file-picker'), fileDrop: $('.rd-file-drop'), popover: $('[data-toggle="popover"]'), dateCountdown: $('.DateCountdown'), statefulButton: $('.btn-stateful'), slick: $('.slick-slider'), scroller: $(".scroll-wrap"), socialite: $(".socialite"), viewAnimate: $('.view-animate'), selectFilter: $("select"), rdInputLabel: $(".form-label"), stacktable: $("[data-responsive=true]"), bootstrapDateTimePicker: $("[data-time-picker]"), customWaypoints: $('[data-custom-scroll-to]'), photoSwipeGallery: $("[data-photo-swipe-item]"), circleProgress: $(".progress-bar-circle"), stepper: $("input[type='number']"), radio: $("input[type='radio']"), checkbox: $("input[type='checkbox']"), customToggle: $("[data-custom-toggle]"), rdMailForm: $(".rd-mailform"), regula: $("[data-constraints]"), search: $(".rd-search"), searchResults: $('.rd-search-results'), imgZoom: $('[mag-thumb]') }; /** * Initialize All Scripts */ $document.ready(function () { /** * getSwiperHeight * @description calculate the height of swiper slider basing on data attr */ function getSwiperHeight(object, attr) { var val = object.attr("data-" + attr), dim; if (!val) { return undefined; } dim = val.match(/(px)|(%)|(vh)$/i); if (dim.length) { switch (dim[0]) { case "px": return parseFloat(val); case "vh": return $(window).height() * (parseFloat(val) / 100); case "%": return object.width() * (parseFloat(val) / 100); } } else { return undefined; } } /** * toggleSwiperInnerVideos * @description toggle swiper videos on active slides */ function toggleSwiperInnerVideos(swiper) { var prevSlide = $(swiper.slides[swiper.previousIndex]), nextSlide = $(swiper.slides[swiper.activeIndex]), videos; prevSlide.find("video").each(function () { this.pause(); }); videos = nextSlide.find("video"); if (videos.length) { videos.get(0).play(); } } /** * toggleSwiperCaptionAnimation * @description toggle swiper animations on active slides */ function toggleSwiperCaptionAnimation(swiper) { var prevSlide = $(swiper.container), nextSlide = $(swiper.slides[swiper.activeIndex]); prevSlide .find("[data-caption-animate]") .each(function () { var $this = $(this); $this .removeClass("animated") .removeClass($this.attr("data-caption-animate")) .addClass("not-animated"); }); nextSlide .find("[data-caption-animate]") .each(function () { var $this = $(this), delay = $this.attr("data-caption-delay"), duration = $this.attr('data-caption-duration'); setTimeout(function () { $this .removeClass("not-animated") .addClass($this.attr("data-caption-animate")) .addClass("animated"); if (duration) { $this.css('animation-duration', duration + 'ms'); } }, delay ? parseInt(delay) : 0); }); } /** * makeParallax * @description create swiper parallax scrolling effect */ function makeParallax(el, speed, wrapper, prevScroll) { var scrollY = window.scrollY || window.pageYOffset; if (prevScroll != scrollY) { prevScroll = scrollY; el.addClass('no-transition'); el[0].style['transform'] = 'translate3d(0,' + -scrollY * (1 - speed) + 'px,0)'; el.height(); el.removeClass('no-transition'); if (el.attr('data-fade') === 'true') { var bound = el[0].getBoundingClientRect(), offsetTop = bound.top * 2 + scrollY, sceneHeight = wrapper.outerHeight(), sceneDevider = wrapper.offset().top + sceneHeight / 2.0, layerDevider = offsetTop + el.outerHeight() / 2.0, pos = sceneHeight / 6.0, opacity; if (sceneDevider + pos > layerDevider && sceneDevider - pos < layerDevider) { el[0].style["opacity"] = 1; } else { if (sceneDevider - pos < layerDevider) { opacity = 1 + ((sceneDevider + pos - layerDevider) / sceneHeight / 3.0 * 5); } else { opacity = 1 - ((sceneDevider - pos - layerDevider) / sceneHeight / 3.0 * 5); } el[0].style["opacity"] = opacity < 0 ? 0 : opacity > 1 ? 1 : opacity.toFixed(2); } } } requestAnimationFrame(function () { makeParallax(el, speed, wrapper, prevScroll); }); } /** * isScrolledIntoView * @description check the element whas been scrolled into the view */ function isScrolledIntoView(elem) { var $window = $(window); return elem.offset().top + elem.outerHeight() >= $window.scrollTop() && elem.offset().top <= $window.scrollTop() + $window.height(); } /** * initOnView * @description calls a function when element has been scrolled into the view */ function lazyInit(element, func) { var $win = jQuery(window); $win.on('load scroll', function () { if ((!element.hasClass('lazy-loaded') && (isScrolledIntoView(element)))) { func.call(); element.addClass('lazy-loaded'); } }); } /** * Live Search * @description create live search results */ function liveSearch(options) { $('#' + options.live).removeClass('cleared').html(); options.current++; options.spin.addClass('loading'); $.get(handler, { s: decodeURI(options.term), liveSearch: options.live, dataType: "html", liveCount: options.liveCount, filter: options.filter, template: options.template }, function (data) { options.processed++; var live = $('#' + options.live); if (options.processed == options.current && !live.hasClass('cleared')) { live.find('> #search-results').removeClass('active'); live.html(data); setTimeout(function () { live.find('> #search-results').addClass('active'); }, 50); } options.spin.parents('.rd-search').find('.input-group-addon').removeClass('loading'); }) } /** * attachFormValidator * @description attach form validation to elements */ function attachFormValidator(elements) { for (var i = 0; i < elements.length; i++) { var o = $(elements[i]), v; o.addClass("form-control-has-validation").after(""); v = o.parent().find(".form-validation"); if (v.is(":last-child")) { o.addClass("form-control-last-child"); } } elements .on('input change propertychange blur', function (e) { var $this = $(this), results; if (e.type != "blur") { if (!$this.parent().hasClass("has-error")) { return; } } if ($this.parents('.rd-mailform').hasClass('success')) { return; } if ((results = $this.regula('validate')).length) { for (i = 0; i < results.length; i++) { $this.siblings(".form-validation").text(results[i].message).parent().addClass("has-error") } } else { $this.siblings(".form-validation").text("").parent().removeClass("has-error") } }) .regula('bind'); } /** * isValidated * @description check if all elemnts pass validation */ function isValidated(elements) { var results, errors = 0; if (elements.length) { for (j = 0; j < elements.length; j++) { var $input = $(elements[j]); if ((results = $input.regula('validate')).length) { for (k = 0; k < results.length; k++) { errors++; $input.siblings(".form-validation").text(results[k].message).parent().addClass("has-error"); } } else { $input.siblings(".form-validation").text("").parent().removeClass("has-error") } } return errors == 0; } return true; } /** * Init Bootstrap tooltip * @description calls a function when need to init bootstrap tooltips */ function initBootstrapTooltip(tooltipPlacement) { if (window.innerWidth < 599) { plugins.bootstrapTooltip.tooltip('destroy'); plugins.bootstrapTooltip.tooltip({ placement: 'bottom' }); } else { plugins.bootstrapTooltip.tooltip('destroy'); plugins.bootstrapTooltip.tooltipPlacement; plugins.bootstrapTooltip.tooltip(); } } /** * ChangeExternalButtons * @description Change active tab in responsive active tab by external buttons (next tab, prev tab) */ function changeExternalButtons(respTabItem, direction) { var prev, next, activeItem; respTabItem.find('.resp-tabs-extertal-list li').removeClass('active'); activeItem = respTabItem.find('.resp-tab-item.resp-tab-active'); next = activeItem.next(); if (!next.length) { next = respTabItem.find('.resp-tab-item:first-child()'); } prev = activeItem.prev(); if (!prev.length) { prev = respTabItem.find('.resp-tab-item:last-child()'); } if (direction) { if (direction === 'next') { next.trigger('click'); } else { prev.trigger('click'); } setTimeout(function () { changeExternalButtons(respTabItem); }, 10); } respTabItem.find('.resp-tab-external-prev li:nth-child(' + (prev.index() + 1) + ')').addClass('active'); respTabItem.find('.resp-tab-external-next li:nth-child(' + (next.index() + 1) + ')').addClass('active'); } /** * Copyright Year * @description Evaluates correct copyright year */ var o = $("#copyright-year"); if (o.length) { o.text(initialDate.getFullYear()); } /** * IE Polyfills * @description Adds some loosing functionality to IE browsers */ if (isIE) { if (isIE < 10) { $html.addClass("lt-ie-10"); } if (isIE < 11) { if (plugins.pointerEvents) { $.getScript(plugins.pointerEvents) .done(function () { $html.addClass("ie-10"); PointerEventsPolyfill.initialize({}); }); } } if (isIE === 11) { $("html").addClass("ie-11"); } if (isIE === 12) { $("html").addClass("ie-edge"); } } /** * Bootstrap Tooltips * @description Activate Bootstrap Tooltips */ if (plugins.bootstrapTooltip.length) { var tooltipPlacement = plugins.bootstrapTooltip.attr('data-placement'); initBootstrapTooltip(tooltipPlacement); $(window).on('resize orientationchange', function () { initBootstrapTooltip(tooltipPlacement); }) } /** * Smooth scrolling * @description Enables a smooth scrolling for Google Chrome (Windows) */ if (plugins.smoothScroll) { $.getScript(plugins.smoothScroll); } /** * RD Audio player * @description Enables RD Audio player plugin */ if (plugins.rdAudioPlayer.length > 0) { var i; for (i = 0; i < plugins.rdAudioPlayer.length; i++) { $(plugins.rdAudioPlayer[i]).RDAudio(); } } /** * Text Rotator * @description Enables Text Rotator plugin */ if (plugins.textRotator.length) { var i; for (i = 0; i < plugins.textRotator.length; i++) { var textRotatorItem = plugins.textRotator[i]; $(textRotatorItem).rotator(); } } /** * RD Google Maps * @description Enables RD Google Maps plugin */ if (plugins.rdGoogleMaps.length) { var i; $.getScript("//maps.google.com/maps/api/js?key=AIzaSyAFeB0kVA6ouyJ_gEvFbMaefLy3cBCyRwo&sensor=false&libraries=geometry,places&v=3.7", function () { var head = document.getElementsByTagName('head')[0], insertBefore = head.insertBefore; head.insertBefore = function (newElement, referenceElement) { if (newElement.href && newElement.href.indexOf('//fonts.googleapis.com/css?family=Roboto') != -1 || newElement.innerHTML.indexOf('gm-style') != -1) { return; } insertBefore.call(head, newElement, referenceElement); }; for (i = 0; i < plugins.rdGoogleMaps.length; i++) { var $googleMapItem = $(plugins.rdGoogleMaps[i]); lazyInit($googleMapItem, $.proxy(function () { var $this = $(this), styles = $this.attr("data-styles"); $this.googleMap({ styles: styles ? JSON.parse(styles) : [], onInit: function (map) { var inputAddress = $('#rd-google-map-address'); if (inputAddress.length) { var input = inputAddress; var geocoder = new google.maps.Geocoder(); var marker = new google.maps.Marker( { map: map, icon: "images/gmap_marker.png", } ); var autocomplete = new google.maps.places.Autocomplete(inputAddress[0]); autocomplete.bindTo('bounds', map); inputAddress.attr('placeholder', ''); inputAddress.on('change', function () { $("#rd-google-map-address-submit").trigger('click'); }); inputAddress.on('keydown', function (e) { if (e.keyCode == 13) { $("#rd-google-map-address-submit").trigger('click'); } }); $("#rd-google-map-address-submit").on('click', function (e) { e.preventDefault(); var address = input.val(); geocoder.geocode({'address': address}, function (results, status) { if (status == google.maps.GeocoderStatus.OK) { var latitude = results[0].geometry.location.lat(); var longitude = results[0].geometry.location.lng(); map.setCenter(new google.maps.LatLng( parseFloat(latitude), parseFloat(longitude) )); marker.setPosition(new google.maps.LatLng( parseFloat(latitude), parseFloat(longitude) )) } }); }); } } }); }, $googleMapItem)); } }); } /** * Bootstrap Date time picker */ if (plugins.bootstrapDateTimePicker.length) { var i; for (i = 0; i < plugins.bootstrapDateTimePicker.length; i++) { var $dateTimePicker = $(plugins.bootstrapDateTimePicker[i]); var options = {}; options['format'] = 'dddd DD MMMM YYYY - HH:mm'; if ($dateTimePicker.attr("data-time-picker") == "date") { options['format'] = 'dddd DD MMMM YYYY'; options['minDate'] = new Date(); } else if ($dateTimePicker.attr("data-time-picker") == "time") { options['format'] = 'HH:mm'; } options["time"] = ($dateTimePicker.attr("data-time-picker") != "date"); options["date"] = ($dateTimePicker.attr("data-time-picker") != "time"); options["shortTime"] = true; $dateTimePicker.bootstrapMaterialDatePicker(options); } } /** * Responsive Tabs * @description Enables Responsive Tabs plugin */ if (plugins.responsiveTabs.length > 0) { var i; for (i = 0; i < plugins.responsiveTabs.length; i++) { var responsiveTabsItem = $(plugins.responsiveTabs[i]); responsiveTabsItem.easyResponsiveTabs({ type: responsiveTabsItem.attr("data-type") === "accordion" ? "accordion" : "default" }); //If have owl carousel inside tab - resize owl carousel on click if (responsiveTabsItem.find('.owl-carousel').length) { responsiveTabsItem.find('.resp-tab-item').on('click', $.proxy(function (event) { var $this = $(this), carouselObj = ($this.find('.resp-tab-content-active .owl-carousel').owlCarousel()).data('owlCarousel'); if (carouselObj && typeof carouselObj.onResize === "function") { carouselObj.onResize(); } }, responsiveTabsItem)); } //If have slick carousel inside tab - resize slick carousel on click if (responsiveTabsItem.find('.slick-slider').length) { responsiveTabsItem.find('.resp-tab-item').on('click', $.proxy(function (event) { var $this = $(this); $this.find('.resp-tab-content-active .slick-slider').slick('setPosition'); }, responsiveTabsItem)); } // Enable external buttons (prev, text tab) if (responsiveTabsItem.attr('data-external-buttons') == "true") { var list = responsiveTabsItem.find('.resp-tabs-list li'), newList = '
...#{token}...
' + 'Terms matched: #{count} - URL: #{href}
'; var defaultFilter = '*.html'; if (plugins.search.length) { for (i = 0; i < plugins.search.length; i++) { var searchItem = $(plugins.search[i]), options = { element: searchItem, filter: (searchItem.attr('data-search-filter')) ? searchItem.attr('data-search-filter') : defaultFilter, template: (searchItem.attr('data-search-template')) ? searchItem.attr('data-search-template') : defaultTemplate, live: (searchItem.attr('data-search-live')) ? searchItem.attr('data-search-live') : false, liveCount: (searchItem.attr('data-search-live-count')) ? parseInt(searchItem.attr('data-search-live')) : 4, current: 0, processed: 0, timer: {} }; if ($('.rd-navbar-search-toggle').length) { var toggle = $('.rd-navbar-search-toggle'); toggle.on('click', function () { if (!($(this).hasClass('active'))) { searchItem.find('input').val('').trigger('propertychange'); } }); } if (options.live) { var clearHandler = false; searchItem.find('input').on("keyup input propertychange", $.proxy(function () { this.term = this.element.find('input').val().trim(); this.spin = this.element.find('.input-group-addon'); clearTimeout(this.timer); if (this.term.length > 2) { this.timer = setTimeout(liveSearch(this), 200); if (clearHandler == false) { clearHandler = true; $("body").on("click", function (e) { if ($(e.toElement).parents('.rd-search').length == 0) { $('#rd-search-results-live').addClass('cleared').html(''); } }) } } else if (this.term.length == 0) { $('#' + this.live).addClass('cleared').html(''); } }, options, this)); } searchItem.submit($.proxy(function () { $('').attr('type', 'hidden') .attr('name', "filter") .attr('value', this.filter) .appendTo(this.element); return true; }, options, this)) } } if (plugins.searchResults.length) { var regExp = /\?.*s=([^&]+)\&filter=([^&]+)/g; var match = regExp.exec(location.search); if (match != null) { $.get(handler, { s: decodeURI(match[1]), dataType: "html", filter: match[2], template: defaultTemplate, live: '' }, function (data) { plugins.searchResults.html(data); }) } } } /** * Slick carousel * @description Enable Slick carousel plugin */ if (plugins.slick.length) { var i; for (i = 0; i < plugins.slick.length; i++) { var $slickItem = $(plugins.slick[i]); $slickItem.slick({ slidesToScroll: parseInt($slickItem.attr('data-slide-to-scroll')) || 1, asNavFor: $slickItem.attr('data-for') || false, dots: $slickItem.attr("data-dots") == "true", infinite: $slickItem.attr("data-loop") == "true", focusOnSelect: true, arrows: $slickItem.attr("data-arrows") == "true", swipe: $slickItem.attr("data-swipe") == "true", autoplay: $slickItem.attr("data-autoplay") == "true", vertical: $slickItem.attr("data-vertical") == "true", centerMode: $slickItem.attr("data-center-mode") == "true", centerPadding: $slickItem.attr("data-center-padding") ? $slickItem.attr("data-center-padding") : '0.50', mobileFirst: true, responsive: [ { breakpoint: 0, settings: { slidesToShow: parseInt($slickItem.attr('data-items')) || 1, } }, { breakpoint: 480, settings: { slidesToShow: parseInt($slickItem.attr('data-xs-items')) || 1, } }, { breakpoint: 768, settings: { slidesToShow: parseInt($slickItem.attr('data-sm-items')) || 1, } }, { breakpoint: 992, settings: { slidesToShow: parseInt($slickItem.attr('data-md-items')) || 1, } }, { breakpoint: 1200, settings: { slidesToShow: parseInt($slickItem.attr('data-lg-items')) || 1, } } ] }) .on('afterChange', function (event, slick, currentSlide, nextSlide) { var $this = $(this), childCarousel = $this.attr('data-child'); if (childCarousel) { $(childCarousel + ' .slick-slide').removeClass('slick-current'); $(childCarousel + ' .slick-slide').eq(currentSlide).addClass('slick-current'); } }); } } /** * Owl carousel * @description Enables Owl carousel plugin */ if (plugins.owl.length) { var i; for (i = 0; i < plugins.owl.length; i++) { var c = $(plugins.owl[i]), responsive = {}; var aliaces = ["-", "-xs-", "-sm-", "-md-", "-lg-"], values = [0, 480, 768, 992, 1200], j, k; for (j = 0; j < values.length; j++) { responsive[values[j]] = {}; for (k = j; k >= -1; k--) { if (!responsive[values[j]]["items"] && c.attr("data" + aliaces[k] + "items")) { responsive[values[j]]["items"] = k < 0 ? 1 : parseInt(c.attr("data" + aliaces[k] + "items")); } if (!responsive[values[j]]["stagePadding"] && responsive[values[j]]["stagePadding"] !== 0 && c.attr("data" + aliaces[k] + "stage-padding")) { responsive[values[j]]["stagePadding"] = k < 0 ? 0 : parseInt(c.attr("data" + aliaces[k] + "stage-padding")); } if (!responsive[values[j]]["margin"] && responsive[values[j]]["margin"] !== 0 && c.attr("data" + aliaces[k] + "margin")) { responsive[values[j]]["margin"] = k < 0 ? 30 : parseInt(c.attr("data" + aliaces[k] + "margin")); } } } c.owlCarousel({ autoplay: c.attr("data-autoplay") === "true", loop: c.attr("data-loop") !== "false", items: 1, dotsContainer: c.attr("data-pagination-class") || false, navContainer: c.attr("data-navigation-class") || false, mouseDrag: c.attr("data-mouse-drag") !== "false", nav: c.attr("data-nav") === "true", dots: c.attr("data-dots") === "true", dotsEach: c.attr("data-dots-each") ? parseInt(c.attr("data-dots-each")) : false, animateIn: c.attr('data-animation-in') ? c.attr('data-animation-in') : 'slide', animateOut: c.attr('data-animation-out') ? c.attr('data-animation-out') : false, responsive: responsive, navText: [] }); } } /** * jQuery Count To * @description Enables Count To plugin */ if (plugins.counter.length) { var i; for (i = 0; i < plugins.counter.length; i++) { var $counterNotAnimated = $(plugins.counter[i]).not('.animated'); $document .on("scroll", $.proxy(function () { var $this = this; if ((!$this.hasClass("animated")) && (isScrolledIntoView($this))) { $this.countTo({ refreshInterval: 40, speed: $this.attr("data-speed") || 1000 }); $this.addClass('animated'); } }, $counterNotAnimated)) .trigger("scroll"); } } /** * Isotope * @description Enables Isotope plugin */ if (plugins.isotope.length) { var i, isogroup = []; for (i = 0; i < plugins.isotope.length; i++) { var isotopeItem = plugins.isotope[i] , iso = new Isotope(isotopeItem, { itemSelector: '.isotope-item', layoutMode: isotopeItem.getAttribute('data-isotope-layout') ? isotopeItem.getAttribute('data-isotope-layout') : 'masonry', filter: '*' }); isogroup.push(iso); } $(window).on('load', function () { setTimeout(function () { var i; for (i = 0; i < isogroup.length; i++) { isogroup[i].element.className += " isotope--loaded"; isogroup[i].layout(); } }, 600); }); var resizeTimout; $("[data-isotope-filter]").on("click", function (e) { e.preventDefault(); var filter = $(this); clearTimeout(resizeTimout); filter.parents(".isotope-filters").find('.active').removeClass("active"); filter.addClass("active"); var iso = $('.isotope[data-isotope-group="' + this.getAttribute("data-isotope-group") + '"]'); iso.isotope({ itemSelector: '.isotope-item', layoutMode: iso.attr('data-isotope-layout') ? iso.attr('data-isotope-layout') : 'masonry', filter: this.getAttribute("data-isotope-filter") == '*' ? '*' : '[data-filter*="' + this.getAttribute("data-isotope-filter") + '"]' }); }).eq(0).trigger("click") } /** * WOW * @description Enables Wow animation plugin */ if (isDesktop && $html.hasClass("wow-animation") && $(".wow").length) { new WOW().init(); } /** * Bootstrap tabs * @description Activate Bootstrap Tabs */ if (plugins.bootstrapTabs.length) { var i; for (i = 0; i < plugins.bootstrapTabs.length; i++) { var bootstrapTabsItem = $(plugins.bootstrapTabs[i]); bootstrapTabsItem.on("click", "a", function (event) { event.preventDefault(); $(this).tab('show'); }); } } /** * JQuery mousewheel plugin * @description Enables jquery mousewheel plugin */ if (plugins.scroller.length) { var i; for (i = 0; i < plugins.scroller.length; i++) { var scrollerItem = $(plugins.scroller[i]); scrollerItem.mCustomScrollbar({ scrollInertia: 200, scrollButtons: {enable: true} }); } } /** * Socialite v2 * @description Enables Socialite v2 plugin */ if (plugins.socialite.length) { Socialite.load(); } /** * RD Video * @description Enables RD Video plugin */ if (plugins.rdVideoBG.length) { var i; for (i = 0; i < plugins.rdVideoBG.length; i++) { var videoItem = $(plugins.rdVideoBG[i]); videoItem.RDVideo({}); } } /** * RD Input Label * @description Enables RD Input Label Plugin */ if (plugins.rdInputLabel.length) { plugins.rdInputLabel.RDInputLabel(); } /** * Regula * @description Enables Regula plugin */ if (plugins.regula.length) { attachFormValidator(plugins.regula); } /** * RD Mailform */ if (plugins.rdMailForm.length) { var i, j, k, msg = { 'MF000': 'Successfully sent!', 'MF001': 'Recipients are not set!', 'MF002': 'Form will not work locally!', 'MF003': 'Please, define email field in your form!', 'MF004': 'Please, define type of your form!', 'MF254': 'Something went wrong with PHPMailer!', 'MF255': 'Aw, snap! Something went wrong.' }; for (i = 0; i < plugins.rdMailForm.length; i++) { var $form = $(plugins.rdMailForm[i]); $form.attr('novalidate', 'novalidate').ajaxForm({ data: { "form-type": $form.attr("data-form-type") || "contact", "counter": i }, beforeSubmit: function () { var form = $(plugins.rdMailForm[this.extraData.counter]); var inputs = form.find("[data-constraints]"); if (isValidated(inputs)) { var output = $("#" + form.attr("data-form-output")); if (output.hasClass("snackbars")) { output.html('Sending
'); output.addClass("active"); } } else { return false; } }, error: function (result) { var output = $("#" + $(plugins.rdMailForm[this.extraData.counter]).attr("data-form-output")); output.text(msg[result]); }, success: function (result) { var form = $(plugins.rdMailForm[this.extraData.counter]), output = $("#" + form.attr("data-form-output")), $select = $form.find('select'); // Clear select2 after submit form if ($select.length) { for (j = 0; j < $select.length; j++) { var $selectitem = $($select[j]); $selectitem.select2('val', null); } } form.addClass('success'); result = result.length == 5 ? result : 'MF255'; output.text(msg[result]); if (result === "MF000") { if (output.hasClass("snackbars")) { output.html('' + msg[result] + '
'); } output.addClass("success active"); } else { if (output.hasClass("snackbars")) { output.html(' '); } output.addClass("error active"); } form.clearForm(); form.find('input, textarea').blur(); setTimeout(function () { output.removeClass("active error success"); form.removeClass('success'); }, 5000); } }); } } /** * RD Range * @description Enables RD Range plugin */ if (plugins.rdRange.length) { plugins.rdRange.RDRange({}); } /** * PhotoSwipe Gallery * @description Enables PhotoSwipe Gallery plugin */ if (plugins.photoSwipeGallery.length) { // init image click event $document.delegate("[data-photo-swipe-item]", "click", function (event) { event.preventDefault(); var $el = $(this), $galleryItems = $el.parents("[data-photo-swipe-gallery]").find("a[data-photo-swipe-item]"), pswpElement = document.querySelectorAll('.pswp')[0], encounteredItems = {}, pswpItems = [], options, pswpIndex = 0, pswp; if ($galleryItems.length == 0) { $galleryItems = $el; } // loop over the gallery to build up the photoswipe items $galleryItems.each(function () { var $item = $(this), src = $item.attr('href'), size = $item.attr('data-size').split('x'), pswdItem; if ($item.is(':visible')) { // if we have this image the first time if (!encounteredItems[src]) { // build the photoswipe item pswdItem = { src: src, w: parseInt(size[0], 10), h: parseInt(size[1], 10), el: $item // save link to element for getThumbBoundsFn }; // store that we already had this item encounteredItems[src] = { item: pswdItem, index: pswpIndex }; // push the item to the photoswipe list pswpItems.push(pswdItem); pswpIndex++; } } }); options = { index: encounteredItems[$el.attr('href')].index, getThumbBoundsFn: function (index) { var $el = pswpItems[index].el, offset = $el.offset(); return { x: offset.left, y: offset.top, w: $el.width() }; } }; // open the photoswipe gallery pswp = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, pswpItems, options); pswp.init(); }); } /** * Stacktable * @description Enables Stacktable plugin */ if (plugins.stacktable.length) { var i; for (i = 0; i < plugins.stacktable.length; i++) { var stacktableItem = $(plugins.stacktable[i]); stacktableItem.stacktable(); } } /** * Custom Toggles */ if (plugins.customToggle.length) { var i; for (i = 0; i < plugins.customToggle.length; i++) { var $this = $(plugins.customToggle[i]); $this.on('click', $.proxy(function (event) { event.preventDefault(); var $ctx = $(this); $($ctx.attr('data-custom-toggle')).add(this).toggleClass('active'); }, $this)); if ($this.attr("data-custom-toggle-disable-on-blur") === "true") { $("body").on("click", $this, function (e) { if (e.target !== e.data[0] && $(e.data.attr('data-custom-toggle')).find($(e.target)).length == 0 && e.data.find($(e.target)).length == 0) { $(e.data.attr('data-custom-toggle')).add(e.data[0]).removeClass('active'); } }) } } } /** * Magnificent image zoom */ if (plugins.imgZoom.length) { var i; for (i = 0; i < plugins.imgZoom.length; i++) { var $imgZoomItem = $(plugins.imgZoom[i]); $imgZoomItem.mag(); } } /** * Custom Waypoints */ if (plugins.customWaypoints.length) { var i; for (i = 0; i < plugins.customWaypoints.length; i++) { var $this = $(plugins.customWaypoints[i]); $this.on('click', function (e) { e.preventDefault(); $("body, html").stop().animate({ scrollTop: $("#" + $(this).attr('data-custom-scroll-to')).offset().top }, 1000, function () { $(window).trigger("resize"); }); }); } } /** * RD Parallax * @description Enables RD Parallax plugin */ if (plugins.rdParallax.length) { var i; $.RDParallax(); if (!isIE && !isMobile) { $(window).on("scroll", function () { for (i = 0; i < plugins.rdParallax.length; i++) { var parallax = $(plugins.rdParallax[i]); if (isScrolledIntoView(parallax)) { parallax.find(".rd-parallax-inner").css("position", "fixed"); } else { parallax.find(".rd-parallax-inner").css("position", "absolute"); } } }); } $("a[href='#'], a[href^='#']").on("click", function (event) { setTimeout(function () { $(window).trigger("resize"); }, 300); }); } });