@@ -21,6 +21,12 @@ import {UrlBuilder} from './url-builder';
21
21
import { closestAncestorElementBySelector } from '../../../src/dom' ;
22
22
import { dev , userAssert } from '../../../src/log' ;
23
23
24
+ /**
25
+ * Surrogate property added to click events marking them as handled by the
26
+ * amp-subscriptions extension.
27
+ */
28
+ const CLICK_HANDLED_EVENT_PROPERTY = '_AMP_SUBSCRIPTIONS_CLICK_HANDLED' ;
29
+
24
30
/**
25
31
* This implements the methods to interact with various subscription platforms.
26
32
*
@@ -109,27 +115,24 @@ export class LocalSubscriptionBasePlatform {
109
115
* @protected
110
116
*/
111
117
initializeListeners_ ( ) {
112
- const handleClickAndStopEventPropagation = e => {
113
- e . stopPropagation ( ) ;
118
+ const handleClickOncePerEvent = e => {
119
+ if ( e [ CLICK_HANDLED_EVENT_PROPERTY ] ) {
120
+ return ;
121
+ }
122
+ e [ CLICK_HANDLED_EVENT_PROPERTY ] = true ;
114
123
115
124
const element = closestAncestorElementBySelector (
116
125
dev ( ) . assertElement ( e . target ) ,
117
126
'[subscriptions-action]'
118
127
) ;
119
128
this . handleClick_ ( element ) ;
120
129
} ;
121
- this . rootNode_ . addEventListener (
122
- 'click' ,
123
- handleClickAndStopEventPropagation
124
- ) ;
130
+ this . rootNode_ . addEventListener ( 'click' , handleClickOncePerEvent ) ;
125
131
126
132
// If the root node has a `body` property, listen to events on that too,
127
133
// to fix an iOS shadow DOM bug (https://github.com/ampproject/amphtml/issues/25754).
128
134
if ( this . rootNode_ . body ) {
129
- this . rootNode_ . body . addEventListener (
130
- 'click' ,
131
- handleClickAndStopEventPropagation
132
- ) ;
135
+ this . rootNode_ . body . addEventListener ( 'click' , handleClickOncePerEvent ) ;
133
136
}
134
137
}
135
138
0 commit comments