window.csrfToken = 'rua4dNV9QO'; //cms has col-sm-6 this has changed in bootstrap, so hotfix $(document).ready(function () { $('.col-xs-6').removeClass('col-xs-6').addClass('col-6'); }); function buildWidget(widgetType, args) { var constructor = window.widgets[widgetType.toLowerCase()]; function F() { return constructor.apply(this, args); } F.prototype = constructor.prototype; return new F(); } function widget(elem) { var $widgetElem = $(elem); while (!$widgetElem.is('[data-widget-id],[data-widget-non-interactive-start]')) { $widgetElem = $widgetElem.parent(); if ($widgetElem.length === 0) { return null; // No widget found } } var widgetId = $widgetElem.attr('data-widget-id'); var widgetType = $widgetElem.attr('data-widget-type'); var widgetInstance = buildWidget(widgetType, [widgetId, $widgetElem]); var widgetBaseFunctionality = { id: widgetId, type: widgetType, element: $widgetElem, call: function (method, args, callback, cacheClientSide) { var widget = this; var url = '/widgetResources.axd?widgetCall=' + widgetId; if (!cacheClientSide) { url += '&rnd=' + Math.random(); } $.ajax({ url: window.location.protocol + '//' + window.location.hostname + ':' + window.location.port + url, type: "POST", data: 'token=' + window.csrfToken + '&method=' + method + '&pageData=' + encodeURIComponent(JSON.stringify(getPageData($widgetElem))) + '&data=' + encodeURIComponent(JSON.stringify(args)), success: function (data, status, xhr) { callback(widget, data, status, xhr); }, error: function (xhr, status, err) { callback(widget, err, status, xhr); } }); } }; return $.extend(widgetInstance, widgetBaseFunctionality); } function getPageData($elem) { while ($elem.length) { if ($elem.attr('data-pageData')) { return JSON.parse($elem.attr('data-pageData')); } $elem = $elem.parent(); } } if (!window.widgets) { window.widgets = {}; } function setupValidation(input) { $(input).parent().parent().addClass('was-validated'); } function validateTextarea(textarea) { var regexMsg = $(textarea).attr('data-regex'); var errorMsg = $(textarea).attr('data-message'); var pattern = new RegExp('^' + $(textarea).attr('pattern') + '$'); // check each line of text $.each($(textarea).val().split("\n"), function () { // check if the line matches the pattern var hasError = !this.match(pattern); if (hasError) { $(textarea).next().text(regexMsg); } else { $(textarea).next().text(errorMsg); } if (typeof textarea.setCustomValidity === 'function') { textarea.setCustomValidity(hasError ? errorMsg : ''); } else { // Not supported by the browser, fallback to manual error display... $(textarea).toggleClass('error', !!hasError); $(textarea).toggleClass('ok', !hasError); if (hasError) { $(textarea).attr('title', errorMsg); } else { $(textarea).removeAttr('title'); } } return !hasError; }); } window.widgets.assetdownloadform = function (args) { return { submitForm: function () { if (typeof (validateChildNodes) != 'undefined') { // This might not be used so check if present if (!validateChildNodes(this.element)) { return; // Invalid } } var buttonText = $('#AssetDownloadForm_' + this.id + '_lnkSubmit').val(); $('#AssetDownloadForm_' + this.id + '_lnkSubmit').val('Please wait...').attr('disabled', true); var data = {}; var $questions = this.element.find(':input[id*=Question]'); // Even though "none" questions dont have any inputs we still need to iterate through them or i will be wrong for (var i = 0; i < $questions.length; i++) { var $question = $($questions[i]); if (typeof ($question.length && $question[0].checkValidity) == 'function') { if (!$question[0].checkValidity()) { $question.css({ outline: 'solid 2px #f00' }).addClass('invalid'); $question.blur(function () { $(this).css({ outline: 'none' }).removeClass('invalid'); }); $question[0].focus(); $('#AssetDownloadForm_' + this.id + '_lnkSubmit').val(buttonText).removeAttr('disabled'); return; } } if ($question.is(':checkbox,:radio')) { data[$question.attr('data')] = $question.is(':checked'); } else { data[$question.attr('name')] = $question.val(); } } this.call('submitForm', data, this.gotResult); }, gotResult: function (widget, data, status) { if (status != 'success') { alert('An error occurred please try again.\n'); } else { widget.element.empty(); widget.element.append($('
').html(data.result)); } } }; } function createCookie(name, value, days) { var expires; if (days) { var date = new Date(); date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); expires = "; expires=" + date.toGMTString(); } else { expires = ""; } document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=/"; } function readCookie(name) { var nameEQ = encodeURIComponent(name) + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) === ' ') c = c.substring(1, c.length); if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length)); } return null; } function setupComponentPopup() { if ('undefined' !== typeof window.jQuery && $('.component-popup-close').length) { var id = $('.component-popup').attr("data-id"); $('.component-popup-close').click(function () { //store a cookie createCookie('component-popup-close', id, 10000); }); //open the popup if (readCookie('component-popup-close') != id) { $('.component-popup').modal('show'); } } } setupComponentPopup(); if (!window.widgets) { window.widgets = {}; } function setupValidation(input) { $(input).parent().parent().addClass('was-validated'); } function validateTextarea(textarea) { var regexMsg = $(textarea).attr('data-regex'); var errorMsg = $(textarea).attr('data-message'); var pattern = new RegExp('^' + $(textarea).attr('pattern') + '$'); // check each line of text $.each($(textarea).val().split("\n"), function () { // check if the line matches the pattern var hasError = !this.match(pattern); if (hasError) { $(textarea).next().text(regexMsg); } else { $(textarea).next().text(errorMsg); } if (typeof textarea.setCustomValidity === 'function') { textarea.setCustomValidity(hasError ? errorMsg : ''); } else { // Not supported by the browser, fallback to manual error display... $(textarea).toggleClass('error', !!hasError); $(textarea).toggleClass('ok', !hasError); if (hasError) { $(textarea).attr('title', errorMsg); } else { $(textarea).removeAttr('title'); } } return !hasError; }); } window.widgets.emailform = function (args) { return { submitForm: function () { if (typeof (validateChildNodes) != 'undefined') { // This might not be used so check if present if (!validateChildNodes(this.element)) { return; // Invalid } } var buttonText = $('#EmailForm_' + this.id + '_lnkSubmit').val(); $('#EmailForm_' + this.id + '_lnkSubmit').val('Please wait...').attr('disabled', true); var data = {}; var $questions = this.element.find(':input[id*=Question]'); // Even though "none" questions dont have any inputs we still need to iterate through them or i will be wrong for (var i = 0; i < $questions.length; i++) { var $question = $($questions[i]); if (typeof ($question.length && $question[0].checkValidity) == 'function') { if (!$question[0].checkValidity()) { $question.css({ outline: 'solid 2px #f00' }).addClass('invalid'); $question.blur(function () { $(this).css({ outline: 'none' }).removeClass('invalid'); }); $question[0].focus(); $('#EmailForm_' + this.id + '_lnkSubmit').val(buttonText).removeAttr('disabled'); return; } } if ($question.is(':checkbox,:radio')) { data[$question.attr('data')] = $question.is(':checked'); } else { data[$question.attr('name')] = $question.val(); } } this.call('submitForm', data, this.gotResult); }, gotResult: function (widget, data, status) { if (status != 'success') { alert('An error occurred please try again.\n'); } else { widget.element.empty(); widget.element.append($('
').append($('

