forked from jeromeetienne/threex.htmlmixer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththreex.htmlmixerhelpers.js
80 lines (68 loc) · 2.44 KB
/
threex.htmlmixerhelpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var THREEx = THREEx || {}
THREEx.HtmlMixerHelpers = THREEx.HtmlMixerHelpers || {}
/**
* create domElement for a iframe to insert in a THREEx.HtmlmixedPlane
*
* @param {String} url the url for the iframe
*/
THREEx.HtmlMixerHelpers.createIframeDomElement = function(url){
// create the iframe element
var domElement = document.createElement('iframe')
domElement.src = url
domElement.style.border = 'none'
//////////////////////////////////////////////////////////////////////////////////
// IOS workaround for iframe
//////////////////////////////////////////////////////////////////////////////////
var onIos = navigator.platform.match(/iP(hone|od|ad)/) !== null ? true : false
if( onIos ){
// - see the following post for explaination 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%'
var container = document.createElement('div')
container.appendChild(domElement)
container.style.overflow = 'scroll'
container.style.webkitOverflowScrolling = 'touch'
return container
}
//////////////////////////////////////////////////////////////////////////////////
// Comment //
//////////////////////////////////////////////////////////////////////////////////
return domElement
}
/**
* set the iframe.src in a mixerPlane.
* - Usefull as it handle IOS specificite
*/
THREEx.HtmlMixerHelpers.setIframeSrc = function(mixerPlane, url){
// handle THREEx.HtmlMultipleMixer.Plane
if( THREEx.HtmlMultipleMixer && mixerPlane instanceof THREEx.HtmlMultipleMixer.Plane ){
mixerPlane.planes.forEach(function(plane){
THREEx.HtmlMixerHelpers.setIframeSrc(plane, url)
})
return
}
// sanity check
console.assert(mixerPlane instanceof THREEx.HtmlMixer.Plane )
// get the domElement
var domElement = mixerPlane.domElement
// handle IOS special case
var onIos = navigator.platform.match(/iP(hone|od|ad)/) !== null ? true : false
if( onIos ){
var domElement = mixerPlane.domElement.firstChild
}
// sanity check
console.assert( 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
*/
THREEx.HtmlMixerHelpers.createImageDomElement = function(url){
var domElement = document.createElement('img')
domElement.src = url
return domElement
}