Fix relative-to-screen-size calculation (h and w) (#799)

This commit is contained in:
thawk
2022-01-30 23:17:56 +08:00
committed by GitHub
parent ecbdd43ca8
commit 20f74a8b56
7 changed files with 148 additions and 33 deletions

View File

@@ -177,6 +177,9 @@
transitionDuration: 1000
};
// Configuration options
var config = null;
// It's just an empty function ... and a useless comment.
var empty = function() { return false; };
@@ -228,9 +231,6 @@
// Array of step elements
var steps = null;
// Configuration options
var config = null;
// Scale factor of the browser window
var windowScale = null;
@@ -321,9 +321,27 @@
steps.forEach( initStep );
};
// Build configuration from root and defaults
var buildConfig = function() {
var rootData = root.dataset;
return {
width: lib.util.toNumber( rootData.width, defaults.width ),
height: lib.util.toNumber( rootData.height, defaults.height ),
maxScale: lib.util.toNumber( rootData.maxScale, defaults.maxScale ),
minScale: lib.util.toNumber( rootData.minScale, defaults.minScale ),
perspective: lib.util.toNumber( rootData.perspective, defaults.perspective ),
transitionDuration: lib.util.toNumber(
rootData.transitionDuration, defaults.transitionDuration
)
};
};
// `init` API function that initializes (and runs) the presentation.
var init = function() {
if ( initialized ) { return; }
// Initialize the configuration object, so it can be used by pre-init plugins.
config = buildConfig();
execPreInitPlugins( root );
// First we set up the viewport for mobile devices.
@@ -335,19 +353,6 @@
document.head.appendChild( meta );
}
// Initialize configuration object
var rootData = root.dataset;
config = {
width: lib.util.toNumber( rootData.width, defaults.width ),
height: lib.util.toNumber( rootData.height, defaults.height ),
maxScale: lib.util.toNumber( rootData.maxScale, defaults.maxScale ),
minScale: lib.util.toNumber( rootData.minScale, defaults.minScale ),
perspective: lib.util.toNumber( rootData.perspective, defaults.perspective ),
transitionDuration: lib.util.toNumber(
rootData.transitionDuration, defaults.transitionDuration
)
};
windowScale = computeWindowScale( config );
// Wrap steps with "canvas" element
@@ -888,6 +893,10 @@
preStepLeavePlugins[ weight ].push( plugin );
};
impress.getConfig = function() {
return config;
};
// Called at beginning of goto(), to execute all preStepLeave plugins.
var execPreStepLeavePlugins = function( event ) { //jshint ignore:line
for ( var i = 0; i < preStepLeavePlugins.length; i++ ) {

View File

@@ -72,7 +72,8 @@
return toNumber( numeric, fallback );
} else {
var value = parseFloat( ratio[ 1 ] );
var multiplier = ratio[ 2 ] === "w" ? window.innerWidth : window.innerHeight;
var config = window.impress.getConfig();
var multiplier = ratio[ 2 ] === "w" ? config.width : config.height;
return value * multiplier;
}
};