Diff: STRATO-apps/wordpress_03/app/wp-content/themes/blocksy/static/js/frontend/social-buttons.js

Keine Baseline-Datei – Diff nur gegen leer.
Zur Liste
1 -
1 + import $script from 'scriptjs'
2 +
3 + export const mount = (el, { event }) => {
4 + if (el.dataset.network === 'pinterest') {
5 + event.preventDefault()
6 + if (window.PinUtils) {
7 + window.PinUtils.pinAny()
8 + } else {
9 + $script(
10 + 'https://assets.pinterest.com/js/pinit.js',
11 +
12 + () => {
13 + // $log.info('Pinterest script loaded.')
14 +
15 + setTimeout(() => {
16 + window.PinUtils.pinAny()
17 + }, 300)
18 + }
19 + )
20 + }
21 +
22 + return
23 + }
24 +
25 + if (el.dataset.network === 'clipboard') {
26 + event.preventDefault()
27 +
28 + const text =
29 + el.href.indexOf('wish_list_id') !== -1
30 + ? el.href
31 + : window.location.href
32 +
33 + const tooltip = el.querySelector('.ct-tooltip')
34 + let initialText = ''
35 +
36 + if (tooltip) {
37 + initialText = tooltip.innerHTML
38 + }
39 +
40 + if (navigator.clipboard && window.isSecureContext) {
41 + navigator.clipboard.writeText(text)
42 +
43 + if (tooltip) {
44 + tooltip.innerHTML = ct_localizations.clipboard_copied
45 + }
46 + } else {
47 + const textArea = document.createElement('textarea')
48 + textArea.value = text
49 +
50 + // Move textarea out of the viewport so it's not visible
51 + textArea.style.position = 'absolute'
52 + textArea.style.left = '-999999px'
53 +
54 + document.body.prepend(textArea)
55 + textArea.select()
56 +
57 + try {
58 + document.execCommand('copy')
59 + } catch (error) {
60 + console.error(error)
61 +
62 + if (tooltip) {
63 + tooltip.innerHTML = ct_localizations.clipboard_failed
64 + }
65 + } finally {
66 + textArea.remove()
67 +
68 + if (tooltip) {
69 + tooltip.innerHTML = ct_localizations.clipboard_copied
70 + }
71 + }
72 + }
73 +
74 + setTimeout(() => {
75 + if (tooltip) {
76 + tooltip.innerText = initialText
77 + }
78 + }, 2000)
79 +
80 + return
81 + }
82 +
83 + if (el.hasClickListener) {
84 + return
85 + }
86 +
87 + el.hasClickListener = true
88 + el.addEventListener('click', (e) => {
89 + e.preventDefault()
90 +
91 + const url = el.href
92 + const title = ''
93 + const w = 600
94 + const h = 500
95 +
96 + // PopupCenter(el.querySelector('a').href, '', 600, 500)
97 + // Fixes dual-screen position
98 + // Most browsers Firefox
99 + var dualScreenLeft =
100 + window.screenLeft != undefined ? window.screenLeft : screen.left
101 + var dualScreenTop =
102 + window.screenTop != undefined ? window.screenTop : screen.top
103 +
104 + var width = window.innerWidth
105 + ? window.innerWidth
106 + : document.documentElement.clientWidth
107 + ? document.documentElement.clientWidth
108 + : screen.width
109 + var height = window.innerHeight
110 + ? window.innerHeight
111 + : document.documentElement.clientHeight
112 + ? document.documentElement.clientHeight
113 + : screen.height
114 +
115 + var left = width / 2 - w / 2 + dualScreenLeft
116 + var top = height / 2 - h / 2 + dualScreenTop
117 +
118 + var newWindow = window.open(
119 + url,
120 + title,
121 + 'scrollbars=yes, width=' +
122 + w +
123 + ', height=' +
124 + h +
125 + ', top=' +
126 + top +
127 + ', left=' +
128 + left
129 + )
130 +
131 + // Puts focus on the newWindow
132 + if (window.focus) {
133 + newWindow.focus()
134 + }
135 + })
136 + }
137 +