Skip to content

Instantly share code, notes, and snippets.

function isInTheDOM(element) {
return element.ownerDocument === getRootNode(element);
function getRootNode(element) {
var rootNode = element;
var parentNode;
while (parentNode = rootNode.parentNode) {
rootNode = parentNode;
}
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
@anddoutoi
anddoutoi / index.html
Created June 15, 2011 13:14
Google Chrome bug with list-style-type: none / position: relative / floats combo. Tested in GC12.0.742.91
<!DOCTYPE html>
<html class="no-js" lang="en">
<head>
<meta charset="utf-8">
<title></title>
<style>
ul {
margin: 0;
padding: 0;
}
@anddoutoi
anddoutoi / gist:1345268
Created November 7, 2011 15:23
A somewhat working patch for ie7 button width issues
.ie7 button,
.ie7 input[type="button"],
.ie7 input[type="reset"],
.ie7 input[type="submit"]
{
margin: 0;
padding: 0 15px;
overflow: expression(
this.style.overflow = 'visible',
this.style.pixelWidth = function (w) {
@anddoutoi
anddoutoi / gist:1596643
Created January 11, 2012 20:39
Mozilla Gecko about:s
Mozilla Gecko about:s
about:about
about:config
about:home
about:mozilla
about:plugins
about:rights
about:robots
@anddoutoi
anddoutoi / forEachInObject.js
Created January 23, 2012 21:59
JavaScript utility functions
var forEachInObject = (function () {
'use strict';
var fn = function ( f, args ) {
var o = this,
keys = Object.keys( o ),
i, key;
i = 0;
while ( (key = keys[i++]) ) {
@anddoutoi
anddoutoi / ms.js
Created February 13, 2012 11:44
Function that parses stuff to milliseconds
/* inspiration from Jan-Marten de Boer´s Time.js, https://github.com/johmanx10/Time.js */
var ms = (function () {
'use strict';
var second = 1000,
minute = second*60,
hour = minute*60,
day = hour*24,
//week = day*7,
//year = second*3.154e7,// According to Wolfram|Alpha
@anddoutoi
anddoutoi / ReAnimator.js
Created February 13, 2012 15:43
Function that tweens element
var tweenWithReAnimator = (function () {
var defaults,
getStyleProperties;
defaults = {
frameRate: 24,// The human eye can only register motion at a rate of approximately 24 frames per second. Faster than that, and the brain just doesn't recognize the difference.
tweenTime: 400
};
getStyleProperties = function ( o ) {
@anddoutoi
anddoutoi / DebugPubSub.bookmarklet
Created December 13, 2012 12:42
Bookmarklet that activates PubSub debugging.
javascript:(function(){pubsub.subscribe('*',function%20(data,topic){console.log(topic+':%20'+JSON.stringify(data));});}());
@anddoutoi
anddoutoi / my-directive.js
Created September 28, 2013 09:33
The so called 2-way binding in AngularJS. More like lol-binding imo.
angular.directive( 'myDirective', function () {
return {
link: function ( scope, element ) {
element.on( 'click', function ( event ) {
scope.foo = 'bar';
// need to $scope.$apply here. Ugly! Should be automagic.
} );
},
restrict: 'E'
};