Skip to content

Instantly share code, notes, and snippets.

@psiborg
psiborg / gist:1569737
Created January 6, 2012 08:38
JS Stop events from propagating
if (!e) var e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
@psiborg
psiborg / gist:1569753
Created January 6, 2012 08:45
JS Serialize
var serialize = function (obj) {
"use strict";
var val, vArr, vObj, i, attr;
if (obj !== undefined) {
switch (obj.constructor) {
case "Array":
vArr = "[";
for (i = 0; i < obj.length; i += 1) {
if (i > 0) {
@psiborg
psiborg / gist:1569773
Created January 6, 2012 08:54
JS Event Listener
document.getElementById("elem1").addEventListener("click", function (evt) {
console.log("click", this.id, evt.srcElement);
}, false);
@psiborg
psiborg / app.js
Created January 6, 2012 08:58
JS Zepto-style Selector
a$('div').css('color:red');
a$('p>span').css('color:red');
a$('#testElem2').html('Hello World!').css('color:red');
a$('#testElem3').html(new Date()).css('background-color:yellow').css('color:red');
@psiborg
psiborg / Base File.sublime-settings
Created January 6, 2012 09:13
Sublime Text 2 - Settings
// Path: Packages/User/Base File.sublime-settings
{
"color_scheme": "Packages/Textmate/HelvectorLight.tmTheme",
"font_face": "Meslo LG M DZ",
"font_size": 8,
//"draw_white_space": "all",
"trim_trailing_white_space_on_save": true
}
@psiborg
psiborg / gist:1569852
Created January 6, 2012 09:28
CSS Trigger GPU for hardware acceleration
-webkit-transform: translate3d(0, 0, 0);
@psiborg
psiborg / gist:1572150
Created January 6, 2012 20:00 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
@psiborg
psiborg / gist:1622431
Created January 16, 2012 19:11
JS Get document height
function getDocHeight() {
var D = document;
return Math.max(
Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
Math.max(D.body.clientHeight, D.documentElement.clientHeight)
);
}
@psiborg
psiborg / gist:1622446
Created January 16, 2012 19:14
CSS RGBa Alpha Transparency
div {
background: rgb(0, 0, 0); /* fallback */
background: rgba(0, 0, 0, 0.65);
}
@psiborg
psiborg / namespace.js
Created January 29, 2012 03:25
JS Namespace Template
/*jslint devel: true, browser: true, white: true, nomen: true */
/**
* @description
*
*/
var namespace = (function () {
"use strict";
var internal = function () {