').text(data.result))); } } }; } if ('undefined' == typeof window.jQuery) { } else { $(document).ready(function () { $.fn.isInViewport = function () { if ($(this).offset()) { var elementTop = $(this).offset().top; var elementBottom = elementTop + $(this).outerHeight(); var viewportTop = $(window).scrollTop(); var viewportBottom = viewportTop + $(window).height(); return elementBottom > viewportTop && elementTop < viewportBottom; } else { return false; } }; $(window).on('resize', function () { AnimateImages(); }); $(window).scroll(function () { AnimateImages(); }); $(document).ready(function () { if ($('.four-image-wrapper').length) { var fullWidth = $('.four-image-wrapper').width(); var itemWidth = $('.four-image-wrapper').parent().parent().height() / 2; $('.fourimageblock > div').height('100%'); $('.four-image-wrapper').width('100%').css({ position: 'relative' }); $('.four-image-item').width(itemWidth).height(itemWidth).css({ right: 0, position: 'absolute' }); $('.four-image-item.item_1').css('z-index', 4); $('.four-image-item.item_2').css('z-index', 3); $('.four-image-item.item_3').css('z-index', 2); $('.four-image-item.item_4').css('z-index', 1); } AnimateImages(); }); function AnimateImages() { if (!$('.four-image-wrapper').hasClass('setup')) { if ($('.four-image-wrapper').isInViewport()) { $('.four-image-wrapper').addClass('setup'); var itemWidth = $('.four-image-item.item_1').width(); $('.four-image-item').animate({ 'right': itemWidth + 'px' }, 500, function () { $('.four-image-item.item_2').animate({ 'top': itemWidth + 'px' }, 500, function () { $('.four-image-item.item_3').css({ top: itemWidth + 'px' }); $('.four-image-item.item_4').css({ top: itemWidth + 'px' }); $('.four-image-item.item_3').animate({ 'right': 0 }, 500, function () { $('.four-image-item.item_4').css({ right: 0 }); $('.four-image-item.item_4').animate({ 'top': '0' }, 500, function () { // Animation complete. }); }); }); }); } } else { var itemWidth = $('.four-image-wrapper').parent().parent().height() / 2; $('.four-image-item.item_1').width(itemWidth).height(itemWidth).css({ right: itemWidth }); $('.four-image-item.item_2').width(itemWidth).height(itemWidth).css({ right: itemWidth, top: itemWidth + 'px' }); $('.four-image-item.item_3').width(itemWidth).height(itemWidth).css({ top: itemWidth + 'px' }); $('.four-image-item.item_4').width(itemWidth).height(itemWidth).css({ top: 0 }); } } }); } if (!window.widgets) { window.widgets = {}; } function setupValidation(input) { $(input).parent().parent().addClass('was-validated'); } function validateTextarea(textarea) { var regexMsg = $(textarea).attr('data-regex'); var errorMsg = $(textarea).attr('data-message'); var pattern = new RegExp('^' + $(textarea).attr('pattern') + '$'); // check each line of text $.each($(textarea).val().split("\n"), function () { // check if the line matches the pattern var hasError = !this.match(pattern); if (hasError) { $(textarea).next().text(regexMsg); } else { $(textarea).next().text(errorMsg); } if (typeof textarea.setCustomValidity === 'function') { textarea.setCustomValidity(hasError ? errorMsg : ''); } else { // Not supported by the browser, fallback to manual error display... $(textarea).toggleClass('error', !!hasError); $(textarea).toggleClass('ok', !hasError); if (hasError) { $(textarea).attr('title', errorMsg); } else { $(textarea).removeAttr('title'); } } return !hasError; }); } window.widgets.newsletterform = function (args) { return { submitForm: function () { if (typeof (validateChildNodes) != 'undefined') { // This might not be used so check if present if (!validateChildNodes(this.element)) { return; // Invalid } } var buttonText = $('#NewsletterForm_' + this.id + '_lnkSubmit').val(); $('#NewsletterForm_' + this.id + '_lnkSubmit').val('Please wait...').attr('disabled', true); var data = {}; var $questions = this.element.find(':input[id*=Question]'); // Even though "none" questions dont have any inputs we still need to iterate through them or i will be wrong for (var i = 0; i < $questions.length; i++) { var $question = $($questions[i]); if (typeof ($question.length && $question[0].checkValidity) == 'function') { if (!$question[0].checkValidity()) { $question.css({ outline: 'solid 2px #f00' }).addClass('invalid'); $question.blur(function () { $(this).css({ outline: 'none' }).removeClass('invalid'); }); $question[0].focus(); $('#NewsletterForm_' + this.id + '_lnkSubmit').val(buttonText).removeAttr('disabled'); return; } } if ($question.is(':checkbox,:radio')) { data[$question.attr('data')] = $question.is(':checked'); } else { data[$question.attr('name')] = $question.val(); } } this.call('submitForm', data, this.gotResult); }, gotResult: function (widget, data, status) { if (status != 'success') { alert('An error occurred please try again.\n'); } else { widget.element.empty(); widget.element.append($('

