Last active
March 27, 2016 16:20
-
-
Save gaogao-9/6497fa78becacc347b4b to your computer and use it in GitHub Desktop.
動作未確認です
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
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<!-- 省略 --> | |
<script src="widget.js"></script> | |
<script src="index.js"></script> | |
</head> | |
</html> |
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
window.twttr.ready(function(){ | |
var elm = document.getElementById('親となる要素'); | |
twttr.widgets.createTimeline('タイムラインID', elm, { | |
/* オプションは https://dev.twitter.com/web/javascript/creating-widgets#create-timeline */ | |
}).then(function(iframe){ | |
// ここでいろいろする | |
iframe.style.width = "100%"; | |
}); | |
}); |
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
// 例のスクリプトがゴミすぎたので改良した話 | |
window.twttr = (function(d, s, id){ | |
var readyEvents = []; | |
if(document.readyState !== "loading"){ | |
window.twttr = createTwttr(d, s, id); | |
return; | |
} | |
document.addEventListener("DOMContentLoaded", registerTwttr, false); | |
// ダミーを作っておく | |
return { | |
ready: function(callback){ | |
readyEvents.push(callback); | |
} | |
}; | |
function registerTwttr(eve){ | |
window.twttr = createTwttr(d, s, id); | |
document.removeEventListener("DOMContentLoaded", registerTwttr, false); | |
} | |
function createTwttr(d, s, id){ | |
var js, fjs = d.getElementsByTagName(s)[0], | |
t = window.twttr || {}; | |
if (d.getElementById(id)) return t; | |
js = d.createElement(s); | |
js.id = id; | |
js.src = "https://platform.twitter.com/widgets.js"; | |
fjs.parentNode.insertBefore(js, fjs); | |
t._e = readyEvents; | |
t.ready = function(f){ | |
t._e.push(f); | |
}; | |
return t; | |
} | |
})(document, "script", "twitter-wjs"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment