discourse/app/assets/javascripts/preload-application-data.js.es6
Robin Ward a3f0543f99
Support for transpiling .js files (#9160)
* Remove some `.es6` from comments where it does not matter

* Use a post processor for transpilation

This will allow us to eventually use the directory structure to
transpile rather than the extension.

* FIX: Some errors and clean up in confirm-new-email

It would throw an error if the webauthn element wasn't present.
Also I changed things so that no-module is not explicitly
referenced.

* Remove `no-module`

Instead we allow a magic comment: `// discourse-skip-module` to prevent
the asset pipeline from creating a module.

* DEV: Enable babel transpilation based on directory

If it's in `app/assets/javascripts/dicourse` it will be transpiled
even without the `.es6` extension.

* REFACTOR: Remove Tilt/ES6ModuleTranspiler
2020-03-11 09:43:55 -04:00

84 lines
2.5 KiB
JavaScript

// discourse-skip-module
(function() {
var ps = require("preload-store").default;
var preloadedDataElement = document.getElementById("data-preloaded");
var setupData = document.getElementById("data-discourse-setup").dataset;
if (preloadedDataElement) {
var preloaded = JSON.parse(preloadedDataElement.dataset.preloaded);
Object.keys(preloaded).forEach(function(key) {
ps.store(key, JSON.parse(preloaded[key]));
if (setupData.debugPreloadedAppData === "true") {
/* eslint-disable no-console */
console.log(key, ps.get(key));
/* eslint-enable no-console */
}
});
}
window.Logster = window.Logster || {};
window.Logster.enabled = setupData.enableJsErrorReporting === "true";
Discourse.CDN = setupData.cdn;
Discourse.BaseUrl = setupData.baseUrl;
Discourse.BaseUri = setupData.baseUri;
Discourse.Environment = setupData.environment;
Discourse.SiteSettings = ps.get("siteSettings");
Discourse.ThemeSettings = ps.get("themeSettings");
Discourse.LetterAvatarVersion = setupData.letterAvatarVersion;
Discourse.MarkdownItURL = setupData.markdownItUrl;
Discourse.ServiceWorkerURL = setupData.serviceWorkerUrl;
I18n.defaultLocale = setupData.defaultLocale;
Discourse.start();
Discourse.set("assetVersion", setupData.assetVersion);
let Session = require("discourse/models/session").default;
Session.currentProp(
"disableCustomCSS",
setupData.disableCustomCss === "true"
);
if (setupData.safeMode) {
Session.currentProp("safe_mode", setupData.safeMode);
}
Discourse.HighlightJSPath = setupData.highlightJsPath;
Discourse.SvgSpritePath = setupData.svgSpritePath;
if (Discourse.Environment === "development") {
Discourse.SvgIconList = setupData.svgIconList;
}
if (setupData.s3BaseUrl) {
Discourse.S3CDN = setupData.s3Cdn;
Discourse.S3BaseUrl = setupData.s3BaseUrl;
}
// eslint-disable-next-line
Ember.RSVP.configure("onerror", function(e) {
// Ignore TransitionAborted exceptions that bubble up
if (e && e.message === "TransitionAborted") {
return;
}
if (Discourse.Environment === "development") {
/* eslint-disable no-console */
if (e) {
if (e.message || e.stack) {
console.log(e.message);
console.log(e.stack);
} else {
console.log("Uncaught promise: ", e);
}
} else {
console.log("A promise failed but was not caught.");
}
/* eslint-enable no-console */
}
window.onerror(e && e.message, null, null, null, e);
});
})();