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'; |
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 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) { |
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'); |
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...'; |
View set_get_css.js
!function() { | |
// style | |
var styleObj = d.documentElement.style; | |
var vendors = {'moz':1,'webkit':1,'ms':1,'o':1}; | |
c1.dom.css = function(el, style, value) { | |
if (value === undefined) { | |
if (typeof style === 'string') { | |
// getter | |
if (styleObj[style] !== undefined) return getComputedStyle(el).getPropertyValue(style); | |
return getComputedStyle(el).getPropertyValue( c1.dom.css.experimental(style) ); |
View stringToFragment.js
function stringToFragment(html){ | |
var tmpl = document.createElement('template'); | |
tmpl.innerHTML = html; | |
if (tmpl.content == void 0){ // ie11 | |
var fragment = document.createDocumentFragment(); | |
var isTableEl = /^[^\S]*?<(t(?:head|body|foot|r|d|h))/i.test(html); | |
tmpl.innerHTML = isTableEl ? '<table>'+html : html; | |
var els = isTableEl ? tmpl.querySelector(RegExp.$1).parentNode.childNodes : tmpl.childNodes; | |
while(els[0]) fragment.appendChild(els[0]); |
NewerOlder