video_privacy_enhancer_jquery.js 1.6 KB

1234567891011121314151617181920
  1. $(document).ready(function() {
  2. // NOTE WELL: This is wrapped in a `$(document).ready(function() {...})` function (i.e., a "Document Ready" function that starts a section that won't load until the rest of the document/page has loaded (i.e., is "ready")). HOWEVER, this makes it so that jQuery functions from different .js files here are not able to see and talk to functions within this Document Ready function. Within a Document Ready function, functions and variables lose global scope. See http://stackoverflow.com/a/6547906 for more information.
  3. // Whenever a link for an image created with the video_privacy_enhancer plugin is clicked, transform it into a video embed:
  4. $('body').on("click",'img.youtube-embed-dummy-image',function(event) // Whenever an image with the class "youtube-embed-dummy-image" is clicked...
  5. {
  6. // '$(this)' below refers to the image that's been clicked. Before we go down into the function below, where the definition/scope of '$(this)' will change, we'll set it in a variable so that we can refer to it within the function below.
  7. var image_that_was_clicked = $(this);
  8. var youtube_video_id = $(this).attr('id'); // This assumes that the img ID attribute is set to the youtube video id.
  9. // Fade out the image, and replace it with the iframe embed code for the actual YouTube video:
  10. $(this).fadeOut(250, function() {
  11. image_that_was_clicked.replaceWith('<iframe class="embedded_youtube_video" src="//www.youtube-nocookie.com/embed/' + youtube_video_id + '" frameborder="0" allowfullscreen></iframe>') // This will automatically show again.
  12. }); // End fadeOut.
  13. });
  14. }) // End Document Ready wrapper.