').html(data.result)); } } }; } /*Scrolling Widget*/ if ('undefined' == typeof window.jQuery) { } else { $(document).ready(function () { $.fn.isInViewport = function () { if ($(this).offset()) { var elementTop = $(this).offset().top; var elementBottom = elementTop + $(this).outerHeight(); var viewportTop = $(window).scrollTop(); var viewportBottom = viewportTop + $(window).height(); return elementBottom > viewportTop && elementTop < viewportBottom; } else { return false; } }; if ($('.scrolling-photo-wrapper').length) { $('.scrolling-photo-wrapper').mouseenter(function () { $(this).addClass('hovered'); }).mouseleave(function () { $(this).removeClass('hovered'); }); $('.scrolling-photo-wrapper').each(function (index) { var width = $(this).parent().parent().width(); $(this).width(width); $(this).attr("data-index", "1").attr("data-count", "0").attr("data-width", $(this).width()); var dataId = $(this).parent().parent().attr("data-widget-id"); $(this).find(".btn-right").click(function () { photoSlide(dataId, "left", true) }); $(this).find(".btn-left").click(function () { photoSlide(dataId, "right", true) }); $(this).find(".scrolling-item").width(width).css({ left: width }); $(this).find(".scrolling-item img").width(width); $(this).attr("data-count", $(this).find(".scrolling-item").length); $(this).find(".btn-left > i").css({ marginTop: ($(this).height() / 2) - 40 }); $(this).find(".btn-right > i").css({ marginTop: ($(this).height() / 2) - 40 }); setInterval(function () { photoSlide(dataId, 'left', false); }, 8000); $(window).scroll(function () { if (!$(this).attr("data-setup")) { $(this).attr("data-setup", "true"); var height = $(this).find(".scrolling-item.item_1 img").height(); var count = parseInt($(this).attr("data-count")); $(this).find(".scrolling-item.item_" + count).height() + 20; $(this).height(height); $(this).parent().height(height); } }); }); setTimeout( function () { resizePhotoSlide(); $(".scrolling-item.item_1").css({ left: 0 }); }, 500); } }); $(window).on('resize', function () { resizePhotoSlide(); }); function resizePhotoSlide() { if ($('.scrolling-photo-wrapper').length) { $('.scrolling-photo-wrapper').each(function (i) { var count = parseInt($(this).attr("data-count")); var width = parseInt($(this).parent().parent().width()); $(this).attr("data-width", width); $(this).width(width); var index = parseInt($(this).attr("data-index")); $(this).find(".scrolling-item").width(width).css({ left: width }); $(this).find(".scrolling-item.item_" + index).css({ left: 0 }); $(this).find(".scrolling-item img").width(width); var height = $(this).find(".scrolling-item.item_" + index + " img").height(); $(this).height(height); $(this).parent().height(height); $(this).find(".btn-left > i").css({ marginTop: ($(this).height() / 2) - 20 }); $(this).find(".btn-right > i").css({ marginTop: ($(this).height() / 2) - 20 }); }); } } function photoSlide(ctlId, direction, clicked) { $this = $('.photogallery[data-widget-id="' + ctlId + '"]').find('.scrolling-photo-wrapper'); if ($this.isInViewport()) { if (!clicked && !$this.hasClass('hovered') || clicked) { var width = parseInt($this.parent().parent().width()); var index = parseInt($this.attr("data-index")); var count = parseInt($this.attr("data-count")); if (direction == 'left') { if (index == count) { return; } var height = $this.find(".scrolling-item.item_" + (index + 1) + " img").height(); $this.height(height); $this.parent().height(height); if (index == 2) { $this.find(".scrolling-item.item_1").css({ left: width }); $this.find(".scrolling-item.item_" + count).css({ left: width }); } $this.find(".scrolling-item.item_" + index).animate({ left: "-" + width }, 500); if (index == count) { $this.find(".scrolling-item").css({ left: width }); index = 0; } $this.find(".scrolling-item.item_" + (index + 1)).animate({ left: "0" }, 500); $this.attr("data-index", index + 1); } else if (index > 1 && direction == 'right') { var height = $this.find(".scrolling-item.item_" + (index - 1) + " img").height(); $this.height(height); $this.parent().height(height); if (index == 2) { $this.find(".scrolling-item.item_1").css({ left: - width }); } $this.find(".scrolling-item.item_" + index).animate({ left: width }, 500); $this.find(".scrolling-item.item_" + (index - 1)).animate({ left: "0" }, 500); $this.attr("data-index", index - 1); } index = parseInt($this.attr("data-index")); $this.find(".icons i").removeClass('selected'); $this.find(".icons .item_" + index).addClass('selected'); $this.find(".scrolling-item img").width(width); $this.find(".btn-left > i").css({ marginTop: ($this.height() / 2) - 20 }); $this.find(".btn-right > i").css({ marginTop: ($this.height() / 2) - 20 }); } } } } /*light-box*/ function lightboxOpen() { $('.lightbox-modal').show(); } function lightboxClose() { $('.lightbox-modal').hide(); } var lightboxIndex = 1; function lightboxSlide(n) { lightboxSlides(lightboxIndex += n); } function lightboxCurrent(n) { lightboxSlides(lightboxIndex = n); } function lightboxSlides(n) { var i; var slides = $('.lightbox-slide'); if (n > slides.length) { lightboxIndex = 1 } if (n < 1) { lightboxIndex = slides.length } for (i = 0; i < slides.length; i++) { $(slides[i]).hide(); } if ($(window).width() > 575) { var imgWidth = $(slides[lightboxIndex - 1]).find('img')[0].width; $(slides[lightboxIndex - 1]).parent().width(imgWidth); } $(slides[lightboxIndex - 1]).show(); } if ('undefined' == typeof window.jQuery) { } else { $(document).ready(function () { if ($(".video-data").length) { var e = document.createElement("script"); e.src = "https://www.youtube.com/player_api"; var t = document.getElementsByTagName("script")[0]; t.parentNode.insertBefore(e, t) } }); function onYouTubePlayerAPIReady() { var e = $(".video-data"); if (void 0 !== e) for (var a = 0; a < e.length; a++) { var t = createPlayer(e[a].attributes["video-data"].value.split(",")); players[a] = t } } var players = new Array; function createPlayer(e) { return new YT.Player(e[0], { width: "100%", videoId: e[4], playerVars: { controls: e[1], autoplay: e[2], rel: 0, fs: 1, origin: "https://" + $(location).attr('host') }, events: { onReady: onPlayerReady, onStateChange: onPlayerStateChange } }) } function onPlayerReady(e) { var a = e.target.getIframe().attributes["video-data"].value; a.length && (1 == a.split(",")[2] && (e.target.mute(), e.target.playVideo())) } function onPlayerStateChange(e) { if (e.data == YT.PlayerState.ENDED) { var a = e.target.getIframe().attributes["video-data"].value; if (a.length) 1 == a.split(",")[3] && (e.target.seekTo(0), e.target.playVideo()) } } } /*Scrolling Widget*/ if ('undefined' == typeof window.jQuery) { } else { window.onload = function () { $(document).ready(function () { $.fn.isInViewport = function () { if ($(this).offset()) { var elementTop = $(this).offset().top; var elementBottom = elementTop + $(this).outerHeight(); var viewportTop = $(window).scrollTop(); var viewportBottom = viewportTop + $(window).height(); return elementBottom > viewportTop && elementTop < viewportBottom; } else { return false; } }; if ($('.componentscroller .scrolling-wrapper').length) { $('.componentscroller .scrolling-wrapper').mouseenter(function () { $(this).addClass('hovered'); }).mouseleave(function () { $(this).removeClass('hovered'); }); $('.componentscroller .scrolling-wrapper').each(function (i) { var width = $(this).parent().parent().width(); $(this).width(width); $(this).attr("data-index", "1").attr("data-count", "0").attr("data-width", $(this).width()); var dataId = $(this).parent().parent().attr("data-widget-id"); $(this).find(".btn-right").click(function () { componentSlide(dataId, "left", true) }); $(this).find(".btn-left").click(function () { componentSlide(dataId, "right", true) }); $(this).find(".scrolling-item").width(width).css({ left: width }); $(this).find(".scrolling-item.item_1").css({ left: 0 }); $(this).attr("data-count", $(this).find(".scrolling-item").length); $(this).find(".btn-left > i").css({ marginTop: ($(this).height() / 2) - 40 }); $(this).find(".btn-right > i").css({ marginTop: ($(this).height() / 2) - 40 }); setInterval(function () { componentSlide(dataId, 'left', false); }, 8000); $(window).scroll(function () { if (!$(this).attr("data-setup")) { $(this).attr("data-setup", "true"); var height = $(this).find(".scrolling-item.item_1").height(); var count = parseInt($(this).attr("data-count")); $(this).find(".scrolling-item.item_" + count).height() + 20; $(this).height(height); $(this).parent().height(height); } }); }); setTimeout( function () { resizeComponentSlide(); $(".componentscroller .scrolling-item.item_1").css({ left: 0 }); }, 500); } }); $(window).on('resize', function () { resizeComponentSlide(); }); } function resizeComponentSlide() { if ($('.componentscroller .scrolling-wrapper').length) { $('.componentscroller .scrolling-wrapper').each(function (i) { var count = parseInt($(this).attr("data-count")); var width = parseInt($(this).parent().parent().width()); $(this).attr("data-width", width); $(this).width(width); var index = parseInt($(this).attr("data-index")); $(this).find(".scrolling-item").width(width).css({ left: width }); $(this).find(".scrolling-item.item_" + index).css({ left: 0 }); $(this).find(".scrolling-item img").width(width); var height = $(this).find(".scrolling-item.item_" + index).height() - 8; $(this).height(height); $(this).parent().height(height); $(this).find(".btn-left > i").css({ marginTop: ($(this).height() / 2) - 20 }); $(this).find(".btn-right > i").css({ marginTop: ($(this).height() / 2) - 20 }); $(this).find(".btn-left").css({ height: $(this).height() }); $(this).find(".btn-right").css({ height: $(this).height() }); }); } } function componentSlide(ctlId, direction, clicked) { $this = $('.componentscroller[data-widget-id="' + ctlId + '"]').find('.scrolling-wrapper'); if ($this.isInViewport()) { if (!clicked && !$this.hasClass('hovered') || clicked) { var width = parseInt($this.parent().parent().width()); var index = parseInt($this.attr("data-index")); var count = parseInt($this.attr("data-count")); if (direction == 'left') { if (clicked && index == count) { return; } var findIndex = index + 1; var height = $this.find(".scrolling-item.item_" + findIndex).height() - 8; $this.height(height); $this.parent().height(height); if (index == 2) { $this.find(".scrolling-item.item_1").css({ left: width }); $this.find(".scrolling-item.item_" + count).css({ left: width }); } $this.find(".scrolling-item.item_" + index).animate({ left: "-" + width }, 500); if (index == count) { $this.find(".scrolling-item").css({ left: width }); index = 0; } $this.find(".scrolling-item.item_" + (index + 1)).animate({ left: "0" }, 500); $this.attr("data-index", index + 1); } else if (index > 1 && direction == 'right') { var findIndex = index - 1; var height = $this.find(".scrolling-item.item_" + findIndex).height() - 8; $this.height(height); $this.parent().height(height); if (index == 2) { $this.find(".scrolling-item.item_1").css({ left: - width }); } $this.find(".scrolling-item.item_" + index).animate({ left: width }, 500); $this.find(".scrolling-item.item_" + (index - 1)).animate({ left: "0" }, 500); $this.attr("data-index", index - 1); } index = parseInt($this.attr("data-index")); $this.find(".icons i").removeClass('selected'); $this.find(".icons .item_" + index).addClass('selected'); $this.find(".scrolling-item img").width(width); $this.find(".btn-left > i").css({ marginTop: ($this.height() / 2) - 20 }); $this.find(".btn-right > i").css({ marginTop: ($this.height() / 2) - 20 }); } } } } //instagram $(document).ready(function () { if ($('#pnlContentViewContent').length) { //cms preview mode $('.instagram-feed > div').empty(); $('.instagram-feed > div').html("Instragram Feed Unavilable in CMS Preview Mode"); } else if ($('.instagram-data').length) { var data = $('.instagram-data').attr("data-id"); var url = "/WidgetLoader.ashx"; fetch(url, { method: "post", body: data, headers: { 'Content-Type': 'application/x-www-form-urlencoded' } } ).then(function (response) { // The API call was successful! return response.text(); }).then(function (html) { if (html.length) { $('.instagram-feed > div').empty(); $('.instagram-feed > div').html(html); instaImageResize(); instaImageLoad(); } else { //alert('not found'); } }).catch(function (err) { //alert(err); }); } }); function instaImageLoad() { $('.insta-item').each(function (i, obj) { var $this = $(this); var data = $this.attr("data-id"); var url = "/WidgetLoader.ashx?img=1"; fetch(url, { method: "post", body: data, headers: { 'Content-Type': 'application/x-www-form-urlencoded' } } ).then(function (response) { // The API call was successful! return response.text(); }).then(function (html) { if (html.length) { $this.empty(); $this.html(html); } else { $this.html("Not Found"); } }).catch(function (err) { $this.html("Not Found"); }); }); } $(window).on('resize', function () { instaImageResize(); }); function instaImageResize() { if ($('.instagram-feed').length) { //remove margin from width var itemMargin = $('.insta-item').css('margin').replace('px', ''); var widthPercentage = 10; if ($(window).width() < 960) { var mobileCols = $('.instagram-feed > div').attr("data-mc"); var mobileWidth = $('.instagram-feed > div').attr("data-mw"); mobileWidth = 100 / mobileCols; mobileWidth = Math.floor(mobileWidth * 100) / 100; widthPercentage = mobileWidth; } else { var desktopCols = $('.instagram-feed > div').attr("data-dc"); var desktopWidth = $('.instagram-feed > div').attr("data-dw"); desktopWidth = 100 / desktopCols; desktopWidth = Math.floor(desktopWidth * 100) / 100; widthPercentage = desktopWidth; } itemMargin = itemMargin * 2; widthPercentage = Math.floor(widthPercentage * 100) / 100; $('.insta-item').width("calc(" + widthPercentage.toFixed(2) + "% + -" + itemMargin + "px)"); } } /* https://github.com/peledies/google-places */ (function ($) { var namespace = 'googlePlaces'; var googlePlaceId = ''; $.googlePlaces = function (element, options) { var defaults = { placeId: googlePlaceId // placeId provided by google api documentation , render: ['reviews'] , min_rating: 0 , max_rows: 0 , map_plug_id: 'map-plug' , rotateTime: false , shorten_names: true , schema: { displayElement: '#schema' , type: 'Store' , beforeText: 'Google Users Have Rated' , middleText: 'based on' , afterText: 'ratings and reviews' , image: null , priceRange: null } , address: { displayElement: "#google-address" } , phone: { displayElement: "#google-phone" } , staticMap: { displayElement: "#google-static-map" , width: 512 , height: 512 , zoom: 17 , type: "roadmap" } , hours: { displayElement: "#google-hours" } }; var plugin = this; plugin.settings = {} var $element = $(element), element = element; plugin.init = function () { plugin.settings = $.extend({}, defaults, options); plugin.settings.schema = $.extend({}, defaults.schema, options.schema); $element.html("
"); // create a plug for google to load data into initialize_place(function (place) { plugin.place_data = place; // Trigger event before render $element.trigger('beforeRender.' + namespace); if (plugin.settings.render.indexOf('rating') > -1) { renderRating(plugin.place_data.rating); } // render specified sections if (plugin.settings.render.indexOf('reviews') > -1) { renderReviews(plugin.place_data.reviews); if (!!plugin.settings.rotateTime) { initRotation(); } } if (plugin.settings.render.indexOf('address') > -1) { renderAddress( capture_element(plugin.settings.address.displayElement) , plugin.place_data.adr_address ); } if (plugin.settings.render.indexOf('phone') > -1) { renderPhone( capture_element(plugin.settings.phone.displayElement) , plugin.place_data.formatted_phone_number ); } if (plugin.settings.render.indexOf('staticMap') > -1) { renderStaticMap( capture_element(plugin.settings.staticMap.displayElement) , plugin.place_data.formatted_address ); } if (plugin.settings.render.indexOf('hours') > -1) { renderHours( capture_element(plugin.settings.hours.displayElement) , plugin.place_data.opening_hours ); } // render schema markup addSchemaMarkup( capture_element(plugin.settings.schema.displayElement) , plugin.place_data ); // Trigger event after render $element.trigger('afterRender.' + namespace); }); } var capture_element = function (element) { if (element instanceof jQuery) { return element; } else if (typeof element == 'string') { try { var ele = $(element); if (ele.length) { return ele; } else { throw 'Element [' + element + '] couldnt be found in the DOM. Skipping ' + element + ' markup generation.'; } } catch (e) { console.warn(e); } } } var initialize_place = function (c) { var map = new google.maps.Map(document.getElementById(plugin.settings.map_plug_id)); var request = { placeId: plugin.settings.placeId }; var service = new google.maps.places.PlacesService(map); service.getDetails(request, function (place, status) { if (status == google.maps.places.PlacesServiceStatus.OK) { c(place); } }); } var sort_by_date = function (ray) { ray.sort(function (a, b) { var keyA = new Date(a.time), keyB = new Date(b.time); // Compare the 2 dates if (keyA < keyB) return -1; if (keyA > keyB) return 1; return 0; }); return ray; } var filter_minimum_rating = function (reviews) { for (var i = reviews.length - 1; i >= 0; i--) { if (reviews[i].rating < plugin.settings.min_rating) { reviews.splice(i, 1); } } return reviews; } var renderRating = function (rating) { var html = ""; var star = renderAverageStars(rating); html = "

