Skip to content

Commit 87b7824

Browse files
committed
feat: Add data-transferable-url-parameters attribute to embed
1 parent d523d47 commit 87b7824

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/core/attributes.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ const transformLegacyDataMode = dataMode => {
1818
return element ? element.mode : dataMode
1919
}
2020

21+
const parseTransferableUrlParameters = transferableUrlParameters => {
22+
return transferableUrlParameters.replace(/ /g, '').split(',')
23+
}
24+
2125
const getDataset = element => {
2226
const data = {}
2327
;[].forEach.call(element.attributes, attr => {
@@ -73,6 +77,10 @@ const sanitizePopupAttributes = data => {
7377
obj.height = parseInt(data.height, 10)
7478
}
7579

80+
if (data.transferableUrlParameters) {
81+
obj.transferableUrlParameters = parseTransferableUrlParameters(data.transferableUrlParameters)
82+
}
83+
7684
return obj
7785
}
7886

@@ -100,6 +108,10 @@ const sanitizeWidgetAttributes = data => {
100108
obj.buttonText = data.buttonText
101109
}
102110

111+
if (data.transferableUrlParameters) {
112+
obj.transferableUrlParameters = parseTransferableUrlParameters(data.transferableUrlParameters)
113+
}
114+
103115
return obj
104116
}
105117

src/core/attributes.spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ describe('Attributes', () => {
4242
mode: 'drawer_right'
4343
})
4444
})
45+
46+
it('takes in account the data-transferable-url-parameters option and parse the options correctly', () => {
47+
const mockElement = document.createElement('div')
48+
mockElement.setAttribute('data-transferable-url-parameters', 'foo, bar, john')
49+
expect(sanitizePopupAttributes(getDataset(mockElement))).toEqual({ transferableUrlParameters: ['foo', 'bar', 'john'] })
50+
})
4551
})
4652

4753
describe('Widget', () => {
@@ -61,5 +67,11 @@ describe('Attributes', () => {
6167

6268
expect(sanitizeWidgetAttributes(getDataset(widgetMockElem))).toEqual(widgetOptions)
6369
})
70+
71+
it('takes in account the data-transferable-url-parameters option and parse the options correctly', () => {
72+
const widgetMockElem = document.createElement('div')
73+
widgetMockElem.setAttribute('data-transferable-url-parameters', ' foo, bar, john')
74+
expect(sanitizeWidgetAttributes(getDataset(widgetMockElem))).toEqual({ transferableUrlParameters: ['foo', 'bar', 'john'] })
75+
})
6476
})
6577
})

0 commit comments

Comments
 (0)