Skip to content

Instantly share code, notes, and snippets.

Tobias Buschor nuxodin

View GitHub Profile
@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++) {
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...';
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) );
@nuxodin
nuxodin / stringToFragment.js
Last active Apr 8, 2017
string to dom-nodes with support for old ie's and table-elements
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]);
@nuxodin
nuxodin / CSSStyleRule.selectorText.js
Last active Mar 22, 2017
hacky repair of CSSRule.selectorText, edge, chrome, safari
View CSSStyleRule.selectorText.js
/* 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)
You can’t perform that action at this time.