Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const AppRootAttrsBlacklist = ['_nghost', 'ng-version'];
const MockRootAttrsBlacklist = [];

registerPlugin('render', FlashPrevention, flashPreventionPlugin);
registerPlugin('router', FlashPrevention, async (ur) => [{ route: ur }]);
registerPlugin('router', FlashPrevention, async ur => [{ route: ur }]);

interface FlashPreventionPluginOptions {
appRootSelector?: string;
Expand All @@ -25,7 +25,7 @@ export function getFlashPreventionPlugin({
appLoadedClass,
appRootAttributesBlacklist,
mockAttributesBlacklist,
displayType,
displayType
}: FlashPreventionPluginOptions = {}) {
if (appRootSelector) {
AppRootSelector = appRootSelector;
Expand Down Expand Up @@ -83,8 +83,23 @@ async function createSecondAppRoot(html) {
async function addBitsToHead(html) {
const contentScript = `
<script type="text/javascript" id="scully-plugin-discount-flash-prevention">
const capt = (ev) => {
if (document.documentElement.scrollTop === 0){
document.documentElement.scrollTop = window['ScullyIO-scrollPosition'];
}
window['ScullyIO-scrollPosition'] = document.documentElement.scrollTop;
const detach = () => {
window.removeEventListener('scroll', capt);
document.removeEventListener("AngularReady", detach);
};
document.addEventListener("AngularReady", detach);
};

window.addEventListener('scroll', capt);

window.addEventListener('AngularReady', scullyDiscountFlashPreventionContentScript);
function scullyDiscountFlashPreventionContentScript(){
document.documentElement.scrollTop = window['ScullyIO-scrollPosition'];
document.body.classList.add('${LoadedClass}');
const tempAppRoot = document.querySelector('${AppRootSelector}-scully');
tempAppRoot.parentNode.removeChild(tempAppRoot);
Expand All @@ -111,7 +126,7 @@ function pushItemsToArray(src, dest) {
if (src.length && !Array.isArray(src)) {
src = [src];
}
src.forEach((item) => dest.push(item));
src.forEach(item => dest.push(item));
}
}

Expand Down