Last active
November 5, 2021 01:42
-
-
Save MaruscaGabriel/01d25b33ccd3140c73f7f4eae1ca2815 to your computer and use it in GitHub Desktop.
DIVI theme JavaScript code snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Open external links into new tab | |
<script type="text/javascript"> | |
jQuery('a').filter(function () { | |
return this.hostname != window.location.hostname; | |
}).attr('target', '_blank'); | |
</script> | |
//Adding Fly-in Animations To Any Divi Section, Row and Module | |
//thanks to Gino Quiroz : https://quiroz.co/adding-fly-in-animations-to-any-divi-module/ | |
//Below are the CSS Class groups for each animation. | |
//et_pb_animation_top et-animated et-waypoint | |
//et_pb_animation_bottom et-animated et-waypoint | |
//et_pb_animation_right et-animated et-waypoint | |
//et_pb_animation_left et-animated et-waypoint | |
//et_pb_animation_fade_in et-animated et-waypoint | |
<script> | |
(function($) { | |
var $animation_elements = $('.et-waypoint'), | |
$window = $(window); | |
function check_if_in_view() { | |
var window_height = $window.height(), | |
window_top_position = $window.scrollTop(), | |
window_bottom_position = (window_top_position + window_height); | |
$animation_elements.each(function() { | |
var $element = $(this), | |
element_height = $element.outerHeight(), | |
element_top_position = $element.offset().top, | |
element_bottom_position = (element_top_position + element_height); | |
//check to see if this element is within viewport | |
if ((element_bottom_position >= window_top_position) && (element_top_position <= window_bottom_position)) { | |
$element.addClass('et-animated'); | |
} else { | |
$element.removeClass('et-animated'); | |
} | |
}); | |
} | |
$window.on('scroll resize', check_if_in_view); | |
})(jQuery); | |
</script> | |
// Slide In menu to close automatically when you click on a menu item? | |
// Add this code to: Divi > Theme Options > Integration tab > Add code to the <head> of your blog: | |
<script> | |
(function($) { | |
$(document).ready(function() { | |
var menuItem = $('.menu-item a'); | |
menuItem.each(function(){ | |
$(this).bind('click', function(){ | |
$('#-et-top-navigation .mobile_menu_bar').trigger('click'); | |
}) | |
}) | |
}); | |
})(jQuery) | |
</script> | |
//Change Divi contact form submit button text: | |
//Give your contact form a custom class | |
//Add the following script to Divi > Theme Options > Integration > Add code to the < head >: | |
<script type=”text/javascript”> | |
jQuery(document).ready(function(){ | |
jQuery(“.myclass button.et_pb_contact_submit”).text(‘Text you want displayed‘); | |
}); | |
</script> | |
//Change the read more button text: | |
//Add the following script to Divi > Theme Options > Integration > Add code to the < head >: | |
<script type="text/javascript"> | |
(function($) { | |
$(document).ready(function() { | |
var newVal = 'Text you want displayed'; | |
$('.more-link').html( newVal ); | |
}); | |
})(jQuery); | |
</script> | |
//Move the blog post title above the featured image in the Divi blog module: | |
//Add the following script to Divi > Theme Options > Integration > Add code to the < head > | |
<script type="text/javascript"> | |
jQuery(document).ready(function(){ | |
jQuery("body.blog article").each(function(){ | |
jQuery(">a:first-child", this).insertAfter(jQuery("h2.entry-title", this)); | |
}); | |
}); | |
</script> | |
//Hide div using class on row and jQuerry | |
<script type="text/javascript"> | |
//if the HTML had one extra layer of nesting use `find()` method | |
jQuery(".hide-if-empty").each(function() | |
{ | |
if(jQuery(this).find(".et_pb_module").children("div").length == 0) | |
{ | |
jQuery(this).hide(); | |
} | |
}); | |
//direct children method targeting the class ACF in this case | |
jQuery(".hide-if-empty-sidebar").each(function() | |
{ | |
if(jQuery(this).children(".sb_mod_acf_single_item").length == 0) | |
{ | |
jQuery(this).hide(); | |
} | |
}); | |
</script> | |
//Make the full blurb clickable in Divi | |
//Add the class in the Blurb Advance settings and after that add this to CSS: .blurb_click:hover {cursor: pointer;} and one of the below JS code | |
// In the same tab: | |
<script type="text/javascript"> | |
jQuery(document).ready(function($) { | |
$(".blurb_click").click(function() { | |
window.location = $(this).find("a").attr("href"); | |
return false; | |
}); | |
}); | |
</script> | |
//In new tab | |
<script type="text/javascript"> | |
jQuery(document).ready(function($) { | |
$(".blurb_click_newtab").click(function() { | |
var blurbLink = $(this).find("a"); | |
blurbLink.attr("target", "_blank"); | |
window.open(blurbLink.attr("href")); | |
return false; | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment