Skip to content

Instantly share code, notes, and snippets.

@barnabywalters
Last active December 21, 2015 23:09
Show Gist options
  • Save barnabywalters/6380386 to your computer and use it in GitHub Desktop.
Save barnabywalters/6380386 to your computer and use it in GitHub Desktop.
Original Post Discovery minimal client side implementation. Requires promisejs (HTTP) and bean (events)
// Original post discovery (in progress)
var noteForms = document.querySelectorAll('.note-post-form');
if (noteForms.length > 0) {
for (var i = 0;i < noteForms.length;i++) {
var form = noteForms[i];
var inReplyToField = form.querySelector('.in-reply-to');
bean.on(inReplyToField, 'blur', function(event) {
var url = event.target.value;
// TODO: Start loading indicator
promise.get('/services/original-post', {'url': url}).then(function (error, text, xhr) {
// TODO: Stop loading indicator
if (error) return;
inReplyToField.value = text;
});
});
if (inReplyToField.value !== '')
bean.fire(inReplyToField, 'blur');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment