Skip to content

Commit

Permalink
add data-rel-inherit
Browse files Browse the repository at this point in the history
  • Loading branch information
thawk committed Jan 19, 2022
1 parent aba0578 commit 3bf75ad
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
29 changes: 28 additions & 1 deletion js/impress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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 = {
Expand Down Expand Up @@ -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;
}
};
Expand Down
29 changes: 28 additions & 1 deletion src/plugins/rel/rel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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 = {
Expand Down Expand Up @@ -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;
}
};
Expand Down

0 comments on commit 3bf75ad

Please sign in to comment.