This repository has been archived by the owner on Apr 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove tooltip 🐿 v2.5.16 * remove o-header subnav 🐿 v2.5.16 * main-without-n-ui.js -> main.js & force some hings on 🐿 v2.5.16 * pass n-ui-config imperitively 🐿 v2.5.16 * better namespacing of bootstrapping stuff 🐿 v2.5.16 * the rijiggening 🐿 v2.5.16 * update demo to rejiggeninig 🐿 v2.5.16 * link 🐿 v2.5.16 * linting and all that 🐿 v2.5.16 * slight improvement of initializer 🐿 v2.5.16 * loadsa tests 🐿 v2.5.16 * stop providing a stylesheet 🐿 v2.5.16 * start working towards not building n-ui styles in app 🐿 v2.5.16 * some way to getting the demo app working 🐿 v2.5.16 * stop bloody brotlifying the bloody darn thing 🐿 v2.5.16 * more buildy stuff 🐿 v2.5.16 * revert stylesheet changes... for nooo 🐿 v2.5.16 * all js builds exclude n-ui 🐿 v2.5.16 * docs 🐿 v2.5.16 * fixing more tests 🐿 v2.5.16 * now that's waht I call a test suite 🐿 v2.5.16 * fixed demo app 🐿 v2.5.16 * de-preactify 🐿 v2.5.16 * lint 🐿 v2.5.16 * fix build prod 🐿 v2.5.16 * minor fixes 🐿 v2.5.16 * some fixes 🐿 v2.5.16 * lots of tidying and fixing 🐿 v2.5.16 * fix crazy webpack sourcemap paths? 🐿 v2.5.16 * doc tweaks 🐿 v2.5.16 * no more circular mindfuck (#1107) * no more circular mindfuck 🐿 v2.5.16 * Update main.js * expose a few more externals 🐿 v2.5.16 * Dora/v7 error handling (#1111) * add fatal script flags and basic load error handling 🐿 v2.5.16 * bump webpack 🐿 v2.5.16 * being pedantic 🐿 v2.5.16 * more pedantic 🐿 v2.5.16 * use Array.map correctly 🐿 v2.5.16 * lint 🐿 v2.5.16 * better naming and error handling 🐿 v2.5.16 * guard for the existence of onerror 🐿 v2.5.16 * undo stupid 🐿 v2.5.16 * experiment: onload and onerror complexity 🐿 v2.5.16 * remove complexity 🐿 v2.5.16 * experiment: is it onerror? 🐿 v2.5.16 * no empty arguments 🐿 v2.5.16 * Add deferred scripts to ctm (#1110) * turn off o-errors when a script fails to load (#1113) * turn off o-errors when a script fails to load 🐿 v2.5.16 * log to spoor 🐿 v2.5.16 * careful - es5 only inline 🐿 v2.5.16 * verbose names... what's a few bytes between friends 🐿 v2.5.16 * simplify loadScript 🐿 v2.5.16 * Update README.md
- Loading branch information
1 parent
02ea5fd
commit 1b86a6e
Showing
54 changed files
with
808 additions
and
1,127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,45 @@ | ||
const nUi = require('../js/main'); | ||
// Expose entry points to shared bundle | ||
import oAds from 'o-ads'; | ||
import ads from '../../components/n-ui/ads'; | ||
import tracking from '../../components/n-ui/tracking'; | ||
import oTracking from 'o-tracking'; | ||
import oDate from 'o-date'; | ||
import nUiFoundations from 'n-ui-foundations'; | ||
import oGrid from 'o-grid'; | ||
import oViewport from 'o-viewport'; | ||
import * as nImage from 'n-image'; | ||
|
||
nUi.bootstrap(window.ftNextUiConfig || { | ||
preset: 'discrete', | ||
preload: true | ||
// Export some third party components we're unlikely to remove in a hurry | ||
import ftdomdelegate from 'ftdomdelegate'; | ||
import superstore from 'superstore'; | ||
import superstoreSync from 'superstore-sync'; | ||
|
||
import { AppInitializer } from '../js/app-initializer'; | ||
|
||
// returns {flags, allStylesLoaded, appInfo} | ||
const app = new AppInitializer(); | ||
|
||
window.FT.nUi = Object.assign({}, app.env, { | ||
onAppInitialized: app.onAppInitialized, | ||
ads: ads, | ||
tracking: tracking, | ||
_hiddenComponents: { | ||
oAds, | ||
oTracking, | ||
oDate, | ||
oViewport, | ||
nUiFoundations, | ||
oGrid, | ||
nImage, | ||
ftdomdelegate, | ||
superstore, | ||
superstoreSync | ||
} | ||
}); | ||
|
||
window.ftNextUi = nUi; | ||
// must be after the definition of window.ft.Nui as some subcomponents will | ||
// depend on it | ||
// TODO - see if webpack 3's dynamic imports can replace the above hack | ||
app.bootstrap(window.FT.nUiConfig || { | ||
preset: 'discrete' | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import ads from '../../components/n-ui/ads'; | ||
import tracking from '../../components/n-ui/tracking'; | ||
import date from 'o-date'; | ||
import header from '../../components/n-ui/header'; | ||
import oCookieMessage from 'o-cookie-message'; | ||
import footer from 'o-footer'; | ||
import { lazyLoad as lazyLoadImages } from 'n-image'; | ||
import * as serviceWorker from 'n-service-worker'; | ||
import DesktopAppBanner from 'n-desktop-app-banner'; | ||
import * as syndication from 'n-syndication'; | ||
import { perfMark } from 'n-ui-foundations'; | ||
|
||
export const presets = { | ||
discrete: { | ||
header: true, | ||
footer: true, | ||
date: true | ||
}, | ||
complete: { | ||
header: true, | ||
footer: true, | ||
date: true, | ||
cookieMessage: true, | ||
ads: true, | ||
syndication: true | ||
} | ||
}; | ||
|
||
const waitForCondition = (conditionName, action) => { | ||
window.FT.conditions[conditionName] ? action() : document.addEventListener(`FT.${conditionName}`, action); | ||
}; | ||
|
||
// Dispatch a custom `ftNextLoaded` event after the app executes. | ||
const dispatchLoadedEvent = () => { | ||
let ftNextLoaded = false; | ||
const ftNextLoadedTrigger = () => { | ||
if (document.readyState === 'complete' && ftNextLoaded === false) { | ||
ftNextLoaded = true; | ||
window.dispatchEvent(new CustomEvent('ftNextLoaded')); | ||
return true; | ||
} | ||
}; | ||
if (!ftNextLoadedTrigger()) { | ||
window.addEventListener('load', ftNextLoadedTrigger); | ||
document.onreadystatechange = ftNextLoadedTrigger; | ||
} | ||
}; | ||
|
||
export class AppInitializer { | ||
constructor () { | ||
this.onAppInitialized = this.onAppInitialized.bind(this); | ||
|
||
const appInfo = { | ||
isProduction: document.documentElement.hasAttribute('data-next-is-production'), | ||
version: document.documentElement.getAttribute('data-next-version'), | ||
name: document.documentElement.getAttribute('data-next-app'), | ||
product: document.documentElement.getAttribute('data-next-product') | ||
}; | ||
|
||
const flags = Object.assign(window.FT.flags, { | ||
get: function (name) { | ||
return this[name]; | ||
}, | ||
getAll: function () { | ||
return this; | ||
} | ||
}); | ||
|
||
this.env = { | ||
flags, | ||
appInfo, | ||
allStylesLoaded: new Promise(res => { | ||
// if this element exists it means the page is setup to deliver critical/main css | ||
if (document.querySelector('style.n-layout-head-css')) { | ||
waitForCondition('allStylesLoaded', res); | ||
} else { | ||
res(); | ||
} | ||
}) | ||
}; | ||
} | ||
|
||
bootstrap (config) { | ||
config = config || {}; | ||
this.enabledFeatures = Object.assign({}, presets[config.preset], config.features); | ||
this.initializeComponents(); | ||
perfMark('nUiJsExecuted'); | ||
return this.env; | ||
} | ||
|
||
initializeComponents () { | ||
const { flags, allStylesLoaded, appInfo } = this.env; | ||
|
||
// FT and next tracking | ||
tracking.init(flags, appInfo); | ||
|
||
if (flags.get('serviceWorker')) { | ||
serviceWorker | ||
.register(flags) | ||
.catch(() => { }); | ||
|
||
serviceWorker.message({ type: 'updateCache', data: {}}); | ||
} else { | ||
serviceWorker.unregister(); | ||
} | ||
|
||
if (this.enabledFeatures.header) { | ||
header.init(flags); | ||
} | ||
|
||
if (this.enabledFeatures.date) { | ||
date.init(); | ||
} | ||
|
||
if (this.enabledFeatures.ads) { | ||
ads.init(flags, appInfo, this.enabledFeatures.ads); | ||
} | ||
|
||
if (this.enabledFeatures.lazyLoadImages) { | ||
lazyLoadImages(); | ||
} | ||
|
||
// TODO - shouldn't it be possible to turn this off via the usual API? | ||
if (flags.get('subscriberCohort') && flags.get('onboardingMessaging') === 'appPromotingBanner') { | ||
new DesktopAppBanner(); | ||
} | ||
|
||
allStylesLoaded | ||
.then(() => { | ||
|
||
if (this.enabledFeatures.footer) { | ||
footer.init(); | ||
} | ||
|
||
if (this.enabledFeatures.cookieMessage && flags.get('cookieMessage')) { | ||
oCookieMessage.init(); | ||
} | ||
|
||
if (this.enabledFeatures.syndication) { | ||
syndication.init(flags); | ||
} | ||
}); | ||
} | ||
|
||
onAppInitialized () { | ||
perfMark('appJsExecuted'); | ||
dispatchLoadedEvent(); | ||
tracking.lazyInit(this.env.flags); | ||
document.documentElement.classList.add('js-success'); | ||
} | ||
} |
Oops, something went wrong.