Skip to content

Instantly share code, notes, and snippets.

Avatar

Tobias Buschor nuxodin

View GitHub Profile
@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)
@nuxodin
nuxodin / document.nodeFromPoint.js
Last active Nov 20, 2017
Browsers have "elementFromPoint", here is "nodeFromPoint" (including text-nodes) !
View document.nodeFromPoint.js
/* 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();
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 / easy-console.js
Created Dec 8, 2016
Like to write to the console like this "console = xyz" instead of "console.log(xyz)" ?
View easy-console.js
!(function(){
var original = console;
Object.defineProperty(window, 'console', {
get:function(){
return original;
},
set:function(value){
original.log(value)
}
})
@nuxodin
nuxodin / image-ratio.js
Last active Dec 6, 2016
ensure image ratio before load
View image-ratio.js
// ussage:
// - include this script
// - add the data-c1-ratio-attribute to your images
// <img src="big.jpg" data-c1-ratio="1.245" style="width:200px; max-width:100%">
!function(){
'use strict';
var listener = function(e){
this.removeEventListener('load',listener);
this.removeEventListener('error',listener);
@nuxodin
nuxodin / webkit contenteditable focus bug workaround.html
Last active Aug 29, 2015
WebKit bug workaround: outside click of inline or floated contentEditable-elements focuses the element
View webkit contenteditable focus bug workaround.html
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>WebKit bug workaround: outside click of inline or floated contentEditable-elements focuses the element</title>
<script>
if (/AppleWebKit\/([\d.]+)/.exec(navigator.userAgent)) {
document.addEventListener('DOMContentLoaded', function(){
var fixEl = document.createElement('input');
fixEl.style.cssText = 'width:1px;height:1px;border:none;margin:0;padding:0; position:fixed; top:0; left:0';
fixEl.tabIndex = -1;
@nuxodin
nuxodin / php Scalar Type Hints.php
Last active Dec 14, 2016
I would welcome php like this
View php Scalar Type Hints.php
<?php
// Stirct types
function test(string $name, int $age, float $cuteness, bool $evil) {
//....
}
// Convert types
function test((string)$name, (int)$age, (float)$cuteness, (bool)$evil) {
//....
@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 / node.js "global" and browser "window"
Created Dec 18, 2012
node.js "global" and browser "window"
View node.js "global" and browser "window"
(function (global) {
/* ... Code that defines MyModule ... */
global.MyModule = (global.module || {}).exports = MyModule;
})(this);
@nuxodin
nuxodin / Vibration Polyfill
Created Dec 13, 2012
Vibration Polyfill using sound (prototype)
View Vibration Polyfill
navigator.q1Vibrate = function(){
var native = navigator.vibrate || navigator.mozVibrate || navigator.wekbitVibrate;
if(native){
return native;
}
var scripts = document.getElementsByTagName('script');
var script = scripts[scripts.length-1];
var path = script.src.replace(/vibrate.js/,'');
You can’t perform that action at this time.