-
-
Save akatz/1015013 to your computer and use it in GitHub Desktop.
Adds a permalink to all Zendesk comments, and scrolls to them when linked to
This file contains 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
/* | |
* Please take note of the following when using this JavaScript snippet: | |
* | |
* 1. It's provided as is, is not an officially support Zendesk widget | |
* no matter whom the author may be working for. | |
* 2. You are very welcome to fork this, in fact I encourage it if you | |
* have some awesome changes! | |
* 3. You'll notice a short delay before the permalinks display or indeed | |
* before the page scrolls to the permalink location. This is intended. | |
* | |
*/ | |
// We have to wait for comments to dynamically load in. It normally takes less than a second | |
setTimeout("doCommentID()", 1500); | |
function doCommentID() { | |
var items = $j("#history > div .public").parents(".item"); | |
items.each(function(e) { | |
if($j(".tab_organization").size() == 0) { | |
if(items.size() - e == 1) { | |
$j(this).addClass("initial_response") | |
} else { | |
$j(this).addClass("comment"+(items.size() - (e + 1))) | |
} | |
} else { | |
$j(this).addClass("comment"+(items.size() - e)) | |
} | |
}) | |
// Get the page's hash | |
var pageHash = window.location.hash; | |
// Check if we have a page hash, and if we do scroll to it | |
if (pageHash != "") { | |
$j('html, body').animate({ | |
scrollTop: $j(pageHash.replace("#",".")).offset().top | |
}, 1000); | |
} | |
// Go through each comment on a ticket | |
items.each(function (e) { | |
// Get the ID of the comment, found in the ID of the DOM object for the comment itself | |
var commentID = $j(this).attr("id"); | |
var commentNumber = items.size() - e; | |
if($j(".tab_organization").size() == 0) { | |
if(items.size() - e == 1) { | |
$j(this).find(".gray-text").append("| <a href=\"#initial_response\">Initial Response</a>"); | |
} else { | |
$j(this).find(".gray-text").append("| <a href=\"#comment" + commentNumber + "\">Comment #" + (commentNumber - 1) + "</a>"); | |
}; | |
} else { | |
$j(this).find(".gray-text").append("| <a href=\"#comment" + commentNumber + "\">Comment #" + commentNumber + "</a>"); | |
}; | |
// Find the area for the date of the comment, and append the ID to this. | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mm, nice! Only problem I can foresee is the "initial response" part. If you have the comment order flipped (which is possible to do in Zendesk) then that statement is false. Pagination will also be an issue there.
If this had some more comments inline explaining your code I'd love to merge this into my original gist - only reason for more comments is because people with very basic coding knowledge will likely use this, so want them to be informed as possible.