This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/lib/mobile.js.es6
Penar Musaraj 14eb8eea01 FIX: Prevent input zooming in iOS
Since enabling pinch-to-zoom in iOS (eae22548de), there was an issue with inputs: Safari auto-zooms inputs with font-size under 16px. Now zooming will be disabled while focus is on an input.

This commit also removes a) a lightbox zoom-enabling event (no longer needed) and b) a comment about iOS zoom issues.
2019-04-15 13:05:43 -04:00

77 lines
1.8 KiB
JavaScript

import deprecated from "discourse-common/lib/deprecated";
let mobileForced = false;
// An object that is responsible for logic related to mobile devices.
const Mobile = {
isMobileDevice: false,
mobileView: false,
init() {
const $html = $("html");
this.isMobileDevice = mobileForced || $html.hasClass("mobile-device");
this.mobileView = mobileForced || $html.hasClass("mobile-view");
if (Ember.testing || mobileForced) {
return;
}
try {
if (window.location.search.match(/mobile_view=1/)) {
localStorage.mobileView = true;
}
if (window.location.search.match(/mobile_view=0/)) {
localStorage.mobileView = false;
}
if (window.location.search.match(/mobile_view=auto/)) {
localStorage.removeItem("mobileView");
}
if (localStorage.mobileView) {
var savedValue = localStorage.mobileView === "true";
if (savedValue !== this.mobileView) {
this.reloadPage(savedValue);
}
}
} catch (err) {
// localStorage may be disabled, just skip this
// you get security errors if it is disabled
}
},
toggleMobileView() {
try {
if (localStorage) {
localStorage.mobileView = !this.mobileView;
}
} catch (err) {
// localStorage may be disabled, skip
}
this.reloadPage(!this.mobileView);
},
reloadPage(mobile) {
window.location.assign(
window.location.pathname + "?mobile_view=" + (mobile ? "1" : "0")
);
}
};
export function forceMobile() {
mobileForced = true;
}
export function resetMobile() {
mobileForced = false;
}
Object.defineProperty(Discourse, "Mobile", {
get() {
deprecated(
"`Discourse.Mobile` is deprecated, use `this.site.mobileView` instead"
);
return Mobile;
}
});
export default Mobile;