Skip to content

Instantly share code, notes, and snippets.

View nuxodin's full-sized avatar

Tobias Buschor nuxodin

View GitHub Profile
@nuxodin
nuxodin / webkit contenteditable focus bug workaround.html
Last active August 29, 2015 14:22
WebKit bug workaround: outside click of inline or floated contentEditable-elements focuses the element
<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 / prefered iterator
Created November 15, 2010 16:37
my prefered iterator with item lookup
for (var i=0, x; x = array[i++];) { }
@nuxodin
nuxodin / gist:4269504
Last active October 13, 2015 22:59
Why is there no "originalScrop" property of the event Object? This would be very useful
{
show: function(){
$(document).on('keydown',this.keydownListener);
},
keydownListener: function(e){
if(e.which===27){ e.originalScope.hide(); } /// <----- originalScope
},
hide: function(){
$(document).off('keydown',this.keydownListener);
}
@nuxodin
nuxodin / Vibration Polyfill
Created December 13, 2012 16:07
Vibration Polyfill using sound (prototype)
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/,'');
@nuxodin
nuxodin / node.js "global" and browser "window"
Created December 18, 2012 00:46
node.js "global" and browser "window"
(function (global) {
/* ... Code that defines MyModule ... */
global.MyModule = (global.module || {}).exports = MyModule;
})(this);
@nuxodin
nuxodin / image-ratio.js
Last active December 6, 2016 16:05
ensure image ratio before load
// 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 / php Scalar Type Hints.php
Last active December 14, 2016 23:11
I would welcome php like this
<?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 / easy-console.js
Created December 8, 2016 15:13
Like to write to the console like this "console = xyz" instead of "console.log(xyz)" ?
!(function(){
var original = console;
Object.defineProperty(window, 'console', {
get:function(){
return original;
},
set:function(value){
original.log(value)
}
})
@nuxodin
nuxodin / CSSStyleRule.selectorText.js
Last active March 22, 2017 10:49
hacky repair of CSSRule.selectorText, edge, chrome, safari
/* 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 / stringToFragment.js
Last active April 8, 2017 11:26
string to dom-nodes with support for old ie's and table-elements
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]);