Skip to content

Instantly share code, notes, and snippets.

@benadamstyles
benadamstyles / roundToCashString.js
Last active August 29, 2015 14:08
Returns a Number or String, with two decimal places ONLY if necessary, for displaying cash figures
var roundToCashString = function roundToCashString(v) {
var integer=Math.floor(v);
return v-integer>0.004 ?
v.toFixed(2) :
integer;
}
/**
* VH and VW units can cause issues on iOS devices: http://caniuse.com/#feat=viewport-units
*
* To overcome this, create media queries that target the width, height, and orientation of iOS devices.
* It isn't optimal, but there is really no other way to solve the problem. In this example, I am fixing
* the height of element `.foo` —which is a full width and height cover image.
*
* iOS Resolution Quick Reference: http://www.iosres.com/
*/
@benadamstyles
benadamstyles / Q.js
Created October 14, 2014 11:13
Helper to queue a function at the end of the call stack
window.namespace.Q=function(f) {
setTimeout(f,1);
};
@benadamstyles
benadamstyles / CheckConnection.js
Created October 14, 2014 11:00
Check internet connection on Cordova/Phonegap
window.namespace.checkConnection=function() {
return navigator.connection.type!==Connection.NONE;
};
@benadamstyles
benadamstyles / CurrencyRound.js
Last active August 29, 2015 14:07
Return a number rounded to given decimal places
window.namespace.round=function(v,decimalPlaces) {
var d=decimalPlaces||2;
return Number(Math.round(v+'e'+d)+'e-'+d);
};
window.namespace.hideKB=function() {
document.activeElement.blur();
};
@benadamstyles
benadamstyles / Killer.js
Last active August 29, 2015 14:07
Helper function to remove element from DOM after a CSS transition has completed
window.namespace.killer=function(el,classNameString) {
function die() {
el.removeEventListener("webkitTransitionEnd",die);
el.parentNode.removeChild(el);
}
el.addEventListener("webkitTransitionEnd",die);
el.classList.toggle(classNameString);
};
( function( window, undefined ) {
'use strict';
// helper function
function capitalize( str ) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
// ========================= getStyleProperty by kangax ===============================
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width;height=device-height; user-scalable=no" />
<meta http-equiv="Content-type" content="text/html;charset=utf-8">
<title>PhoneGap Reverse Geolocation Lookup</title>
<script type="text/javascript" src="cordova-1.7.0.js"></script>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=true"></script>