-
-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(web): modularizes app/browser's touch-based language menu
- Loading branch information
Showing
9 changed files
with
679 additions
and
653 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Found a bit of magic formatting that allows dynamic return typing for a specified element tag! | ||
export function _CreateElement<E extends "p"|"style"|"script"|"div"|"canvas"|"span">(nodeName:E) { | ||
const e = document.createElement<E>(nodeName); | ||
e.style.userSelect="none"; | ||
|
||
// @ts-ignore | ||
e.style.MozUserSelect="none"; | ||
// @ts-ignore | ||
e.style.KhtmlUserSelect="none"; | ||
// @ts-ignore | ||
e.style.UserSelect="none"; | ||
// @ts-ignore | ||
e.style.WebkitUserSelect="none"; | ||
return e; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/** | ||
* Get browser-independent computed style value for element | ||
* | ||
* @param {Element} e HTML element | ||
* @param {string} s CSS style name | ||
* @return {*} | ||
*/ | ||
export function getStyleValue(e:HTMLElement, s:string) { | ||
// Build 349: error trap added, since on iOS, getPropertyValue may fail | ||
// and crash in some cases, possibly if passed a text node | ||
try | ||
{ | ||
if(e && (typeof(window.getComputedStyle) != 'undefined')) { | ||
return window.getComputedStyle(e,'').getPropertyValue(s); | ||
} | ||
} | ||
catch(ex){} | ||
|
||
// Return empty string if unable to get style value | ||
return ''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
/** | ||
* Get viewport scale factor for this document | ||
* | ||
* @return {number} | ||
*/ | ||
export function getViewportScale(): number { | ||
// This can sometimes fail with some browsers if called before document defined, | ||
// so catch the exception | ||
try { | ||
// For emulation of iOS on a desktop device, use a default value | ||
if(this.device.formFactor == 'desktop') { | ||
return 1; | ||
} | ||
|
||
// Get viewport width | ||
var viewportWidth = document.documentElement.clientWidth; | ||
|
||
// Return a default value if screen width is greater than the viewport width (not fullscreen). | ||
if(screen.width > viewportWidth) { | ||
return 1; | ||
} | ||
|
||
// Get the orientation corrected screen width | ||
var screenWidth = screen.width; | ||
if(this.landscapeView()) { | ||
// Take larger of the two dimensions | ||
if(screen.width < screen.height) { | ||
screenWidth = screen.height; | ||
} | ||
} else { | ||
// Take smaller of the two dimensions | ||
if(screen.width > screen.height) { | ||
screenWidth = screen.height; | ||
} | ||
} | ||
// Calculate viewport scale | ||
return Math.round(100*screenWidth / viewportWidth)/100; | ||
} catch(ex) { | ||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { _CreateElement } from './createElement.js'; | ||
export { getStyleValue } from './getStyleValue.js'; | ||
export { getViewportScale } from './getViewportScale.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.