Skip to content

Commit 6921ab5

Browse files
Merge pull request #906 from sghoweri/fix/partial-code-panel-toggle-fix
Partial Fix for Code Panel Toggle JS Errors on Master
2 parents 15d9a54 + 35c5726 commit 6921ab5

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
packages/core/scripts/api.handlebars
99
packages/core/scripts/events.handlebars
1010
packages/core/test/files/annotations.js
11+
**/uikit-workshop/src/js/**/*

packages/uikit-workshop/src/js/modal-styleguide.js

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,29 @@ var modalStyleguide = {
116116
* @param {Boolean} if the text in the dropdown should be switched
117117
*/
118118
collectAndSend: function(el, iframePassback, switchText) {
119-
var patternData = JSON.parse(el.innerHTML);
120-
if (patternData.patternName !== undefined) {
121-
patternMarkupEl = document.querySelector(
122-
'#' + patternData.patternPartial + ' > .pl-js-pattern-example'
123-
);
124-
patternData.patternMarkup =
125-
patternMarkupEl !== null
126-
? patternMarkupEl.innerHTML
127-
: document.querySelector('body').innerHTML;
128-
modalStyleguide.patternQueryInfo(patternData, iframePassback, switchText);
119+
/**
120+
* Verify <script> tag has JSON data available (not just whitespace) - helps prevents JS errors from
121+
* getting thrown when certain script tags aren't rendered with partial.patternData content.
122+
*/
123+
if (/\S/.test(el.innerHTML)) {
124+
var patternData = JSON.parse(el.innerHTML);
125+
if (patternData.patternName !== undefined) {
126+
patternMarkupEl = document.querySelector(
127+
'#' + patternData.patternPartial + ' > .pl-js-pattern-example'
128+
);
129+
patternData.patternMarkup =
130+
patternMarkupEl !== null
131+
? patternMarkupEl.innerHTML
132+
: document.querySelector('body').innerHTML;
133+
modalStyleguide.patternQueryInfo(
134+
patternData,
135+
iframePassback,
136+
switchText
137+
);
138+
}
139+
} else {
140+
// @todo: how are we handling conditional logging for debugging based on the dev environment?
141+
// console.log('This <script> tag\'s JSON is empty for some reason...');
129142
}
130143
},
131144

0 commit comments

Comments
 (0)