i need some help with javascript and datalife engine.
I have a youtube video on my posts, that are displayed calling on the .tpl files(template files) the tag
[xfvalue_treyler]
Basicly this fetches the info that is on the field "treyler" on that specific post. In my case, that value is the iframe code to the youtube video.
I have been researching and i found this javascript code for what i want to use.
<script type="text/javascript">
var self = $(this) //button
, content = $('.content');
$('element_to_pop_up').bPopup({
onOpen: function() {
content.html(self.data('bpopup') || '');
},
onClose: function() {
content.empty();
}
});
</script>
and i call it by using
<div class="element_to_pop_up">[xfvalue_online]</div>
I gave some random css just to define the class "element_to_pop_up", but for some reason this doesn't seem to work. Can you give me a example of this code working on a jsfiddle page please?
Ok, by the looks of things you are having trouble with jQuery.bPopup.js, so here is a basic example which should hopefully point you in the right direction.
HTML:
JavaScript:
CSS:
In my example, I have chosen to popup trailers via a button with a common class of
trailerbutton. This allows me to use common JS code for alltrailerbuttonclick events.I have also chosen to hide my YouTube iframe inside a div just below the button. Note that this has a class of
hiddenTrailerwhich is hidden via the CSS.As you can see, I store the ID of the trailer div I want to show for each button in the
data-traileridattribute.I also have a hidden "popup" placeholder, called
my-popup, which again is hidden with CSS.When the user clicks the button, the JS event is fired, and the correct trailer is loaded into the content div in the ready and waiting popup, based on that all important data attribute.
Here is a JSFiddle. Note that I've had to paste the entire jQuery.bPopup.min.js into the JavaScript window, so scroll down to check out the real content.
EDIT:
Should you wish this to work for multiple posts, you can do something like this:
HTML:
JavaScript:
The updated line here is
var trailerhtml = $(this).next('.hiddenTrailer').html();- I am now using jQuery to select the nexthiddenTrailerelement (i.e. - the one just under the button you pressed).See this updated Fiddle.