i have a javascript object that contains video information(title and src url). In my HTML i have image placeholders and what i'm trying to do is when someone clicks on an image, a modal pops up (twitter bootstrap modal) of that specific video. i'm thinking of using HTML5's data-attribute to link the title of the element to the title of the javascript object as a reference so that i can then insert the proper src url in the modal popup, but when i click on an image, i'm not getting the right url. I'm having trouble reference the data-attribute to the proper src url in the JavaScript object. I'm trying to learn and would appreciate some insight to a viable solution. Any help is greatly appreciated!
EDIT
i realized that the for loop is ending on the last object, so when i reference the srcMp4 property, i'm ending up with the last one. so when i click on any of the posters, its referencing that value...i'll continue investigating...
JavaScript
var dataCollection = {
'videoData': [
{
'id' : 0,
'title' : 'Badminton',
'company' : 'Pepto Bismol',
'gifLink' : 'http://reneinla.com/kris/gifs/BadmintonPeptoBismolCommercial.gif',
'srcMp4' : 'http://reneinla.com/kris/videos/BadmintonPeptoBismolCommercial.m4v',
'srcWebm' : 'http://reneinla.com/kris/videos/BadmintonPeptoBismolCommercial.webm',
'srcOgv' : 'http://reneinla.com/kris/videos/BadmintonPeptoBismolCommercial.ogv',
'poster' : 'http://reneinla.com/kris/videos/BadmintonPeptoBismolCommercial.jpg'
},
{
'id' : 1,
'title' : 'Home Brewer',
'company' : 'Buffalo Wild Wings',
'gifLink' : 'http://reneinla.com/kris/gifs/BuffaloWildWingsHomeBrewer.gif',
'srcMp4' : 'http://reneinla.com/kris/videos/BuffaloWildWingsHomeBrewer.m4v',
'srcWebm' : 'http://reneinla.com/kris/videos/BuffaloWildWingsHomeBrewer.webm',
'srcOgv' : 'http://reneinla.com/kris/videos/BuffaloWildWingsHomeBrewer.ogv',
'poster' : 'http://reneinla.com/kris/videos/BuffaloWildWingsHomeBrewer.jpg'
},
{
'id' : 2,
'title' : 'Directly to Fabulous',
'company' : 'California Lottery',
'gifLink' : 'http://reneinla.com/kris/gifs/CaliforniaLottoMonopolyGoDirectlytoFabulous.gif',
'srcMp4' : 'http://reneinla.com/kris/videos/CaliforniaLottoMonopolyGoDirectlytoFabulous.m4v',
'srcWebm' : 'http://reneinla.com/kris/videos/CaliforniaLottoMonopolyGoDirectlytoFabulous.webm',
'srcOgv' : 'http://reneinla.com/kris/videos/CaliforniaLottoMonopolyGoDirectlytoFabulous.ogv',
'poster' : 'http://reneinla.com/kris/videos/CaliforniaLottoMonopolyGoDirectlytoFabulous.jpg'
}
]
};
$(function() {
var videos = $('#videos');
var modalContent = $('#insert-here');
for (var i = 0; i < dataCollection.videoData.length; i++) {
var obj = dataCollection.videoData[i];
// variable for poster image
var video = obj.poster;
videos.append('<div class="video"><img src="' + obj.poster + '" data-title="' + obj.title + '"/></div>');
$('.video img').click(function(){
//modalContent.append('<video src="' + obj.srcMp4 + '"></video>');
// debug
alert(obj.srcMp4);
console.log(obj.srcMp4);
});
}
});
HTML
<div class="container row">
<div id="videos"></div>
</div>
// this is going to be bootstrap modal, but just as an example...
<div class="modal container">
<div id="insert-here"></div>
</div>
srcMp4value is being passed once the image is clicked. what i want it to do is when i click on the first image, thesrcMp4that corresponds to that image is presented. so if i click on the second image, i should get thesrcMp4value for that image only and if i click on the third image, i should get thesrcMp4for that image only.