Skip to content

Instantly share code, notes, and snippets.

@gregdangelo
gregdangelo / jsGetSelection
Created April 9, 2012 11:54
Support: IE6, Fx2, Opera9, Safari Cross browser getSelection().
function getSelection() {
return (!!document.getSelection) ? document.getSelection() :
(!!window.getSelection) ? window.getSelection() :
document.selection.createRange().text;
}
@gregdangelo
gregdangelo / JS padding integers
Created March 16, 2012 14:57
JS padding integers
/*
src: http://jsconsole.com/?v%20%3D%204%3B%20'0'.substr(v%20%3C%2010%20%3F%200%20%3A%201)%20%2B%20v%3B
via @rem
*/
v = 4; '0'.substr(v < 10 ? 0 : 1) + v;
@gregdangelo
gregdangelo / logtime.js
Created January 4, 2012 16:33 — forked from ryanflorence/logtime.js
Log the time of JS operations
var logtime = (function() {
var ids = {};
return function(id) {
if (!ids[id]) {
ids[id] = +new Date();
return;
}
var time = +new Date() - ids[id];
@gregdangelo
gregdangelo / hideaddrbar.js
Created December 20, 2011 18:02 — forked from scottjehl/hideaddrbar.js
Normalized hide address bar for iOS & Android
/*
* Normalized hide address bar for iOS & Android
* (c) Scott Jehl, scottjehl.com
* MIT License
*/
(function( win ){
var doc = win.document;
// If there's a hash, or addEventListener is undefined, stop here
if( !location.hash && win.addEventListener ){