Skip to content

Instantly share code, notes, and snippets.

@muks999
Last active January 11, 2019 23:42
Show Gist options
  • Save muks999/46ad60d0f6c81198e15652b685af3574 to your computer and use it in GitHub Desktop.
Save muks999/46ad60d0f6c81198e15652b685af3574 to your computer and use it in GitHub Desktop.
DIVI "hacks" sticky script + Scripts
<script type="text/javascript">
jQuery(document).ready(function($) {
$('div:not(.et_mobile_menu) .lightbox-content, div:not(.et_mobile_menu) [class*="lightbox-content-"]').addClass('mfp-hide');
$('div:not(.et_mobile_menu) .lightbox-trigger').magnificPopup({ items: { src: 'div:not(.et_mobile_menu) .lightbox-content', type: 'inline' } });
$('div:not(.et_mobile_menu) [class*="lightbox-trigger-"]').each(function(){
var triggerClass = Array.prototype.find.call(this.classList, function(clazz){
return clazz.indexOf('lightbox-trigger-') > -1;
});
var suffix = triggerClass.split('lightbox-trigger-')[1];
var content = '.lightbox-content-'+ suffix;
$(this).magnificPopup({ items: { src: content, type: 'inline' } });
});
$('[class*="lightbox-content"]').prepend('<div class="lightbox-overlay"></div>');
$('.lightbox-overlay, .mfp-close').click(function() {
$("[class*='lightbox-content'].et_pb_video.autoplay iframe").each(function(){
var removeautoplay = $(this).attr("src").replace("&autoplay=1", "");
$(this).attr("src",removeautoplay);
});
$.magnificPopup.close();
});
function myFunction(stickydesktop) {
if (stickydesktop.matches) { // If media query matches
$(".divi-hacks-sticky:not(.admin-bar) .sticky-module, .divi-hacks-sticky.admin-bar.divi-hacks-autohide-admin-bar .sticky-module").stick_in_parent({parent:'.et_pb_row', offset_top:50});
$(".divi-hacks-sticky.admin-bar:not(.divi-hacks-autohide-admin-bar) .sticky-module").stick_in_parent({parent:'.et_pb_row', offset_top:50 + 32});
$(".sticky-row").parent(".et_pb_section").addClass("has-sticky-row");
$(".divi-hacks-sticky:not(.admin-bar) .sticky-row, .divi-hacks-sticky.admin-bar.divi-hacks-autohide-admin-bar .sticky-row").stick_in_parent({offset_top:50});
$(".divi-hacks-sticky.admin-bar:not(.divi-hacks-autohide-admin-bar) .sticky-row").stick_in_parent({offset_top:50 + 32});
$(".divi-hacks-sticky:not(.admin-bar) .sticky-section, .divi-hacks-sticky.admin-bar.divi-hacks-autohide-admin-bar .sticky-section").stick_in_parent({offset_top:50});
$(".divi-hacks-sticky.admin-bar:not(.divi-hacks-autohide-admin-bar) .sticky-section").stick_in_parent({offset_top:50 + 32});
$(".sticky-column").wrapInner("<div class='sticky-column-wrapper'></div>");
$(".divi-hacks-sticky:not(.admin-bar) .sticky-column .sticky-column-wrapper, .divi-hacks-sticky.admin-bar.divi-hacks-autohide-admin-bar .sticky-column .sticky-column-wrapper").stick_in_parent({parent:'.et_pb_row',offset_top:50});
$(".divi-hacks-sticky.admin-bar:not(.divi-hacks-autohide-admin-bar) .sticky-column .sticky-column-wrapper").stick_in_parent({parent:'.et_pb_row',offset_top:50 + 32});
} else {
$(".sticky-row").parent(".et_pb_section").addClass("has-sticky-row");
$(".sticky-column").parent(".et_pb_row").addClass("has-sticky-column");
$(".divi-hacks-sticky:not(.admin-bar) .sticky-module").stick_in_parent({parent:'.et_pb_row', offset_top:50});
$(".divi-hacks-sticky.admin-bar .sticky-module").stick_in_parent({parent:'.et_pb_row', offset_top:50 + 32});
$(".divi-hacks-sticky:not(.admin-bar) .sticky-row").stick_in_parent({offset_top:50});
$(".divi-hacks-sticky.admin-bar .sticky-row").stick_in_parent({offset_top:50 + 32});
$(".divi-hacks-sticky:not(.admin-bar) .sticky-section").stick_in_parent({offset_top:50});
$(".divi-hacks-sticky.admin-bar .sticky-section").stick_in_parent({offset_top:50});
$(".sticky-column").wrapInner("<div class='sticky-column-wrapper'></div>");
$(".divi-hacks-sticky:not(.admin-bar) .sticky-column .sticky-column-wrapper").stick_in_parent({parent:'.et_pb_row',offset_top:50});
$(".divi-hacks-sticky.admin-bar .sticky-column .sticky-column-wrapper").stick_in_parent({parent:'.et_pb_row',offset_top:50 + 32});
$('.sticky-module').closest('.et_pb_row').css('flex-direction', 'column');
}
}
var stickydesktop = window.matchMedia("(min-width: 981px)")
myFunction(stickydesktop) // Call listener function at run time
stickydesktop.addListener(myFunction) // Attach listener function on state changes
});
</script>
/*===========================================================================*/
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('body').addClass('divi-hacks-animenu-2');
});
</script>
/*============================================================================*/
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('body').addClass('divi-hacks-heading-fonts');
});
</script>
/*============================================================================*/
<script id="preloader-js">
jQuery(document).ready(function($) {
// When an article with article grid is clicked, display the loader
$(".is-desktop input.et_pb_searchsubmit, a.hover-link").on("click", function() {
$("#preloader").fadeIn("slow");
});
$(window).load(function() {
// When the page is loading show the #preloader element
$("#preloader").fadeOut("slow");
$(".divi-hacks-archive-grid.author .et_pb_post a, .divi-hacks-archive-grid.post-type-archive .et_pb_post a, .divi-hacks-archive-grid.tag .et_pb_post a, .divi-hacks-archive-grid.archive .et_pb_post a, .divi-hacks-archive-grid.category .et_pb_post a, .divi-hacks-archive-grid.search-results .et_pb_post a, .divi-hacks-archive-grid.blog .et_pb_post a, .et_mobile_menu .menu-item a:not([href^='#'])").on("click", function() {
event.preventDefault();
newLocation = this.href;
$("#preloader").fadeIn("slow", newpage);
});
function newpage() {
window.location = newLocation;
}
});
if(window.location.hash) {
var URLnoHash = window.location.href.split('#')[0];
$("body:not(.et-fb) a[href*='" + URLnoHash + "']").addClass("no-preloader");
} else {
$("body:not(.et-fb) a[href*='#']").each(function() {
var oldUrl = $(this).attr("href");
var oldURLnoHash = oldUrl.split("#")[0];
if ( oldURLnoHash == window.location.href ) {
$(this).addClass("no-preloader");
}
});
}
// When a link is clicked, display the loader unless it is one of the links listed
$("body:not(.et-fb) a").not("#wpadminbar a, .gallery-icon a, .et_social_share, .no-preloader a, a.no-preloader, a[href^='#'], a[href^='mailto:'], a[href^='tel:'], a[target='_blank'], [class*='lightbox-trigger'], [class*='lightbox-trigger'] > a").on("click", function() {
event.preventDefault();
newLocation = this.href;
$("#preloader").fadeIn("slow", newpage);
});
function newpage() {
window.location = newLocation;
}
});
</script>
@muks999
Copy link
Author

muks999 commented Jan 11, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment