Skip to content

Instantly share code, notes, and snippets.

@paulirish
paulirish / gist:3910471
Created October 18, 2012 08:33
page visibility API : tribulations with prefixes
// this is the least sucky way i could think of to
// detect and deal with a cross-browser impl of the page visibility api
// forks welcome.
function getHiddenProp(){
var prefixes = ['webkit','moz','ms','o'];
if ('hidden' in document) return 'hidden';
@addyosmani
addyosmani / cranium.js
Last active February 7, 2019 15:02
Cranium
/* Cranium MVC
* A minimalist MVC implementation written for
* demonstration purposes at my workshops
* http://addyosmani.com
* Copyright (c) 2012 Addy Osmani; Licensed MIT */
var Cranium = Cranium || {};
// Set DOM selection utility
@domi-papin
domi-papin / jquery-ui-draggable-touch-support
Created January 2, 2012 14:39
Add touch event support to jquery ui draggables AND faster clicks on touch devices as a bonus
/*
* picked from http://stackoverflow.com/questions/5186441/javascript-drag-and-drop-for-touch-devices
*
*/
function touchHandler(event)
{
// trick to add support for touch event to elements/widgets that do not support it
// by convetting convert touchevents into mouseevents
// only apply this trick to ui-draggable elements
String.prototype.reverse = function() {
return this.split("").reverse().join("");
}
Number.prototype.formatAsCurrency = function() {
return this.toString()
.replace(/^(\d)$/, "00$1") // pad 1 digit
.replace(/^(\d{2})$/, "0$1") // pad 2 digits
.reverse()
.replace(/(\d{2}(?=\d))/, "$1.") // place decimal point