11/* global Vue, $, Fieldtype, translate */
22
3+ // Polyfill Object.assign for IE...
4+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill
5+ if ( typeof Object . assign !== 'function' ) {
6+ // Must be writable: true, enumerable: false, configurable: true
7+ Object . defineProperty ( Object , "assign" , {
8+ value : function assign ( target , varArgs ) { // .length of function is 2
9+ 'use strict' ;
10+ if ( target === null || target === undefined ) {
11+ throw new TypeError ( 'Cannot convert undefined or null to object' ) ;
12+ }
13+
14+ var to = Object ( target ) ;
15+
16+ for ( var index = 1 ; index < arguments . length ; index ++ ) {
17+ var nextSource = arguments [ index ] ;
18+
19+ if ( nextSource !== null && nextSource !== undefined ) {
20+ for ( var nextKey in nextSource ) {
21+ // Avoid bugs when hasOwnProperty is shadowed
22+ if ( Object . prototype . hasOwnProperty . call ( nextSource , nextKey ) ) {
23+ to [ nextKey ] = nextSource [ nextKey ] ;
24+ }
25+ }
26+ }
27+ }
28+ return to ;
29+ } ,
30+ writable : true ,
31+ configurable : true
32+ } ) ;
33+ }
34+
335Vue . component ( 'video_embed-fieldtype' , {
436 mixins : [ Fieldtype ] ,
537
@@ -8,9 +40,8 @@ Vue.component('video_embed-fieldtype', {
840 loading : true ,
941 fail : false ,
1042 previous_url : '' ,
11- youTubeKeySet : this . data . key . length > 0 ,
43+ youTubeKeySet : this . data . youtube_key . length > 0 ,
1244 ajax : undefined ,
13- autoBindChangeWatcher : false // Disable the automagic binding
1445 }
1546 } ,
1647
@@ -172,7 +203,7 @@ Vue.component('video_embed-fieldtype', {
172203 }
173204
174205 this . ajax = $ . ajax ( {
175- url : 'https://www.googleapis.com/youtube/v3/videos?part=id%2C+snippet,contentDetails&id=' + this . getYouTubeID + '&key=' + this . data . key
206+ url : 'https://www.googleapis.com/youtube/v3/videos?part=id%2C+snippet,contentDetails&id=' + this . getYouTubeID + '&key=' + this . data . youtube_key
176207 } ) . done ( function ( data ) {
177208 if ( ! data . items [ 0 ] ) {
178209 that . fail = translate ( 'addons.VideoEmbed::settings.youtube_lookup_no_data' ) ;
@@ -233,6 +264,11 @@ Vue.component('video_embed-fieldtype', {
233264 } ,
234265
235266 ready : function ( ) {
267+ // Make sure the default props is not mutated, a unique copy should be made
268+ // this works around a bug where adding more than one video field in a replicator or grid
269+ // before a save causes all url fields to share data / be linked
270+ // https://github.com/jrc9designstudio/statamic-video-embed/issues/22
271+ this . data = Object . assign ( { } , this . data ) ;
236272 // Update the data as soon as Vue is ready.
237273 this . getData ( ) ;
238274 } ,
0 commit comments