Skip to content

Instantly share code, notes, and snippets.

@Garconis
Created February 26, 2018 20:34
Show Gist options
  • Save Garconis/0d724dc699400bcbb9d18f26ef360d03 to your computer and use it in GitHub Desktop.
Save Garconis/0d724dc699400bcbb9d18f26ef360d03 to your computer and use it in GitHub Desktop.
jQuery | Useful jQuery functions to manipulate content
(function($) {
// do this even when ajax updates content
function doStuff(){
$("<span class='icr-item type_checkbox'></span>").insertAfter(".checkbox input");
}
$(document).ready(doStuff);
$(document).ajaxComplete(doStuff);
// add target blank to anchor
$( "a.evcal_list_a" ).attr('target','_blank');
// update URL to include protocol if it's missing
$('.evo_metarow_learnMICS a').each(function(){
var currentlink = $(this);
var linkloc = currentlink.attr('href');
var httpcheck = linkloc.substr(0,7);
if(httpcheck!="http://"){
currentlink.attr( { href:"http://"+linkloc, target:"_blank" } );
}
});
// find text in this selector wrap it in an anchor if it's a URL
$( ".website .sb_mod_acf_single_item" ).text(function () {
if ( ($(this).text().length >=5) && ($(this).text().substr(0, 5) != 'http:') && ($(this).text().substr(0, 5) != 'https') ) {
$(this).replaceWith( '<a href="http://' + $(this).text() + '" target="_blank">' + $(this).text() + '</a>' );
}
else {
$(this).replaceWith( '<a href="' + $(this).text() + '" target="_blank">' + $(this).text() + '</a>' );
}
});
// find text in this selector and wrap it with a tel link
$( ".phone .sb_mod_acf_single_item " ).text(function () {
$value = $( this ).text().replace(/[^\/\d]/g,'');
$( this ).replaceWith( '<a href="tel:' + $value + '">' + $( this ).text() + '</a>' );
});
// find text in this selector and wrap it with a mailto link
$( ".email .sb_mod_acf_single_item " ).text(function () {
$( this ).replaceWith( '<a href="mailto:' + $( this ).text() + '">' + $( this ).text() + '</a>' );
});
// open in new tab
function mapLinkNewTab(){
$('.list_view_holder .cspml_thumb_container a').attr('target', '_blank');
$('.list_view_holder .cspml_details_container .cspml_details_title a').attr('target', '_blank');
}
$(document).ready(mapLinkNewTab);
$(document).ajaxComplete(mapLinkNewTab);
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment