este-library-oldschool
Version:
Library for github.com/steida/este.git
107 lines (102 loc) • 2.99 kB
JavaScript
// Generated by github.com/steida/coffee2closure 900.1.18
/**
@fileoverview Various utils for mobile devices.
@namespace este.mobile
*/
goog.provide('este.mobile');
goog.require('goog.dom');
goog.require('goog.dom.classlist');
goog.require('goog.events.FocusHandler');
goog.require('goog.style');
goog.require('goog.userAgent');
goog.require('goog.userAgent.platform');
goog.require('goog.userAgent.product.isVersion');
goog.require('goog.labs.userAgent.platform');
/**
@type {number}
*/
este.mobile.defaultHomeScroll = 1;
este.mobile.hideAddressBar = function() {
window.scrollTo(0, 1);
if (goog.dom.getDocumentScroll().y === 1) {
este.mobile.defaultHomeScroll = 0;
}
return setTimeout(function() {
return window.scrollTo(0, este.mobile.defaultHomeScroll);
}, 0);
};
/**
Adds basic iPhone home icon link to the head
@param {string} url
*/
este.mobile.addiPhoneAppIcon = function(url) {
var link;
link = document.createElement('link');
link.rel = 'apple-touch-icon';
link.href = url;
return document.head.appendChild(link);
};
/**
Hide all fixed positioned elements on focus, because fixed positioned
elements are not updated, when mobile is in edit mode, e.g. keyboard is
shown. Based on jQuery Mobile code, except it is more general, since all
fixed positioned elements are hidden.
*/
este.mobile.hideFixedPositionedOnFocus = function() {
var handler, hideTimer, isVisible, showTimer, toggleFixedDisplay;
showTimer = null;
hideTimer = null;
isVisible = true;
handler = new goog.events.FocusHandler(document.body);
toggleFixedDisplay = function(shown) {
var el, i, len, ref;
ref = document.body.getElementsByTagName('*');
for (i = 0, len = ref.length; i < len; i++) {
el = ref[i];
if (goog.style.getComputedPosition(el) !== 'fixed') {
continue;
}
goog.style.setElementShown(el, shown);
}
};
return goog.events.listen(handler, ['focusin', 'focusout'], function(e) {
var ref;
if ((ref = e.target.tagName) !== 'INPUT' && ref !== 'TEXTAREA' && ref !== 'SELECT') {
return;
}
if (e.type === 'focusout' && !isVisible) {
isVisible = true;
clearTimeout(hideTimer);
showTimer = setTimeout(function() {
return toggleFixedDisplay(true);
}, 0);
} else if (e.type === 'focusin' && !!isVisible) {
clearTimeout(showTimer);
isVisible = false;
hideTimer = setTimeout(function() {
return toggleFixedDisplay(false);
}, 0);
}
});
};
/*
Default mobile support behaviour.
*/
este.mobile.init = function() {
if (!goog.userAgent.MOBILE) {
return;
}
este.mobile.hideAddressBar();
return este.mobile.hideFixedPositionedOnFocus();
};
/*
Cross-device history back.
*/
este.mobile.back = function() {
var ref;
if ((ref = window.navigator['app']) != null ? ref['backHistory'] : void 0) {
window.navigator['app']['backHistory']();
return;
}
return window.history.back();
};