Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: static/js/video.js

Issue 29703633: Noissue - Abstracted embedded video for use in blog (Closed) Base URL: https://hg.adblockplus.org/web.adblockplus.org
Patch Set: Moved no-js application and iframe height+width Created Feb. 20, 2018, 10:35 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« static/css/video.css ('K') | « static/js/main.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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)
ire 2018/02/22 09:25:41 NIT: Move this logic to it's own function instead
juliandoucette 2018/02/23 13:31:08 Done.
53 {
54 event.preventDefault();
55
56 if (this.parent.classList.contains("contains-disclaimer") === false)
ire 2018/02/22 09:25:41 NIT: I prefer: if (!condition) Over: if (condi
juliandoucette 2018/02/23 13:31:08 Good catch. Done.
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()
ire 2018/02/22 09:25:41 The .contains-disclaimer class still shows even wh
juliandoucette 2018/02/23 13:31:08 Good catch. ~Done. (I changed the approach from "c
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 "allowfullscreen " +
87 "src='" + this.src + "'>" +
88 "</iframe>";
89 }
90
91 };
OLDNEW
« static/css/video.css ('K') | « static/js/main.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld