Skip to content

Instantly share code, notes, and snippets.

Avatar

Tobias Buschor nuxodin

View GitHub Profile
@nuxodin
nuxodin / keyboard word event.js
Last active Jul 1, 2022
track words using a delay to clean
View keyboard word event.js
// better a "WordObserver" that can better handle chanching targets?
let word = '';
let wordClearTimeout = null;
let wordTarget = null;
addEventListener('keyup', e=>{
const isChar = /^.$/u.test(e.key);
// if (wordTarget !== e.target) { // clear if target changes
View elementComputedLang.js
function computedLang(el){
let root = el.closest('[lang]');
let lang = root ? root.getAttribute('lang') : navigator.language;
if (!el.matches(':lang('+lang+')')) {
console.warn('lang missmatch!');
for (let l of ['de','en','it','es', /*...*/ ]) if (el.matches(':lang('+l+')')) return l;
}
View date-time-local-polyfill.js
c1.c1Use('onElement',function(){ 'use strict';
// check supported
var x = document.createElement('input');
x.type = 'datetime-local';
if (x.type === 'datetime-local') return;
document.head.insertAdjacentHTML(
'afterbegin',
View scrollend event futurfill.js
if (!('onscrollend' in document.documentElement)) {
document.addEventListener('scroll',function(e){
var scrollPort = e.target
clearTimeout(scrollPort._scrollEndTimeout);
scrollPort._scrollEndTimeout = setTimeout(function () {
const event = new Event('scrollend');
Object.defineProperty(event,'snapTarget',{
get(){
return 'todo';
View onstylesheet.js
document.addEventListener('load',function(e){
if (e.target.tagName !== 'LINK') return;
if (e.target.rel !== 'stylesheet') return;
console.log(e.target.sheet)
},true);
@nuxodin
nuxodin / style-once.js
Last active Mar 24, 2021
Polyfill "style once" hopefully standardised soon :)
View style-once.js
const selector = 'link[rel="stylesheet"], style';
onElement(selector, function(el){ // NOT IMPLEMENTED IN THIS SCRIPT
// checks all styleSheets and importRules, todo store urls global and check all if used url found
// console.log(el.sheet)
checkAllSheets()
});
function checkAllSheets(){
const urls = {};
View feature-test-flex-gap.js
/* ussage
<div flex-gap=fallback-margin style="--x-gap:10px">
<span>a</span>
<span>b</span>
</div>
*/
var div = document.createElement('div');
div.innerHTML = '<i></i><i></i>';
div.style.display = 'inline-flex';
@nuxodin
nuxodin / href-everywere.js
Last active Jun 9, 2020
Enable each element to be linked
View href-everywere.js
/* Copyright (c) 2016 Tobias Buschor https://goo.gl/gl0mbf | MIT License https://goo.gl/HgajeK */
/**
ussage:
<table>
<tr data-c1-href="https://example.com" data-c1-target="_blank">
<td> <a href="https://example.com" target="_blank">example.com</a>
<td> Do not forget to add a real link so that your content is accessible.
</table>
*/
c1 = {
@nuxodin
nuxodin / requestSubmit_and_reportValidity.js
Last active Apr 17, 2020 — forked from mcshaz/reportValidity.js
reportValidity polyfill for IE 10, 11
View requestSubmit_and_reportValidity.js
if (!HTMLFormElement.prototype.requestSubmit) {
HTMLFormElement.prototype.requestSubmit = function(submitter) {
let submitBtn = submitter;
if (!submitBtn) {
submitBtn = document.createElement('input');
submitBtn.type = 'submit';
submitBtn.hidden = true;
this.appendChild(submitBtn);
}
submitBtn.click();
View Event.submitter.polyfill.js
!function(){
var lastBtn = null
document.addEventListener('click',function(e){
if (!e.target.closest) return;
lastBtn = e.target.closest('button, input[type=submit]');
}, true);
document.addEventListener('submit',function(e){
if (e.submitter) return;
var canditates = [document.activeElement, lastBtn];
for (var i=0; i < canditates.length; i++) {