Skip to content

Instantly share code, notes, and snippets.

@ezrabrook
Created July 21, 2014 13:47
Show Gist options
  • Save ezrabrook/a262b71f678c1f22a362 to your computer and use it in GitHub Desktop.
Save ezrabrook/a262b71f678c1f22a362 to your computer and use it in GitHub Desktop.
Add icon to pdf, doc or any other file extension based on extension type.
/* Add PDF/Doc icons to Documents. */
String.prototype.endsWith = function (suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
$('.sub_content_area .sub_right a').each(function () {
if ($(this).attr("href")) {
var href = $(this).attr("href");
if (href.endsWith("xlsx") || href.endsWith("xls")) {
$(this).append('&nbsp;<img width="88" height="28" class="excel-icon" src="/sites/all/themes/hdfsresponsive/css/images/download_excel.png" />');
}
if (href.endsWith("pptx") || href.endsWith("ppt")) {
$(this).append('&nbsp;<img width="88" height="28" class="ppt-icon" src="/sites/all/themes/hdfsresponsive/css/images/download_ppt.png" />');
}
if (href.endsWith("docx") || href.endsWith("doc")) {
$(this).append('&nbsp;<img width="88" height="28" class="doc-icon" src="/sites/all/themes/hdfsresponsive/css/images/download_word.png" />');
}
if (href.endsWith("pdf")) {
$(this).append('&nbsp;<img width="88" height="28" class="pdf-icon" src="/sites/all/themes/hdfsresponsive/css/images/download_pdf.png" />');
}
if (href.endsWith("txt")) {
$(this).addClass('txt');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment