Skip to content

Instantly share code, notes, and snippets.

Avatar

Tobias Buschor nuxodin

View GitHub Profile
@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 / prefered iterator
Created Nov 15, 2010
my prefered iterator with item lookup
View prefered iterator
for (var i=0, x; x = array[i++];) { }
@nuxodin
nuxodin / gist:4269504
Last active Oct 13, 2015
Why is there no "originalScrop" property of the event Object? This would be very useful
View gist:4269504
{
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 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/,'');
@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 / 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 / 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 / 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 / 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 / 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]);
You can’t perform that action at this time.