@reuters-graphics/graphics-components 1.0.11 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -28,7 +28,6 @@ export { default as ReutersLogo } from "./components/ReutersLogo/ReutersLogo.sve
28
28
  export { default as Scroller } from "./components/Scroller/Scroller.svelte";
29
29
  export { default as SearchInput } from "./components/SearchInput/SearchInput.svelte";
30
30
  export { default as SEO } from "./components/SEO/SEO.svelte";
31
- export { default as Sharer } from "./components/Sharer/Sharer.svelte";
32
31
  export { default as SimpleTimeline } from "./components/SimpleTimeline/SimpleTimeline.svelte";
33
32
  export { default as SiteFooter } from "./components/SiteFooter/SiteFooter.svelte";
34
33
  export { default as SiteHeader } from "./components/SiteHeader/SiteHeader.svelte";
@@ -2,6 +2,35 @@
2
2
  import { onMount } from 'svelte';
3
3
  import { loadBootstrap } from './adScripts/bootstrap';
4
4
  import { loadScript } from './adScripts/loadScript';
5
+ import { throttle } from 'lodash-es';
6
+
7
+ let lastScroll = 0;
8
+ let showManagePreferences = true;
9
+
10
+ const togglePrefs = (on = true) => {
11
+ const btn = document.getElementById('ot-sdk-btn-floating');
12
+ if (!btn) return;
13
+ if (on) {
14
+ showManagePreferences = true;
15
+ btn.style.bottom = '';
16
+ } else {
17
+ showManagePreferences = false;
18
+ btn.style.bottom = '-5rem';
19
+ }
20
+ };
21
+
22
+ const handleScroll = () => {
23
+ if (lastScroll > window.scrollY) {
24
+ if (!showManagePreferences) {
25
+ togglePrefs(true);
26
+ }
27
+ } else {
28
+ if (showManagePreferences && window.scrollY > 250) {
29
+ togglePrefs(false);
30
+ }
31
+ }
32
+ lastScroll = window.scrollY;
33
+ };
5
34
 
6
35
  onMount(() => {
7
36
  window.graphicsAdQueue = window.graphicsAdQueue || [];
@@ -9,6 +38,9 @@
9
38
  'https://graphics.thomsonreuters.com/cdn/js/bootstrap.static.js',
10
39
  loadBootstrap
11
40
  );
41
+ window.addEventListener('scroll', throttle(handleScroll, 250), {
42
+ passive: true,
43
+ });
12
44
  });
13
45
  </script>
14
46
 
package/dist/index.js CHANGED
@@ -35,7 +35,6 @@ export { default as ReutersLogo } from './components/ReutersLogo/ReutersLogo.sve
35
35
  export { default as Scroller } from './components/Scroller/Scroller.svelte';
36
36
  export { default as SearchInput } from './components/SearchInput/SearchInput.svelte';
37
37
  export { default as SEO } from './components/SEO/SEO.svelte';
38
- export { default as Sharer } from './components/Sharer/Sharer.svelte';
39
38
  export { default as SimpleTimeline } from './components/SimpleTimeline/SimpleTimeline.svelte';
40
39
  export { default as SiteFooter } from './components/SiteFooter/SiteFooter.svelte';
41
40
  export { default as SiteHeader } from './components/SiteHeader/SiteHeader.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reuters-graphics/graphics-components",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "homepage": "https://reuters-graphics.github.io/graphics-components",
@@ -186,11 +186,6 @@
186
186
  "./components/SearchInput/MagnifyingGlass.svelte": "./dist/components/SearchInput/MagnifyingGlass.svelte",
187
187
  "./components/SearchInput/SearchInput.svelte": "./dist/components/SearchInput/SearchInput.svelte",
188
188
  "./components/SearchInput/X.svelte": "./dist/components/SearchInput/X.svelte",
189
- "./components/Sharer/Sharer.svelte": "./dist/components/Sharer/Sharer.svelte",
190
- "./components/Sharer/utils/copyToClipboard": "./dist/components/Sharer/utils/copyToClipboard.js",
191
- "./components/Sharer/utils/facebook": "./dist/components/Sharer/utils/facebook.js",
192
- "./components/Sharer/utils/meta": "./dist/components/Sharer/utils/meta.js",
193
- "./components/Sharer/utils/twitter": "./dist/components/Sharer/utils/twitter.js",
194
189
  "./components/SimpleTimeline/SimpleTimeline.svelte": "./dist/components/SimpleTimeline/SimpleTimeline.svelte",
