Skip to content

Instantly share code, notes, and snippets.

@jrunning
Last active December 19, 2015 00:39
Show Gist options
  • Select an option

  • Save jrunning/5870126 to your computer and use it in GitHub Desktop.

Select an option

Save jrunning/5870126 to your computer and use it in GitHub Desktop.
var seenLinks = {}
function removeNewsItemParent(el) {
return $(el).closest('.news > .alert').remove()
}
function getGist(gistId) {
return $.get('https://api.github.com/gists/' + gistId);
}
function getGistDescription(gist) {
if(gist.description && gist.description.length) {
return gist.description;
}
return Object.keys(gist.files)[0];
}
function gistPrettyName(gist) {
var name = "Gist #" + gist.id,
desc = getGistDescription(gist)
;
if(desc) { name += ": " + desc; }
return name;
}
function gistTitlesInit() {
$(".news a[href*='gist.github']:not([data-pretty-title])")
.each(function() {
if(seenLinks[this.href]) {
removeNewsItemParent(this);
return
}
seenLinks[this.href] = true;
gistId = this.href.split('/').pop();
getGist(gistId).done($.proxy(function(gist) {
this.innerText = gistPrettyName(gist);
this.setAttribute('data-pretty-title', true);
}, this));
});
}
$(function() {
gistTitlesInit();
$(document).ajaxSuccess(function(e, xhr, opts) {
if(opts.url.match(/^\/dashboard\/index/)) { gistTitlesInit(); }
return true;
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment