Skip to content

Instantly share code, notes, and snippets.

@Garconis
Created October 23, 2018 20:45
Show Gist options
  • Save Garconis/c2f076da844775c6b3d2f25ada4efab4 to your computer and use it in GitHub Desktop.
Save Garconis/c2f076da844775c6b3d2f25ada4efab4 to your computer and use it in GitHub Desktop.
WordPress | wpDataTables column data overrides
// Code for inventory image
function inventoryTable(){
// grab the URL in the new column and make into an image
jQuery('td.inventory-col-photo a').each(function () {
var image_anchor = jQuery(this).find("a");
var image_url = jQuery(this).attr("href");
//jQuery(this).prepend(jQuery('<img>',{class:'theImg',src:'theImg.png'}))
jQuery(this).html('<img src="' + image_url + '">');
});
// grab text in the Stock # column and assume its OK to make into a clickable image with that filename
jQuery('td.inventory-col-stock').each(function () {
var stock_numb = jQuery(this).text()
var image_anchor = jQuery(this).closest("a");
//jQuery(this).prepend(jQuery('<img>',{class:'theImg',src:'theImg.png'}))
if (jQuery(this).children('a').length) {
//it already has a link
} else {
jQuery(this).html('<a href="https://garysupullit.com/GUP_CarPictures/' + stock_numb + '.jpg" target="_blank" class="inventory-img-link" title="' + stock_numb + '"><img src="https://garysupullit.com/GUP_CarPictures/' + stock_numb + '.jpg" alt="' + stock_numb + '"></a>');
}
});
// if image has an error, then hide or display a different one
jQuery(".wpDataTable td img").each(function() {
jQuery(this).error(function(){
//jQuery(this).hide();
this.src = 'http://freshyjon.dev.freshysites.com/wp-content/uploads/freshysites-lime.png';
});
});
// This requires "Dynamically load theme JS components" to be disabled
jQuery('.wpDataTable td').find('a[href$=".gif"], a[href$=".jpg"], a[href$=".png"], a[href$=".bmp"]').magnificPopup({
type: 'image',
// gallery:{enabled:true},
// type: 'image',
image: {
titleSrc: 'title', // Attribute of the target element that contains caption for the slide.
}
});
}
jQuery(window).load(function() {
// do the function on load
inventoryTable();
wpDataTables.table_1.addOnDrawCallback(
// and then again if/when the particular table is sorted or filtered or paginated, etc.
function(){
inventoryTable()
}
)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment