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
| /* 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'; |
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 */ | |
| /** | |
| 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 = { |
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
| 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(); |
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]); |