rel: In teardown, only reset data-x/y/z attribute if we modified it.

Fixes downstream bug in impressionist:
https://github.com/henrikingo/impressionist/issues/20
This commit is contained in:
Henrik Ingo
2019-06-27 06:58:48 +03:00
parent 628b78f3fd
commit 05cf6ffded
3 changed files with 58 additions and 30 deletions

View File

@@ -32,7 +32,9 @@ var output = files.map((f)=>{
return fs.readFileSync(f).toString(); return fs.readFileSync(f).toString();
}).join('\n') }).join('\n')
fs.writeFileSync('js/impress.js', '// This file was automatically generated from files in src/ directory.\n\n' + output) var filename = 'js/impress.js';
fs.writeFileSync(filename, '// This file was automatically generated from files in src/ directory.\n\n' + output)
console.log(filename);
// terser --compress --mangle --comments '/^!/' --source-map --output js/impress.min.js js/impress.js // terser --compress --mangle --comments '/^!/' --source-map --output js/impress.min.js js/impress.js
var code = fs.readFileSync('js/impress.js').toString(); var code = fs.readFileSync('js/impress.js').toString();
@@ -46,8 +48,13 @@ var options = {
} }
}; };
var result = Terser.minify({'js/impress.js': code}, options); var result = Terser.minify({'js/impress.js': code}, options);
fs.writeFileSync('js/impress.min.js', result.code);
fs.writeFileSync('js/impress.min.js.map', result.map); filename = 'js/impress.min.js';
fs.writeFileSync(filename, result.code);
console.log(filename);
filename = 'js/impress.min.js.map';
fs.writeFileSync(filename, result.map);
console.log(filename);
/* Auto generate an index.html that lists all the directories under examples/ /* Auto generate an index.html that lists all the directories under examples/
* This is useful for gh-pages, so you can link to http://impress.github.io/impress.js/examples * This is useful for gh-pages, so you can link to http://impress.github.io/impress.js/examples
@@ -62,5 +69,6 @@ var html = '<html>\n<head>\n<title>Example presentations</title>\n</head>\n<body
html += '<h1>Example presentations</h1>\n' + html_list html += '<h1>Example presentations</h1>\n' + html_list
html += '</body>\n</html>' html += '</body>\n</html>'
var filename = path.resolve(__dirname, 'examples', 'index.html'); filename = path.resolve(__dirname, 'examples', 'index.html');
fs.writeFileSync(filename, html); fs.writeFileSync(filename, html);
console.log(filename);

View File

@@ -3721,7 +3721,10 @@
el: el, el: el,
x: el.getAttribute( "data-x" ), x: el.getAttribute( "data-x" ),
y: el.getAttribute( "data-y" ), y: el.getAttribute( "data-y" ),
z: el.getAttribute( "data-z" ) z: el.getAttribute( "data-z" ),
relX: el.getAttribute( "data-rel-x" ),
relY: el.getAttribute( "data-rel-y" ),
relZ: el.getAttribute( "data-rel-z" )
} ); } );
var step = computeRelativePositions( el, prev ); var step = computeRelativePositions( el, prev );
@@ -3743,20 +3746,27 @@
var steps = startingState[ root.id ]; var steps = startingState[ root.id ];
var step; var step;
while ( step = steps.pop() ) { while ( step = steps.pop() ) {
if ( step.x === null ) { // Reset x/y/z in cases where this plugin has changed it.
step.el.removeAttribute( "data-x" ); if ( step.relX !== null ) {
} else { if ( step.x === null ) {
step.el.setAttribute( "data-x", step.x ); step.el.removeAttribute( "data-x" );
} else {
step.el.setAttribute( "data-x", step.x );
}
} }
if ( step.y === null ) { if ( step.relY !== null ) {
step.el.removeAttribute( "data-y" ); if ( step.y === null ) {
} else { step.el.removeAttribute( "data-y" );
step.el.setAttribute( "data-y", step.y ); } else {
step.el.setAttribute( "data-y", step.y );
}
} }
if ( step.z === null ) { if ( step.relZ !== null ) {
step.el.removeAttribute( "data-z" ); if ( step.z === null ) {
} else { step.el.removeAttribute( "data-z" );
step.el.setAttribute( "data-z", step.z ); } else {
step.el.setAttribute( "data-z", step.z );
}
} }
} }
delete startingState[ root.id ]; delete startingState[ root.id ];

View File

@@ -159,7 +159,10 @@
el: el, el: el,
x: el.getAttribute( "data-x" ), x: el.getAttribute( "data-x" ),
y: el.getAttribute( "data-y" ), y: el.getAttribute( "data-y" ),
z: el.getAttribute( "data-z" ) z: el.getAttribute( "data-z" ),
relX: el.getAttribute( "data-rel-x" ),
relY: el.getAttribute( "data-rel-y" ),
relZ: el.getAttribute( "data-rel-z" )
} ); } );
var step = computeRelativePositions( el, prev ); var step = computeRelativePositions( el, prev );
@@ -181,20 +184,27 @@
var steps = startingState[ root.id ]; var steps = startingState[ root.id ];
var step; var step;
while ( step = steps.pop() ) { while ( step = steps.pop() ) {
if ( step.x === null ) { // Reset x/y/z in cases where this plugin has changed it.
step.el.removeAttribute( "data-x" ); if ( step.relX !== null ) {
} else { if ( step.x === null ) {
step.el.setAttribute( "data-x", step.x ); step.el.removeAttribute( "data-x" );
} else {
step.el.setAttribute( "data-x", step.x );
}
} }
if ( step.y === null ) { if ( step.relY !== null ) {
step.el.removeAttribute( "data-y" ); if ( step.y === null ) {
} else { step.el.removeAttribute( "data-y" );
step.el.setAttribute( "data-y", step.y ); } else {
step.el.setAttribute( "data-y", step.y );
}
} }
if ( step.z === null ) { if ( step.relZ !== null ) {
step.el.removeAttribute( "data-z" ); if ( step.z === null ) {
} else { step.el.removeAttribute( "data-z" );
step.el.setAttribute( "data-z", step.z ); } else {
step.el.setAttribute( "data-z", step.z );
}
} }
} }
delete startingState[ root.id ]; delete startingState[ root.id ];