" + star + "

"; $element.append(html); } var shorten_name = function (name) { if (name.split(" ").length > 1) { var xname = ""; xname = name.split(" "); return xname[0] + " " + xname[1][0] + "."; } } var renderReviews = function (reviews) { reviews = sort_by_date(reviews); reviews = filter_minimum_rating(reviews); var html = ""; var row_count = (plugin.settings.max_rows > 0) ? plugin.settings.max_rows - 1 : reviews.length - 1; // make sure the row_count is not greater than available records row_count = (row_count > reviews.length - 1) ? reviews.length - 1 : row_count; for (var i = row_count; i >= 0; i--) { var stars = renderStars(reviews[i].rating); var date = convertTime(reviews[i].time); if (plugin.settings.shorten_names == true) { var name = shorten_name(reviews[i].author_name); } else { var name = reviews[i].author_name + ", "; }; html = html + "
" + name + "" + date + "
" + stars + "

" + reviews[i].text + "

" }; $element.append('
' + html + '
'); } var renderHours = function (element, data) { if (element instanceof jQuery) { var html = "
    "; data.weekday_text.forEach(function (day) { html += "
  • " + day + "
  • "; }); html += "
"; element.append(html); } } var renderStaticMap = function (element, data) { if (element instanceof jQuery) { var map = plugin.settings.staticMap; element.append( "" + ""); } } var renderAddress = function (element, data) { if (element instanceof jQuery) { element.append(data); } } var renderPhone = function (element, data) { if (element instanceof jQuery) { element.append(data); } } var initRotation = function () { var $reviewEls = $element.children('.review-item'); var currentIdx = $reviewEls.length > 0 ? 0 : false; $reviewEls.hide(); if (currentIdx !== false) { $($reviewEls[currentIdx]).show(); setInterval(function () { if (++currentIdx >= $reviewEls.length) { currentIdx = 0; } $reviewEls.hide(); $($reviewEls[currentIdx]).fadeIn('slow'); }, plugin.settings.rotateTime); } } var renderStars = function (rating) { var stars = "
    "; // fill in gold stars for (var i = 0; i < rating; i++) { stars = stars + "
  • "; }; // fill in empty stars if (rating < 5) { for (var i = 0; i < (5 - rating); i++) { stars = stars + "
  • "; }; } stars = stars + "
