Browse Source

Apply JSHint fixes.

tags/2.5.0
Matthew Petroff 5 years ago
parent
commit
aadbd08fef
2 changed files with 62 additions and 64 deletions
  1. +6
    -6
      src/js/libpannellum.js
  2. +56
    -58
      src/js/pannellum.js

+ 6
- 6
src/js/libpannellum.js View File

@@ -304,9 +304,9 @@ function Renderer(container) {
} }
} else if (imageType == 'cubemap') { } else if (imageType == 'cubemap') {
if (cubeImgWidth > gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE)) { if (cubeImgWidth > gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE)) {
console.log('Error: The image is too big; it\'s ' + width + 'px wide, '+
console.log('Error: The image is too big; it\'s ' + cubeImgWidth + 'px wide, ' +
'but this device\'s maximum supported size is ' + maxWidth + 'px.'); 'but this device\'s maximum supported size is ' + maxWidth + 'px.');
throw {type: 'webgl size error', width: width, maxWidth: maxWidth};
throw {type: 'webgl size error', width: cubeImgWidth, maxWidth: maxWidth};
} }
} }


@@ -695,9 +695,9 @@ function Renderer(container) {
program.nodeCache.length > program.currentNodes.length + 50) { program.nodeCache.length > program.currentNodes.length + 50) {
// Remove older nodes from cache // Remove older nodes from cache
var removed = program.nodeCache.splice(200, program.nodeCache.length - 200); var removed = program.nodeCache.splice(200, program.nodeCache.length - 200);
for (var i = 0; i < removed.length; i++) {
for (var j = 0; j < removed.length; j++) {
// Explicitly delete textures // Explicitly delete textures
gl.deleteTexture(removed[i].texture);
gl.deleteTexture(removed[j].texture);
} }
} }
program.currentNodes = []; program.currentNodes = [];
@@ -1153,7 +1153,7 @@ function Renderer(container) {
}); });
this.image.addEventListener('load', loadFn); this.image.addEventListener('load', loadFn);
this.image.addEventListener('error', loadFn); // ignore missing tile file to support partial image, otherwise retry loop causes high CPU load this.image.addEventListener('error', loadFn); // ignore missing tile file to support partial image, otherwise retry loop causes high CPU load
};
}


TextureImageLoader.prototype.loadTexture = function(src, texture, callback) { TextureImageLoader.prototype.loadTexture = function(src, texture, callback) {
this.texture = texture; this.texture = texture;
@@ -1166,7 +1166,7 @@ function Renderer(container) {
this.src = src; this.src = src;
this.texture = texture; this.texture = texture;
this.callback = callback; this.callback = callback;
};
}


function releaseTextureImageLoader(til) { function releaseTextureImageLoader(til) {
if (pendingTextureRequests.length) { if (pendingTextureRequests.length) {


+ 56
- 58
src/js/pannellum.js View File

@@ -134,7 +134,7 @@ defaultConfig.strings = {
'%spx wide. Try another device.' + '%spx wide. Try another device.' +
' (If you\'re the author, try scaling down the image.)', // Two substitutions: image width, max image width ' (If you\'re the author, try scaling down the image.)', // Two substitutions: image width, max image width
unknownError: 'Unknown error. Check developer console.', unknownError: 'Unknown error. Check developer console.',
}
};


// Initialize container // Initialize container
container = typeof container === 'string' ? document.getElementById(container) : container; container = typeof container === 'string' ? document.getElementById(container) : container;
@@ -464,7 +464,7 @@ function init() {
function absoluteURL(url) { function absoluteURL(url) {
// From http://stackoverflow.com/a/19709846 // From http://stackoverflow.com/a/19709846
return new RegExp('^(?:[a-z]+:)?//', 'i').test(url) || url[0] == '/' || url.slice(0, 5) == 'blob:'; return new RegExp('^(?:[a-z]+:)?//', 'i').test(url) || url[0] == '/' || url.slice(0, 5) == 'blob:';
};
}


/** /**
* Create renderer and initialize event listeners once image is loaded. * Create renderer and initialize event listeners once image is loaded.
@@ -1218,12 +1218,11 @@ function keyRepeat() {
latestInteraction = Date.now(); latestInteraction = Date.now();


// If auto-rotate // If auto-rotate
var inactivityInterval = Date.now() - latestInteraction;
if (config.autoRotate) { if (config.autoRotate) {
// Pan // Pan
if (newTime - prevTime > 0.001) { if (newTime - prevTime > 0.001) {
var timeDiff = (newTime - prevTime) / 1000; var timeDiff = (newTime - prevTime) / 1000;
var yawDiff = (speed.yaw / timeDiff * diff - config.autoRotate * 0.2) * timeDiff
var yawDiff = (speed.yaw / timeDiff * diff - config.autoRotate * 0.2) * timeDiff;
yawDiff = (-config.autoRotate > 0 ? 1 : -1) * Math.min(Math.abs(config.autoRotate * timeDiff), Math.abs(yawDiff)); yawDiff = (-config.autoRotate > 0 ? 1 : -1) * Math.min(Math.abs(config.autoRotate * timeDiff), Math.abs(yawDiff));
config.yaw += yawDiff; config.yaw += yawDiff;
} }
@@ -1406,6 +1405,8 @@ function render() {
var tmpyaw; var tmpyaw;


if (loaded) { if (loaded) {
var canvas = renderer.getCanvas();

// Keep a tmp value of yaw for autoRotate comparison later // Keep a tmp value of yaw for autoRotate comparison later
tmpyaw = config.yaw; tmpyaw = config.yaw;


@@ -1413,8 +1414,7 @@ function render() {
var hoffcut = 0, var hoffcut = 0,
voffcut = 0; voffcut = 0;
if (config.avoidShowingBackground) { if (config.avoidShowingBackground) {
var canvas = renderer.getCanvas(),
hfov2 = config.hfov / 2,
var hfov2 = config.hfov / 2,
vfov2 = Math.atan2(Math.tan(hfov2 / 180 * Math.PI), (canvas.width / canvas.height)) * 180 / Math.PI, vfov2 = Math.atan2(Math.tan(hfov2 / 180 * Math.PI), (canvas.width / canvas.height)) * 180 / Math.PI,
transposed = config.vaov > config.haov; transposed = config.vaov > config.haov;
if (transposed) { if (transposed) {
@@ -1454,7 +1454,6 @@ function render() {
} }


// Ensure the calculated pitch is within min and max allowed // Ensure the calculated pitch is within min and max allowed
var canvas = renderer.getCanvas();
var vfov = 2 * Math.atan(Math.tan(config.hfov / 180 * Math.PI * 0.5) / var vfov = 2 * Math.atan(Math.tan(config.hfov / 180 * Math.PI * 0.5) /
(canvas.width / canvas.height)) / Math.PI * 180; (canvas.width / canvas.height)) / Math.PI * 180;
var minPitch = config.minPitch + vfov / 2, var minPitch = config.minPitch + vfov / 2,
@@ -1509,7 +1508,7 @@ Quaternion.prototype.multiply = function(q) {
this.x*q.w + this.w*q.x + this.y*q.z - this.z*q.y, this.x*q.w + this.w*q.x + this.y*q.z - this.z*q.y,
this.y*q.w + this.w*q.y + this.z*q.x - this.x*q.z, this.y*q.w + this.w*q.y + this.z*q.x - this.x*q.z,
this.z*q.w + this.w*q.z + this.x*q.y - this.y*q.x); this.z*q.w + this.w*q.z + this.x*q.y - this.y*q.x);
}
};


/** /**
* Converts quaternion to Euler angles. * Converts quaternion to Euler angles.
@@ -1523,7 +1522,7 @@ Quaternion.prototype.toEulerAngles = function() {
psi = Math.atan2(2 * (this.w * this.z + this.x * this.y), psi = Math.atan2(2 * (this.w * this.z + this.x * this.y),
1 - 2 * (this.y * this.y + this.z * this.z)); 1 - 2 * (this.y * this.y + this.z * this.z));
return [phi, theta, psi]; return [phi, theta, psi];
}
};


/** /**
* Converts device orientation API Tait-Bryan angles to a quaternion. * Converts device orientation API Tait-Bryan angles to a quaternion.
@@ -1676,7 +1675,7 @@ function createHotSpot(hs) {
hs.yaw = Number(hs.yaw) || 0; hs.yaw = Number(hs.yaw) || 0;


var div = document.createElement('div'); var div = document.createElement('div');
div.className = 'pnlm-hotspot-base'
div.className = 'pnlm-hotspot-base';
if (hs.cssClass) if (hs.cssClass)
div.className += ' ' + hs.cssClass; div.className += ' ' + hs.cssClass;
else else
@@ -1689,24 +1688,24 @@ function createHotSpot(hs) {
var a; var a;
if (hs.video) { if (hs.video) {
var video = document.createElement('video'), var video = document.createElement('video'),
p = hs.video;
if (config.basePath && !absoluteURL(p))
p = config.basePath + p;
video.src = sanitizeURL(p);
vidp = hs.video;
if (config.basePath && !absoluteURL(vidp))
vidp = config.basePath + vidp;
video.src = sanitizeURL(vidp);
video.controls = true; video.controls = true;
video.style.width = hs.width + 'px'; video.style.width = hs.width + 'px';
renderContainer.appendChild(div); renderContainer.appendChild(div);
span.appendChild(video); span.appendChild(video);
} else if (hs.image) { } else if (hs.image) {
var p = hs.image;
if (config.basePath && !absoluteURL(p))
p = config.basePath + p;
var imgp = hs.image;
if (config.basePath && !absoluteURL(imgp))
imgp = config.basePath + imgp;
a = document.createElement('a'); a = document.createElement('a');
a.href = sanitizeURL(hs.URL ? hs.URL : p);
a.href = sanitizeURL(hs.URL ? hs.URL : imgp);
a.target = '_blank'; a.target = '_blank';
span.appendChild(a); span.appendChild(a);
var image = document.createElement('img'); var image = document.createElement('img');
image.src = sanitizeURL(p);
image.src = sanitizeURL(imgp);
image.style.width = hs.width + 'px'; image.style.width = hs.width + 'px';
image.style.paddingTop = '5px'; image.style.paddingTop = '5px';
renderContainer.appendChild(div); renderContainer.appendChild(div);
@@ -1758,7 +1757,7 @@ function createHotSpot(hs) {
span.className += ' pnlm-pointer'; span.className += ' pnlm-pointer';
} }
hs.div = div; hs.div = div;
};
}


/** /**
* Creates hot spot elements for the current scene. * Creates hot spot elements for the current scene.
@@ -1992,7 +1991,7 @@ function processOptions(isPreview) {
link.target = '_blank'; link.target = '_blank';
link.textContent = 'Click here to view this panorama in an alternative viewer.'; link.textContent = 'Click here to view this panorama in an alternative viewer.';
var message = document.createElement('p'); var message = document.createElement('p');
message.textContent = 'Your browser does not support WebGL.'
message.textContent = 'Your browser does not support WebGL.';
message.appendChild(document.createElement('br')); message.appendChild(document.createElement('br'));
message.appendChild(link); message.appendChild(link);
infoDisplay.errorMsg.innerHTML = ''; // Removes all children nodes infoDisplay.errorMsg.innerHTML = ''; // Removes all children nodes
@@ -2166,7 +2165,7 @@ function constrainHfov(hfov) {
} }
if (minHfov > config.maxHfov) { if (minHfov > config.maxHfov) {
// Don't change view if bounds don't make sense // Don't change view if bounds don't make sense
console.log('HFOV bounds do not make sense (minHfov > maxHfov).')
console.log('HFOV bounds do not make sense (minHfov > maxHfov).');
return config.hfov; return config.hfov;
} }
var newHfov = config.hfov; var newHfov = config.hfov;
@@ -2182,8 +2181,7 @@ function constrainHfov(hfov) {
var canvas = renderer.getCanvas(); var canvas = renderer.getCanvas();
newHfov = Math.min(newHfov, newHfov = Math.min(newHfov,
Math.atan(Math.tan((config.maxPitch - config.minPitch) / 360 * Math.PI) / Math.atan(Math.tan((config.maxPitch - config.minPitch) / 360 * Math.PI) /
canvas.height * canvas.width)
* 360 / Math.PI);
canvas.height * canvas.width) * 360 / Math.PI);
} }
return newHfov; return newHfov;
} }
@@ -2412,9 +2410,9 @@ this.setPitch = function(pitch, animated, callback, callbackArgs) {
'startPosition': config.pitch, 'startPosition': config.pitch,
'endPosition': pitch, 'endPosition': pitch,
'duration': animated 'duration': animated
}
};
if (typeof callback == 'function') if (typeof callback == 'function')
setTimeout(function(){callback(callbackArgs)}, animated);
setTimeout(function(){callback(callbackArgs);}, animated);
} else { } else {
config.pitch = pitch; config.pitch = pitch;
} }
@@ -2473,22 +2471,22 @@ this.setYaw = function(yaw, animated, callback, callbackArgs) {
return this; return this;
} }
animated = animated == undefined ? 1000: Number(animated); animated = animated == undefined ? 1000: Number(animated);
yaw = ((yaw + 180) % 360) - 180 // Keep in bounds
yaw = ((yaw + 180) % 360) - 180; // Keep in bounds
if (animated) { if (animated) {
// Animate in shortest direction // Animate in shortest direction
if (config.yaw - yaw > 180) if (config.yaw - yaw > 180)
yaw += 360
yaw += 360;
else if (yaw - config.yaw > 180) else if (yaw - config.yaw > 180)
yaw -= 360
yaw -= 360;


animatedMove.yaw = { animatedMove.yaw = {
'startTime': Date.now(), 'startTime': Date.now(),
'startPosition': config.yaw, 'startPosition': config.yaw,
'endPosition': yaw, 'endPosition': yaw,
'duration': animated 'duration': animated
}
};
if (typeof callback == 'function') if (typeof callback == 'function')
setTimeout(function(){callback(callbackArgs)}, animated);
setTimeout(function(){callback(callbackArgs);}, animated);
} else { } else {
config.yaw = yaw; config.yaw = yaw;
} }
@@ -2553,9 +2551,9 @@ this.setHfov = function(hfov, animated, callback, callbackArgs) {
'startPosition': config.hfov, 'startPosition': config.hfov,
'endPosition': constrainHfov(hfov), 'endPosition': constrainHfov(hfov),
'duration': animated 'duration': animated
}
};
if (typeof callback == 'function') if (typeof callback == 'function')
setTimeout(function(){callback(callbackArgs)}, animated);
setTimeout(function(){callback(callbackArgs);}, animated);
} else { } else {
setHfov(hfov); setHfov(hfov);
} }
@@ -2616,7 +2614,7 @@ this.lookAt = function(pitch, yaw, hfov, animated, callback, callbackArgs) {
if (typeof callback == 'function') if (typeof callback == 'function')
callback(callbackArgs); callback(callbackArgs);
return this; return this;
}
};


/** /**
* Returns the panorama's north offset. * Returns the panorama's north offset.
@@ -2725,7 +2723,7 @@ this.stopAutoRotate = function() {
this.stopMovement = function() { this.stopMovement = function() {
stopAnimation(); stopAnimation();
speed = {'yaw': 0, 'pitch': 0, 'hfov': 0}; speed = {'yaw': 0, 'pitch': 0, 'hfov': 0};
}
};


/** /**
* Returns the panorama renderer. * Returns the panorama renderer.
@@ -2751,7 +2749,7 @@ this.setUpdate = function(bool) {
else else
animateInit(); animateInit();
return this; return this;
}
};


/** /**
* Calculate panorama pitch and yaw from location of mouse event. * Calculate panorama pitch and yaw from location of mouse event.
@@ -2762,7 +2760,7 @@ this.setUpdate = function(bool) {
*/ */
this.mouseEventToCoords = function(event) { this.mouseEventToCoords = function(event) {
return mouseEventToCoords(event); return mouseEventToCoords(event);
}
};


/** /**
* Change scene being viewed. * Change scene being viewed.
@@ -2778,7 +2776,7 @@ this.loadScene = function(sceneId, pitch, yaw, hfov) {
if (loaded !== false) if (loaded !== false)
loadScene(sceneId, pitch, yaw, hfov); loadScene(sceneId, pitch, yaw, hfov);
return this; return this;
}
};


/** /**
* Get ID of current scene. * Get ID of current scene.
@@ -2788,7 +2786,7 @@ this.loadScene = function(sceneId, pitch, yaw, hfov) {
*/ */
this.getScene = function() { this.getScene = function() {
return config.scene; return config.scene;
}
};


/** /**
* Add a new scene. * Add a new scene.
@@ -2826,7 +2824,7 @@ this.removeScene = function(sceneId) {
this.toggleFullscreen = function() { this.toggleFullscreen = function() {
toggleFullscreen(); toggleFullscreen();
return this; return this;
}
};


/** /**
* Get configuration of current scene. * Get configuration of current scene.
@@ -2836,7 +2834,7 @@ this.toggleFullscreen = function() {
*/ */
this.getConfig = function() { this.getConfig = function() {
return config; return config;
}
};


/** /**
* Get viewer's container element. * Get viewer's container element.
@@ -2846,7 +2844,7 @@ this.getConfig = function() {
*/ */
this.getContainer = function() { this.getContainer = function() {
return container; return container;
}
};


/** /**
* Add a new hot spot. * Add a new hot spot.
@@ -2872,7 +2870,7 @@ this.addHotSpot = function(hs, sceneId) {
} }
initialConfig.scenes[id].hotSpots.push(hs); // Add hot spot to config initialConfig.scenes[id].hotSpots.push(hs); // Add hot spot to config
} else { } else {
throw 'Invalid scene ID!'
throw 'Invalid scene ID!';
} }
} }
if (sceneId === undefined || config.scene == sceneId) { if (sceneId === undefined || config.scene == sceneId) {
@@ -2882,7 +2880,7 @@ this.addHotSpot = function(hs, sceneId) {
renderHotSpot(hs); renderHotSpot(hs);
} }
return this; return this;
}
};


/** /**
* Remove a hot spot. * Remove a hot spot.
@@ -2914,11 +2912,11 @@ this.removeHotSpot = function(hotSpotId, sceneId) {
if (initialConfig.scenes.hasOwnProperty(sceneId)) { if (initialConfig.scenes.hasOwnProperty(sceneId)) {
if (!initialConfig.scenes[sceneId].hasOwnProperty('hotSpots')) if (!initialConfig.scenes[sceneId].hasOwnProperty('hotSpots'))
return false; return false;
for (var i = 0; i < initialConfig.scenes[sceneId].hotSpots.length; i++) {
if (initialConfig.scenes[sceneId].hotSpots[i].hasOwnProperty('id') &&
initialConfig.scenes[sceneId].hotSpots[i].id === hotSpotId) {
for (var j = 0; j < initialConfig.scenes[sceneId].hotSpots.length; j++) {
if (initialConfig.scenes[sceneId].hotSpots[j].hasOwnProperty('id') &&
initialConfig.scenes[sceneId].hotSpots[j].id === hotSpotId) {
// Remove hot spot from configuration // Remove hot spot from configuration
initialConfig.scenes[sceneId].hotSpots.splice(i, 1);
initialConfig.scenes[sceneId].hotSpots.splice(j, 1);
return true; return true;
} }
} }
@@ -2926,7 +2924,7 @@ this.removeHotSpot = function(hotSpotId, sceneId) {
return false; return false;
} }
} }
}
};


/** /**
* This method should be called if the viewer's container is resized. * This method should be called if the viewer's container is resized.
@@ -2936,7 +2934,7 @@ this.removeHotSpot = function(hotSpotId, sceneId) {
this.resize = function() { this.resize = function() {
if (renderer) if (renderer)
onDocumentResize(); onDocumentResize();
}
};


/** /**
* Check if a panorama is loaded. * Check if a panorama is loaded.
@@ -2946,7 +2944,7 @@ this.resize = function() {
*/ */
this.isLoaded = function() { this.isLoaded = function() {
return loaded; return loaded;
}
};


/** /**
* Check if device orientation control is supported. * Check if device orientation control is supported.
@@ -2956,7 +2954,7 @@ this.isLoaded = function() {
*/ */
this.isOrientationSupported = function() { this.isOrientationSupported = function() {
return orientationSupport || false; return orientationSupport || false;
}
};


/** /**
* Stop using device orientation. * Stop using device orientation.
@@ -2965,7 +2963,7 @@ this.isOrientationSupported = function() {
*/ */
this.stopOrientation = function() { this.stopOrientation = function() {
stopOrientation(); stopOrientation();
}
};


/** /**
* Start using device orientation (does nothing if not supported). * Start using device orientation (does nothing if not supported).
@@ -2975,7 +2973,7 @@ this.stopOrientation = function() {
this.startOrientation = function() { this.startOrientation = function() {
if (orientationSupport) if (orientationSupport)
startOrientation(); startOrientation();
}
};


/** /**
* Check if device orientation control is currently activated. * Check if device orientation control is currently activated.
@@ -2985,7 +2983,7 @@ this.startOrientation = function() {
*/ */
this.isOrientationActive = function() { this.isOrientationActive = function() {
return Boolean(orientation); return Boolean(orientation);
}
};


/** /**
* Subscribe listener to specified event. * Subscribe listener to specified event.
@@ -2999,7 +2997,7 @@ this.on = function(type, listener) {
externalEventListeners[type] = externalEventListeners[type] || []; externalEventListeners[type] = externalEventListeners[type] || [];
externalEventListeners[type].push(listener); externalEventListeners[type].push(listener);
return this; return this;
}
};


/** /**
* Remove an event listener (or listeners). * Remove an event listener (or listeners).
@@ -3029,7 +3027,7 @@ this.off = function(type, listener) {
delete externalEventListeners[type]; delete externalEventListeners[type];
} }
return this; return this;
}
};


/** /**
* Fire listeners attached to specified event. * Fire listeners attached to specified event.
@@ -3069,7 +3067,7 @@ this.destroy = function() {
} }
container.innerHTML = ''; container.innerHTML = '';
container.classList.remove('pnlm-container'); container.classList.remove('pnlm-container');
}
};


} }




Loading…
Cancel
Save