195
190
  "./components/SiteFooter/CompanyLinks.svelte": "./dist/components/SiteFooter/CompanyLinks.svelte",
196
191
  "./components/SiteFooter/LegalLinks.svelte": "./dist/components/SiteFooter/LegalLinks.svelte",
@@ -1,23 +0,0 @@
1
- /** @typedef {typeof __propDef.props} SharerProps */
2
- /** @typedef {typeof __propDef.events} SharerEvents */
3
- /** @typedef {typeof __propDef.slots} SharerSlots */
4
- export default class Sharer extends SvelteComponentTyped<{
5
- [x: string]: never;
6
- }, {
7
- [evt: string]: CustomEvent<any>;
8
- }, {}> {
9
- }
10
- export type SharerProps = typeof __propDef.props;
11
- export type SharerEvents = typeof __propDef.events;
12
- export type SharerSlots = typeof __propDef.slots;
13
- import { SvelteComponentTyped } from "svelte";
14
- declare const __propDef: {
15
- props: {
16
- [x: string]: never;
17
- };
18
- events: {
19
- [evt: string]: CustomEvent<any>;
20
- };
21
- slots: {};
22
- };
23
- export {};
@@ -1,2 +0,0 @@
1
- export default copyToClipboard;
2
- declare function copyToClipboard(str: any): void;
@@ -1,2 +0,0 @@
1
- export default handlePost;
2
- declare function handlePost(): void;
@@ -1,2 +0,0 @@
1
- export function getTitle(): string;
2
- export function getHref(): string;
@@ -1,2 +0,0 @@
1
- export default handleTweet;
2
- declare function handleTweet(): void;
@@ -1,155 +0,0 @@
1
- <script>
2
- import Fa from 'svelte-fa/src/fa.svelte';
3
- import { faShareAlt } from '@fortawesome/free-solid-svg-icons';
4
- import { faTwitter } from '@fortawesome/free-brands-svg-icons';
5
- import { faFacebookF } from '@fortawesome/free-brands-svg-icons';
6
- import { throttle } from 'lodash-es';
7
- import handleTweet from './utils/twitter';
8
- import handlePost from './utils/facebook';
9
- import UAParser from 'ua-parser-js';
10
- import { onMount } from 'svelte';
11
-
12
- const uaParser = new UAParser();
13
-
14
- const getMetaContent = (property) => {
15
- const el = document.querySelector(`meta[property="${property}"]`);
16
- if (el) return el.getAttribute('content');
17
- return '';
18
- };
19
- const handleShare = async function () {
20
- if (showSecondaryDialogue) {
21
- showSecondaryDialogue = false;
22
- return;
23
- }
24
- if (
25
- navigator &&
26
- navigator.share &&
27
- uaParser.getBrowser().name !== 'Safari'
28
- ) {
29
- try {
30
- await navigator.share({
31
- title: getMetaContent('og:title'),
32
- text: getMetaContent('og:description'),
33
- url: window.location.href,
34
- });
35
- } catch (err) {
36
- console.log('Share error', err);
37
- }
38
- // Otherwise copy URL to a clipboard
39
- } else {
40
- showSecondaryDialogue = true;
41
- }
42
- };
43
- let lastScroll = 0;
44
- let showShare = false;
45
- let showSecondaryDialogue = false;
46
- function handleScroll() {
47
- if (lastScroll > window.scrollY) {
48
- if (!showShare) {
49
- showShare = true;
50
- }
51
- } else {
52
- if (showShare) {
53
- if (showSecondaryDialogue) {
54
- showSecondaryDialogue = false;
55
- } else {
56
- showShare = false;
57
- }
58
- }
59
- }
60
- lastScroll = window.scrollY;
61
- }
62
- onMount(() => {
63
- window.addEventListener('scroll', throttle(handleScroll, 250));
64
- });
65
- </script>
66
-
67
- <div class="sharetool" class:active="{showShare}">
68
- <div class="drawer" class:active="{showSecondaryDialogue}">
69
- <button
70
- on:click="{handleShare}"
71
- title="Share this!"
72
- disabled="{showSecondaryDialogue}"
73
- class="box-shadow-low"
74
- >
75
- <div><Fa fw icon="{faShareAlt}" /></div>
76
- </button>
77
- <button on:click="{handleTweet}" title="Twitter">
78
- <div><Fa fw icon="{faTwitter}" /></div>
79
- </button>
80
- <button on:click="{handlePost}" title="Facebook">
81
- <div><Fa fw icon="{faFacebookF}" /></div>
82
- </button>
83
- </div>
84
- </div>
85
-
86
- <style>.sharetool.active {
87
- bottom: 10px;
88
- }
89
-
90
- .sharetool {
91
- position: fixed;
92
- bottom: -5rem;
93
- right: 10px;
94
- transition: all 0.2s;
95
- z-index: 9999;
96
- }
97
-
98
- .sharetool button {
99
- background: #333;
100
- color: white;
101
- border: 1px solid white;
102
- border-radius: 50%;
103
- font-size: 1.25rem;
104
- text-align: center;
105
- height: 2.25rem;
106
- width: 2.25rem;
107
- outline: none !important;
108
- transition: color 0.2s;
109
- cursor: pointer;
110
- }
111
- .sharetool button div {
112
- width: 100%;
113
- height: 100%;
114
- display: flex;
115
- align-items: center;
116
- justify-content: center;
117
- }
118
-
119
- .sharetool button:active {
120
- transform: translate(1px, 1px);
121
- }
122
-
123
- .sharetool button:disabled {
124
- background: white;
125
- color: #ddd;
126
- cursor: default;
127
- box-shadow: none;
128
- pointer-events: none;
129
- }
130
-
131
- .drawer {
132
- width: calc(2.25rem + 4px);
133
- overflow-x: hidden;
134
- transition: width 0.2s;
135
- white-space: nowrap;
136
- padding: 2px;
137
- }
138
-
139
- .drawer.active {
140
- width: calc(7.25rem + 4px);
141
- }
142
-
143
- @media only screen and (max-width: 600px) {
144
- .sharetool button {
145
- font-size: 1.75rem;
146
- height: 3rem;
147
- width: 3rem;
148
- }
149
- .drawer {
150
- width: calc(3rem + 4px);
151
- }
152
- .drawer.active {
153
- width: calc(9.5rem + 4px);
154
- }
155
- }</style>
@@ -1,10 +0,0 @@
1
- const copyToClipboard = (str) => {
2
- const el = document.createElement('textarea');
3
- el.value = str;
4
- document.body.appendChild(el);
5
- el.select();
6
- document.execCommand('copy');
7
- document.body.removeChild(el);
8
- };
9
-
10
- export default copyToClipboard;
@@ -1,22 +0,0 @@
1
- import { getHref } from './meta';
2
-
3
- const handlePost = () => {
4
- const windowOptions = 'scrollbars=yes,resizable=yes,toolbar=no,location=yes';
5
- const width = 550;
6
- const height = 420;
7
- const winHeight = screen.height;
8
- const winWidth = screen.width;
9
-
10
- const left = Math.round(winWidth / 2 - width / 2);
11
- const top = winHeight > height ? Math.round(winHeight / 2 - height / 2) : 0;
12
-
13
- const target = `https://www.facebook.com/sharer/sharer.php?u=${getHref()}`;
14
-
15
- window.open(
16
- target,
17
- 'intent',
18
- `${windowOptions},width=${width},height=${height},left=${left},top=${top}`
19
- );
20
- };
21
-
22
- export default handlePost;
@@ -1,7 +0,0 @@
1
- export const getTitle = () => {
2
- const ogTag = document.querySelector("meta[property='og:title']");
3
- if (ogTag) return encodeURIComponent(ogTag.getAttribute('content'));
4
- return encodeURIComponent(document.title);
5
- };
6
-
7
- export const getHref = () => encodeURIComponent(window.location.href);
@@ -1,22 +0,0 @@
1
- import { getHref, getTitle } from './meta';
2
-
3
- const handleTweet = () => {
4
- const windowOptions = 'scrollbars=yes,resizable=yes,toolbar=no,location=yes';
5
- const width = 550;
6
- const height = 420;
7
- const winHeight = screen.height;
8
- const winWidth = screen.width;
9
-
10
- const left = Math.round(winWidth / 2 - width / 2);
11
- const top = winHeight > height ? Math.round(winHeight / 2 - height / 2) : 0;
12
-
13
- const target = `https://twitter.com/intent/tweet?text=${getTitle()}&via=Reuters&url=${getHref()}`;
14
-
15
- window.open(
16
- target,
17
- 'intent',
18
- `${windowOptions},width=${width},height=${height},left=${left},top=${top}`
19
- );
20
- };
21
-
22
- export default handleTweet;