aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHakim El Hattab <hakim.elhattab@gmail.com>2014-05-07 22:02:05 +0200
committerHakim El Hattab <hakim.elhattab@gmail.com>2014-05-07 22:02:05 +0200
commitc4e202cd0ffeedc817c0506116744102dd63419a (patch)
tree82da480da37a20da684fd314877caeb2ead79bec
parentf31f0ffa700f860a6d4492bdb3b5c0dee6d565d7 (diff)
downloadfreenode-live-2017-presentation-c4e202cd0ffeedc817c0506116744102dd63419a.tar
freenode-live-2017-presentation-c4e202cd0ffeedc817c0506116744102dd63419a.tar.gz
fix edge case in singleton node creation
-rw-r--r--js/reveal.js24
1 files changed, 16 insertions, 8 deletions
diff --git a/js/reveal.js b/js/reveal.js
index cccc387..da43738 100644
--- a/js/reveal.js
+++ b/js/reveal.js
@@ -518,18 +518,26 @@
*/
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
- if( !node || node.parentNode !== container ) {
- node = document.createElement( tagname );
- node.classList.add( classname );
- if( typeof innerHTML === 'string' ) {
- node.innerHTML = innerHTML;
+ // Check all matches to find one which is a direct child of
+ // the specified container
+ for( var i = 0; i < nodes.length; i++ ) {
+ var testNode = nodes[i];
+ if( testNode.parentNode === container ) {
+ return testNode;
}
- container.appendChild( node );
}
+ // If no node was found, create it now
+ var node = document.createElement( tagname );
+ node.classList.add( classname );
+ if( typeof innerHTML === 'string' ) {
+ node.innerHTML = innerHTML;
+ }
+ container.appendChild( node );
+
return node;
}