JS
x$('').xhrjson('xhrTarget.json', {map:{'name':'#tName', 'colour':'#tColour', 'age':'#tAge'}});
<3 XUI: http://www.schrodinger.net/PhoneGapWebTest/xui/index.html
x$('').xhrjson('xhrTarget.json', {map:{'name':'#tName', 'colour':'#tColour', 'age':'#tAge'}});
<3 XUI: http://www.schrodinger.net/PhoneGapWebTest/xui/index.html
function live(selector, eventType, callback) {
document.addEventListener(eventType, function (e) {
if (e.target.webkitMatchesSelector(selector)) {
callback.call(e.target, e);
}
}, false);}
live('.link', 'click', function(e) {
e.preventDefault();
//do something cool
});
Event delegation: http://www.sitepoint.com/forums/showthread.php?786594-Vanilla-Js-version-of-.live()
window.history.back();
window.history.go(-2);
//go to nearest scriptogram.com page
history.go(“scriptogram.com”);
(function(d, c) {
d[c] = d[c].replace(/\bno-js\b/, "js");
})(document.documentElement, "className");
<html class="no-js"> //Becomes <html class="js">
document.body.addEventListener('touchmove', function(event) {
event.preventDefault();}, false);
Add a bit of native flair
if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
location.replace("http://url-to-send-them/iphone.html");}
Hack, look away
if (window.devicePixelRatio == 2) {// code }
Dirty quick little hack for targeting highdpi devices
window.addEventListener('load', function(e) {
setTimeout(function() { window.scrollTo(0, 1); }, 1);
}, false);
Hides mobile browser's address bar when page is done loading
document.body.onorientationchange = (function(){
document.body.className =
orientation % 180 == 0 ? 'vertical' : 'horizontal';
return arguments.callee;
})();
Adds class .vertical and .horizontal :)
media only screen and (device-width: 768px) and (orientation: landscape) {
#wrap{opacity:0;}#mensaje {opacity:1;}
}
#mensaje {opacity:0;-webkit-transition: opacity .8s ease; transition: opacity .8s ease;}
#wrap{opacity:1; -webkit-transition: opacity .1s ease; transition: opacity .1s ease;}
Deal with portrait/landscape issues with mediaqueries if previous JS was too much