From 3bf75adeac8fe33b5340de6198be5ad0c8c03312 Mon Sep 17 00:00:00 2001 From: thawk Date: Wed, 19 Jan 2022 17:52:45 +0800 Subject: [PATCH] add data-rel-inherit --- js/impress.js | 29 ++++++++++++++++++++++++++++- src/plugins/rel/rel.js | 29 ++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/js/impress.js b/js/impress.js index 6341439de..26390cdb0 100644 --- a/js/impress.js +++ b/js/impress.js @@ -4116,9 +4116,10 @@ }; } + var ref = prev; if ( data.relTo ) { - var ref = document.getElementById( data.relTo ); + ref = document.getElementById( data.relTo ); if ( ref ) { // Test, if it is a previous step that already has some assigned position data @@ -4155,6 +4156,7 @@ } } + // While ``data-rel-reset="relative"`` or just ``data-rel-reset``, // ``data-rel-x/y/z`` and ``data-rel-rotate-x/y/z`` will have default value of 0, // instead of inherit from previous slide. @@ -4176,6 +4178,25 @@ if ( data.relReset === "all" ) { inheritRotation = false; } + } else if ( el.hasAttribute( "data-rel-inherit" ) ) { + var inheritFrom = null; + if ( data.relInherit ) { + + // If data-rel-inherit has value, it's the referenced node + inheritFrom = document.getElementById( data.relInherit ); + } + + if ( ! inheritFrom ) { + inheritFrom = ref; + } + + prev.relative.x = toNumberAdvanced( inheritFrom.getAttribute( "data-rel-x" ), 0 ); + prev.relative.y = toNumberAdvanced( inheritFrom.getAttribute( "data-rel-y" ), 0 ); + prev.relative.z = toNumberAdvanced( inheritFrom.getAttribute( "data-rel-z" ), 0 ); + prev.relative.rotate.x = toNumberAdvanced( inheritFrom.getAttribute( "data-rel-rotate-x" ), 0 ); + prev.relative.rotate.y = toNumberAdvanced( inheritFrom.getAttribute( "data-rel-rotate-y" ), 0 ); + prev.relative.rotate.z = toNumberAdvanced( inheritFrom.getAttribute( "data-rel-rotate-z" ), 0 ); + prev.relative.rotate.order = inheritFrom.getAttribute( "data-rel-rotate-order" ) || "xyz"; } var step = { @@ -4285,6 +4306,12 @@ el.setAttribute( "data-rotate-z", step.rotate.z ); el.setAttribute( "data-rotate-order", step.rotate.order ); el.setAttribute( "data-rel-position", step.relative.position ); + el.setAttribute( "data-rel-x", step.relative.x ); + el.setAttribute( "data-rel-y", step.relative.y ); + el.setAttribute( "data-rel-z", step.relative.z ); + el.setAttribute( "data-rel-rotate-x", step.relative.rotate.x ); + el.setAttribute( "data-rel-rotate-y", step.relative.rotate.y ); + el.setAttribute( "data-rel-rotate-z", step.relative.rotate.z ); prev = step; } }; diff --git a/src/plugins/rel/rel.js b/src/plugins/rel/rel.js index a9877ab76..96698b2d8 100644 --- a/src/plugins/rel/rel.js +++ b/src/plugins/rel/rel.js @@ -95,9 +95,10 @@ }; } + var ref = prev; if ( data.relTo ) { - var ref = document.getElementById( data.relTo ); + ref = document.getElementById( data.relTo ); if ( ref ) { // Test, if it is a previous step that already has some assigned position data @@ -134,6 +135,7 @@ } } + // While ``data-rel-reset="relative"`` or just ``data-rel-reset``, // ``data-rel-x/y/z`` and ``data-rel-rotate-x/y/z`` will have default value of 0, // instead of inherit from previous slide. @@ -155,6 +157,25 @@ if ( data.relReset === "all" ) { inheritRotation = false; } + } else if ( el.hasAttribute( "data-rel-inherit" ) ) { + var inheritFrom = null; + if ( data.relInherit ) { + + // If data-rel-inherit has value, it's the referenced node + inheritFrom = document.getElementById( data.relInherit ); + } + + if ( ! inheritFrom ) { + inheritFrom = ref; + } + + prev.relative.x = toNumberAdvanced( inheritFrom.getAttribute( "data-rel-x" ), 0 ); + prev.relative.y = toNumberAdvanced( inheritFrom.getAttribute( "data-rel-y" ), 0 ); + prev.relative.z = toNumberAdvanced( inheritFrom.getAttribute( "data-rel-z" ), 0 ); + prev.relative.rotate.x = toNumberAdvanced( inheritFrom.getAttribute( "data-rel-rotate-x" ), 0 ); + prev.relative.rotate.y = toNumberAdvanced( inheritFrom.getAttribute( "data-rel-rotate-y" ), 0 ); + prev.relative.rotate.z = toNumberAdvanced( inheritFrom.getAttribute( "data-rel-rotate-z" ), 0 ); + prev.relative.rotate.order = inheritFrom.getAttribute( "data-rel-rotate-order" ) || "xyz"; } var step = { @@ -264,6 +285,12 @@ el.setAttribute( "data-rotate-z", step.rotate.z ); el.setAttribute( "data-rotate-order", step.rotate.order ); el.setAttribute( "data-rel-position", step.relative.position ); + el.setAttribute( "data-rel-x", step.relative.x ); + el.setAttribute( "data-rel-y", step.relative.y ); + el.setAttribute( "data-rel-z", step.relative.z ); + el.setAttribute( "data-rel-rotate-x", step.relative.rotate.x ); + el.setAttribute( "data-rel-rotate-y", step.relative.rotate.y ); + el.setAttribute( "data-rel-rotate-z", step.relative.rotate.z ); prev = step; } };