"; return stars; } var renderAverageStars = function (rating) { var stars = "
  • " + rating + " 
  • "; var activeStars = parseInt(rating); var inactiveStars = 5 - activeStars; var width = (rating - activeStars) * 100 + '%'; // fill in gold stars for (var i = 0; i < activeStars; i++) { stars += "
  • "; }; // fill in empty stars if (inactiveStars > 0) { for (var i = 0; i < inactiveStars; i++) { if (i === 0) { stars += "
  • "; } else { stars += "
  • "; } }; } stars += "
"; return stars; } var convertTime = function (UNIX_timestamp) { var a = new Date(UNIX_timestamp * 1000); var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; var time = months[a.getMonth()] + ' ' + a.getDate() + ', ' + a.getFullYear(); return time; } var addSchemaMarkup = function (element, placeData) { if (element instanceof jQuery) { var schema = plugin.settings.schema; var schemaMarkup = ''; if (schema.image !== null) { schemaMarkup += generateSchemaItemMarkup('image', schema.image); } else { console.warn('Image is required for some schema types. Visit https://search.google.com/structured-data/testing-tool to test your schema output.'); } if (schema.priceRange !== null) { schemaMarkup += generateSchemaItemMarkup('priceRange', schema.priceRange); } schemaMarkup += generateSchemaItemMarkup('url', location.origin); schemaMarkup += generateSchemaItemMarkup('telephone', plugin.place_data.formatted_phone_number); schemaMarkup += generateSchemaAddressMarkup(); schemaMarkup += generateSchemaRatingMarkup(placeData, schema); schemaMarkup += ''; element.append(schemaMarkup); } } var generateSchemaAddressMarkup = function () { var $address = $('
', { itemprop: "address" , itemscope: '' , itemtype: "http://schema.org/PostalAddress" }).css('display', 'none'); $address.append(plugin.place_data.adr_address); $address.children('.street-address').attr('itemprop', 'streetAddress'); $address.children('.locality').attr('itemprop', 'addressLocality'); $address.children('.region').attr('itemprop', 'addressRegion'); $address.children('.postal-code').attr('itemprop', 'postalCode'); $address.children('.country-name').attr('itemprop', 'addressCountry'); return $address[0].outerHTML; } var generateSchemaRatingMarkup = function (placeData, schema) { var reviews = placeData.reviews; var lastIndex = reviews.length - 1; var reviewPointTotal = 0; for (var i = lastIndex; i >= 0; i--) { reviewPointTotal += reviews[i].rating; }; var averageReview = reviewPointTotal / (reviews.length); return schema.beforeText + ' ' + placeData.name + ' ' + '' + '' + averageReview.toFixed(2) + '/5 ' + schema.middleText + ' ' + reviews.length + ' ' + schema.afterText + '' } var generateSchemaItemMarkup = function (name, value) { return '' } plugin.init(); } $.fn.googlePlaces = function (options) { return this.each(function () { if (undefined == $(this).data(namespace)) { var plugin = new $.googlePlaces(this, options); $(this).data(namespace, plugin); } }); } })(jQuery); $(document).ready(function () { if ($('.google-reviews').length) { $(".google-reviews").googlePlaces({ placeId: $('.google-reviews').attr("data-id"), render: ['reviews'], min_rating: 5, max_rows: 0 }); setTimeout(function () { $('.google-reviews').attr('data-index', 0); $('.google-reviews .left').click(function () { var index = parseInt($('.google-reviews').attr('data-index')); if (index > 0) { var newIndex = index - 1; $('.google-reviews').attr('data-index', newIndex); var width = $('.google-reviews .review-item').width() + 42; var posLeft = $('.google-reviews .pane').position().left + width; $('.google-reviews .pane').animate({ left: posLeft }); } }); $('.google-reviews .right').click(function () { var index = parseInt($('.google-reviews').attr('data-index')); if (index < 2) { var newIndex = index + 1; $('.google-reviews').attr('data-index', newIndex); var width = $('.google-reviews .review-item').width() + 42; var posLeft = $('.google-reviews .pane').position().left - width; $('.google-reviews .pane').animate({ left: posLeft }); } }); resizeGoogleReviews(); }, 2500); } $(window).on('resize', function () { resizeGoogleReviews(); }); function resizeGoogleReviews() { if ($('.google-reviews').length) { if ($(window).width() > 990) { var googleItemWidth = $('.google-reviews').width() / 3; $('.google-reviews .review-item').width(googleItemWidth - 40 + 'px'); $('.google-reviews .pane').width((googleItemWidth * 5) + 50 + 'px'); } else { var googleItemWidth = $('.google-reviews').width(); $('.google-reviews .review-item').width(googleItemWidth - 34 + 'px'); $('.google-reviews .pane').width((googleItemWidth * 5) + 50 + 'px'); } } } });