Skip to content

Commit b049efd

Browse files
hjdivadcyril-sf
authored andcommitted
Tutorial: Update child card data.
1 parent 087e4d3 commit b049efd

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

example/cards/tutorial/ad_card.js

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
/*global Handlebars */
2+
13
Conductor.require('/vendor/jquery.js');
4+
Conductor.require('/example/libs/handlebars-1.0.0-rc.3.js');
25
Conductor.requireCSS('/example/cards/tutorial/ad_card.css');
36

47
var RSVP = Conductor.Oasis.RSVP;
5-
var destinationUrl = window.location.protocol + "//" + window.location.hostname + ":" + (parseInt(window.location.port, 10) + 2);
8+
var crossOrigin = window.location.protocol + "//" + window.location.hostname + ":" + (parseInt(window.location.port, 10) + 2),
9+
videoCardUrl = crossOrigin + '/example/cards/tutorial/youtube_card.html';
10+
var videoSelectTemplate = '<div id="selectWrapper">Load Video: <select id="videoSelect">{{#each videoIds}}<option value="{{this}}">{{this}}</option>{{/each}}</select></div>';
611

712
var card = Conductor.card({
813
videoIds: ['4d8ZDSyFS2g', 'EquPUW83D-Q'],
@@ -52,21 +57,23 @@ var card = Conductor.card({
5257
},
5358

5459
childCards: [
55-
{url: destinationUrl + '/example/cards/tutorial/youtube_card.html', id: '1', options: { capabilities: ['video']}},
56-
{url: destinationUrl + '/example/cards/tutorial/survey_card.html', id: '1', options: { capabilities: ['survey']}}
60+
{url: videoCardUrl, id: '1', options: { capabilities: ['video']}},
61+
{url: crossOrigin + '/example/cards/tutorial/survey_card.html', id: '1', options: { capabilities: ['survey']}}
5762
],
5863

5964
loadDataForChildCards: function(data) {
6065
var videoCardOptions = this.childCards[0],
6166
surveyCardOptions = this.childCards[1];
6267

63-
videoCardOptions.data = { videoId: data.videoId };
68+
this.videoId = this.videoIds[0];
69+
videoCardOptions.data = { videoId: this.videoId };
6470
},
6571

66-
activate: function (data) {
72+
activate: function () {
6773
Conductor.Oasis.RSVP.EventTarget.mixin(this);
74+
this.consumers.height.autoUpdate = false;
6875

69-
this.videoId = data.videoId;
76+
videoSelectTemplate = Handlebars.compile(videoSelectTemplate);
7077
this.videoCard = this.childCards[0].card;
7178
this.surveyCard = this.childCards[1].card;
7279
},
@@ -107,8 +114,25 @@ var card = Conductor.card({
107114
},
108115

109116
initializeDOM: function () {
110-
this.videoCard.appendTo(document.body);
111-
this.surveyCard.appendTo(document.body);
117+
var card = this;
118+
119+
$(videoSelectTemplate(this)).appendTo('body');
120+
$('#videoSelect').change(function () {
121+
card.changeVideo($(this).val());
122+
});
123+
124+
this.selectWrapperDiv = $('#selectWrapper');
125+
this.cardWrapperDiv = $('<div id="cardWrapper"></div>');
126+
this.cardWrapperDiv.appendTo('body');
127+
this.videoCard.appendTo(this.cardWrapperDiv[0]);
128+
this.surveyCard.appendTo(this.cardWrapperDiv[0]);
129+
},
130+
131+
changeVideo: function (videoId) {
132+
this.videoId = videoId;
133+
console.log('Change the video to ' + videoId);
134+
this.conductor.loadData(videoCardUrl, '1', { videoId: this.videoId });
135+
this.render('video');
112136
},
113137

114138
getDimensions: function () {
@@ -125,5 +149,7 @@ var card = Conductor.card({
125149
width: window.innerWidth
126150
};
127151
}
152+
153+
this.cardWrapperDiv.height(this._dimensions.height - this.selectWrapperDiv.height());
128154
}
129155
});

example/playground/js/playground.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ window.Playground = {
3737

3838
this.cardTemplate = $('.card-wrapper').hide();
3939

40-
this.conductor.loadData(
41-
Playground.crossOriginHtmlUrl('../cards/tutorial/ad_card.js'),
42-
'1',
43-
{ videoId: '4d8ZDSyFS2g'}
44-
);
4540
this.addCard('../cards/tutorial/ad_card.js', 1, ['video', 'survey']);
4641
}
4742
};

0 commit comments

Comments
 (0)