Skip to content

Instantly share code, notes, and snippets.

@kaaes
kaaes / popup.html
Created August 15, 2012 21:42
Css animated popup - prototype
<!DOCTYPE html>
<html>
<link href="style.css" rel="stylesheet" />
<body>
<button id="open">click!</button>
<div id="popup" class="closed"><button id="close">click!</button></div>
</body>
<script src="popup.js"></script>
<script>
var p = document.getElementById('popup');
@kaaes
kaaes / delegate.js
Created May 20, 2012 22:22
Function to delegate events. Can be used with any css selector
function delegate(element, eventType, selector, callback, bubble) {
var selectorObj = getSelectorType(selector);
var callbackFn;
selector = selectorObj.value;
switch (selectorObj.type) {
case 'tag':
callbackFn = tagSelector;
break;
@kaaes
kaaes / multiple-event-listeners-with-same-callback.html
Created August 7, 2011 23:48
Binding the same event listeners more than once
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Binding the same event listeners more than once</title>
</head>
@kaaes
kaaes / objects.js
Created June 26, 2011 14:11
ECMA5 object cheatsheet
/**
* Object descriptor
**/
var a = {
prop1 : 14
}
var descriptorObj1 = Object.getOwnPropertyDescriptor(a, 'prop1');
@kaaes
kaaes / gradients.css
Created June 24, 2011 13:11
bulletproof css gradients
#container {
background: #fff url(gradient.gif) repeat-x bottom;
background: -webkit-gradient(
linear, 0 100%, 0 0,
from(#ecebe7), color-stop(50%, #fff), to(#fff)
);
background: -webkit-linear-gradient(bottom, #ecebe7, #fff 50%, #fff);
background: -moz-linear-gradient(bottom, #ecebe7, #fff 50%, #fff);
}
@kaaes
kaaes / add-event-listener.js
Created June 24, 2011 12:50
Event delegation blog post gists
interface EventTarget {
void addEventListener(in DOMString type,
in EventListener listener,
in boolean useCapture);
};
var link = document.getElementById('#myLink');
// use bubbling:
link.addEventListener('click', callbackFnForClick, false);
@kaaes
kaaes / event-loop-example.html
Created June 8, 2011 22:13
JS event loop example - uncomment alerts to see how blocking can stop whole app even if it is asynchronous & event based
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<script src="http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js" charset="utf-8" type="text/javascript">
</script>
<title>Event Loop</title>
<style type="text/css">
div {height: 5px; margin-bottom: 3px;}
</style>
@kaaes
kaaes / apply_call_ex.js
Created May 19, 2011 15:14
apply and call example
el.onclick = function(evt) {
addStyle.call(this, '#f00', 'solid 2px blue');
}
// both will have identical effect
el.onclick = function(evt) {
addStyle.apply(this, ['#f00', 'solid 2px blue']);
}
@kaaes
kaaes / context_pitfall_ex4.js
Created May 19, 2011 15:11
Watch out for context part 4
el.onclick = function(evt) {
this.style.backgroundColor = '#f00';
this.style.borderBottom = 'solid 2px blue';
}
el2.onclick = function(evt) {
this.style.backgroundColor = '#ff0';
this.style.borderBottom = 'dotted 1px green';
}