5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-26 09:36:21 +00:00
panel/app/javascript/packs/application.js

111 lines
3.4 KiB
JavaScript
Raw Normal View History

/* eslint no-console:0 */
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
//
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
// layout file, like app/views/layouts/application.html.erb
// Uncomment to copy all static images under ../images to the output folder and reference
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
// or the `imagePath` JavaScript helper below.
//
// const images = require.context('../images', true)
// const imagePath = (name) => images(name, true)
import { Notifier } from '@airbrake/browser'
window.airbrake = new Notifier({
projectId: process.env.AIRBRAKE_SITE_ID,
projectKey: process.env.AIRBRAKE_API_KEY,
host: process.env.PANEL_URL
})
2020-11-19 23:35:29 +00:00
import 'core-js/stable'
import 'regenerator-runtime/runtime'
2020-11-19 23:38:33 +00:00
import 'controllers'
import 'editor/editor'
2020-05-26 21:32:46 +00:00
import {EditorState} from "prosemirror-state"
import {EditorView} from "prosemirror-view"
import {schema, defaultMarkdownParser, defaultMarkdownSerializer} from "prosemirror-markdown"
import {exampleSetup} from "prosemirror-example-setup"
import "prosemirror-gapcursor/style/gapcursor.css"
import "prosemirror-menu/style/menu.css"
import "prosemirror-view/style/prosemirror.css"
import "prosemirror-example-setup/style/style.css"
2020-06-28 00:42:15 +00:00
// Lista de equivalencias entre Date#getTimezoneOffset de JS y
// MetadataEvent
const timeZoneOffsets = {
'720': '-12:00',
'660': '-11:00',
'600': '-10:00',
'570': '-09:30',
'540': '-09:00',
'480': '-08:00',
'420': '-07:00',
'360': '-06:00',
'300': '-05:00',
'240': '-04:00',
'210': '-03:30',
'180': '-03:00',
'120': '-02:00',
'60': '-01:00',
'0': '00:00',
'-60': '+01:00',
'-120': '+02:00',
'-180': '+03:00',
'-210': '+03:30',
'-240': '+04:00',
'-270': '+04:30',
'-300': '+05:00',
'-330': '+05:30',
'-345': '+05:45',
'-360': '+06:00',
'-390': '+06:30',
'-420': '+07:00',
'-480': '+08:00',
'-525': '+08:45',
'-540': '+09:00',
'-570': '+09:30',
'-600': '+10:00',
'-630': '+10:30',
'-660': '+11:00',
'-720': '+12:00',
'-765': '+12:45',
'-780': '+13:00',
'-840': '+14:00'
};
// Obtiene el huso horario local
const timeZoneOffset = timeZoneOffsets[(new Date).getTimezoneOffset().toString()];
2019-11-15 15:31:40 +00:00
document.addEventListener('turbolinks:load', () => {
2020-06-28 00:42:15 +00:00
// Aplicar el huso horario descubierto en los campos de evento solo
// cuando estamos creando un artículo.
document.querySelectorAll('.new .event .zone select').forEach(zone => zone.value = timeZoneOffset);
2020-05-26 21:32:46 +00:00
document.querySelectorAll('.markdown-content').forEach(mdc => {
let textArea = mdc.querySelector(".content"),
2020-11-18 12:10:21 +00:00
editor = mdc.querySelector(".markdown-editor");
2020-05-26 21:32:46 +00:00
let view = new EditorView(editor, {
state: EditorState.create({
doc: defaultMarkdownParser.parse(textArea.value),
plugins: exampleSetup({schema})
})
})
2019-11-15 15:31:40 +00:00
2020-05-26 21:32:46 +00:00
// Guardar los cambios al enviar el formulario y cada 10 segundos
textArea.form.addEventListener('submit', e => textArea.value = defaultMarkdownSerializer.serialize(view.state.doc));
setInterval(() => textArea.value = defaultMarkdownSerializer.serialize(view.state.doc), 10 * 1000);
// Ocultar el area
textArea.style.display = 'none'
})
2019-11-15 15:31:40 +00:00
})