This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!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++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
writeStack = []; | |
write = function(callback){ | |
if (!writeStack.length) requestAnimationFrame(handleWriteStack); | |
writeStack.push(callback); | |
} | |
handleWriteStack = function(){ | |
while (writeStack.length) writeStack.pop()(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
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...'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!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) ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright (c) 2016 Tobias Buschor https://goo.gl/gl0mbf | MIT License https://goo.gl/HgajeK */ | |
// hacky fix of CSSRule.selectorText, edge, chrome, safari, https://bugs.chromium.org/p/chromium/issues/detail?id=681814 | |
var desc = Object.getOwnPropertyDescriptor(CSSStyleRule.prototype, 'selectorText'); | |
var getter = desc.get; | |
desc.get = function(){ | |
var str = getter.apply(this).replace(/\[([^\]]+[^\\\]]):([^\]]+)\]/g, '[$1\\:$2]'); | |
return str; | |
} | |
Object.defineProperty(CSSStyleRule.prototype, 'selectorText', desc) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright (c) 2016 Tobias Buschor https://goo.gl/gl0mbf | MIT License https://goo.gl/HgajeK */ | |
document.nodeFromPoint = function(x, y) { | |
const el = document.elementFromPoint(x, y); | |
const nodes = el.childNodes; | |
for (let i = 0, node; node = nodes[i++];) { | |
if (node.nodeType === 3) { | |
const range = document.createRange(); | |
range.selectNode(node); | |
const rects = range.getClientRects(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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; |