Skip to content

Instantly share code, notes, and snippets.

View nuxodin's full-sized avatar

Tobias Buschor nuxodin

View GitHub Profile
@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 / focusin focusout support for firefox.js
Last active February 7, 2024 16:40
focusin focusout support for firefox
/* 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 / 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 / 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 / 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 / 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 / HTMLFormElement-HTMLInputElement.reportValidity.js
Last active January 7, 2023 19:52
Polyfill for reportValidity()
/* 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;