-
Notifications
You must be signed in to change notification settings - Fork 18
youtube component #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jeanrodriguez
wants to merge
49
commits into
master
Choose a base branch
from
code-component-youtube
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
9a021df
component youtube
jeanrodriguez 732019b
added new files for twitter component
jeanrodriguez b6b99f1
youtube component
jeanrodriguez 03770ca
Create youtube.css
jeanrodriguez aa83fc3
added youtube video player js
jeanrodriguez a20a5bb
yotube component
jeanrodriguez 69379a6
youtube component _layout and _component
jeanrodriguez c10b45e
fix css
jeanrodriguez 858397e
added YOUTUBE_API_KEY env variable, remove unuse css
jeanrodriguez f42ee11
Revert "added YOUTUBE_API_KEY env variable, remove unuse css"
jeanrodriguez 5358dc6
fix css and add env variable
jeanrodriguez 21b8185
added YOUTUBE_API_KEY
jeanrodriguez b36e19a
Update schema.yaml
jeanrodriguez ab1db28
remove unnecesary description. update youtube css
jeanrodriguez 8ddcc6f
Update client.js
jeanrodriguez 9f192f9
remove unused functions
jeanrodriguez cf79110
Update visibility.js
jeanrodriguez 5abe5ce
removed getViewportHeight
jeanrodriguez e468746
Update visibility.js
jeanrodriguez 8dd8f1c
removed _assign visbility.js
jeanrodriguez 52b9202
Update gtm.js
jeanrodriguez 3ec66f5
remove unused code visibility and gtm js
jeanrodriguez d529ab6
remove unused files
jeanrodriguez b587e7d
Update youtube-video-player.js
jeanrodriguez 86a4ac4
Update youtube.js
jeanrodriguez fc5c953
update byline removed join and map lodash
jeanrodriguez 0269a5c
Update byline.js
jeanrodriguez 01540b7
Merge branch 'master' of https://github.com/clay/clay-starter into co…
jeanrodriguez 69208b0
youtube component for clay-starter
jeanrodriguez fa81bda
Merge branch 'code-component-youtube' of https://github.com/clay/clay…
jeanrodriguez 44870bb
js docs
jeanrodriguez 4b08edf
Update subheader.css
jeanrodriguez d496d06
Update client.js
jeanrodriguez 2bb136f
destruct visible object
jeanrodriguez b1559d0
Update youtube.css
jeanrodriguez c659775
Update client-env.json
jeanrodriguez 1dfefbc
Merge branch 'master' of https://github.com/clay/clay-starter into co…
jeanrodriguez 632f53a
Update client.js
jeanrodriguez d82a6de
feedbacks
jeanrodriguez 679f8bf
Update model.js
jeanrodriguez daf4866
Update visibility.js
jeanrodriguez 29d5468
removed analytics and added js docs
jeanrodriguez b34d3f6
removed gtm.js
jeanrodriguez 88538d8
remove nym reference
jeanrodriguez cea0b08
Merge branch 'master' of https://github.com/clay/clay-starter into co…
jeanrodriguez fb0dd95
Update schema.yaml
jeanrodriguez 8fc5739
feedback
jeanrodriguez da8a9e5
Update template.hbs
jeanrodriguez dbac03e
Update template.hbs
jeanrodriguez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,6 +61,7 @@ content: | |
| - image | ||
| - code-sample | ||
| - list | ||
| - youtube | ||
|
|
||
| ledeUrl: | ||
| _label: Lede Image URL | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| _components: | ||
| youtube-player-head: | ||
| allowed: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| _description: | | ||
| Note: Required for `video-player` component. YouTube API scripts, add component to head for best YouTube player performance. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <!-- data-uri="{{ default _ref _self }}" --> | ||
| {{#unless @root.locals.edit}} | ||
| {{! youtube flags for `video-player` component instances | ||
| player instances will first look for `youtubeApiReady` to be `true` | ||
| if `false`, player instances will listen for the event `youtube-event:youtube-api-ready` }} | ||
| <script> | ||
| var youtubeApiReady = false; | ||
| window.onYouTubeIframeAPIReady = function () { | ||
| {{! when the YouTube API script is ready, dispatch an `youtube-event:youtube-api-ready` event }} | ||
| var eventYTApiReady = new Event('youtube-event:youtube-api-ready'); | ||
| document.dispatchEvent(eventYTApiReady); | ||
| {{! change this flag to 'true' when the YouTube api is ready }} | ||
| youtubeApiReady = true; | ||
| } | ||
| </script> | ||
|
|
||
| {{! add the YouTube API script to the head for fastest player creation }} | ||
| <script type="text/javascript" src="https://www.youtube.com/iframe_api"></script> | ||
| {{/unless}} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| _components: | ||
| youtube: | ||
| videoId: '' | ||
| videoType: 'editorial' | ||
| videoLocation: 'article' | ||
| playerCaption: '' | ||
| autoPlay: true | ||
| autoPlayNextVideo: true | ||
| videoPlaylist: '' | ||
| playerBorderTopCTA: 'Watch' | ||
| playerBorderTop: false | ||
| playerBorderBottom: false | ||
| previousTypeRelated: false | ||
| customPlay: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| 'use strict'; | ||
|
|
||
| const youtubeVideoPlayer = require('../../services/universal/youtube-video-player'), | ||
| { Visible, isElementNotHidden } = require('../../services/client/visibility'); | ||
|
|
||
| module.exports = (el) => { | ||
| const autoplay = el.getAttribute('data-autoplay-video') === 'true', | ||
| videoConfig = { | ||
| videoContainerId: el.getAttribute('data-element-id').trim(), | ||
| videoId: el.getAttribute('data-video-id').trim(), | ||
| // player variables and settings | ||
| playerParams: { | ||
| loop: 1, | ||
| listType: 'playlist', | ||
| list: el.getAttribute('data-playlist').trim(), | ||
| autoplay: autoplay ? 1 : 0, | ||
| controls: 1, | ||
| enablejsapi: 1, | ||
| modestbranding: 1, | ||
| rel: 0, | ||
| showinfo: 0, | ||
| wmode: 'transparent' | ||
| }, | ||
| customParams: { | ||
| autoPlayNextVideo: el.getAttribute('data-autoplay-next-video').trim(), | ||
| trackVideoType: el.getAttribute('data-track-video-type').trim(), | ||
| customPlayer: el.getAttribute('data-custom-play').trim(), | ||
| templateid: el.getAttribute('data-element-id').trim(), | ||
| muted: autoplay // always mute autplaying videos | ||
| } | ||
| }, | ||
| visible = new Visible(el, { preloadThreshold: 800 }); | ||
|
|
||
| if (videoConfig.customParams.trackVideoType === 'Sponsored') { | ||
| videoConfig.playerParams.list = ''; | ||
| } | ||
|
|
||
| // when the video player element enters the viewport, load the video(s) | ||
| if (visible.preload && isElementNotHidden(el)) { | ||
| // if the YouTube api is ready the videos(s) can be loaded | ||
| if (window.youtubeApiReady === true) { | ||
| youtubeVideoPlayer.init(videoConfig); | ||
| } else { | ||
| // wait and listen for the YouTube api to be ready before loading the video(s) | ||
| document.addEventListener('youtube-event:youtube-api-ready', function () { | ||
| youtubeVideoPlayer.init(videoConfig); | ||
| }); | ||
| } | ||
| } else { | ||
| visible.on('preload', function () { | ||
| youtubeVideoPlayer.init(videoConfig); | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Player start event | ||
| * we don't need to send an event here, updating the video id for posterity | ||
| */ | ||
| document.addEventListener('player-start-' + videoConfig.videoContainerId, function (evt) { | ||
| const hasChanged = el.getAttribute('data-video-id') !== evt.player.videoId; | ||
|
|
||
| if (hasChanged) { | ||
| updateElementAttributes(el, evt.player); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| /** | ||
| * Updates Element attributes | ||
| * @param {Object} el - DOM node element | ||
| * @param {Object} config - Attributes values from player | ||
| */ | ||
| function updateElementAttributes(el, config) { | ||
| el.setAttribute('data-video-id', config.videoId); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| 'use strict'; | ||
|
|
||
| const _get = require('lodash/get'), | ||
| { getVideoDetails } = require('../../services/universal/youtube'), | ||
| defaultPlayerBorderTopCTA = 'Watch'; | ||
|
|
||
| /** | ||
| * Override various settings by type of video | ||
| * @param {Object} data | ||
| */ | ||
| function updateSettingsByType(data) { | ||
| switch (data.videoType) { | ||
| case 'related': | ||
| // By default, display borders and CTA when `related` type is first selected, afterwards accept user's selection | ||
| data.playerBorderTopCTA = !data.previousTypeRelated && !data.playerBorderTopCTA ? defaultPlayerBorderTopCTA : data.playerBorderTopCTA; | ||
| data.playerBorderTop = !data.previousTypeRelated ? true : data.playerBorderTop; | ||
| data.playerBorderBottom = !data.previousTypeRelated ? true : data.playerBorderBottom; | ||
| data.previousTypeRelated = true; | ||
| break; | ||
| case 'sponsored': | ||
| data.autoPlay = false; | ||
| data.autoPlayNextVideo = false; | ||
| break; | ||
| default: | ||
manuelurenah marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Toggle borders off if user previously selected `related` type. `sponsored` and `editorial` types share defaults | ||
| data.playerBorderTop = data.previousTypeRelated ? false : data.playerBorderTop; | ||
| data.playerBorderBottom = data.previousTypeRelated ? false : data.playerBorderBottom; | ||
| data.previousTypeRelated = false; | ||
| } | ||
| } | ||
|
|
||
| function clearVideoId(data) { | ||
| data.videoId = (data.videoId || '').split('&')[0]; | ||
|
|
||
| return data; | ||
| } | ||
|
|
||
| function setVideoDetails(data, videoDetails) { | ||
| if (!videoDetails.title) { | ||
| data.videoValid = false; | ||
|
|
||
| return data; | ||
| } | ||
|
|
||
| const maxResThumb = _get(videoDetails, 'thumbnails.maxres.url'); | ||
|
|
||
| data.videoValid = true; | ||
| data.channelName = videoDetails.channelTitle; | ||
| data.videoTitle = videoDetails.title; | ||
| data.videoThumbnail = maxResThumb ? maxResThumb : _get(videoDetails, 'thumbnails.high.url'); // get the maxres if available, otherwise get the high res which we know will be there | ||
| data.videoDuration = videoDetails.duration; | ||
|
|
||
| return data; | ||
| } | ||
|
|
||
| module.exports.save = (uri, data) => { | ||
| clearVideoId(data); | ||
| updateSettingsByType(data); | ||
|
|
||
| if (data.videoId) { | ||
| return getVideoDetails(data.videoId) | ||
| .then(videoDetails => setVideoDetails(data, videoDetails)); | ||
| } | ||
|
|
||
| data.videoValid = true; // technically not an invalid video because no videoId so we don't want to show an error message in edit mode | ||
|
|
||
| return data; | ||
| }; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,143 @@ | ||
| _description: | | ||
| Youtube video embed for Clay. For technical reasons, YouTube embeds don't display a preview in edit mode. | ||
| Preview the video by previewing the full page (from the Clay toolbar). Embeds can display a specific video ID. | ||
| videoId: | ||
| _label: YouTube Video ID | ||
| _publish: videoPlayerId | ||
| _has: | ||
| input: text | ||
|
|
||
| videoType: | ||
| _label: Type | ||
| _has: | ||
| input: radio | ||
| options: | ||
| - | ||
| name: Editorial (Original) | ||
| value: editorial | ||
| - | ||
| name: Editorial (External) | ||
| value: embedded | ||
| - | ||
| name: Related | ||
| value: related | ||
| - | ||
| name: Sponsored | ||
| value: sponsored | ||
| validate: | ||
| required: true | ||
| requiredMessage: Please select a video type | ||
|
|
||
| videoSize: | ||
| _label: Size | ||
| _has: | ||
| input: radio | ||
| options: | ||
| - | ||
| name: Column Width | ||
| value: column-width | ||
| - | ||
| name: Break-out | ||
| value: break-out | ||
| _reveal: | ||
| field: videoType | ||
| operator: === | ||
| values: | ||
| - sponsored | ||
| - editorial | ||
|
|
||
| playerHeadline: | ||
| _label: Video Headline | ||
| _has: | ||
| input: text | ||
| _reveal: | ||
| field: videoType | ||
| value: related | ||
|
|
||
| playerCaption: | ||
| _label: Video Caption | ||
| _has: text | ||
|
|
||
| autoPlay: | ||
| _label: Autoplay with muted audio on Page Load | ||
| _has: checkbox | ||
|
|
||
| autoPlayNextVideo: | ||
| _label: Automatically start next video | ||
| _has: checkbox | ||
| _reveal: | ||
| field: videoType | ||
| operator: '!==' | ||
| value: sponsored | ||
|
|
||
| videoPlaylist: | ||
| _label: Youtube Playlist (defaults to current site) | ||
| _reveal: | ||
| field: autoPlayNextVideo | ||
| operator: truthy | ||
| _has: | ||
| input: text | ||
| validate: | ||
| required: | ||
| field: autoPlayNextVideo | ||
| operator: truthy | ||
| requiredMessage: Video Player should contain video playlist | ||
| help: Playlists are used for auto playing additional videos in the YouTube component after the assigned video is finished. Only required for videos that are selected to automatically start next video above | ||
|
|
||
| playerBorderTopCTA: | ||
| _label: Top Border Title | ||
| _has: text | ||
|
|
||
| playerBorderTop: | ||
| _label: Show Top Border | ||
| _has: checkbox | ||
|
|
||
| playerBorderBottom: | ||
| _label: Show Bottom Border | ||
| _has: checkbox | ||
|
|
||
| customPlay: | ||
| _subscribe: customPlay | ||
|
|
||
| _groups: | ||
| settings: | ||
| fields: | ||
| - autoPlay (Autoplay) | ||
| - autoPlayNextVideo (Autoplay) | ||
| - videoPlaylist (Autoplay) | ||
| - playerBorderTopCTA (Borders and Border Title) | ||
| - playerBorderTop (Borders and Border Title) | ||
| - playerBorderBottom (Borders and Border Title) | ||
| inline: | ||
| fields: | ||
| - videoId | ||
| - videoType | ||
| - videoSize | ||
| - playerHeadline | ||
| - playerCaption | ||
| _label: Youtube Video Player | ||
| _placeholder: | ||
| text: Youtube Video Player | ||
| height: 100px | ||
| ifEmpty: videoId | ||
|
|
||
| # set by bootstrap or first-run | ||
| videoLocation: | ||
| help: For analytics, to tell what kind of page the video is on | ||
|
|
||
| # non-user-editable fields, set by model.js | ||
| previousTypeRelated: | ||
| help: Toggle for displaying convenience-based changes to player borders based on previously selected video type. Set by model.js | ||
| videoValid: | ||
| help: Used to decide whether or not to display a video in the template | ||
| _placeholder: | ||
| text: Invalid video id ${videoId}. This video will not display. | ||
| permanent: true | ||
| channelName: | ||
| help: Name of the channel the video comes from. Used to decide whether or not to listen to GTM triggers for this video | ||
| videoTitle: | ||
| help: Title of the video | ||
| videoThumbnail: | ||
| help: maxres video thumbnail | ||
| videoDuration: | ||
| help: video duration in seconds |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.