-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implemention & refactor of
threex
### Description - `threex`'s structure improvement | From @jeromeetienne Co-Authored-By: Jerome Etienne <[email protected]>
- Loading branch information
1 parent
dc72475
commit 662cf71
Showing
11 changed files
with
466 additions
and
9 deletions.
There are no files selected for viewing
Binary file not shown.
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
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
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,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2013 Jerome Etienne | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,91 @@ | ||
import { HtmlMixerPlane } from "./html-mixer"; | ||
import { HtmlMultipleMixerPlane } from "./html-multiple-mixer"; | ||
|
||
export const isIOS = () => { | ||
var iosQuirkPresent = function () { | ||
var audio = new Audio(); | ||
|
||
audio.volume = 0.5; | ||
return audio.volume === 1; // volume cannot be changed from "1" on iOS 12 and below | ||
}; | ||
|
||
var isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent); | ||
var isAppleDevice = navigator.userAgent.includes("Macintosh"); | ||
var isTouchScreen = navigator.maxTouchPoints >= 1; // true for iOS 13 (and hopefully beyond) | ||
|
||
return isIOS || (isAppleDevice && (isTouchScreen || iosQuirkPresent())); | ||
}; | ||
|
||
/** | ||
* create domElement for a iframe to insert in a THREEx.HtmlmixedPlane | ||
* | ||
* @param {String} url the url for the iframe | ||
*/ | ||
export const createIframeDomElement = ( | ||
url: string | ||
): HTMLDivElement | HTMLIFrameElement => { | ||
// create the iframe element | ||
let domElement = document.createElement("iframe"); | ||
domElement.src = url; | ||
domElement.style.border = "none"; | ||
|
||
// TODO:: Ensure the IOS (and other mobile devices) compatibility | ||
// IOS workaround for iframe | ||
if (isIOS()) { | ||
// - see the following post for explanation on this workaround | ||
// - http://dev.magnolia-cms.com/blog/2012/05/strategies-for-the-iframe-on-the-ipad-problem/ | ||
domElement.style.width = "100%"; | ||
domElement.style.height = "100%"; | ||
|
||
let container = document.createElement("div"); | ||
|
||
container.appendChild(domElement); | ||
container.style.overflow = "scroll"; | ||
|
||
return container; | ||
} | ||
|
||
return domElement; | ||
}; | ||
|
||
/** | ||
* Set the iframe.src in a mixerPlane. | ||
* - Useful as it handle IOS specificities | ||
*/ | ||
export const setIframeSrc = ( | ||
mixerPlane: HtmlMultipleMixerPlane | HtmlMixerPlane, | ||
url: string | ||
) => { | ||
// handle THREEx.HtmlMultipleMixer.Plane | ||
if (mixerPlane instanceof HtmlMultipleMixerPlane) { | ||
mixerPlane.planes.forEach(function (plane) { | ||
setIframeSrc(plane, url); | ||
}); | ||
return; | ||
} | ||
|
||
// Sanity check | ||
console.assert(mixerPlane instanceof HtmlMixerPlane); | ||
// Get the domElement | ||
let domElement = mixerPlane.domElement; | ||
// Handle IOS special case | ||
if (isIOS() && mixerPlane.domElement.firstChild instanceof HTMLElement) | ||
domElement = mixerPlane.domElement.firstChild; | ||
|
||
// sanity check | ||
console.assert(domElement instanceof HTMLIFrameElement); | ||
if (domElement instanceof HTMLIFrameElement) | ||
// actually set the iframe.src | ||
domElement.src = url; | ||
}; | ||
|
||
/** | ||
* Create domElement for a image to insert in a THREEx.HtmlmixedPlane | ||
* | ||
* @param {String} url the url for the iframe | ||
*/ | ||
export const createImageDomElement = (url: string) => { | ||
let domElement = document.createElement("img"); | ||
domElement.src = url; | ||
return domElement; | ||
}; |
Oops, something went wrong.