Skip to content

Commit 02d55f9

Browse files
committed
parent fa81bda
author jean rodriguez <[email protected]> 1551980917 -0500 committer jean rodriguez <[email protected]> 1552514592 -0400 feedbacks
1 parent fa81bda commit 02d55f9

File tree

11 files changed

+101
-116
lines changed

11 files changed

+101
-116
lines changed

app/client-env.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
["CLAY_LOG_PRETTY","LOG","NODE_DEBUG","NODE_ENV","JSONP_CLIENT_ENABLE_LOCAL_SUPPORT","SUPERAGENT_MOCK","CLAY_ACCESS_KEY","ELASTIC_PREFIX","YOUTUBE_API_KEY"]
1+
["ELASTIC_PREFIX","NODE_DEBUG"]

app/components/article/model.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function stripHeadlineTags(oldHeadline) {
2222

2323
/**
2424
* sanitize headline
25-
* @param {object} data
25+
* @param {Object} data
2626
*/
2727
function sanitizeInputs(data) {
2828
if (has(data.headline)) {
@@ -33,8 +33,8 @@ function sanitizeInputs(data) {
3333
/**
3434
* set the publish date from the locals (even if it's already set),
3535
* and format it correctly
36-
* @param {object} data
37-
* @param {object} locals
36+
* @param {Object} data
37+
* @param {Object} locals
3838
*/
3939
function formatDate(data, locals) {
4040
if (_get(locals, 'date')) {
@@ -51,8 +51,8 @@ function formatDate(data, locals) {
5151

5252
/**
5353
* set the canonical url from the locals (even if it's already set)
54-
* @param {object} data
55-
* @param {object} locals
54+
* @param {Object} data
55+
* @param {Object} locals
5656
*/
5757
function setCanonicalUrl(data, locals) {
5858
if (_get(locals, 'publishUrl')) {
@@ -62,7 +62,7 @@ function setCanonicalUrl(data, locals) {
6262

6363
/**
6464
* Set the feed image to the lede url if it isn't already set
65-
* @param {object} data
65+
* @param {Object} data
6666
*/
6767
function generateFeedImage(data) {
6868
if (data.ledeUrl) {

app/components/youtube/client.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
'use strict';
22

33
const youtubeVideoPlayer = require('../../services/universal/youtube-video-player'),
4-
$visibility = require('../../services/client/visibility'),
5-
$gtm = require('../../services/client/gtm');
4+
{ Visible, isElementNotHidden } = require('../../services/client/visibility'),
5+
{ reportNow } = require('../../services/client/gtm');
66

77
module.exports = (el) => {
8-
var autoplay = el.getAttribute('data-autoplay-video') === 'true',
8+
let autoplay = el.getAttribute('data-autoplay-video') === 'true',
99
videoConfig = {
1010
videoContainerId: el.getAttribute('data-element-id').trim(),
1111
videoId: el.getAttribute('data-video-id').trim(),
@@ -37,10 +37,10 @@ module.exports = (el) => {
3737
videoConfig.playerParams.list = '';
3838
}
3939

40-
visible = new $visibility.Visible(el, { preloadThreshold: 800 });
40+
visible = new Visible(el, { preloadThreshold: 800 });
4141

4242
// when the video player element enters the viewport, load the video(s)
43-
if (visible.preload && $visibility.isElementNotHidden(el)) {
43+
if (visible.preload && isElementNotHidden(el)) {
4444
// if the YouTube api is ready the videos(s) can be loaded
4545
if (window.nymYTApiReady === true) {
4646
youtubeVideoPlayer.init(videoConfig);
@@ -62,8 +62,8 @@ module.exports = (el) => {
6262
* component into the data layer. Information about the video itself is captured from the
6363
* native gtm.video trigger on play and finish
6464
*/
65-
document.addEventListener('player-ready-' + videoConfig.videoContainerId, function () {
66-
$gtm.reportNow(Object.assign({
65+
document.addEventListener('player-ready-' + videoConfig.videoContainerId, () => {
66+
reportNow(Object.assign({
6767
youtubeAction: 'player ready'
6868
}, analytics));
6969
});
@@ -75,14 +75,14 @@ module.exports = (el) => {
7575
* also might be nice to send an event if we see the video id changed?
7676
*/
7777
document.addEventListener('player-start-' + videoConfig.videoContainerId, function (evt) {
78-
var hasChanged = el.getAttribute('data-video-id') !== evt.player.videoId;
78+
const hasChanged = el.getAttribute('data-video-id') !== evt.player.videoId;
7979

8080
if (hasChanged) {
8181
updateElementAttributes(el, evt.player);
8282
// this will tell the gtm.video trigger to stop ignoring gtm.video events
8383
// in the case that an external video was played initially then switched to
8484
// an internal playlist
85-
$gtm.reportNow(Object.assign({
85+
reportNow(Object.assign({
8686
event: 'youtubeVideoReset',
8787
youtubeVideoId: evt.player.videoId,
8888
youtubeChannelName: 'New York Magazine'

app/components/youtube/model.js

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
'use strict';
2+
23
const _get = require('lodash/get'),
34
{ getVideoDetails } = require('../../services/universal/youtube'),
45
defaultPlayerBorderTopCTA = 'Watch';
56

67
/**
78
* Override various settings by type of video
8-
* @param {object} data
9+
* @param {Object} data
910
*/
1011
function updateSettingsByType(data) {
1112
switch (data.videoType) {
@@ -19,6 +20,7 @@ function updateSettingsByType(data) {
1920
case 'sponsored':
2021
data.autoPlay = false;
2122
data.autoPlayNextVideo = false;
23+
break;
2224
default:
2325
// Toggle borders off if user previously selected `related` type. `sponsored` and `editorial` types share defaults
2426
data.playerBorderTop = data.previousTypeRelated ? false : data.playerBorderTop;
@@ -34,15 +36,13 @@ function clearVideoId(data) {
3436
}
3537

3638
function setVideoDetails(data, videoDetails) {
37-
var maxResThumb;
38-
3939
if (!videoDetails.title) {
4040
data.videoValid = false;
4141

4242
return data;
4343
}
4444

45-
maxResThumb = _get(videoDetails, 'thumbnails.maxres.url');
45+
const maxResThumb = _get(videoDetails, 'thumbnails.maxres.url');
4646

4747
data.videoValid = true;
4848
data.channelName = videoDetails.channelTitle;
@@ -53,26 +53,20 @@ function setVideoDetails(data, videoDetails) {
5353
return data;
5454
}
5555

56-
function getDefaultPlaylistBySite(data, locals) {
56+
function getDefaultPlaylistBySite(locals) {
5757
switch (locals.site.slug) {
5858
case 'wwwthecut':
5959
return 'PL4B448958847DA6FB';
60-
break;
6160
case 'vulture':
6261
return 'PLZQfnFyelTBOQ15kmHSgEbdjzLMWzZpL7';
63-
break;
6462
case 'grubstreet':
6563
return 'PLtmzdzCeRsyG_td56GV9JtS3yif177lfK';
66-
break;
6764
case 'di':
6865
return 'PLtmzdzCeRsyHbGTxOX4BZvSgXBh20n-_4';
69-
break;
7066
case 'selectall':
7167
return 'PLtmzdzCeRsyHh67c-VlEj8Nqpj5nL8pf6';
72-
break;
7368
default:
7469
return 'PLtmzdzCeRsyFQ64kOTZS7eBLQ1fH2feu7'; // if its a site without a default playlist, use the 'latest from new york' playlist
75-
break;
7670
}
7771
}
7872

@@ -81,7 +75,7 @@ module.exports.save = (uri, data, locals) => {
8175
updateSettingsByType(data);
8276

8377
if (data.videoId && !data.videoPlaylist) {
84-
data.videoPlaylist = getDefaultPlaylistBySite(data, locals);
78+
data.videoPlaylist = getDefaultPlaylistBySite(locals);
8579
}
8680

8781
if (data.videoId) {

app/components/youtube/template.hbs

+45-45
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
11
{{ set 'uniquePlayerID' (randomString 'youtube-player-') }}
22
{{#ifAny @root.locals.edit videoValid}}
3-
<div data-uri="{{ default _ref _self }}"
4-
class="youtube{{if @root.locals.edit ' edit-mode'}}{{ if playerBorderTop ' border-top' }} {{ videoSize }} {{ videoType }}"
5-
data-element-id="{{ uniquePlayerID }}"
6-
data-video-id="{{ videoId }}"
7-
data-autoplay-next-video="{{ autoPlayNextVideo }}"
8-
data-autoplay-video="{{ autoPlay }}"
9-
data-playlist="{{ videoPlaylist }}"
10-
data-track-video-type="{{ videoType }}"
11-
data-track-video-location="{{ videoLocation }}"
12-
data-track-video-title="{{ videoTitle }}"
13-
data-track-video-duration="{{ videoDuration }}"
14-
data-track-channel-name="{{ channelName }}"
15-
data-editable="inline"
16-
data-custom-play="{{ customPlay }}"
17-
data-origsrc="https://www.youtube.com/watch?v={{ videoId }}">
18-
{{#if playerBorderTopCTA }}
19-
<style>
20-
.youtube[data-uri="{{ default _ref _self }}"].border-top:before {
21-
content: '{{ playerBorderTopCTA }}';
22-
}
23-
</style>
24-
{{/if}}
3+
<div data-uri="{{ default _ref _self }}"
4+
class="youtube{{if @root.locals.edit ' edit-mode'}}{{ if playerBorderTop ' border-top' }} {{ videoSize }} {{ videoType }}"
5+
data-element-id="{{ uniquePlayerID }}"
6+
data-video-id="{{ videoId }}"
7+
data-autoplay-next-video="{{ autoPlayNextVideo }}"
8+
data-autoplay-video="{{ autoPlay }}"
9+
data-playlist="{{ videoPlaylist }}"
10+
data-track-video-type="{{ videoType }}"
11+
data-track-video-location="{{ videoLocation }}"
12+
data-track-video-title="{{ videoTitle }}"
13+
data-track-video-duration="{{ videoDuration }}"
14+
data-track-channel-name="{{ channelName }}"
15+
data-editable="inline"
16+
data-custom-play="{{ customPlay }}"
17+
data-origsrc="https://www.youtube.com/watch?v={{ videoId }}">
18+
{{#if playerBorderTopCTA }}
19+
<style>
20+
.youtube[data-uri="{{ default _ref _self }}"].border-top:before {
21+
content: '{{ playerBorderTopCTA }}';
22+
}
23+
</style>
24+
{{/if}}
2525

26-
<div class="player-wrapper">
27-
{{#unless @root.locals.edit}}
28-
<div class="player">
29-
{{!-- The <iframe> (and video player) will replace this <div> tag. --}}
30-
<div id="{{ uniquePlayerID }}"></div>
31-
</div>
32-
{{else}}
33-
{{#unless videoValid}}
34-
<div data-placeholder="videoValid"></div>
26+
<div class="player-wrapper">
27+
{{#unless @root.locals.edit}}
28+
<div class="player">
29+
{{!-- The <iframe> (and video player) will replace this <div> tag. --}}
30+
<div id="{{ uniquePlayerID }}"></div>
31+
</div>
3532
{{else}}
36-
{{#if videoThumbnail}}
37-
<img class="youtube-video-preview" src="{{ videoThumbnail }}" alt="">
38-
{{/if}}
33+
{{#unless videoValid}}
34+
<div data-placeholder="videoValid"></div>
35+
{{else}}
36+
{{#if videoThumbnail}}
37+
<img class="youtube-video-preview" src="{{ videoThumbnail }}" alt="">
38+
{{/if}}
39+
{{/unless}}
3940
{{/unless}}
40-
{{/unless}}
41-
</div>
41+
</div>
4242

43-
{{#ifAll playerHeadline (compare videoType 'related')}}
44-
<h2 class="youtube-headline">{{ playerHeadline }}</h2>
45-
{{/ifAll}}
43+
{{#ifAll playerHeadline (compare videoType 'related')}}
44+
<h2 class="youtube-headline">{{ playerHeadline }}</h2>
45+
{{/ifAll}}
4646

47-
{{#if playerCaption}}
48-
<div class="attribution youtube-caption">
49-
<span class="caption">{{ playerCaption }}</span>
50-
</div>
51-
{{/if}}
52-
</div>
47+
{{#if playerCaption}}
48+
<div class="attribution youtube-caption">
49+
<span class="caption">{{ playerCaption }}</span>
50+
</div>
51+
{{/if}}
52+
</div>
5353
{{/ifAny}}

app/services/client/visibility.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -37,42 +37,42 @@ function updateVisibility() {
3737
/**
3838
* updates seen property
3939
* @param {Visible} item
40-
* @param {{}} evt
40+
* @param {{}} event
4141
* @fires Visible#shown
4242
* @fires Visible#hidden
4343
*/
44-
function updateSeen(item, evt) {
45-
var px = evt.visiblePx,
46-
percent = evt.visiblePercent;
44+
function updateSeen(item, event) {
45+
var px = event.visiblePx,
46+
percent = event.visiblePercent;
4747

4848
// if some pixels are visible and we're greater/equal to threshold
4949
if (px && percent >= item.shownThreshold && !item.seen) {
5050
item.seen = true;
5151
setTimeout(function () {
52-
item.trigger('shown', new VisibleEvent('shown', evt));
52+
item.trigger('shown', new VisibleEvent('shown', event));
5353
}, 15);
5454

5555
// if no pixels or percent is less than threshold
5656
} else if ((!px || percent < item.hiddenThreshold) && item.seen) {
5757
item.seen = false;
5858
setTimeout(function () {
59-
item.trigger('hidden', new VisibleEvent('hidden', evt));
59+
item.trigger('hidden', new VisibleEvent('hidden', event));
6060
}, 15);
6161
}
6262
}
6363

6464
/**
6565
* sets preload property
6666
* @param {Visible} item
67-
* @param {Object} evt
68-
* @param {Number} innerHeight
67+
* @param {Object} event
68+
* @param {number} innerHeight
6969
* @fires Visible#preload
7070
*/
71-
function updatePreload(item, evt, innerHeight) {
72-
if (!item.preload && item.preloadThreshold && shouldBePreloaded(evt.target, evt.rect, item.preloadThreshold, innerHeight)) {
71+
function updatePreload(item, event, innerHeight) {
72+
if (!item.preload && item.preloadThreshold && shouldBePreloaded(event.target, event.rect, item.preloadThreshold, innerHeight)) {
7373
item.preload = true;
7474
setTimeout(function () {
75-
item.trigger('preload', new VisibleEvent('preload', evt));
75+
item.trigger('preload', new VisibleEvent('preload', event));
7676
}, 15);
7777
}
7878
}
@@ -86,21 +86,21 @@ function updateVisibilityForItem(item) {
8686
innerHeight = $window.innerHeight || $document.documentElement.clientHeight,
8787
px = getVerticallyVisiblePixels(rect, innerHeight),
8888
percent = px / (rect.height || innerHeight),
89-
evt = {
89+
event = {
9090
target: item.el,
9191
rect: rect,
9292
visiblePx: px,
9393
visiblePercent: percent
9494
};
9595

96-
updateSeen(item, evt);
97-
updatePreload(item, evt, innerHeight);
96+
updateSeen(item, event);
97+
updatePreload(item, event, innerHeight);
9898
}
9999

100100
/**
101101
* make sure an element isn't hidden by styles or etc
102102
* @param {Element} el
103-
* @return {Boolean}
103+
* @return {boolean}
104104
*/
105105
function isElementNotHidden(el) {
106106
return el && el.offsetParent !== null && !el.getAttribute('hidden') && getComputedStyle(el).display !== 'none' && getComputedStyle(el).visibility !== 'hidden';
@@ -109,9 +109,9 @@ function isElementNotHidden(el) {
109109
/**
110110
* @param {Element} el
111111
* @param {ClientRect} rect
112-
* @param {Number} preloadThreshold
113-
* @param {Number} innerHeight
114-
* @return {Boolean}
112+
* @param {number} preloadThreshold
113+
* @param {number} innerHeight
114+
* @return {boolean}
115115
*/
116116
function shouldBePreloaded(el, rect, preloadThreshold, innerHeight) {
117117
return rect.bottom > preloadThreshold * -1 && rect.top <= innerHeight + preloadThreshold && isElementNotHidden(el);

app/services/universal/rest.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ require('isomorphic-fetch');
77

88
/**
99
* if you're doing api calls to Clay, authenticate on the server/client side
10-
* @param {object} payload
11-
* @return {object}
10+
* @param {Object} payload
11+
* @return {Object}
1212
*/
1313
function authenticate(payload) {
1414
// the access key is stringified at runtime
@@ -29,8 +29,8 @@ function addFakeCallback() {
2929
* check status after doing http calls
3030
* note: this is necessary because fetch doesn't reject on errors,
3131
* only on network failure or incomplete requests
32-
* @param {object} res
33-
* @return {object}
32+
* @param {Object} res
33+
* @return {Object}
3434
* @throws {Error} on non-2xx status
3535
*/
3636
function checkStatus(res) {
@@ -47,7 +47,7 @@ function checkStatus(res) {
4747
/**
4848
* GET
4949
* @param {string} url
50-
* @param {object} opts See https://github.github.io/fetch/#options
50+
* @param {Object} opts See https://github.github.io/fetch/#options
5151
* @return {Promise}
5252
*/
5353
module.exports.get = function (url, opts) {

0 commit comments

Comments
 (0)