//Img Replacement
//Replaces the img source with the source provided and the selector
function replaceImgSrc(url, selector) {
$(selector).attr('src', url);
}
//Social Media Additions
//Adds social media links to the social media header and footer
function addSocialIcons(socialMediaLinks){
socialMediaLinks.forEach(link=>{
if((link.hasOwnProperty('name') && link?.name?.length) && (link.hasOwnProperty('url') && link?.url?.length)){
$('.c-social-media > a').parent().append(``);
$('footer .c-socialMedia').append(``);
}
else {
throw Error(`Missing Required Fields: name or url`);
}
});
}
//Second Header Button
//Adds additionalButtons in the header when given an array of button objects
function addHeaderBtn(buttons){
buttons.forEach(btn=>{
if((btn.hasOwnProperty('text') && btn?.text?.length) && (btn.hasOwnProperty('url') && btn?.url?.length)){
//Setup Properties
const selector = btn?.selector || 'additionalHeaderBtn';
const searchSelector = '.' + selector.replace(' ', '.');
const icon = btn?.icon || '';
const target = btn?.target || '_self';
if($('.c-topbar-cta-links').find('.c-header-btn').length > 0){ //Has a header button already
$('.c-header .c-header-btn a').first().clone().addClass(selector).appendTo('.c-topbar .c-header-btn');
$('.c-header .c-header-btn').find(searchSelector).attr('href', btn.url).attr('target', target).text(btn.text);
if(icon){
$('.c-topbar-cta-links .c-header-btn').find(searchSelector).prepend('');
$('.c-topbar-cta-links .c-header-btn').find(searchSelector + ' i').addClass(icon);
}
//Mobile Addittion
$('#mainNav .c-topnav__navwrapper .c-header-nav--btn').append(``);
}
else {
$('.c-topbar-cta-links').append('
');
$('.c-topbar-cta-links .c-header-btn').append(``);
if(icon){
$('.c-topbar-cta-links .c-header-btn').find(searchSelector).prepend('');
$('.c-topbar-cta-links .c-header-btn').find(searchSelector + ' i').addClass(icon);
}
//Mobil Addition
$('#mainNav .c-topnav__navwrapper').append(``);
}
}
else{
throw Error(`Missing Required Fields: text or url`);
}
});
}
//Custom Icons
//Replaces icons in a given section
function replaceIcon(iconSet){
const { icons} = iconSet;
const selector = iconSet?.selector || '.dev-customIcons';
if(typeof icons !== "undefined" && icons?.length){
// Run for Each Section With Class
$(selector).each(function(){
//Run for Each Box in Section
$(this).find('.box').each(function(){
icons.forEach(icon=>{
if($(this).find('.c-box__title:contains(' + icon.name + ')').length){
//Exchange Icons
if(icon.hasOwnProperty('imgSrc')){
$(this).find('.c-box-icon').replaceWith('
');
}
else if (icon.hasOwnProperty('icon')){
$(this).find('.c-box-icon').removeClass().addClass('c-box-icon ' + icon.icon);
}
}
});
});
$(this).addClass('iconReplaced');
})
}
else{
throw Error('Missing Required Fields: selector or icons');
}
}
//Video Backgrounds
function videoBackground(videoObject){
videoObject.forEach(video=>{
if(typeof video.type !== 'undefined' && video.type.length){
if(typeof video.selector !== 'undefined' && video.selector.length){
if(video.type == 'youtube'){
youtubeBGsetup(video);
}
else if(video.type == 'video'){
videoBGsetup(video);
}
else if(video.type == 'iframe'){
iframeBGSetup(video);
}
}
else {
throw Error('Missing Required Fields: selector');
}
}
else{
throw Error('Missing Required Fields: type');
}
});
};
//Youtube Video BG Code
function youtubeBGsetup(videoBG) {
if(typeof videoBG.youtubeCode !== 'undefined' && videoBG.youtubeCode.length){ ///Make sure code is added
const selector = videoBG?.selector.length ? '.' + videoBG.selector : '';
const videoContainer = $('.dev-videoBackground' + selector);
if ($(videoContainer).length){
$(videoContainer).find('.overlay').first().append(``);
// Activate YouTube Video Banner Backgrounds
jQuery(document).ready(function(){
jQuery('[data-youtube]').youtube_background();
});
}
}
else{
throw Error('Missing Required Field: youtubeCode');
}
};
//Uploaded Video BG Code
function videoBGsetup(videoBG) {
if((typeof videoBG.videoSRC !== 'undefined' && videoBG.videoSRC.length) && (typeof videoBG.poster !== 'undefined' && videoBG.poster.length)){
const selector = videoBG?.selector.length ? '.' + videoBG.selector : '';
const videoContainer = $('.dev-videoBackground' + selector);
if($(videoContainer).length){
//Add Video to Section
const videoBannerCode = ``;
$(videoContainer).find('.overlay').first().append(videoBannerCode);
}
}
else{
throw Error('Missing Required Field: videoSRC or poster');
}
}
//Iframe Video BG Code
function iframeBGSetup(videoBG) {
if(typeof videoBG.iframeSRC !== 'undefined' && videoBG.iframeSRC.length){
const selector = videoBG?.selector.length ? '.' + videoBG.selector : '';
const videoContainer = $('.dev-videoBackground' + selector);
if($(videoContainer).length){
//Add Video to Section
const videoBannerCode = ``;
$(videoContainer).find('.overlay').first().append(videoBannerCode);
function resizeVideo(section) {
section = `${selector}.dev-videoBackground`;
var sectionHeight = $(section).outerHeight(true);
var sectionWidth = $(section).outerWidth(true);
var sectionRatio = sectionWidth/sectionHeight;
var ratio = 16/9;
if(sectionHeight >= sectionWidth){
sectionWidth = sectionHeight * ratio;
}
else {
sectionHeight = sectionWidth/ratio;
if(!checkRatio(ratio, sectionRatio)){
var difference = ratio - sectionRatio;
sectionWidth = sectionWidth + (sectionWidth * difference);
sectionHeight = sectionWidth/ratio;
}
}
//Assign dimensions to iframe
$(section).find('iframe').css('height', sectionHeight + 'px');
$(section).find('iframe').css('width', sectionWidth + 'px');
}
function checkRatio(aspectRatio, sectionRatio){
if(aspectRatio <= sectionRatio){
return true;
}
else {
return false;
}
}
$(window).load(resizeVideo);
$(window).resize(resizeVideo);
}
}
else{
throw Error('Missing Required Field: iframeSRC');
}
}
//Team Image Replacement
function replaceTeamImages(teamImages){
//Team Sections
if($('.section_TeamList').length){
$('.section_TeamList img[class*="img--developer"]').each(function(){
if ($(this).attr('alt')){
const key = $(this).attr('alt').match(/^[\w\s\.]*?(?=,)|^[\w\s\.]*$/gi)[0].replace(/\s+/g, ' ');
if (key){
teamImages.forEach(teamMember=>{
if(typeof teamMember.teamName !== 'undefined' && teamMember.teamName.length){
if(teamMember.teamName == key){
if (teamMember.imgSrc) {
$(this).attr('src', teamMember.imgSrc);
}
}
}
});
}
}
});
}
//Individual Bio Sections
if($('body[class*="page-team"]').length){
$('#agentContent .team-img img')
if ($('#agentContent .team-img img').attr('alt')){
const key = $('#agentContent .team-img img').attr('alt').match(/^[\w\s\.]*?(?=,)|^[\w\s\.]*$/g)[0].replace(/\s+/g, ' ');
if (key){
teamImages.forEach(teamMember=>{
if(typeof teamMember.teamName !== 'undefined' && teamMember.teamName.length){
if(teamMember.teamName == key){
if (teamMember.imgSrc) {
$('#agentContent .team-img img').attr('src', teamMember.imgSrc);
}
}
}
});
}
}
}
}
//Modify Contact Page
function contactPageModify(contactEdits){
if($('body').hasClass('page-contact')){
contactEdits.forEach(function(loc){
if((loc.hasOwnProperty('location') && loc?.location?.length) && (loc.hasOwnProperty('edits') && loc?.edits?.length)){
if (loc.location == 'all'){
$('.c-contacts .contact-block').each(function(){
modifyContactBlock($(this), loc.edits);
});
}
else{
const parent = $(`.c-contacts .contact-block__info h2:contains("${loc.location}")`).closest('.contact-block');
if($(parent).length){
modifyContactBlock($(parent), loc.edits);
}
else{
throw Error(`${loc.location} is not a valid Location`);
}
}
}
});
}
}
//System Page Modification
function modifyContactBlock(parent, edits){
edits.forEach(function(edit){
if((edit.hasOwnProperty('type') && edit?.type.length) && (edit.hasOwnProperty('selector') && edit?.selector.length)){
const {type, selector, edit: change} = edit;
switch (type) {
case 'Add Before':
if (typeof change == 'undefined' || !change?.length) throw Error('Edit field cannot be missing');
$(parent).find(selector).before(change);
break;
case 'Add After':
if (typeof change == 'undefined' || !change?.length) throw Error('Edit field cannot be missing');
$(parent).find(selector).after(change);
break;
case 'Edit':
if (typeof change == 'undefined' || !change?.length) throw Error('Edit field cannot be missing');
$(parent).find(selector).html(change);
break;
case 'Delete':
$(parent).find(selector).remove();
break;
case 'Replace':
if (typeof change == 'undefined' || !change?.length) throw Error('Edit field cannot be missing');
$(parent).find(selector).replaceWith(change);
break;
default:
throw Error(`${type} is not a valid Edit Type`);
}
}
else{
throw Error('Missing required edits field (type or selector)');
}
});
}
//Cookie notification
function cookiePopUp(cookieObj){
if(typeof cookieObj.type !== 'undefined' && cookieObj.type.length){
const time = cookieObj?.time || '4000';
const contentType = cookieObj?.contentType || 'html';
if(cookieObj.type == 'one-page'){
if(typeof cookieObj.selector !== 'undefined' && cookieObj.selector.length){
if($(cookieObj.selector).length){
$(cookieObj.selector).addClass('popUpSection');
$(cookieObj.selector).wrapInner('');
var backgroundSettings = $(cookieObj.selector).css('background');
$('.popUpContent').css('background', backgroundSettings);
checkCookie(cookieObj.selector, time, contentType);
}
}
else{
throw Error('Missing required edits field (selector)');
}
}
else if(cookieObj.type == 'sitewide'){
if(typeof cookieObj.content !== 'undefined' && cookieObj.content.length){
checkCookieSite(cookieObj.content, time, contentType)
}
else{
throw Error('Missing content');
}
}
else {
throw Error('Invalid type.');
}
}
else{
throw Error('Missing required edits field (type)');
}
}
//Set cookie
function setCookie(cname, cvalue) {
document.cookie = cname + "=" + cvalue + "; ";
}
//Get cookie
function getCookie(cname) {
var name = cname + "=";
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);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
//Check cookie is existing for single section/page
function checkCookie(selector, seconds, type) {
var popUp = getCookie("customPopUp");
if (popUp == "alreadyAppeared") {
} else {
setCookie("customPopUp", "alreadyAppeared");
setTimeout(function(){
$.fancybox.open({
src : $(selector).find('.popUpContent'),
type : type,
animationEffect: "fade",
hideOnContentClick: false
});
}, seconds);
}
}
//Check cookie is existing for sitewide
function checkCookieSite(content, seconds, type) {
var popUp = getCookie("customPopUp");
if (popUp == "alreadyAppeared") {
} else {
setCookie("customPopUp", "alreadyAppeared");
setTimeout(function(){
$.fancybox.open({
src : content,
type : type,
animationEffect: "fade",
hideOnContentClick: false
});
}, seconds);
}
}
//Custom Floating Button
//Adds a floating button on the site when given an array of button objects
function addFloatingBtn(btns, mobileStandard, desktopPosition){
btns.forEach(b=>{
if((b.hasOwnProperty('content') && b?.content?.length) && (b.hasOwnProperty('url') && b?.url?.length)){
//Setup Properties
const btnClass = b?.btnClass || 'customFloatingBtn';
const target = b?.target || '_self';
if($('.customFloatingBtn-Container').length == 0){
$('header.c-header').prepend('');
if(mobileStandard){
$('.customFloatingBtn-Container').addClass('mobileStandard');
}
else {
$('.customFloatingBtn-Container').addClass('mobileFixed');
}
if(desktopPosition == 'left'){
$('.customFloatingBtn-Container').addClass('desktopLeft');
}
else if (desktopPosition == 'right'){
$('.customFloatingBtn-Container').addClass('desktopRight');
}
}
$('.customFloatingBtn-Container').append('' + b.content + '');
}
else{
throw Error(`Missing Required Fields: content or url`);
}
});
}