Skip to content

Commit 7b64a06

Browse files
Infrastructure: Codepen button should show only when resources loaded (pull #1533)
* Code pen button should show only when resources loaded * Switch log to warn Co-authored-by: Matt King <[email protected]>
1 parent c7fc4d8 commit 7b64a06

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

examples/js/examples.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,8 @@ function addOpenInCodePenForm(
380380

381381
var button = document.createElement('button');
382382
button.innerText = 'Open In CodePen';
383+
button.id = buttonId;
384+
button.style.display = 'none';
383385

384386
form.appendChild(input);
385387
form.appendChild(button);
@@ -425,32 +427,36 @@ function addOpenInCodePenForm(
425427
}
426428
totalFetchedFiles++;
427429
} else {
428-
hideButton(buttonId, 'Could not load resource: ' + href);
430+
console.warn(
431+
"Not showing 'Open in Codepen' button. Could not load resource: " +
432+
href
433+
);
429434
}
430435
};
431436
request.onerror = function () {
432-
hideButton(buttonId, 'Could not load resource: ' + fileLink.href);
437+
console.warn(
438+
"Not showing 'Open in Codepen' button. Could not load resource: " +
439+
fileLink.href
440+
);
433441
};
434442
request.send();
435443
}
436444

437445
var timerId = setInterval(() => {
438-
console.log(totalFetchedFiles);
439446
if (totalFetchedFiles === fileLinks.length) {
440-
document.getElementById(jsonInputId).value = JSON.stringify(postJson);
441447
clearInterval(timerId);
448+
document.getElementById(jsonInputId).value = JSON.stringify(postJson);
449+
var button = document.getElementById(buttonId);
450+
button.style.display = '';
442451
}
443452
}, 500);
444453

445454
setTimeout(() => {
446455
clearInterval(timerId);
456+
console.warn(
457+
"Not showing 'Open in Codepen' button. Timeout when loading resource."
458+
);
447459
}, 10000);
448460
}
449461

450-
function hideButton(buttonId, errorMsg) {
451-
let button = document.querySelector(buttonId);
452-
button.style.display = 'none';
453-
console.log("Removing 'Open in Codepen button'. " + errorMsg);
454-
}
455-
456462
var sourceCode = new aria.widget.SourceCode();

0 commit comments

Comments
 (0)