Skip to content

Instantly share code, notes, and snippets.

Avatar

Tobias Buschor nuxodin

View GitHub Profile
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 = {
View HTMLFormElement-HTMLInputElement.reportValidity.js
/* Copyright (c) 2016 Tobias Buschor https://goo.gl/gl0mbf | MIT License https://goo.gl/HgajeK */
if (!HTMLFormElement.prototype.reportValidity) {
HTMLFormElement.prototype.reportValidity = function() {
if (this.checkValidity()) return true;
var btn = document.createElement('button');
this.appendChild(btn);
btn.click();
this.removeChild(btn);
return false;
@nuxodin
nuxodin / focusin focusout support for firefox.js
Last active Apr 26, 2020
focusin focusout support for firefox
View focusin focusout support for firefox.js
/* Copyright (c) 2016 Tobias Buschor https://goo.gl/gl0mbf | MIT License https://goo.gl/HgajeK */
/* focusin/out event polyfill (firefox) */
!function(){
var w = window,
d = w.document;
if (w.onfocusin === undefined) {
d.addEventListener('focus' ,addPolyfill ,true);
d.addEventListener('blur' ,addPolyfill ,true);
d.addEventListener('focusin' ,removePolyfill ,true);
@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++) {
View dom read write.js
/*
if (!window.requestPostAnimationFrame) {
window.requestPostAnimationFrame = function(callback){
requestAnimationFrame(function(){
setTimeout(callback)
})
}
}
*/
View interceptObjectProperties.js
function interceptObjectProperties(obj, options){
if (!options) options = {};
if (!options.ignore) options.ignore = {};
for (var i in obj) {
const prop = i;
if (!obj.hasOwnProperty(prop)) continue;
if (options.ignore[prop]) continue;
var descriptor = Object.getOwnPropertyDescriptor(obj, prop);
if (descriptor.set) {
@nuxodin
nuxodin / c1.cssImport.js
Last active Jun 10, 2019
CSS Import function. Loads a CSS file relative to the script where the function was called! (like js-module imports)
View c1.cssImport.js
c1CssImport = function (location) { // todo: handle absolute urls
const e = new Error();
const calledFile = e.stack.split('\n')[2].match(/[a-z]+:[^:]+/);
const calledUrl = new URL(calledFile);
calledUrl.search = '';
const target = new URL(location, calledUrl).toString();
for (let el of document.querySelectorAll('link[rel=stylesheet]')) {
if (el.href === target) return; // already loaded
}
const link = document.createElement('link');
@nuxodin
nuxodin / custom_globals.js
Last active Aug 31, 2018
Find custom globals variables
View custom_globals.js
{
const iframe = document.createElement('iframe');
document.body.append(iframe)
setTimeout(()=>{ // wait some time until chrome adds console-accessible properties to the iframe too
const customNames = Object.getOwnPropertyNames(window).filter(item => !(item in iframe.contentWindow) );
const object = Object.create(null);
customNames.forEach(name => object[name] = window[name] )
console.log(object)
},2000);
'wait...';
You can’t perform that action at this time.