From 5b4550edb212228cb643f331b23131363a85a1c0 Mon Sep 17 00:00:00 2001 From: Erik Ziegler Date: Tue, 22 May 2018 10:32:54 +0200 Subject: [PATCH] fix(protocolEngine) Stop adding Array.prototype.move, since it is interfering with other code --- .../components/stageSortable/stageSortable.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Packages/ohif-hanging-protocols/client/components/stageSortable/stageSortable.js b/Packages/ohif-hanging-protocols/client/components/stageSortable/stageSortable.js index 97591d91b..1e4c8776d 100644 --- a/Packages/ohif-hanging-protocols/client/components/stageSortable/stageSortable.js +++ b/Packages/ohif-hanging-protocols/client/components/stageSortable/stageSortable.js @@ -6,18 +6,17 @@ import { OHIF } from 'meteor/ohif:core'; import 'meteor/ohif:viewerbase'; /** - * Extend the Array prototype with a Swap function - * so we can swap stages more easily + * Add an array index swapping function so we can swap stages more easily */ -Array.prototype.move = function(oldIndex, newIndex) { - var value = this[oldIndex]; +move = function(array, oldIndex, newIndex) { + var value = array[oldIndex]; newIndex = Math.max(0, newIndex); - newIndex = Math.min(this.length, newIndex); + newIndex = Math.min(array.length, newIndex); - this.splice(oldIndex, 1); - this.splice(newIndex, 0, value); - return this; + array.splice(oldIndex, 1); + array.splice(newIndex, 0, value); + return array; }; /** @@ -227,7 +226,7 @@ Template.stageSortable.events({ // Swap the stages in the current Protocol's display set sequence // using our addition to the Array prototype - ProtocolEngine.protocol.stages = ProtocolEngine.protocol.stages.move(oldIndex, newIndex); + ProtocolEngine.protocol.stages = move(ProtocolEngine.protocol.stages, oldIndex, newIndex); // If the currently displayed stage was reordered into a new position, // update the value for the stage index in the displayed Protocol @@ -247,7 +246,7 @@ Template.stageSortable.events({ // Swap the stages in the current Protocol's display set sequence // using our addition to the Array prototype - ProtocolEngine.protocol.stages = ProtocolEngine.protocol.stages.move(oldIndex, newIndex); + ProtocolEngine.protocol.stages = move(ProtocolEngine.protocol.stages.move, oldIndex, newIndex); // If the currently displayed stage was reordered into a new position, // update the value for the stage index in the displayed Protocol