define(function(require){let text=require("text");let Class=require("Class");let Modal;const TrackingController=require("TrackingController");let footerInView=!1;const UiVersion={RENAISSANCE_2024:'renaissance2024',};let MainController=Class.extend({options:{heightOffset:90,seenDelay:2000,markNotificationsSeenUrl:"",dismissNotificationUrl:"",isDesigner:!1,isProduction:!1,isStaging:!1,isUpgradedFramework:!1,uiDesignVersion:null,priceMatchShown:0,csrfToken:null,csrfTokenName:null,scoopEmail:null,},model:{isNotificationsListOpen:!1,markAsSeenTimeoutHandler:null,},initialize:function(options){this.options=$.extend({},this.options,options||{});Modal=MainController.requireModal(this.options);if(this.options.correctedLanguageUrl){history.replaceState({},"",this.options.correctedLanguageUrl)} if($.fn.tooltip){$('.badge-help,.apply-tooltip').tooltip()} if(this.options.isProduction||this.options.isStaging){$.ajaxSetup({cache:!0})} $('#reviewLink').on('click',function(){let projectId=$('#projectMetaContainer').data('projectid');let logClickReviewLinkUrl='/project/logClickReviewLink/'+projectId;$.post(logClickReviewLinkUrl)});$('.flash-close').on('click',function(){if($(this).parents('.flash-row-reviewbanner').length>0){let projectId=$('#projectMetaContainer').data('projectid');let logCloseReviewBannerUrl='/project/logCloseReviewBanner/'+projectId;$.post(logCloseReviewBannerUrl)} $(this).parents('.flash-row-container').slideUp().addClass('flash-closed')});if(this.options.isUpgradedFramework){$('#footerEmail').keypress($.proxy(function(evt){if(evt.which==13){this.handleSubscribe(evt)}},this));$('.btn-footer-subscribe').on('click',$.proxy(this.handleSubscribe,this))} $('#dec-notify').on('mouseenter',$.proxy(this.onNotificationsListOpen,this));$('#dec-notify').on('mouseleave',$.proxy(this.onNotificationsListClose,this));$(document).on('notifications-panel-open',$.proxy(this.onNotificationsPanelOpen,this));$(document).on('notifications-panel-close',$.proxy(this.onNotificationsPanelClose,this));$('.dec-notify-lnk .rem-notify').on('click',$.proxy(this.dismissNotification,this));$('.dropdown-notifications .mark-all-notes-read').on('click',$.proxy(this.dismissAllNotification,this));$('.simple-nav-contact').on('click',$.proxy(this.simpleNavContact,this));$('.show-image-rotation').on('click',$.proxy(this.showImageRotation,this));$('div#content').on('click','.prod-link-match',$.proxy(this.handleLinkOut,this));$('.decorilla-navbar-responsive .nav-collapse').on('show',function(){$(this).parents('.decorilla-navbar-responsive').addClass('showing-menu');window.scrollTo(0,0)}).on('hide',function(){$(this).parents('.decorilla-navbar-responsive').removeClass('showing-menu')});$('.js-vid-link').on('click',$.proxy(this.handleVidLaunch,this));$('.dec-share-btn').on('click',$.proxy(this.handleShareBtn,this));if(typeof Waypoint!="undefined"&&(($('#top-hero-bottom').length||$('.after-top-hero').length))){let element=document.querySelector('#top-hero-bottom');if(!element){console.log('No top-hero-bottom element found, using after-top-hero');element=document.querySelector('.after-top-hero')} const waypoint=new Waypoint({element:element,handler:this.handleWaypointTransition,offset:'15%'})} $('#navbar-collapse-1').on('show.dec.collapse',function(evt){$('#navbar').addClass('showing-menu');$('#chatstack-container').css('z-index',190)}).on('hide.dec.collapse',function(evt){$('#navbar').removeClass('showing-menu');$('#chatstack-container').css('z-index',1050)}).on('shown.dec.collapse hidden.dec.collapse',function(evt){if(typeof Waypoint!="undefined"){Waypoint.refreshAll()}});$(document).on('chatstackUploadImage',$.proxy(this.handleChatstackUploadImage,this));$('.edit-container-margin-guide').on('click',$.proxy(this.handleEditContainerMarginGuideClick,this));this.fixNotificationsDropdownStyle();this.trackingController=new TrackingController(options);this.initFooterObserver();const urlParams=new URLSearchParams(window.location.search);const smsSignup=urlParams.get('smssignup');if(smsSignup&&smsSignup==='true'){this.launchSmsSignupModal(!0)} this.injectNavigationParameters()},handleWaypointTransition:function(direction){const $body=$('body');const $navbar=$('#navbar');if(direction=='down'){const $decNavbarToggle=$('.dec-navbar-toggle');if(!$decNavbarToggle.hasClass('dec-collapsed')){$decNavbarToggle.click()} if($body.hasClass('transparent-navbar')){$navbar.hide();$body.addClass('below-top-hero');$navbar.fadeIn()}else{$body.addClass('below-top-hero')}}else{if($body.hasClass('below-top-hero')){if($body.hasClass('transparent-navbar')){$navbar.fadeOut({duration:200,complete:()=>{$body.removeClass('below-top-hero');$navbar.show()}})}else{$body.removeClass('below-top-hero')}}}},handleLinkOut:function(evt){if(this.options.priceMatchShown==0){evt.preventDefault();let $btn=$(evt.currentTarget);this.modal=new Modal({modalId:"price-match-modal",title:"We Price Match OR Do Better!",content:""+"If you see a lower price from this vendor, we'll happily match it and see if we can do better! Contact us at "+"orders@decorilla.com "+"with the link and we'll help ensure you're getting the best price."+"
Continue ",buttons:[]});this.options.priceMatchShown=1}},showImageRotation:function(evt){evt.preventDefault();let $btn=$(evt.delegateTarget);if($btn.hasClass('setup-done')){return} $btn.addClass('setup-done');let encodedLoc=encodeURIComponent(window.location.href);let csrfToken=this.options.csrfToken;let csrfTokenName=this.options.csrfTokenName;$('img').each(function(index,elem){let src=$(this).attr('src');if(src.indexOf('/images/')>=0){let encodedSrc=encodeURIComponent(src);let imageRef='imgRotID'+index;$(this).addClass(imageRef);let urlPartial="/upload/imageRotation?imgUrl="+encodedSrc+"&"+csrfTokenName+"="+csrfToken+"&dir=";$(this).after($(""+"
"+"left 1"+"left 2"+"right 1"+"right 2"+"

"))}});$('body').on('click','.img-rot-btn',function(evt){evt.preventDefault();let $btn=$(evt.currentTarget);let $img=$($btn.data('image-class'));$img.attr('alt','');let w=$img.css('width');let h=$img.css('height');$img.css({backgroundImage:"url('https://cdn.decorilla.com/img/loading.gif')",backgroundRepeat:"no-repeat",backgroundPosition:"center",width:w,height:h});$img.attr('src','');let rotUrl=$btn.attr('href');let postRotation=$.post(rotUrl);let onSuccess=$.proxy(function(response){$img.attr('src',response);$img.css({backgroundImage:"none",width:"auto",height:"auto"})},this);let onFailure=$.proxy(function(error){alert('Whoops! Something went wrong, please try again later.')},this);postRotation.then(onSuccess,onFailure)})},simpleNavContact:function IndexPageView_simpleNavContact(evt){evt.preventDefault();window.HubSpotConversations.widget.open()},handleSubscribe:function IndexPageView_handleSubscribe(evt){evt.preventDefault();let $btn=$(evt.delegateTarget);if($btn.hasClass('btn-footer-subscribe')){$btn=$($btn).parent("div").children("input")} const email=$('#'+$btn.data('input-id')).val();this.options.scoopEmail=email;const source=$btn.data('source');const ourStr="our";if(source.indexOf('southernliving_')===0){ourStr="Southern Living"} const postScoopSubscribe=$.post('/site/scoop/email/',{email:email,source:source});const onSuccess=$.proxy(function(response){if(response=="OK"){this.updateSubscribeMessage("Your email was successfully added","success");this.launchSmsSignupModal();$('#ScoopEmail').val('')}else if(response=="DUPLICATE_EMAIL_NO_PHONE"){this.launchSmsSignupModal();$('#ScoopEmail').val('')}else if(response=="DUPLICATE_EMAIL"){this.updateSubscribeMessage("Your info is already on our list!","warning");$('#ScoopEmail').val('');this.options.scoopEmail=null}else if(response=="BLANK_EMAIL"){this.updateSubscribeMessage("Sorry. This email is not valid","danger");this.options.scoopEmail=null}else if(response=="INVALID_EMAIL"){this.updateSubscribeMessage("Sorry. This email is not valid","danger");this.options.scoopEmail=null}else{this.updateSubscribeMessage("Something appears to have gone wrong adding your email to the list. Please try again later.","danger")}},this);const onFailure=$.proxy(function(error){this.updateSubscribeMessage("Something appears to have gone wrong adding your email to the list. Please try again later.","danger")},this);postScoopSubscribe.then(onSuccess,onFailure)},updateSubscribeMessage:function(message,cssClass){const $subscribeNewsletter=$('.subscribe-newsletter');const $subscribeMessage=$subscribeNewsletter.find('.subscribe-message');$subscribeNewsletter.removeClass('danger warning success').addClass(cssClass);$subscribeMessage.text(message)},launchSmsSignupModal:function(auto=!1){const controller=this;const urlParams=new URLSearchParams(window.location.search);let email=null;if(auto){if(!(email=urlParams.get('email'))){email='no-email'}}else{email=this.options.scoopEmail} controller.modal=new Modal({modalId:"sms-signup-modal",remoteUrl:`/site/smsSignupModal/auto/${auto ? 1 : 0}?email=${encodeURIComponent(email)}`,buttons:[],})},onNotificationsListOpen:function(evt){this.model.isNotificationsListOpen=!0},onNotificationsListClose:function(evt){this.model.isNotificationsListOpen=!1},onNotificationsPanelOpen:function(){this.clearMarkAsSeenTimeout();if($('.dec-notification-unseen').length>0){this.model.markAsSeenTimeoutHandler=setTimeout($.proxy(this.markAsSeen,this),this.options.seenDelay)} const self=this;setTimeout(function(){self.updateNotificationsFade();const $ul=$('#notifications-dropdown .notifications-list-box ul');const $dropdown=$('#notifications-dropdown');$ul.off('scroll.notificationsfade').on('scroll.notificationsfade',function(){self.updateNotificationsFade()});$(window).off('resize.notificationsfade').on('resize.notificationsfade',function(){if($dropdown.hasClass('open')){self.updateNotificationsFade()}})},400)},onNotificationsPanelClose:function(){this.clearMarkAsSeenTimeout();$('#notifications-dropdown .dec-dropdown-content.dropdown-notifications').removeClass('notifications-panel-has-more-below');$('#notifications-dropdown .notifications-list-box ul').off('scroll.notificationsfade');$(window).off('resize.notificationsfade')},updateNotificationsFade:function(){const $dropdown=$('#notifications-dropdown');const $content=$dropdown.find('.dec-dropdown-content.dropdown-notifications');if(!$dropdown.hasClass('open')){return} const ul=$dropdown.find('.notifications-list-box ul')[0];if(!ul){$content.removeClass('notifications-panel-has-more-below');return} const hasMoreBelow=ul.scrollHeight>ul.clientHeight&&(ul.scrollTop+ul.clientHeight700){this.modal=new Modal({modalId:"vidModal",content:"",modalDialogClass:"modal-md",buttons:[]})}else{this.modal=new Modal({modalId:"vidModal",content:"",buttons:[]})}},handleShareBtn:function(evt){const $btn=$(evt.currentTarget);const isPopUp=$btn.hasClass('dec-share-btn-popup');if(isPopUp){window.open($btn.attr('href'),'','menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600')} try{const parameterNames=['method','contentType','itemId'];const formData=new FormData();parameterNames.forEach(parameterName=>{let parameterValue=$btn.data(parameterName);if(!parameterValue){parameterValue=$btn.parents('.dec-share-btn-container').data(parameterName)} if(parameterValue){formData.append(parameterName,parameterValue)}});navigator.sendBeacon(`/site/contentShared`,formData)}catch(error){console.error(`Unable to generate Share event: ${error}`)} if(isPopUp){return!1}},fixNotificationsDropdownStyle:function(){if(window.matchMedia&&window.matchMedia('(min-width: 769px)').matches){return} const notificationsDropdownToggle=document.querySelector('.notifications-dropdown-item .dec-dropdown-toggle');if(notificationsDropdownToggle){notificationsDropdownToggle.addEventListener('mouseenter',()=>{const notificationsIcon=document.querySelector('.notifications-dropdown-item .dec-icon');const notificationsDropdownContent=document.querySelector('#notifications-dropdown .dec-dropdown-content');const contentTriangle=notificationsDropdownContent.querySelector('.dec-dropdown-content-bubble-top-triangle');if(notificationsIcon&¬ificationsDropdownContent&&contentTriangle){const iconRect=notificationsIcon.getBoundingClientRect();const contentRect=notificationsDropdownContent.getBoundingClientRect();const triangleRect=contentTriangle.getBoundingClientRect();let triangleLeft=iconRect.left-contentRect.left+((iconRect.width-triangleRect.width)/2);contentTriangle.style.left=`${triangleLeft}px`;contentTriangle.style.borderBottomColor='#FFFFFF'}},{once:!0})} return},handleEditContainerMarginGuideClick:function(evt){const $btn=$(evt.currentTarget);const $containerMarginGuide=$btn.parents('.container-margin-guide');const id=$containerMarginGuide.data('containerMarginGuideId');const width=$containerMarginGuide.data('containerMarginGuideWidth');const newWidth=prompt('Please enter new width for this container margin guide. You can use 0 or empty to delete this container margin guide. '+'(No changes will be made to the page)',width);if(newWidth===null){return} window.location=`/admin/module/setContainerMarginGuide/id/${id}/width/${newWidth}?returnUrl=${window.location}`},handleChatstackUploadImage:function(evt){let chatstackContainer=$('#chatstack-container');let zIndex=chatstackContainer.css('z-index');chatstackContainer.css('z-index',1000);let withDescription=evt.detail?.withDescription??!1;this.modal=new Modal({modalId:'chatstackUploadImageModal',title:"Upload Image",remoteUrl:"/chatAIResponse/uploadImage/withDescription/"+withDescription,modalDialogClass:"modal-dialog-centered",destroyOnHide:!0,buttons:[]});let _modal=this.modal;this.modal.$el.on('loaded',$.proxy(function(e){$('.btn-upload-img-for-chatstack').on('click',$.proxy(function(e){let btn=$(e.currentTarget);let $imgDescription=btn.closest('.modal').find('#img-description');if($imgDescription.length>0){$('#img-description-for-chatstack').val($imgDescription.val())} let uploadImage=btn.closest('.modal').find('.qq-upload-success').find('.qq-thumbnail-selector');if(uploadImage.length>0){let imgSrc=[];uploadImage.each(function(){imgSrc.push($(this).attr('src'))});let chatstackIframe=document.getElementById('chatstack-js-frame');let event=new CustomEvent('uploadImage',{detail:imgSrc.join(',')});chatstackIframe.contentWindow.document.dispatchEvent(event);let event2=new CustomEvent('chatstackImageUploaded',{detail:imgSrc.join(',')});document.dispatchEvent(event2);_modal.hide()}},this))},this));this.modal.$el.on("hidden.bs.modal",$.proxy(function(e){chatstackContainer.css('z-index',zIndex)},this));this.modal.$el.on("hide",$.proxy(function(e){chatstackContainer.css('z-index',zIndex)},this))},isFooterInView:function(){return footerInView},initFooterObserver:function(){const footer=document.getElementById('footer');if(!footer)return;const observer=new IntersectionObserver((entries)=>{const onMobile=window.innerWidth<=768;const $helloBar=$('#hellobar-bar');const helloBarClosed=$helloBar.length?$helloBar.css('display')==='none':!0;const $chatStackFrame=$("#chatstack-launcher-frame");entries.forEach(entry=>{footerInView=entry.isIntersecting;if(onMobile&&footerInView){$chatStackFrame.addClass('with-hellobar')}else if((onMobile&&!footerInView&&helloBarClosed)||(!onMobile&&footerInView&&helloBarClosed)){$chatStackFrame.removeClass('with-hellobar')}})},{root:null,threshold:0.1,});observer.observe(footer)},injectNavigationParameters:function(){const urlParams=new URLSearchParams(window.location.search);const paramNames=['lang','ct','cc'];paramNames.forEach(paramName=>{const paramValue=urlParams.get(paramName);if(paramValue){this.addUrlParamToAllLinks(paramName,paramValue)}})},addUrlParamToAllLinks:function(paramName,paramValue){if(!paramName||!paramValue){console.error("Parameter name and value must be provided.");return} const links=document.querySelectorAll('a[href]');links.forEach(link=>{const currentHref=link.getAttribute('href');if(!currentHref||currentHref.startsWith('#')||currentHref.startsWith('mailto:')||currentHref.startsWith('javascript:')){return} try{const absoluteUrl=new URL(currentHref,window.location.href);if(absoluteUrl.origin!==window.location.origin){return} const params=absoluteUrl.searchParams;if(!params.has(paramName)){params.set(paramName,paramValue);let newHref=absoluteUrl.pathname+absoluteUrl.search+absoluteUrl.hash;if(currentHref.startsWith(window.location.origin)){newHref=absoluteUrl.href}else if(currentHref.startsWith('/')){newHref=absoluteUrl.pathname+absoluteUrl.search+absoluteUrl.hash} link.setAttribute('href',newHref)}}catch(e){console.warn("Skipping malformed URL:",currentHref,e)}})}});MainController.requireModal=function(options){let ModalModule;if(options.isUpgradedFramework){if(options.uiDesignVersion==UiVersion.RENAISSANCE_2024){ModalModule=require("Modal-ren")}else{ModalModule=require("ModalUpgraded")}}else{ModalModule=require("Modal")} return ModalModule};return MainController})