Skip to content

Commit

Permalink
fix(project): default to <null> for Node#insertBefore
Browse files Browse the repository at this point in the history
We must ensure that we default to <null> as the reference node
when using Node#insertBefore in our code base.

Cf. https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore

This may be related to bpmn-io/bpmn-js#746
  • Loading branch information
nikku committed Jan 28, 2019
1 parent 914441b commit 47ca05c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
4 changes: 3 additions & 1 deletion lib/core/GraphicsFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,5 +222,7 @@ GraphicsFactory.prototype.remove = function(element) {
// helpers //////////////////////

function prependTo(newNode, parentNode, siblingNode) {
parentNode.insertBefore(newNode, siblingNode || parentNode.firstChild);
// must ensure second argument is node or _null_
// cf. https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore
parentNode.insertBefore(newNode, siblingNode || parentNode.firstChild || null);
}
11 changes: 8 additions & 3 deletions lib/features/overlays/Overlays.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,14 @@ Overlays.prototype._init = function() {

// helpers /////////////////////////////

function createRoot(parent) {
var root = domify('<div class="djs-overlay-container" style="position: absolute; width: 0; height: 0;" />');
parent.insertBefore(root, parent.firstChild);
function createRoot(parentNode) {
var root = domify(
'<div class="djs-overlay-container" style="position: absolute; width: 0; height: 0;" />'
);

// must ensure second argument is node or _null_
// cf. https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore
parentNode.insertBefore(root, parentNode.firstChild || null);

return root;
}
Expand Down
12 changes: 9 additions & 3 deletions lib/features/tooltips/Tooltips.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ import Ids from '../../util/IdGenerator';
var ids = new Ids('tt');


function createRoot(parent) {
var root = domify('<div class="djs-tooltip-container" style="position: absolute; width: 0; height: 0;" />');
parent.insertBefore(root, parent.firstChild);
function createRoot(parentNode) {
var root = domify(
'<div class="djs-tooltip-container" style="position: absolute; width: 0; height: 0;" />'
);

// must ensure second argument is node or _null_
// cf. https://developer.mozilla.org/en-US/docs/Web/API/Node/insertBefore
parentNode.insertBefore(root, parentNode.firstChild || null);


return root;
}
Expand Down

0 comments on commit 47ca05c

Please sign in to comment.