Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /** | |
2 * Creats a GDPR compatible video | |
3 * @constructor | |
4 * @param {Element} parent - video parent / container | |
5 * @example | |
6 * <div id="example-video" class="video-parent"> | |
7 * <a | |
8 * class="video-link" | |
9 * target="_blank" | |
10 * href="http://example.com/iframe/video/src"> | |
11 * <img | |
12 * class="video-thumbnail" | |
13 * alt="Short description of video" | |
14 * src="/img/video-thumbnail.png" /> | |
15 * <img | |
16 * class="video-play" | |
17 * alt="Open video in separate window"" | |
18 * src="/img/video-link.png" /> | |
19 * </a> | |
20 * <p class="video-disclaimer">Disclaimer text</p> | |
21 * </div> | |
22 * | |
23 * <script>new Video(document.getElementById('example-video'));</script> | |
24 */ | |
25 function Video(parent) | |
26 { | |
27 /** | |
28 * Video parent / container element | |
29 * @member {Element} | |
30 */ | |
31 this.parent = parent; | |
32 | |
33 /** | |
34 * The last time that the play button was clicked | |
35 * @member {number} | |
36 */ | |
37 this.lastClicked = 0; | |
38 | |
39 var videoLink = parent.querySelector(".video-link"); | |
40 | |
41 /** | |
42 * The iframe video src url | |
43 * @member {string} | |
44 */ | |
45 this.src = videoLink.getAttribute("href"); | |
46 | |
47 //change external link icon into play button icon | |
48 parent.querySelector(".video-play") | |
49 .setAttribute("src", "/img/video-play.png"); | |
50 | |
51 //show disclaimer or replace thumbnail with video on click | |
52 videoLink.addEventListener("click", function(event) | |
53 { | |
54 event.preventDefault(); | |
55 | |
56 if (this.parent.classList.contains("contains-disclaimer") === false) | |
57 { | |
58 this.toggleDisclaimer(); | |
59 } | |
60 else if (new Date().getTime() - this.lastClicked > 600) | |
61 { | |
62 this.insertVideo(); | |
63 } | |
64 }.bind(this)); | |
65 } | |
66 | |
67 Video.prototype = { | |
68 | |
69 /** Toggle video disclaimer */ | |
70 toggleDisclaimer: function() | |
71 { | |
72 this.parent.classList.toggle("contains-disclaimer"); | |
73 this.lastClicked = new Date().getTime(); | |
74 }, | |
75 | |
76 /** Replace video thumbnail with video iframe */ | |
77 insertVideo: function() | |
78 { | |
79 this.parent.classList.add("contains-iframe"); | |
80 | |
81 //replace static thumbnail with iframe video | |
82 this.parent.innerHTML = | |
83 "<iframe " + | |
84 "class='video-iframe' " + | |
85 "frameborder=0 " + | |
86 "height=285 " + | |
juliandoucette
2018/02/20 22:28:11
Detail: These height/widths are not necessary. I t
juliandoucette
2018/02/20 22:36:07
Done.
| |
87 "width=520 " + | |
88 "allowfullscreen " + | |
89 "src='" + this.src + "'>" + | |
90 "</iframe>"; | |
91 } | |
92 | |
93 }; | |
OLD | NEW |