A Pen by Kaoru Hagihara on CodePen.
Last active
October 6, 2015 12:52
-
-
Save kaorun343/1e4788094d71cfbf094b to your computer and use it in GitHub Desktop.
yNQWGP
This file contains hidden or 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
div#app.container | |
.panel.panel-default | |
.panel-heading | |
h3.panel-title YouTube API | |
.panel-body | |
youtube(v-repeat="list") | |
.panel-footer | |
button.btn.btn-default(type="button", v-on="click: check") add | |
template#youtubeComponent | |
div | |
div(v-el="target") |
This file contains hidden or 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
Vue.component 'youtube', | |
props: ['videoId'] | |
data: -> | |
age: 40 | |
template: '#youtubeComponent' | |
ready: -> | |
if YT? and YT.Player? | |
@createPlayer() | |
else | |
old = window.onYouTubeIframeAPIReady or () -> return | |
window.onYouTubeIframeAPIReady = => | |
old() | |
@createPlayer() | |
return | |
return | |
methods: | |
createPlayer: -> | |
@player = new YT.Player @$$.target, | |
height: 390 | |
width: 640 | |
videoId: @videoId | |
events: | |
onReady: @onPlayerReady | |
onStateChange: @onPlayerStateChange | |
return | |
onPlayerReady: -> | |
@$dispatch 'youtube:player:ready', @videoId | |
return | |
onPlayerStateChange: (event) -> | |
return | |
id = "M7lc1UVf-VE" | |
app = new Vue | |
el: '#app' | |
data: | |
apple: 30 | |
list: [ | |
videoId: "M7lc1UVf-VE" | |
] | |
methods: | |
check: -> | |
@list.push videoId: id | |
return | |
events: | |
'youtube:player:ready': (id) -> | |
@apple += id | |
return |
This file contains hidden or 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
<script src="https://www.youtube.com/iframe_api"></script> | |
<script src="http://cdnjs.cloudflare.com/ajax/libs/vue/0.12.8/vue.min.js"></script> |
This file contains hidden or 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
#app { | |
margin-top: 40px; | |
} |
This file contains hidden or 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
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment