Created
June 1, 2011 16:23
-
-
Save jakeisonline/1002685 to your computer and use it in GitHub Desktop.
[Zendesk] 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() { | |
// 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).offset().top | |
}, 1000); | |
} | |
// Go through each comment on a ticket | |
$j("#history .item").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"); | |
// Find the area for the date of the comment, and append the ID to this. | |
$j(this).find(".gray-text").append("| <a href=\"#" + commentID + "\">Permalink</a>"); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment