sutty-base-jekyll-theme/_packs/entry.js

76 lines
2.2 KiB
JavaScript
Raw Permalink Normal View History

2021-11-22 17:51:50 +00:00
import BotDetector from "device-detector-js/dist/parsers/bot";
import { Notifier } from "@airbrake/browser";
2021-01-12 17:14:14 +00:00
2021-11-22 17:51:50 +00:00
window.bot_detector = new BotDetector();
const bot = window.bot_detector.parse(navigator.userAgent);
2021-01-12 17:14:14 +00:00
if (!bot) {
window.airbrake = new Notifier({
projectId: window.env.AIRBRAKE_PROJECT_ID,
projectKey: window.env.AIRBRAKE_PROJECT_KEY,
2021-11-22 17:51:50 +00:00
host: "https://panel.sutty.nl",
});
2021-11-22 17:51:50 +00:00
console.originalError = console.error;
console.error = (...e) => {
2021-11-22 17:51:50 +00:00
window.airbrake.notify(e.join(" "));
return console.originalError(...e);
};
}
2021-01-12 17:14:14 +00:00
2021-11-22 17:51:50 +00:00
import "core-js/stable";
import "regenerator-runtime/runtime";
2021-01-12 16:35:23 +00:00
// Turbo acelera la navegación al no tener que recargar todo el JS y CSS
// de la página, con lo que se siente más rápida y "nativa".
//
// Cambiamos de turbolinks a turbo porque turbo soporta la función
// fetch(), que luego es interceptada por el SW para obtener las
// direcciones localmente.
2021-11-22 17:51:50 +00:00
import * as Turbo from "@hotwired/turbo";
Turbo.start();
2021-01-12 16:38:32 +00:00
2021-11-22 17:51:50 +00:00
import { Application } from "stimulus";
import { definitionsFromContext } from "stimulus/webpack-helpers";
2020-11-12 16:28:24 +00:00
2021-11-22 17:51:50 +00:00
const application = Application.start();
const context = require.context("./controllers", true, /\.js$/);
application.load(definitionsFromContext(context));
2021-01-12 16:38:32 +00:00
2021-11-22 17:51:50 +00:00
import { makeClient } from "@spree/storefront-api-v2-sdk";
import { Sutty } from "./endpoints/sutty";
2021-06-01 21:33:49 +00:00
2021-11-22 17:51:50 +00:00
window.spree = makeClient({ host: window.env.SPREE_URL });
window.spree.sutty = new Sutty(window.spree.host);
2021-06-01 21:33:49 +00:00
try {
2021-11-22 17:51:50 +00:00
window.axe = require("axe-core/axe");
} catch (e) {}
2021-11-22 17:51:50 +00:00
if (window.axe)
window.axe.configure({ locale: require("axe-core/locales/es.json") });
2021-11-22 17:51:50 +00:00
document.addEventListener("turbo:load", (event) => {
document
.querySelectorAll("a[href^='http://'],a[href^='https://'],a[href^='//']")
.forEach((a) => {
a.rel = "noopener";
a.target = "_blank";
});
2021-11-22 17:51:50 +00:00
if (!window.axe) return;
2021-11-22 17:51:50 +00:00
window.axe.run().then((results) => {
results.violations.forEach((violation) => {
violation.nodes.forEach((node) => {
node.target.forEach((target) => {
document.querySelectorAll(target).forEach((element) => {
element.classList.add("inaccesible");
element.ariaLabel = node.failureSummary;
});
});
});
});
});
});