Merge branch 'turbo' into 'master'
Deprecar Turbolinks en favor de Turbo See merge request sutty/jekyll/sutty-base-jekyll-theme!14
This commit is contained in:
commit
288a84e427
7 changed files with 60 additions and 77 deletions
|
@ -1,4 +1,17 @@
|
|||
<input type="checkbox" id="share" class="toggler" autocomplete="off" />
|
||||
{%- assign title = include.title | escape -%}
|
||||
{%- assign text = include.description | strip_html | escape -%}
|
||||
{%- assign url = site.url | append: include.url | escape -%}
|
||||
|
||||
<input
|
||||
data-controller="share"
|
||||
data-action="share#share"
|
||||
data-share-title-value="{{ title }}"
|
||||
data-share-text-value="{{ text }}"
|
||||
data-share-url-value="{{ url }}"
|
||||
type="checkbox"
|
||||
id="share"
|
||||
class="toggler"
|
||||
autocomplete="off" />
|
||||
|
||||
<label class="share btn border btn-block" for="share">
|
||||
{{ site.i18n.share.text }}
|
||||
|
|
27
_packs/controllers/share_controller.js
Normal file
27
_packs/controllers/share_controller.js
Normal file
|
@ -0,0 +1,27 @@
|
|||
import { Controller } from 'stimulus'
|
||||
|
||||
export default class extends Controller {
|
||||
static values = {
|
||||
title: String,
|
||||
text: String,
|
||||
url: String
|
||||
}
|
||||
|
||||
async share (event = undefined) {
|
||||
event?.preventDefault()
|
||||
event?.stopPropagation()
|
||||
|
||||
const title = this.titleValue
|
||||
const text = this.textValue
|
||||
const url = this.urlValue
|
||||
const data = { title, text, url }
|
||||
|
||||
if ('share' in navigator) {
|
||||
if (navigator.canShare(data)) {
|
||||
navigator.share(data)
|
||||
} else {
|
||||
console.error('No se puede compartir', data)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,8 +9,14 @@ window.airbrake = new Notifier({
|
|||
import 'core-js/stable'
|
||||
import 'regenerator-runtime/runtime'
|
||||
|
||||
const Turbolinks = require("turbolinks")
|
||||
Turbolinks.start()
|
||||
// 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.
|
||||
import * as Turbo from "@hotwired/turbo"
|
||||
Turbo.start()
|
||||
|
||||
import { Application } from 'stimulus'
|
||||
import { definitionsFromContext } from "stimulus/webpack-helpers"
|
||||
|
@ -19,33 +25,17 @@ const application = Application.start()
|
|||
const context = require.context("./controllers", true, /\.js$/)
|
||||
application.load(definitionsFromContext(context))
|
||||
|
||||
// Prevenir que Turbolinks interfiera con la navegación por anchors
|
||||
// https://github.com/turbolinks/turbolinks/issues/75#issuecomment-445325162
|
||||
document.addEventListener('turbolinks:click', event => {
|
||||
const anchorElement = event.target
|
||||
const isSamePageAnchor = (
|
||||
anchorElement.hash &&
|
||||
anchorElement.origin === window.location.origin &&
|
||||
anchorElement.pathname === window.location.pathname
|
||||
)
|
||||
|
||||
if (!isSamePageAnchor) return
|
||||
|
||||
Turbolinks.controller.pushHistoryWithLocationAndRestorationIdentifier(event.data.url, Turbolinks.uuid())
|
||||
|
||||
event.preventDefault()
|
||||
})
|
||||
|
||||
try {
|
||||
window.axe = require('axe-core/axe')
|
||||
} catch(e) {}
|
||||
|
||||
if (window.axe) window.axe.configure({ locale: require('axe-core/locales/es.json') })
|
||||
|
||||
// Prevenir que Turbolinks interfiera la navegación a un anchor al
|
||||
// recargar la página
|
||||
document.addEventListener('turbolinks:load', event => {
|
||||
window.location.hash = window.location.hash
|
||||
document.addEventListener('turbo:load', event => {
|
||||
document.querySelectorAll("a[href^='http://'],a[href^='https://'],a[href^='//']").forEach(a => {
|
||||
a.rel = "noopener"
|
||||
a.target = "_blank"
|
||||
})
|
||||
|
||||
if (!window.axe) return
|
||||
|
||||
|
|
|
@ -118,9 +118,6 @@ $label-margin-bottom: 0;
|
|||
@import "editor";
|
||||
@import "menu";
|
||||
|
||||
/// La barra de progreso de Turbolinks tiene el color primario
|
||||
/// de la paleta, definido por Bootstrap o por nosotres.
|
||||
.turbolinks-progress-bar { background-color: $primary; }
|
||||
/// La barra de progreso de Turbo tiene el color primario
|
||||
/// de la paleta, definido por Bootstrap o por nosotres.
|
||||
.turbo-progress-bar { background-color: $primary; }
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
---
|
||||
---
|
||||
|
||||
const loadEvent = () => {
|
||||
try {
|
||||
if (Turbolinks) return 'turbolinks:load'
|
||||
} catch {
|
||||
return 'DOMContentLoaded'
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener(loadEvent(), () => {
|
||||
document.querySelectorAll('.share').forEach(share => {
|
||||
share.addEventListener('click', event => {
|
||||
if (!Navigator.share) return;
|
||||
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
const title = document.querySelector('title').text;
|
||||
|
||||
try {
|
||||
const text = document.querySelector('meta[property="og:description"]').content;
|
||||
} catch {
|
||||
const text = '';
|
||||
}
|
||||
|
||||
try {
|
||||
const url = document.querySelector('link[rel=canonical]').href;
|
||||
} catch {
|
||||
const url = document.location.href;
|
||||
}
|
||||
|
||||
const data = { title: title, text: text, url: url };
|
||||
|
||||
if (Navigator.canShare(data)) Navigator.share(data).then();
|
||||
});
|
||||
});
|
||||
|
||||
document.querySelectorAll("a[href^='http://'],a[href^='https://'],a[href^='//']").forEach(a => {
|
||||
a.rel = "noopener";
|
||||
a.target = "_blank";
|
||||
});
|
||||
});
|
|
@ -12,6 +12,7 @@
|
|||
"@babel/core": "^7.10.4",
|
||||
"@babel/plugin-proposal-class-properties": "^7.10.4",
|
||||
"@babel/preset-env": "^7.10.4",
|
||||
"@hotwired/turbo": "^7.0.0-rc.4",
|
||||
"axe-core": "^4.1.2",
|
||||
"babel-loader": "^8.1.0",
|
||||
"core-js": "^3.6.5",
|
||||
|
@ -22,7 +23,6 @@
|
|||
"sassdoc-theme-herman": "^4.0.2",
|
||||
"stimulus": "^1.1.1",
|
||||
"svgo": "^2.5.0",
|
||||
"turbolinks": "^5.2.0",
|
||||
"webpack": "^4.43.0",
|
||||
"webpack-assets-manifest": "~4",
|
||||
"webpack-cli": "^3.3.12",
|
||||
|
|
10
yarn.lock
10
yarn.lock
|
@ -880,6 +880,11 @@
|
|||
"@babel/helper-validator-identifier" "^7.14.0"
|
||||
to-fast-properties "^2.0.0"
|
||||
|
||||
"@hotwired/turbo@^7.0.0-rc.4":
|
||||
version "7.0.0-rc.4"
|
||||
resolved "https://registry.yarnpkg.com/@hotwired/turbo/-/turbo-7.0.0-rc.4.tgz#d3ab9555544534f5ec649613553e72ff6c7d7122"
|
||||
integrity sha512-4qx+6O6mUN+cSN+ZLGCOGc+2MxNrs7cFbmnWD6LIfiHAQyuNiIuB87Y5IAtOo8xj16fOBd2CdU1WRJya4Wkw0A==
|
||||
|
||||
"@sindresorhus/is@^0.14.0":
|
||||
version "0.14.0"
|
||||
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.14.0.tgz#9fb3a3cf3132328151f353de4632e01e52102bea"
|
||||
|
@ -6378,11 +6383,6 @@ tty-browserify@0.0.0:
|
|||
resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6"
|
||||
integrity sha1-oVe6QC2iTpv5V/mqadUk7tQpAaY=
|
||||
|
||||
turbolinks@^5.2.0:
|
||||
version "5.2.0"
|
||||
resolved "https://registry.yarnpkg.com/turbolinks/-/turbolinks-5.2.0.tgz#e6877a55ea5c1cb3bb225f0a4ae303d6d32ff77c"
|
||||
integrity sha512-pMiez3tyBo6uRHFNNZoYMmrES/IaGgMhQQM+VFF36keryjb5ms0XkVpmKHkfW/4Vy96qiGW3K9bz0tF5sK9bBw==
|
||||
|
||||
type-fest@^0.8.1:
|
||||
version "0.8.1"
|
||||
resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d"
|
||||
|
|
Loading…
Reference in a new issue