Skip to content

Instantly share code, notes, and snippets.

@tamoot
Created February 18, 2013 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamoot/4977220 to your computer and use it in GitHub Desktop.
Save tamoot/4977220 to your computer and use it in GitHub Desktop.
twitter API V1 でのプラグイン
/*
* tweet_embeded.js : embeded tweet
*
* Copyright (C) 2013 by tamoot <tamoot+tdiary@gmail.com>
* You can distribute it under GPL.
*/
$( function() {
function embeded_callback(twitter_status, twitter_p) {
$.ajax({
type : 'GET',
//url : 'https://api.twitter.com/1.1/statuses/oembed.json?id=' + twitter_status,
url : 'https://api.twitter.com/1/statuses/oembed.json?id=' + twitter_status,
dataType : 'jsonp',
//
// callback on error..
//
error : function() {
},
//
// append dom
//
success : function(data) {
$(twitter_p).append(data.html)
}
});
};
function tweet_embeded(target) {
$('.twitter-tweet', target).each( function() { var twitter_status = $(this).attr('data-twitterstatus')
embeded_callback(twitter_status, this);
}); };
// for AutoPagerize
$(window).bind('AutoPagerize_DOMNodeInserted', function(event) { tweet_embeded(event.target); });
// for AuthPatchWork
// NOTE: jQuery.bind() cannot handle an event that include a dot charactor.
// see http://todayspython.blogspot.com/2011/06/autopager-autopagerize.html
if(window.addEventListener) {
window.addEventListener('AutoPatchWork.DOMNodeInserted', function(event) {
tweet_embeded(event.target);
}, false);
} else if(window.attachEvent) {
window.attachEvent('onAutoPatchWork.DOMNodeInserted', function(event) {
tweet_embeded(event.target);
});
};
tweet_embeded(document);
});
# -*- coding: utf-8 -*-
#
# tweet_embeded.rb - embedded representation of a Tweet, use Twitter REST API v1
# https://dev.twitter.com/docs/api/1/get/statuses/oembed
#
# Copyright (C) 2013, tamoot <tamoot+tdiary@gmail.com>
# You can redistribute it and/or modify it under GPL2.
#
enable_js('tweet_embeded.js') unless feed?
def tweet_embeded(src)
if %r|http(?:s)?://twitter.com/(?:#!/)?[^/]{1,15}/status(?:es)?/([0-9]+)| =~ src.to_s.downcase
src = $1
end
return %Q|<p class="twitter-tweet" data-twitterstatus="#{src}"></p>|
end
# Local Variables:
# mode: ruby
# indent-tabs-mode: t
# tab-width: 3
# ruby-indent-level: 3
# End:
# vim: ts=3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment