Skip to content

Commit 366ab20

Browse files
committed
Preloaded Images
Bubble can now preload images from sites with CORS enabled headers. It uses the 'pic' key in the query string
1 parent 7530fc4 commit 366ab20

23 files changed

+42
-68017
lines changed

js/aroundviewer.js

+40-31
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,34 @@ function handleFiles(files){
55
if (!files.length) {
66

77
} else {
8-
var placeHolder = document.getElementById('virtualArea');
9-
placeHolder.innerHTML= "<p>your image is loading</p>"; //must update to change the texture instead
10-
var img = document.createElement('img');
11-
img.setAttribute('id', 'texture')
12-
img.src = window.URL.createObjectURL(files[0]);
13-
var skys = document.getElementsByTagName('a-sky');
14-
img.onload = function() {
15-
16-
var sky = document.createElement('a-sky');
17-
var scene = document.createElement('a-scene');
18-
var assets = document.createElement('a-assets');
19-
virtualPlaceholder = document.getElementById('virtualArea');
20-
virtualPlaceholder.innerHTML = "";
8+
createImage(files[0], false);
9+
}
10+
}
2111

22-
assets.appendChild(img);
23-
sky.setAttribute('src', '#texture');
24-
scene.appendChild(assets);
25-
scene.appendChild(sky);
26-
virtualPlaceholder.appendChild(scene);
12+
//creates the aframe structure that holds the sky inside the scene.
13+
//can work with a create url from a file from the device or with "isExternal" to target a url
14+
function createImage(url, isExternal){
15+
var placeHolder = document.getElementById('virtualArea');
16+
placeHolder.innerHTML= "<p>your image is loading</p>"; //must update to change the texture instead
17+
var img = document.createElement('img');
18+
img.setAttribute('id', 'texture')
19+
img.src = (isExternal)?url:window.URL.createObjectURL(url);
20+
img.onload = function() {
21+
22+
var sky = document.createElement('a-sky');
23+
var scene = document.createElement('a-scene');
24+
var assets = document.createElement('a-assets');
25+
virtualPlaceholder = document.getElementById('virtualArea');
26+
virtualPlaceholder.innerHTML = "";
2727

28+
assets.appendChild(img);
29+
sky.setAttribute('src', '#texture');
30+
scene.appendChild(assets);
31+
scene.appendChild(sky);
32+
virtualPlaceholder.appendChild(scene);
33+
34+
if(!isExternal)
2835
window.URL.revokeObjectURL(this.src);
29-
}
3036
}
3137
}
3238

@@ -50,16 +56,19 @@ function init(){
5056
}
5157

5258
document.addEventListener('DOMContentLoaded', function() {
53-
if(window.location.search == ''){
54-
init();
55-
}
56-
else{
57-
var ext_res = '';
58-
searchPars = new URLSearchParams(window.location.search);
59-
if(searchPars.has('e') === true){
60-
ext_res = searchPars.get('e');
61-
alert(ext_res);
62-
}
59+
var ext_res = getUrlParameter('pic');
60+
if(ext_res != ''){
61+
var fs = document.getElementById('fileSelector');
62+
fs.style.animationName="minimize";
63+
createImage(ext_res, true);
6364
}
64-
65-
});
65+
init();
66+
});
67+
68+
//gets a query string parameter
69+
function getUrlParameter(name) {
70+
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
71+
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
72+
var results = regex.exec(location.search);
73+
return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
74+
};

manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"lang": "en",
33
"dir": "ltr",
4-
"name": "bubble 360 viewer",
5-
"description": "360 image viewer from Samsung Internet",
4+
"name": "bubble 360° viewer",
5+
"description": "360° image viewer from Samsung Internet",
66
"short_name": "bubble",
77
"icons": [ {
88
"src": "i/icons/launcher-icon-192.png",

sw.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Perform install steps
22
var CACHE_NAME = 'bubble-v1';
33
var urlsToCache = [
4-
'/bubble',
54
'css/style.css',
65
'js/aroundviewer.js',
76
'js/e/aframe.js',

v2/.gitattributes

-17
This file was deleted.

v2/.gitignore

-47
This file was deleted.

v2/README.md

-10
This file was deleted.

v2/css/style.css

-59
This file was deleted.

v2/docs/bubbleDoc.png

-671 KB
Binary file not shown.

v2/i/around.jpg

-634 KB
Binary file not shown.

v2/i/around.old.jpg

-184 KB
Binary file not shown.

v2/i/bubbleicon.png

-19.6 KB
Binary file not shown.

v2/i/icons/launcher-icon-144.png

-8.38 KB
Binary file not shown.

v2/i/icons/launcher-icon-192.png

-11.2 KB
Binary file not shown.

v2/i/icons/launcher-icon-512.png

-30.7 KB
Binary file not shown.

v2/i/icons/launcher-icon-96.png

-5.5 KB
Binary file not shown.

v2/i/icons/launcher-icon.png

-2.57 KB
Binary file not shown.

v2/i/uploadButton.png

-61.9 KB
Binary file not shown.

v2/index.html

-28
This file was deleted.

v2/js/aroundviewer.js

-65
This file was deleted.

0 commit comments

Comments
 (0)