Last active
July 27, 2017 00:48
-
-
Save mozz100/f158f8363b58eb56c9c4 to your computer and use it in GitHub Desktop.
Zendesk embedded PDF viewer via Google Docs
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
// add this javascript to your Zendesk Help Center pages | |
(function($) { | |
$(function() { | |
// for all attachment links whose URLs end with .pdf (case sensitive)... | |
var pdfs = $('.attachments a[href$=".pdf"]'); | |
var eleBody = $('div.article-body'); | |
if (pdfs.length > 0) { | |
var msg = '<b>' + pdfs.length + ' '; | |
msg += 'PDF file'; | |
if (pdfs.length > 1) { msg += 's'; } | |
msg += ' attached</b> - download '; | |
if (pdfs.length > 1) { msg += 'them'; } else { msg += 'it' } | |
msg += ' from the bottom of the page.'; | |
eleBody.append('<p>' + msg + '</p>'); | |
pdfs.each(function(i,o) { | |
// ...build html to an iframe on google docs viewer | |
var html = ''; | |
html = '<iframe src="' + window.location.protocol + '//' + 'docs.google.com/viewer?url='; | |
// url encode the full, absolute URL for the attachment | |
html += encodeURIComponent(window.location.protocol + '//' + window.location.host + $(o).attr('href')); | |
// set width and height | |
html += '&embedded=true" width="100%" height="780" style="border: none;"></iframe>' | |
// place into main body of the article | |
eleBody.append(html); | |
}); | |
} | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there,
Thanks for sharing!
Do you have any working example / demo?
I can't embed article attachments, but can if I upload the file via Zendesk assets.
Thanks,
Vlad