Skip to content

Commit

Permalink
🐛 Fixed emoji on GitHub Gists (re-closes #37);
Browse files Browse the repository at this point in the history
✨ Added emoji caching (re-closes #37);
  • Loading branch information
jerone committed Mar 22, 2015
1 parent c8c77e1 commit 7042a2c
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions Github_Comment_Enhancer/Github_Comment_Enhancer.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,31 +468,44 @@
return false;
};

var suggestionsCache = {};
function addSuggestions(commentForm) {
var jssuggester = commentForm.parentNode.parentNode.querySelector(".suggester-container .suggester");
var url = jssuggester.getAttribute("data-url");
unsafeWindow.$.fetchText(url).then(function(suggestionsData) {
suggestionsData = suggestionsData.replace(/js-navigation-item/g, "function-button js-navigation-item select-menu-item");

var suggestions = document.createElement("div");
suggestions.innerHTML = suggestionsData;

var emojiSuggestions = suggestions.querySelector(".emoji-suggestions");
emojiSuggestions.style.display = "block";
emojiSuggestions.dataset.filterableType = "substring";
emojiSuggestions.dataset.filterableFor = "context-emoji-filter-field";
emojiSuggestions.dataset.filterableLimit = "10";

var suggester = commentForm.parentNode.querySelector(".suggester");
suggester.style.display = "block";
suggester.style.marginTop = "0";
suggester.appendChild(emojiSuggestions);
Array.prototype.forEach.call(suggester.querySelectorAll(".function-button"), function(button) {
button.addEventListener("click", function(e) {
e.preventDefault();
executeAction(MarkDown["function-emoji"], commentForm, this);
return false;
});

if (suggestionsCache[url]) {
parseSuggestions(suggestionsCache[url]);
} else {
unsafeWindow.$.ajax({
url: url,
success: function(suggestionsData) {
suggestionsCache[url] = suggestionsData
parseSuggestions(commentForm, suggestionsData);
}
});
}
}
function parseSuggestions(commentForm, suggestionsData) {
suggestionsData = suggestionsData.replace(/js-navigation-item/g, "function-button js-navigation-item select-menu-item");

var suggestions = document.createElement("div");
suggestions.innerHTML = suggestionsData;

var emojiSuggestions = suggestions.querySelector(".emoji-suggestions");
emojiSuggestions.style.display = "block";
emojiSuggestions.dataset.filterableType = "substring";
emojiSuggestions.dataset.filterableFor = "context-emoji-filter-field";
emojiSuggestions.dataset.filterableLimit = "10";

var suggester = commentForm.parentNode.querySelector(".suggester");
suggester.style.display = "block";
suggester.style.marginTop = "0";
suggester.appendChild(emojiSuggestions);
Array.prototype.forEach.call(suggester.querySelectorAll(".function-button"), function(button) {
button.addEventListener("click", function(e) {
e.preventDefault();
executeAction(MarkDown["function-emoji"], commentForm, this);
return false;
});
});
}
Expand Down

0 comments on commit 7042a2c

Please sign in to comment.