Skip to content

Commit 56b7d33

Browse files
committed
refactor: restore ability to click on pattern lineage links and not open in a new window
1 parent 7c2e375 commit 56b7d33

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

packages/uikit-workshop/src/scripts/components/modal-viewer.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const modalViewer = {
1414
// set up some defaults
1515
delayCheckingModalViewer: false,
1616
iframeElement: document.querySelector('.pl-js-iframe'),
17+
iframeCustomElement: document.querySelector('pl-iframe'),
1718
active: false,
1819
switchText: true,
1920
template: 'info',
@@ -170,9 +171,23 @@ export const modalViewer = {
170171
}
171172

172173
contentContainer.appendChild(templateRendered);
174+
modalViewer.addClickEvents(contentContainer);
173175
}
174176
},
175177

178+
addClickEvents(contentContainer = document) {
179+
contentContainer.querySelectorAll('.pl-js-lineage-link').forEach(link => {
180+
link.addEventListener('click', e => {
181+
const patternPartial = e.target.getAttribute('data-patternpartial');
182+
183+
if (patternPartial && modalViewer.iframeCustomElement) {
184+
e.preventDefault();
185+
modalViewer.iframeCustomElement.navigateTo(patternPartial);
186+
}
187+
});
188+
});
189+
},
190+
176191
/**
177192
* refresh the modal if a new pattern is loaded and the modal is active
178193
* @param {Object} the patternData sent back from the query

packages/uikit-workshop/src/scripts/components/panels-viewer.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -332,19 +332,6 @@ export const panelsViewer = {
332332
}
333333
}
334334

335-
// find lineage links in the rendered content and add postmessage handlers in case it's in the modal
336-
// @todo: refactor and re-enable
337-
// $('.pl-js-lineage-link', templateRendered).on('click', function(e) {
338-
// e.preventDefault();
339-
// const obj = JSON.stringify({
340-
// event: 'patternLab.updatePath',
341-
// path: urlHandler.getFileName($(this).attr('data-patternpartial')),
342-
// });
343-
// document
344-
// .querySelector('.pl-js-iframe')
345-
// .contentWindow.postMessage(obj, panelsViewer.targetOrigin);
346-
// });
347-
348335
// gather panels from plugins
349336
Dispatcher.trigger('insertPanels', [
350337
templateRendered,

0 commit comments

Comments
 (0)