Starting in PhoneGap 0.9.5 there’s an undocumented iOS only feature that allows you to handle whether the device should rotate to a particular orientation. It exposes the iOS Objective-C method shouldAutorotateToInterfaceOrientation with a JavaScript function shouldRotateToOrientation. function shouldRotateToOrientation (rotation) { switch (rotation) { //Portrait or PortraitUpsideDown case 0: case 180: return true; //LandscapeRight or LandscapeLeft case […]
By Ben Collier
|
Posted in iPad, iPhone, Javascript, Mobile, PhoneGap
|
Also tagged Apps, html5, iOS, ipad, iPhone, javascript function, phonegap
|
A cool and little known JavaScript function is .link() available to all string objects. Calling string.link(url) returns an HTML string for an anchor tag with the URL in it. For example: var text = ‘the best website ever’; var html = text.link(‘http://bencollier.net/’); html === “<a href=‘http://bencollier.net/’>the best website ever</a>” //true A great way […]
If you’ve got a password saved, but can’t remember what it is, you can use this bookmarklet to reveal it. Drag the image to the bookmark bar: Click the button above to try it out: If you’re interested in the JavaScript source: javascript:Array.prototype.slice.call(document.querySelectorAll(“input[type=‘password’]”)) .map(function(el){el.setAttribute(‘type’,‘text’)}) It gets all password inputs and turns their type to text; […]
In PhoneGap 0.9.5 they’ve updated how the Android back button works. Here’s what to change. Before in 0.9.4: BackButton.override(); document.addEventListener(“backKeyDown”, function() { someBackButtonHandlingFunction(); }, true); Now in 0.9.5: document.addEventListener(“backbutton”, function() { someBackButtonHandlingFunction(); }, true); In 0.9.5 and later you no longer need to override the back button, as it’s assumed when you’re adding […]
Usability Cramps [yoo-zuh-bill-ity kramps] n. are unpleasant, often painful sensations caused by unbearable unusable user experience mistakes v. usability cramping, usability cramped, why the hell did they do this? Form Labels That Don’t Select the Fields This one mega-stresses me out; when the text label next to checkbox or a label doesn’t select it when you click it: […]
To check if an object is empty in Javascript: Object.getOwnPropertyNames(obj).length === 0; Where obj is the object you’re testing e.g.: var obj = {}; Object.getOwnPropertyNames(obj).length === 0; //true obj = {‘not’ : ‘empty’}; Object.getOwnPropertyNames(obj).length === 0; //false Or to wrap it in a function: function isEmpty(obj){ return (Object.getOwnPropertyNames(obj).length === 0); } […]
The winner of the 2011 Yahoo HackU contest at University of Washington, this is so cool. Click here to activate the Katamari Damacy effect. You can also install it as a bookmarklet by dragging: Katamari to your bookmarks bar. It uses CSS3 transforms and html5 canvas to do this awesome effect. Hats off to the developers, this works […]
Great bit of javscript code that detects if a browser is Internet Explorer in just 7 bytes: if(!+”\v1”) // true only in IE (via http://webreflection.blogspot.com/2009/01/32-bytes-to-know-if-your-browser-is-ie.html)