fix edge case in singleton node creation
This commit is contained in:
parent
f31f0ffa70
commit
c4e202cd0f
18
js/reveal.js
18
js/reveal.js
|
@ -518,17 +518,25 @@
|
||||||
*/
|
*/
|
||||||
function createSingletonNode( container, tagname, classname, innerHTML ) {
|
function createSingletonNode( container, tagname, classname, innerHTML ) {
|
||||||
|
|
||||||
var node = container.querySelector( '.' + classname );
|
// Find all nodes matching the description
|
||||||
|
var nodes = container.querySelectorAll( '.' + classname );
|
||||||
|
|
||||||
// If no node was found or the node is inside another container
|
// Check all matches to find one which is a direct child of
|
||||||
if( !node || node.parentNode !== container ) {
|
// the specified container
|
||||||
node = document.createElement( tagname );
|
for( var i = 0; i < nodes.length; i++ ) {
|
||||||
|
var testNode = nodes[i];
|
||||||
|
if( testNode.parentNode === container ) {
|
||||||
|
return testNode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no node was found, create it now
|
||||||
|
var node = document.createElement( tagname );
|
||||||
node.classList.add( classname );
|
node.classList.add( classname );
|
||||||
if( typeof innerHTML === 'string' ) {
|
if( typeof innerHTML === 'string' ) {
|
||||||
node.innerHTML = innerHTML;
|
node.innerHTML = innerHTML;
|
||||||
}
|
}
|
||||||
container.appendChild( node );
|
container.appendChild( node );
|
||||||
}
|
|
||||||
|
|
||||||
return node;
|
return node;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user