11/*!
2- * Vue YouTube Embed version 2.0.3
2+ * Vue YouTube Embed version 2.1.0
33 * under MIT License copyright 2017 kaorun343
44 */
55( function ( global , factory ) {
1010
1111// fork from https://github.com/brandly/angular-youtube-embed
1212if ( ! String . prototype . includes ) {
13- String . prototype . includes = function ( ) {
13+ String . prototype . includes = function ( ) {
1414 'use strict' ;
1515 return String . prototype . indexOf . apply ( this , arguments ) !== - 1
1616 } ;
@@ -24,20 +24,20 @@ var timeRegexp = /t=(\d+)[ms]?(\d+)?s?/;
2424 * @param {string } url url
2525 * @return {string } id
2626 */
27- function getIdFromURL ( url ) {
28- var id = url . replace ( youtubeRegexp , "$1" ) ;
27+ function getIdFromURL ( url ) {
28+ var id = url . replace ( youtubeRegexp , '$1' ) ;
2929
30- if ( id . includes ( ";" ) ) {
31- var pieces = id . split ( ";" ) ;
30+ if ( id . includes ( ';' ) ) {
31+ var pieces = id . split ( ';' ) ;
3232
33- if ( pieces [ 1 ] . includes ( "%" ) ) {
33+ if ( pieces [ 1 ] . includes ( '%' ) ) {
3434 var uriComponent = decodeURIComponent ( pieces [ 1 ] ) ;
35- id = ( "http://youtube.com" + uriComponent ) . replace ( youtubeRegexp , "$1" ) ;
35+ id = ( "http://youtube.com" + uriComponent ) . replace ( youtubeRegexp , '$1' ) ;
3636 } else {
3737 id = pieces [ 0 ] ;
3838 }
39- } else if ( id . includes ( "#" ) ) {
40- id = id . split ( "#" ) [ 0 ] ;
39+ } else if ( id . includes ( '#' ) ) {
40+ id = id . split ( '#' ) [ 0 ] ;
4141 }
4242
4343 return id
@@ -48,23 +48,23 @@ function getIdFromURL(url) {
4848 * @param {string } url url
4949 * @return {number } time
5050 */
51- function getTimeFromURL ( url ) {
52- if ( url === void 0 ) url = "" ;
51+ function getTimeFromURL ( url ) {
52+ if ( url === void 0 ) url = '' ;
5353
5454 var times = url . match ( timeRegexp ) ;
5555
56- if ( ! times ) {
56+ if ( ! times ) {
5757 return 0
5858 }
5959
6060 var full = times [ 0 ] ;
6161 var minutes = times [ 1 ] ;
6262 var seconds = times [ 2 ] ;
6363
64- if ( typeof seconds !== " undefined" ) {
64+ if ( typeof seconds !== ' undefined' ) {
6565 seconds = parseInt ( seconds , 10 ) ;
6666 minutes = parseInt ( minutes , 10 ) ;
67- } else if ( full . includes ( "m" ) ) {
67+ } else if ( full . includes ( 'm' ) ) {
6868 minutes = parseInt ( minutes , 10 ) ;
6969 seconds = 0 ;
7070 } else {
@@ -79,7 +79,7 @@ var container = {
7979 scripts : [ ] ,
8080 events : { } ,
8181
82- run : function run ( ) {
82+ run : function run ( ) {
8383 var this$1 = this ;
8484
8585 this . scripts . forEach ( function ( callback ) {
@@ -88,7 +88,7 @@ var container = {
8888 this . scripts = [ ] ;
8989 } ,
9090
91- register : function register ( callback ) {
91+ register : function register ( callback ) {
9292 var this$1 = this ;
9393
9494 if ( this . YT ) {
@@ -104,7 +104,27 @@ var container = {
104104var pid = 0 ;
105105
106106var YouTubePlayer = {
107- props : [ 'playerHeight' , 'playerWidth' , 'playerVars' , 'videoId' ] ,
107+ props : {
108+ playerHeight : {
109+ type : [ String , Number ] ,
110+ default : '390'
111+ } ,
112+ playerWidth : {
113+ type : [ String , Number ] ,
114+ default : '640'
115+ } ,
116+ playerVars : {
117+ type : Object ,
118+ default : function ( ) { return ( { autoplay : 0 , time : 0 } ) ; }
119+ } ,
120+ videoId : {
121+ type : String
122+ } ,
123+ mute : {
124+ type : Boolean ,
125+ default : false
126+ }
127+ } ,
108128 render : function render ( h ) {
109129 return h ( 'div' , [
110130 h ( 'div' , { attrs : { id : this . elementId } } )
@@ -114,23 +134,29 @@ var YouTubePlayer = {
114134 watch : {
115135 playerWidth : 'setSize' ,
116136 playerHeight : 'setSize' ,
117- videoId : 'update'
137+ videoId : 'update' ,
138+ mute : 'setMute'
118139 } ,
119- data : function data ( ) {
140+ data : function data ( ) {
120141 pid += 1 ;
121142 return {
122143 elementId : ( "youtube-player-" + pid ) ,
123144 player : { }
124145 }
125146 } ,
126147 methods : {
127- setSize : function setSize ( ) {
128- this . player . setSize ( this . playerWidth || '640' , this . playerHeight || '390' ) ;
148+ setSize : function setSize ( ) {
149+ this . player . setSize ( this . playerWidth , this . playerHeight ) ;
129150 } ,
130- update : function update ( videoId ) {
131- var ref = this ;
132- var playerVars = ref . playerVars ; if ( playerVars === void 0 ) playerVars = { autoplay : 0 } ;
133- var name = ( playerVars . autoplay ? 'load' : 'cue' ) + "VideoById" ;
151+ setMute : function setMute ( value ) {
152+ if ( value ) {
153+ this . player . mute ( ) ;
154+ } else {
155+ this . player . unMute ( ) ;
156+ }
157+ } ,
158+ update : function update ( videoId ) {
159+ var name = ( this . playerVars . autoplay ? 'load' : 'cue' ) + "VideoById" ;
134160 if ( this . player . hasOwnProperty ( name ) ) {
135161 this . player [ name ] ( videoId ) ;
136162 } else {
@@ -140,23 +166,24 @@ var YouTubePlayer = {
140166 }
141167 }
142168 } ,
143- mounted : function mounted ( ) {
169+ mounted : function mounted ( ) {
144170 var this$1 = this ;
145171
146172 container . register ( function ( YouTube ) {
147173 var ref = this$1 ;
148- var height = ref . playerHeight ; if ( height === void 0 ) height = '390' ;
149- var width = ref . playerWidth ; if ( width === void 0 ) width = '640' ;
150- var playerVars = ref . playerVars ; if ( playerVars === void 0 ) playerVars = { autoplay : 0 , start : 0 } ;
174+ var playerHeight = ref . playerHeight ;
175+ var playerWidth = ref . playerWidth ;
176+ var playerVars = ref . playerVars ;
151177 var videoId = ref . videoId ;
152178
153179 this$1 . player = new YouTube . Player ( this$1 . elementId , {
154- height : height ,
155- width : width ,
180+ height : playerHeight ,
181+ width : playerWidth ,
156182 playerVars : playerVars ,
157183 videoId : videoId ,
158184 events : {
159185 onReady : function ( event ) {
186+ this$1 . setMute ( this$1 . mute ) ;
160187 this$1 . $emit ( 'ready' , event . target ) ;
161188 } ,
162189 onStateChange : function ( event ) {
@@ -171,26 +198,26 @@ var YouTubePlayer = {
171198 } ) ;
172199 } ) ;
173200 } ,
174- beforeDestroy : function beforeDestroy ( ) {
201+ beforeDestroy : function beforeDestroy ( ) {
175202 if ( this . player !== null ) {
176203 this . player . destroy ( ) ;
177204 }
178205 delete this . player ;
179206 }
180207} ;
181208
182- function install ( Vue ) {
209+ function install ( Vue ) {
183210 container . Vue = Vue ;
184211 YouTubePlayer . ready = YouTubePlayer . mounted ;
185212 Vue . component ( 'youtube' , YouTubePlayer ) ;
186- Vue . prototype . $youtube = { getIdFromURL : getIdFromURL , getTimeFromURL : getTimeFromURL } ;
213+ Vue . prototype . $youtube = { getIdFromURL : getIdFromURL , getTimeFromURL : getTimeFromURL } ;
187214
188215 var tag = document . createElement ( 'script' ) ;
189- tag . src = " https://www.youtube.com/player_api" ;
216+ tag . src = ' https://www.youtube.com/player_api' ;
190217 var firstScriptTag = document . getElementsByTagName ( 'script' ) [ 0 ] ;
191218 firstScriptTag . parentNode . insertBefore ( tag , firstScriptTag ) ;
192219
193- window . onYouTubeIframeAPIReady = function ( ) {
220+ window . onYouTubeIframeAPIReady = function ( ) {
194221 container . YT = YT ;
195222 var PlayerState = YT . PlayerState ;
196223
@@ -206,15 +233,10 @@ function install(Vue) {
206233 } ;
207234}
208235
209- var index = {
210- getIdFromURL : getIdFromURL , getTimeFromURL : getTimeFromURL , YouTubePlayer : YouTubePlayer , install : install
211- } ;
212-
236+ exports . YouTubePlayer = YouTubePlayer ;
213237exports . getIdFromURL = getIdFromURL ;
214238exports . getTimeFromURL = getTimeFromURL ;
215- exports . YouTubePlayer = YouTubePlayer ;
216- exports . install = install ;
217- exports [ 'default' ] = index ;
239+ exports [ 'default' ] = install ;
218240
219241Object . defineProperty ( exports , '__esModule' , { value : true } ) ;
220242
0 commit comments