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
|
Also posted in iPad, iPhone, Mobile, PhoneGap
|
Tagged Apps, html5, iOS, ipad, iPhone, javascript, 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 […]
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); } […]
Currently only works in Safari 5 & Chrome 7 dev, but this Wonder Wall Demo is extremely awesome!
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)
The Google Maps API overrides the scroll functionality of the scrollwheel so it zooms the map, this often causes problems when you have a large map spanning the page. To prevent this in V3 of the Maps API add: scrollwheel: false To your mapOptions when initialising the map. For example: var mapOptions = { zoom: 14, center: point, […]