Skip to content

Commit

Permalink
syndicationinoninoning fastFT
Browse files Browse the repository at this point in the history
  • Loading branch information
constantology committed Nov 3, 2017
1 parent de1f25b commit 0547b5b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
13 changes: 12 additions & 1 deletion src/js/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,19 @@ export const CSS_SELECTOR_NOT_SYNDICATED = `:not([${ATTR_SYNDICATED}="true"])`;
export const CSS_SELECTOR_PACKAGE_CONTENT_ITEM = 'a.package__content-item';
export const CSS_SELECTOR_REPUBLISHING_HEADER_LINK = '.o-header-services__nav-link';
export const CSS_SELECTOR_REPUBLISHING_BTN = `${CSS_SELECTOR_CONTENT_ID}[${ATTR_SYNDICATED}="true"].${CSS_CLASS_REPUBLISHING_BUTTON}`;
export const CSS_SELECTOR_STORY_LINK = '.story__link'; // for top fastFT bar under main navigation
export const CSS_SELECTOR_SYNDATION_ICON = `${CSS_SELECTOR_CONTENT_ID}[${ATTR_SYNDICATED}="true"].${CSS_CLASS_PREFIX}-icon`;
export const CSS_SELECTOR_TRACKABLE = `[${ATTR_TRACKABLE}]`;
export const CSS_SELECTOR_VIDEO_DOWNLOAD_BUTTON = '.video__actions__download';

export const CSS_SELECTOR_SYNDICATABLE_ITEMS = [
CSS_SELECTOR_CONTENT_ID,
CSS_SELECTOR_ID,
CSS_SELECTOR_CARD_LINK,
CSS_SELECTOR_PACKAGE_CONTENT_ITEM,
CSS_SELECTOR_STORY_LINK
].join(', ');

export const DATA_HIDDEN_ID_PROPERTY = '__id__';
export const DATA_ID_PROPERTY = 'id';
export const DATA_LANG_PROPERTY = 'lang';
Expand Down Expand Up @@ -87,8 +96,10 @@ export const MS_DELAY_HIDE = 500;

export const SYNDICATION_INSERTION_RULES = {
[CSS_SELECTOR_CARD_LINK]: { fn: 'closest', slc: '.card__concept-article' },
[CSS_SELECTOR_PACKAGE_CONTENT_ITEM]: {fn: 'querySelector', slc: '.package__title'},
[CSS_SELECTOR_PACKAGE_CONTENT_ITEM]: {fn: 'querySelector', slc: '.package__title' },
[CSS_SELECTOR_STORY_LINK]: {fn: 'closest', slc: 'article[data-trackable="story"]' },
'a': { fn: 'closest', slc: '.o-teaser__heading' },
'.stream-item': { fn: 'querySelector', slc: '.card-openable__headline' },
'article': { fn: 'querySelector', slc: '.topper__headline' },
'div.hero': { fn: 'querySelector', slc: '.hero__heading' },
'main.video': { fn: 'querySelector', slc: '.video__title' },
Expand Down
6 changes: 2 additions & 4 deletions src/js/iconify.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import {
ATTR_TRACKABLE,
ATTR_TRACKABLE_VALUE,
CSS_CLASS_PREFIX,
CSS_SELECTOR_CARD_LINK,
CSS_SELECTOR_CONTENT_ID,
CSS_SELECTOR_PACKAGE_CONTENT_ITEM,
CSS_SELECTOR_SYNDICATABLE_ITEMS,
DATA_ID_PROPERTY,
DATA_LANG_PROPERTY,
DEFAULT_LANGUAGE,
Expand Down Expand Up @@ -68,7 +66,7 @@ function findElementToSyndicate (el) {
}

function getSyndicatableItems () {
return $$(`${CSS_SELECTOR_CONTENT_ID}, ${CSS_SELECTOR_CARD_LINK}, ${CSS_SELECTOR_PACKAGE_CONTENT_ITEM}`);
return $$(CSS_SELECTOR_SYNDICATABLE_ITEMS);
}

function getSyndicatableItemIDs (items) {
Expand Down
28 changes: 17 additions & 11 deletions src/js/util.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

import {
ATTR_CONTENT_ID
ATTR_CONTENT_ID,
ATTR_ID
} from './config';

function cheapClone (item) {
Expand Down Expand Up @@ -36,23 +37,28 @@ function getContentIDFromHTMLElement (el) {
// there is a case where an item has a `data-content-id` with no value.
// I can't figure it out right now, so temporary "fix"...
if (!id) {
let anchorEl = el;
id = el.getAttribute(ATTR_ID);

if (el.tagName.toUpperCase() !== 'A') {
anchorEl = anchorEl.querySelector('a');
}
if (!id) {
let anchorEl = el;

if (el.tagName.toUpperCase() !== 'A') {
anchorEl = anchorEl.querySelector('a');
}

if (anchorEl && anchorEl.hasAttribute('href')) {
id = anchorEl.getAttribute('href').split('/').pop();
if (anchorEl && anchorEl.hasAttribute('href')) {
id = anchorEl.getAttribute('href').split('/').pop();

id = getContentIDFromHref(id);
id = getContentIDFromHref(id);

if (id) {
el.setAttribute(ATTR_CONTENT_ID, id);
if (id) {
el.setAttribute(ATTR_CONTENT_ID, id);
}
}
}
}
else {

if (id) {
id = getContentIDFromHref(id);

el.setAttribute(ATTR_CONTENT_ID, id);
Expand Down

0 comments on commit 0547b5b

Please sign in to comment.