Skip to content

Commit 087e4d3

Browse files
hjdivadcyril-sf
authored andcommitted
Tutorial: Child cards.
```js Playground.conductor.cards['../cards/tutorial/ad_card.js'][1][0].sandbox.videoPort.send('play'); // we add videoPort to window for convenience in the tutorial window.videoPort.send('play'); ```
1 parent c3a0693 commit 087e4d3

File tree

3 files changed

+19
-35
lines changed

3 files changed

+19
-35
lines changed

example/cards/tutorial/ad_card.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script src="/conductor-0.3.0.js" ></script>
5+
<script src="ad_card.js" ></script>
6+
</head>
7+
<body>
8+
</body>
9+
</html>

example/cards/tutorial/ad_card.js

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

74
var RSVP = Conductor.Oasis.RSVP;
8-
var videoSelectTemplate = '<div id="selectWrapper">Load Video: <select id="videoSelect">{{#each videoIds}}<option value="{{this}}">{{this}}</option>{{/each}}</select></div>';
5+
var destinationUrl = window.location.protocol + "//" + window.location.hostname + ":" + (parseInt(window.location.port, 10) + 2);
96

107
var card = Conductor.card({
118
videoIds: ['4d8ZDSyFS2g', 'EquPUW83D-Q'],
@@ -55,23 +52,21 @@ var card = Conductor.card({
5552
},
5653

5754
childCards: [
58-
{url: '../cards/tutorial/youtube_card.js', id: '1', options: { capabilities: ['video']}},
59-
{url: '../cards/tutorial/survey_card.js', id: '1', options: { capabilities: ['survey']}}
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']}}
6057
],
6158

6259
loadDataForChildCards: function(data) {
6360
var videoCardOptions = this.childCards[0],
6461
surveyCardOptions = this.childCards[1];
6562

66-
this.videoId = this.videoIds[0];
67-
videoCardOptions.data = { videoId: this.videoId };
63+
videoCardOptions.data = { videoId: data.videoId };
6864
},
6965

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

74-
videoSelectTemplate = Handlebars.compile(videoSelectTemplate);
69+
this.videoId = data.videoId;
7570
this.videoCard = this.childCards[0].card;
7671
this.surveyCard = this.childCards[1].card;
7772
},
@@ -112,25 +107,8 @@ var card = Conductor.card({
112107
},
113108

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

136114
getDimensions: function () {
@@ -147,7 +125,5 @@ var card = Conductor.card({
147125
width: window.innerWidth
148126
};
149127
}
150-
151-
this.cardWrapperDiv.height(this._dimensions.height - this.selectWrapperDiv.height());
152128
}
153129
});

example/playground/js/playground.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@ window.Playground = {
3838
this.cardTemplate = $('.card-wrapper').hide();
3939

4040
this.conductor.loadData(
41-
Playground.crossOriginHtmlUrl('../cards/tutorial/youtube_card.js'),
41+
Playground.crossOriginHtmlUrl('../cards/tutorial/ad_card.js'),
4242
'1',
4343
{ videoId: '4d8ZDSyFS2g'}
4444
);
45-
this.addCard('../cards/tutorial/youtube_card.js', 1, []);
46-
this.addCard('../cards/tutorial/youtube_card.js', 1, ['video']);
45+
this.addCard('../cards/tutorial/ad_card.js', 1, ['video', 'survey']);
4746
}
4847
};
4948

0 commit comments

Comments
 (0)