/
var
/
www
/
barefootlaw.org
/
wp-content
/
themes
/
barefoot
/
assets
/
js
/
Upload File
HOME
/** * Theme functions file. * * Contains handlers for navigation, footer and much, much more. */ ;(function ($, window, document, undefined) { 'use strict'; var pluginName = 'themeCore', defaults = {}, $doc = $(document), $body = $('body'), $win = $(window), $html = $('html'), isMobile = false; // The actual plugin constructor function Plugin(element, options) { this.element = element; this.settings = $.extend({}, defaults, options); this._defaults = defaults; this._name = pluginName; this.__constructor(); } // Avoid Plugin.prototype conflicts $.extend(Plugin.prototype, { __constructor: function () { this.body = $(document.body); this.html = $('html'); this.htmlbody = $('html, body'); this.win = $(window); this.adminBar = $('#wpadminbar'); this.preloader = $('.preloader'); this.scrTop = $('.scrolltop'); this.header = $('header[role="banner"]'); this.headerHelper = $('.header-helper'); this.footer = $('footer[role="contentinfo"]'); this.wrapperContent = $('#wrapper-content'); this.buildApp(this.element, this.options); }, buildApp: function (element, options) { var that = this; /*Helpers*/ that.ieDetect(); that.mobileDetect(); that.osDetect(); that.browserDetect(); /*End Helpers*/ that.activate(); that.typography(); that.forms(); that.vc(); that.headerHelpHandler(); that.menu(); // Blog settings that.blog(); that.blogStretchOverlayAuth(); that.simpleMenu(); that.floatPageTitle('load'); that.widgetSettings(); $doc.ajaxComplete(function () { var $cf7 = $('form.wpcf7-form'); if ($cf7.size() > 0) { $cf7.find('.wpcf7-form-control').each(function () { if ($(this).hasClass('wpcf7-not-valid')) { $(this).closest('label').addClass('wpcf7-not-valid-label'); } else { $(this).closest('label').removeClass('wpcf7-not-valid-label'); } }); } }); $(window).load(function () { $body.addClass('body-loaded'); $html.addClass('html-loaded'); that.preloader.delay(100).fadeOut(300); that.scrollTop(); that.headerSticky(); that.stickyFooter('load'); that.widgetStertch(); }).scroll(function () { if (!isMobile) { that.scrollTop(); that.headerSticky(); that.floatPageTitle('scroll'); that.stickyFooter('scroll'); } }); document.addEventListener('touchmove', function () { that.scrollTop(); that.headerSticky(); that.floatPageTitle('scroll'); that.stickyFooter('scroll'); }, {passive: true}); var now = Date.now || function () { return new Date().getTime(); }; var debounce = function (func, wait, immediate) { var timeout, args, context, timestamp, result; var later = function () { var last = now() - timestamp; if (last < wait && last >= 0) { timeout = setTimeout(later, wait - last); } else { timeout = null; if (!immediate) { result = func.apply(context, args); if (!timeout) context = args = null; } } }; return function () { context = this; args = arguments; timestamp = now(); var callNow = immediate && !timeout; if (!timeout) timeout = setTimeout(later, wait); if (callNow) { result = func.apply(context, args); context = args = null; } return result; }; }; var resizeDebounce = debounce(function () { that.stickyFooter('resize'); that.headerHelpHandler(); that.floatPageTitle('resize'); that.widgetStertch(); that.blogStretchOverlayAuth(); }, 200); window.addEventListener('resize', resizeDebounce); }, blogStretchOverlayAuth : function() { var $overlay = $('.js-stretch-overlay'), winWidth = $(window).width(); if($overlay.length > 0) { $overlay.each(function(i,e){ var offsetLeft = $(e).parent().offset().left; $overlay.css({ 'width' : winWidth, 'left' : -1 * offsetLeft }); }); } }, widgetStertch: function () { var self = this; if ($('.widget-hr-fullwidth').length > 0) { $('.widget-hr-fullwidth').each(function () { var $this = $(this), offsetLeft, width; if ($('body').hasClass('layout-type-boxed')) { width = self.footer.width(); offsetLeft = $('.footer-widget-row').offset().left - (($(window).width() - width) / 2); } else { width = $(window).width(); offsetLeft = $('.footer-widget-row').offset().left; } $this.css({ 'width': width, 'position': 'relative', 'max-width': 'none', 'left': -1 * offsetLeft, 'box-sizing': 'border-box' }); }); } }, widgetSettings: function () { var self = this, widgets = ['.widget_calendar', '.widget_archive', '.widget_categories', '.widget_contact_form', '.widget_tag_cloud', '.widget_layered_nav', '.widget_rating_filter', '.widget_product_categories'], widgetClass, $widget, $li, $chosenSingle, clearNode, $formElement, i; $('.widget').find('select:not(.wpcf7-select) option').each(function () { var $html = $(this).html(); $html.replace(/\(([^*]+)\)/g, '<span>$1</span>'); }); for (i = 0; i <= widgets.length; i++) { widgetClass = widgets[i]; $widget = $(widgetClass); if ($widget.size() > 0) { $widget.each(function () { var $this = $(this); switch (widgetClass) { case '.widget_rating_filter' : $li = $this.find('.wc-layered-nav-rating a'); $li.each(function () { var $html = $(this).html(); clearNode = $html.replace(/\((.*?)\)/g, '<span class="counter-list">$1</span>'); $(this).html(clearNode); }); break; case '.widget_tag_cloud' : var $counter = $this.find('.tag-link-count'); $counter.each(function () { var $html = $(this).html(); clearNode = $html.replace(/\((.*?)\)/g, '$1'); $(this).html(clearNode); }); break; case '.widget_layered_nav' : case '.widget_product_categories' : $this.find('.count').each(function(){ var countHtml = $(this).html(); $(this).html( countHtml.replace(/\((.*?)\)/g, '$1') ); }); break; case '.widget_archive' : case '.widget_categories' : $li = $this.find('.widget-body-inner li'); $chosenSingle = $this.find('.chosen-single'); $li.each(function () { var $html = $(this).html(); clearNode = $html.replace(/\((.*?)\)/g, '<span class="counter-list">$1</span>'); if (clearNode.indexOf('counter-list') !== -1) { $this.find('a').css('margin-right', '20px'); if ($(this).find('ul.children').length > 0) { $(this).addClass('has-children'); } } $(this).html(clearNode); }); if ($chosenSingle.size() > 0) { $chosenSingle.html($chosenSingle.html().replace(/ /g, '')); } break; case '.widget_contact_form' : $formElement = $this.find('.wpcf7-form-control-wrap'); if ($formElement.size() > 0) { $formElement.addClass('form-group'); } break } }); } } }, layoutStretchElement: function ($el, $el_full) { var el_margin_left = parseInt($el.css('margin-left'), 10), el_margin_right = parseInt($el.css('margin-right'), 10), offset, width = $(window).width(); if ($el.closest('.modal-maincontent').length > 0) { var widthWindows = $el.closest('.modal-dialog').width(); width = $el.closest('.modal-content').width() + 3; var fakeGutters = $el_full.offset().left - ((widthWindows - width) / 2); offset = 0 - fakeGutters - el_margin_left; } else { if ($('body').hasClass('layout-type-boxed')) { var widthWindow = width; width = $('#wrapper-main').width(); var fakeGutter = $el_full.offset().left - ((widthWindow - width) / 2); offset = 0 - fakeGutter - el_margin_left; } else { offset = 0 - $el_full.offset().left - el_margin_left; } } return {offset: offset, width: width, element: $el, elementFullWidth: $el_full, marginLeft: el_margin_left, marginRight: el_margin_right}; }, blog: function () { var self = this, $figure = $doc.find('figure.gallery-item'), $commentForm = $('#commentform'); $('.comment-text-body table').addClass('table'); if ($body.hasClass('custom-background')) { $html.css('background-color', 'transparent'); } $('blockquote p').each(function () { var $this = $(this); if ($this.html().replace(/\s| /g, '').length === 0) { $this.remove(); } }); if ($commentForm.length > 0) { $commentForm.validate({ errorClass: 'wpcf7-not-valid', errorPlacement: function () { return true }, highlight: function (element, errorClass, validClass) { $(element).addClass(errorClass).removeClass(validClass); }, focusInvalid: false, unhighlight: function (element, errorClass, validClass) { $(element).removeClass(errorClass).addClass(validClass); } }); } if ($figure.size() > 0) { $figure.each(function () { var $a = $(this).find('a'); if ($a.length > 0) { var href = $a.attr('href').slice(-3); if (href === 'jpg' || href === 'png' || href === 'jpeg' || href === 'bmp' || href === 'gif') { $a.addClass('wp-gallery'); } } }); } // Content Feed Carousel var $jsCarouselContainer = $('.js-carousel-container'); if($jsCarouselContainer.length > 0) { $jsCarouselContainer.each(function(index, item){ var $this = $(item), $jsCarousel = $this.find('.js-carousel'), slideCount = $jsCarousel.children().length, $jsPrev = $this.find('.js-prev'), $jsNext = $this.find('.js-next'), slideWidth, $jsPagination = $this.find('.js-pagination'); switch (slideCount) { case 3 : slideWidth = 800; break; case 2 : slideWidth = 800; break; case 1 : slideWidth = 100; break; default : slideWidth = 800; } var carouselParams = { responsive : true, auto: { play: false }, items: { visible: { min: 1, max: slideCount > 3 ? 3 : slideCount }, width: slideWidth, height: 'variable' }, scroll : { fx : 'scroll', items : 1, easing : 'swing' }, prev : $jsPrev, next : $jsNext, pagination: $jsPagination, width: 100, height : 'variable' }; $jsCarousel.carouFredSel(carouselParams); }); } // Comment scroll -> to comment form $('.single-post-head__comments a[href="#respond"]').on('click', function() { if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { var target = $(this.hash); target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); if (target.length) { var moreSpace = 20, $header = $('header[role="banner"]'); if($header.hasClass('affix-top') || $header.hasClass('affix')) { moreSpace += $header.outerHeight(true); } $('html, body').animate({ scrollTop: target.offset().top - moreSpace }, 1000); return false; } } }); }, floatPageTitle: function () { var $pageTitle = $('.page-title-float'), $content = $('.content'), offsetTop, scrollTop, $header, $adminBar, heightHeight, adminBarHeight; if ($pageTitle.size() > 0 && $content.size() > 0) { offsetTop = $content.offset().top; scrollTop = $win.scrollTop(); $header = $('header.header'); $adminBar = $('#wpadminbar'); heightHeight = $header.size() > 0 ? $header.outerHeight(true) : 0; adminBarHeight = $adminBar.size() > 0 ? $adminBar.outerHeight(true) : 0; if ($body.hasClass('admin-bar')) { offsetTop -= adminBarHeight } if ($body.hasClass('basement-enable-sticky')) { offsetTop -= heightHeight } if (scrollTop >= offsetTop) { $pageTitle.addClass('vis'); } else { $pageTitle.removeClass('vis'); } } }, vc: function () { var $accordion = $doc.find('.vc_general.vc_tta.vc_tta-accordion'), xH; if ($accordion.size() > 0) { $accordion.each(function () { var $this = $(this), $h4 = $this.find('.vc_tta-panel-title'); if ($h4.hasClass('vc_tta-controls-icon-position-left')) { $this.addClass('vc_accordion-icon-left'); } else { $this.addClass('vc_accordion-icon-right'); } }); } $(document).on('mouseenter mouseleave', '.vc_single_image_img_scroll figure', function (e) { var height = $(this).outerHeight(true); if (e.type === 'mouseenter') { xH = $(this).find('img').css('height'); xH = parseInt(xH); xH = xH - height; xH = '-' + xH + 'px'; $(this).find('img').css('marginTop', xH); } else { $(this).find('img').css('marginTop', '0px'); } }); }, activate: function () { var instance = this; // scrollTop function instance.scrTop.on('click', function (e) { e.preventDefault(); instance.htmlbody.stop(true, true).animate({ scrollTop: 0 }, 500); }); $('.modal').on('shown.bs.modal', function () { $(this).find('[autofocus]').focus(); }); }, forms: function () { $('.wpcf7-form-control-wrap + br').remove(); $('.wpcf7-submit').parent().addClass('wpcf7-wrap-submit'); $('select:not(.js-bf-grid-filter):not(.orderby)').uniform(); $(document).ajaxComplete(function (t) { var $select = $('.wpcf7-select'); if ($select.size() > 0) { $select.each(function () { if ($(this).hasClass('wpcf7-not-valid')) { $(this).parent().addClass('wpcf7-not-valid'); } else { $(this).parent().removeClass('wpcf7-not-valid'); } }); } }); $('.wpcf7-wrap-submit').prev().css('margin-bottom', '0'); }, menu : function () { var $menu = $('#nav-lang, #nav-menu'); $menu.superfish({ delay: 0, animation: { opacity: 'show', marginTop: 0, marginBottom: 0 }, animationOut: { opacity: 'hide', marginTop: '14px', marginBottom: '14px' }, cssArrows: false, speed: 'fast', speedOut: 'fast', onBeforeShow: function () { var $menu = $(this), $parent = $menu.closest('ul').parent(); if($parent.length > 0) { var depth = $menu.data('depth'), offsetLeft = $parent.offset().left, winWidth = $(window).width(), menuWidth = $parent.outerWidth(true), offsetRight = winWidth - (offsetLeft + menuWidth); if ($parent.hasClass('wpnav-dropdown') && depth > 0 && menuWidth > offsetRight) { $menu.addClass('sf-onleft'); } } }, onHide: function () { var $this = $(this); $this.removeClass('sf-onleft'); } }); }, headerHelpHandler: function () { var $header = this.header, $headerHelper = this.headerHelper; if ($headerHelper.length > 0) { $headerHelper.css({ 'height': $header.outerHeight(true) }); } }, headerSticky: function () { var $header = this.header, scroll = ($(window).scrollTop() || $('body').scrollTop()), headerStyle = $header.data('bg') ? $header.data('bg').split(',') : [], r, g, b, opacity, headerOffset = $header.data('offset-top') || 0; if ($header.hasClass('header_sticky_enable') || $header.hasClass('header_sticky_after_scroll_enable')) { $header.addClass('affix-top'); if (scroll > headerOffset) { $header.addClass('affix').removeClass('affix-top'); } else { $header.addClass('affix-top').removeClass('affix'); } if (headerStyle.length > 0) { r = headerStyle[0]; g = headerStyle[1]; b = headerStyle[2]; opacity = headerStyle[3]; if (opacity !== '1') { if (scroll > headerOffset) { $header.css('background-color', 'rgba(' + r + ',' + g + ',' + b + ',1)'); } else { $header.css('background-color', 'rgba(' + r + ',' + g + ',' + b + ',' + opacity + ')'); } } } } }, simpleMenu: function () { var $menuWrapper = $('.simple-menu-pages'), $link = $menuWrapper.find('.menu-item-has-children > a'), $back = $('.simple-menu-back'); $link.on('click', function (e) { var $this = $(this), id = $this.parent().data('id'), $simpleElement = $this.closest('.simple-menu-element'), $openElement = $menuWrapper.children('div[data-id="' + id + '"]'), depth; if ($openElement.size() > 0 && !$this.parent().hasClass('simple-mega-link')) { e.preventDefault(); $simpleElement.addClass('fade').removeClass('show').delay(150).queue('fx', function () { $(this).addClass('out').dequeue(); $('.menu-simple-controls').css('visibility', 'hidden'); }); setTimeout(function () { $back.addClass('show').attr('href', '#menu-item-' + id); }, 200); $openElement.delay(330).queue('fx', function () { setTimeout(function () { $('.menu-simple-controls').css('visibility', 'visible'); }, 100); $(this).removeClass('out').addClass('show').dequeue(); if ($(this).hasClass('simple-menu-mega')) { $(this).closest('.modal-dialog').addClass('modal-dialog-mega'); } else { $(this).closest('.modal-dialog').removeClass('modal-dialog-mega'); } depth = parseInt($(this).data('depth')); $('.current-lvl').text('0' + depth); $('.prev-lvl').text('0' + (depth - 1)); }); } }); $back.on('click', function (e) { e.preventDefault(); var $this = $(this), goto = $this.attr('href'), id = goto.replace(/\D/g, ''), $goto, $simpleElement, parentId, $openElement, depth; if (goto && $(goto).size() > 0) { $goto = $(goto); $simpleElement = $goto.closest('.simple-menu-element'); parentId = $simpleElement.data('id'); $openElement = $menuWrapper.children('div[data-id="' + id + '"]'); if ($simpleElement.size() > 0) { $openElement.addClass('fade').removeClass('show').delay(150).queue('fx', function () { $(this).addClass('out').dequeue(); $('.menu-simple-controls').css('visibility', 'hidden'); depth = parseInt($simpleElement.data('depth')); if (!depth) { depth = '1'; } $('.current-lvl').text(''); $('.prev-lvl').text(''); setTimeout(function () { $('.current-lvl').text('0' + depth); $('.prev-lvl').text('0' + (depth - 1)); }, 100); }); $simpleElement.delay(330).queue('fx', function () { setTimeout(function () { $('.menu-simple-controls').css('visibility', 'visible'); }, 100); $(this).removeClass('out').addClass('show').dequeue(); $('.modal-dialog').removeClass('modal-dialog-mega'); }); if (parentId === undefined || parentId === null) { $back.removeClass('show').attr('href', ''); $('.prev-lvl').text(''); $('.current-lvl').text(''); } else { $back.addClass('show').attr('href', '#menu-item-' + parentId); } } } }); // TODO: Code for Mega menu // Hide mega menu after mouseleave from megamenu container $(document).on('mouseleave', '.js-container-megamenu-trigger', function (event) { var gotoElement = event.toElement || event.relatedTarget; if (gotoElement !== null && gotoElement.className.indexOf('sf-mega') !== -1) { $(this).closest('.sf-mega').css('display', 'none'); } }); // Fix drop down menu shadow for Safari html.is-safari if($('html.is-safari .menu-shadow--default').length > 0) { var topShadow = parseInt($(' .menu-shadow--default').css('top')); $('html.is-safari .menu-shadow--default').css('top',topShadow + 5); } }, typography: function () { var self = this; $('img').parent('a').addClass('reset-link'); $('.table-responsive > p, .reset-list > p, .liststyle1 > p, .liststyle2 > p, dl > br').remove(); $('.maincontent span > a[style*="color"], .maincontent a > span[style*="color"]').each(function (i, e) { if ($(this).is('span')) { $(this).closest('a').attr('id', 'color-link-' + i); } else { $(this).attr('id', 'color-link-' + i); } self.addStylesheetRules([ /* ['h2', ['color', 'red'], ['background-color', 'green', true] ],*/ ['#color-link-' + i + '::after', [ 'background-color', $(this).css('color') ] ] ]); }); $('.maincontent table').each(function(){ if(!$(this).hasClass('table')) { $(this).addClass('table'); } }); }, addStylesheetRules: function (rules) { var styleEl = document.createElement('style'), styleSheet; document.head.appendChild(styleEl); styleSheet = styleEl.sheet; for (var i = 0, rl = rules.length; i < rl; i++) { var j = 1, rule = rules[i], selector = rules[i][0], propStr = ''; if (Object.prototype.toString.call(rule[1][0]) === '[object Array]') { rule = rule[1]; j = 0; } for (var pl = rule.length; j < pl; j++) { var prop = rule[j]; propStr += prop[0] + ':' + prop[1] + (prop[2] ? ' !important' : '') + ';\n'; } styleSheet.insertRule(selector + '{' + propStr + '}', styleSheet.cssRules.length); } }, scrollTop: function () { var instance = this; if ($win.scrollTop() > 300) { instance.scrTop.addClass('vis'); } else { instance.scrTop.removeClass('vis').removeAttr('style'); } }, stickyFooter: function (type) { var instance = this, $footerRow = instance.footer.find('.footer-row'), footerHeight = instance.footer.outerHeight(true), contentOffsetTop, windowHeight = $win.height(), scrollTop = $win.scrollTop(), wrapperContentOffset = instance.wrapperContent.length > 0 ? instance.wrapperContent.offset().top : 0; if ($('.content').length > 0) { contentOffsetTop = $('.content').offset().top; } else { contentOffsetTop = $('.wrapper-main').length > 0 ? $('.wrapper-main').offset().top : 0; } function hideStickyFooter() { if (instance.body.hasClass('sticky-footer') && $(window).scrollTop() < contentOffsetTop) { instance.footer.css({ 'visibility': 'hidden', 'zIndex': -1 }); } else { instance.footer.css({ 'visibility': 'visible', 'zIndex': 1 }); } } if (type !== 'scroll') { if ($footerRow.length > 0 && instance.isEmpty($footerRow)) { $footerRow.remove(); } else { instance.wrapperContent.attr('style', 'min-height: calc(100vh - ' + (footerHeight + wrapperContentOffset) + 'px)'); if (instance.body.hasClass('is-fix-footer')) { instance.body.css({ 'margin-bottom': footerHeight }); } else if (instance.body.hasClass('is-fix-boxed-footer')) { instance.wrapperContent.css({ 'margin-bottom': footerHeight }); } hideStickyFooter(); } } else { hideStickyFooter(); } }, // Help methods screenType: function () { var envs = ['xs', 'sm', 'md', 'lg'], $el = $('<div>'); $el.appendTo($('body')); for (var i = envs.length - 1; i >= 0; i--) { var env = envs[i]; $el.addClass('hidden-' + env); if ($el.is(':hidden')) { $el.remove(); return env } } }, browserDetect: function () { var browserType = '', isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0, isFirefox = typeof InstallTrigger !== 'undefined', isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === '[object SafariRemoteNotification]'; })(!window['safari'] || safari.pushNotification), isIE = /* @cc_on!@ */false || !!document.documentMode, isEdge = !isIE && !!window.StyleMedia, isChrome = !!window.chrome && !!window.chrome.webstore, isBlink = (isChrome || isOpera) && !!window.CSS; if (isOpera) { browserType = 'is-opera'; } else if (isFirefox) { browserType = 'is-firefox'; } else if (isSafari) { browserType = 'is-safari'; } else if (isIE) { browserType = 'is-ie'; } else if (isEdge) { browserType = 'is-edge'; } else if (isChrome) { browserType = 'is-chrome'; } else if (isBlink) { browserType = 'is-blink'; } $html.addClass(browserType); }, osDetect: function () { var OSName = 'unknown-os'; if (navigator.appVersion.indexOf('Win') !== -1) OSName = 'windows-os'; if (navigator.appVersion.indexOf('Mac') !== -1) OSName = 'mac-os'; if (navigator.appVersion.indexOf('X11') !== -1) OSName = 'unix-os'; if (navigator.appVersion.indexOf('Linux') !== -1) OSName = 'linux-os'; $html.addClass(OSName); }, mobileDetect: function () { if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) { $body.addClass('is-mobile'); isMobile = true; } else { $body.addClass('no-mobile'); isMobile = false; } }, ieDetect: function () { var ua = window.navigator.userAgent, msie = ua.indexOf('MSIE '), trident = ua.indexOf('Trident/'), edge = ua.indexOf('Edge/'); if (msie > 0) { $html.addClass('ie-10'); } else if (trident > 0) { $html.addClass('ie-11'); } else if (edge > 0) { $html.addClass('ie-edge'); } else { return false; } }, isEmpty: function (el) { return !$.trim(el.html()); } }); $.fn[pluginName] = function (options) { return this.each(function () { if (!$.data(this, 'plugin_' + pluginName)) { $.data(this, 'plugin_' + pluginName, new Plugin(this, options)); } }); }; })(jQuery, window, document); jQuery(document).ready(function ($) { $(document.body).themeCore(); });