Index: main/trunk/greenstone3/web/interfaces/default/js/map-scripts-editor-history.js
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/js/map-scripts-editor-history.js	(revision 32768)
+++ main/trunk/greenstone3/web/interfaces/default/js/map-scripts-editor-history.js	(revision 32769)
@@ -1,6 +1,6 @@
-var prevOverlays = [];
-var presentOverlays = [];
-var undoneOverlays = [];
-var cycleComplete = true;
+//var prevOverlays = [];
+//var presentOverlays = [];
+//var undoneOverlays = [];
+//var cycleComplete = true;
 
 function MapEditorHistory()
@@ -12,6 +12,6 @@
 }
 
-MapEditorHistory.prototype.undo = function(overlays) {
-	for (var i = 0; i < overlays.length; i++) {
+MapEditorHistory.prototype.undo = function() {
+	for (let i = 0; i < overlays.length; i++) {
 		overlays[i].setMap(null);
 	}
@@ -34,36 +34,17 @@
 
 	
-function undo() {
-
-	for (var i = 0; i < overlays.length; i++) {
-		overlays[i].setMap(null);
-	}
-	if (prevOverlays.length != 0) {
+
+
+MapEditorHistory.prototype.redo = function() {
+
+	if (this.undoneOverlays.length != 0) {
 		selectedShapes = [];
+		for (let i = 0; i < overlays.length; i++) {
+			overlays[i].setMap(null);
+		}
+
 		overlays = [];
-		undoneOverlaysPush();
-		var prev_overlay = prevOverlays.pop();
-
-		if (prev_overlay.length > 0) {
-			for (var i = 0; i < prev_overlay.length; i++) {
-				overlays[i] = prev_overlay[i];
-				overlays[i].setMap(map);
-				overlays[i].draggable = draggableState;
-			}
-		}
-	}
-}
-
-function redo() {
-
-	if (undoneOverlays.length != 0) {
-		selectedShapes = [];
-		for (var i = 0; i < overlays.length; i++) {
-			overlays[i].setMap(null);
-		}
-
-		overlays = [];
-		var lastEntry = undoneOverlays[undoneOverlays.length - 1];
-		for (var i = 0; i < lastEntry.length; i++) {
+		var lastEntry = this.undoneOverlays[this.undoneOverlays.length - 1];
+		for (let i = 0; i < lastEntry.length; i++) {
 			overlays[i] = lastEntry[i];
 			overlays[i].setMap(map);
@@ -71,13 +52,13 @@
 		}
 
-		var conditionPrevious = presentOverlays[0];
+		var conditionPrevious = this.presentOverlays[0];
 		if (conditionPrevious !== undefined) {
 			if (conditionPrevious.length == 0) {
-				prevOverlays.push(presentOverlays[0]);
+				this.prevOverlays.push(this.presentOverlays[0]);
 			} else {
 				var overlays_copy = [];
-				for (var i = 0; i < presentOverlays[0].length; i++) {
-					var clone_shape = cloneShape(presentOverlays[0][i]);
-					if (overlayItemIsShape(clone_shape)) {
+				for (let i = 0; i < this.presentOverlays[0].length; i++) {
+					var clone_shape = this.cloneShape(this.presentOverlays[0][i]);
+					if (this.overlayItemIsShape(clone_shape)) {
 						addShapeListeners(clone_shape, null);
 					} else {
@@ -86,14 +67,17 @@
 					overlays_copy[i] = clone_shape;
 				}
-				prevOverlays.push(overlays_copy);
-			}
-		}
-		presentOverlays = [];
-		presentOverlays.push(undoneOverlays[undoneOverlays.length - 1]);
-		undoneOverlays.pop();
-	}
-}
-
-function clonePath(path) {
+				this.prevOverlays.push(overlays_copy);
+			}
+		}
+		this.presentOverlays = [];
+		this.presentOverlays.push(this.undoneOverlays[this.undoneOverlays.length - 1]);
+		this.undoneOverlays.pop();
+	}
+}
+
+
+
+
+MapEditorHistory.prototype.clonePath = function(path){
 	var clone_path = [];
 
@@ -111,5 +95,6 @@
 }
 
-function clonePolyline(polyline) {
+
+MapEditorHistory.prototype.clonePolyline = function(polyline){
 	var path = polyline.getPath();
 	var geodesic = polyline.geodesic;
@@ -135,5 +120,6 @@
 }
 
-function clonePolygon(polygon) {
+
+MapEditorHistory.prototype.clonePolygon = function(polygon){
 	var path = polygon.getPath();
 	var geodesic = polygon.geodesic;
@@ -163,5 +149,5 @@
 }
 
-function cloneRectangle(rect) {
+MapEditorHistory.prototype.cloneRectangle = function(rect){
 	var strokeColor = rect.strokeColor;
 	var strokeOpacity = rect.strokeOpacity;
@@ -190,5 +176,5 @@
 }
 
-function cloneCircle(circ) {
+MapEditorHistory.prototype.cloneCircle = function(circ){
 	var strokeColor = circ.strokeColor;
 	var strokeOpacity = circ.strokeOpacity;
@@ -217,5 +203,5 @@
 }
 
-function cloneMarker(marker) {
+MapEditorHistory.prototype.cloneMarker = function(marker){
 	var position = marker.getPosition();
 	var anchorPoint = marker.anchorPoint;
@@ -232,26 +218,26 @@
 }
 
-function cloneShape(shape) {
+MapEditorHistory.prototype.cloneShape = function(shape){
 	if (shape.type === google.maps.drawing.OverlayType.POLYLINE) {
-		var clone_polyline = clonePolyline(shape);
+		let clone_polyline = this.clonePolyline(shape);
 		return clone_polyline;
 	} else if (shape.type === google.maps.drawing.OverlayType.POLYGON) {
-		var clone_polygon = clonePolygon(shape);
+		let clone_polygon = this.clonePolygon(shape);
 		return clone_polygon;
 	} else if (shape.type === google.maps.drawing.OverlayType.RECTANGLE) {
-		var clone_rect = cloneRectangle(shape);
+		let clone_rect = this.cloneRectangle(shape);
 		return clone_rect;
 
 	} else if (shape.type === google.maps.drawing.OverlayType.CIRCLE) {
-		var clone_circ = cloneCircle(shape);
+		let clone_circ = this.cloneCircle(shape);
 		return clone_circ;
 
 	} else {
-		var clone_marker = cloneMarker(shape);
+		let clone_marker = this.cloneMarker(shape);
 		return clone_marker;
 	}
 }
 
-function overlayItemIsShape(overlay_item) {
+MapEditorHistory.prototype.overlayItemIsShape = function(overlay_item){
 	var type = overlay_item.type;
 
@@ -263,12 +249,11 @@
 	return is_shape;
 }
-
-function historyOverlayPush() {
-	if (cycleComplete) {
+MapEditorHistory.prototype.historyOverlayPush = function(){
+	if (this.cycleComplete) {
 		var overlays_copy = [];
 		for (var i = 0; i < overlays.length; i++) {
-			var clone_shape = cloneShape(overlays[i]);
-
-			if (overlayItemIsShape(clone_shape)) {
+			let clone_shape = this.cloneShape(overlays[i]);
+
+			if (this.overlayItemIsShape(clone_shape)) {
 				addShapeListeners(clone_shape, null); // don't have an overlay event!
 			} else {
@@ -278,35 +263,33 @@
 		}
 		undoneOverlays = [];
-		prevOverlays.push(overlays_copy);
+		this.prevOverlays.push(overlays_copy);
 	}
 
 	cycleComplete = false;
 }
-function presentOverlayPush() {
-
-	OVbeforeClearing = overlays;
-	PObeforeClearing = presentOverlays;
-	presentOverlays = [];
+
+MapEditorHistory.prototype.presentOverlayPush = function(){
+	this.presentOverlays = [];
 	var overlays_copy = [];
 	for (var i = 0; i < overlays.length; i++) {
-		var clone_shape = cloneShape(overlays[i]);
-		if (overlayItemIsShape(clone_shape)) {
+		let clone_shape = this.cloneShape(overlays[i]);
+		if (this.overlayItemIsShape(clone_shape)) {
 			addShapeListeners(clone_shape, null); // don't have an overlay event!
 		} else {
-			addMarkerListeners(clone_shape, null); // don't have an overlay event!
+			this.addMarkerListeners(clone_shape, null); // don't have an overlay event!
 		}
 		overlays_copy[i] = clone_shape;
 	}
-	presentOverlays.push(overlays_copy);
+	this.presentOverlays.push(overlays_copy);
 	cycleComplete = true;
 
 }
 
-function undoneOverlaysPush() {
-
+MapEditorHistory.prototype.undoneOverlaysPush = function(){
+presentOverlayPush
 	var conditionUndone = presentOverlays[presentOverlays.length - 1] !== undefined;
 
 	if (conditionUndone) {
-		var overlays_copy = [];
+		let overlays_copy = [];
 		for (var i = 0; i < presentOverlays[0].length; i++) {
 			var clone_shape = cloneShape(presentOverlays[0][i]);
@@ -327,5 +310,5 @@
 		var overlays_copy = [];
 		for (var i = 0; i < prevOverlays[prevOverlays.length - 1].length; i++) {
-			var clone_shape = cloneShape(prevOverlays[prevOverlays.length - 1][i]);
+			let clone_shape = cloneShape(prevOverlays[prevOverlays.length - 1][i]);
 			if (overlayItemIsShape(clone_shape)) {
 				addShapeListeners(clone_shape, null); // don't have an overlay event!
@@ -342,11 +325,11 @@
 MapEditorHistory.prototype.undoneOverlaysPush = function() {
 
-	var conditionUndone = this.presentOverlays[this.presentOverlays.length - 1] !== undefined;
+	let conditionUndone = this.presentOverlays[this.presentOverlays.length - 1] !== undefined;
 
 	if (conditionUndone) {
 		var overlays_copy = [];
 		for (var i = 0; i < this.presentOverlays[0].length; i++) {
-			var clone_shape = cloneShape(this.presentOverlays[0][i]);
-			if (overlayItemIsShape(clone_shape)) {
+			let clone_shape = this.cloneShape(this.presentOverlays[0][i]);
+			if (this.overlayItemIsShape(clone_shape)) {
 				addShapeListeners(clone_shape, null); // don't have an overlay event!
 			} else {
@@ -358,12 +341,12 @@
 	}
 
-	var conditionPresent = this.prevOverlays[this.prevOverlays.length - 1] !== undefined;
+	let conditionPresent = this.prevOverlays[this.prevOverlays.length - 1] !== undefined;
 
 	if (conditionPresent) {
 		this.presentOverlays = [];
 		var overlays_copy = [];
-		for (var i = 0; i < this.prevOverlays[this.prevOverlays.length - 1].length; i++) {
-			var clone_shape = cloneShape(this.prevOverlays[this.prevOverlays.length - 1][i]);
-			if (overlayItemIsShape(clone_shape)) {
+		for (let i = 0; i < this.prevOverlays[this.prevOverlays.length - 1].length; i++) {
+			var clone_shape = this.cloneShape(this.prevOverlays[this.prevOverlays.length - 1][i]);
+			if (this.overlayItemIsShape(clone_shape)) {
 				addShapeListeners(clone_shape, null); // don't have an overlay event!
 			} else {
Index: main/trunk/greenstone3/web/interfaces/default/js/map-scripts-editor.js
===================================================================
--- main/trunk/greenstone3/web/interfaces/default/js/map-scripts-editor.js	(revision 32768)
+++ main/trunk/greenstone3/web/interfaces/default/js/map-scripts-editor.js	(revision 32769)
@@ -176,5 +176,5 @@
 			if (resizable) {
 				if(dontResize == false){
-					historyOverlayPush();
+					mapEditorHistory.historyOverlayPush();
 				}
 				
@@ -187,5 +187,5 @@
 
 	if (selectedShapes.length > 0) {
-		historyOverlayPush();
+		mapEditorHistory.historyOverlayPush();
 	}
 }
@@ -193,5 +193,5 @@
 function shapeSpecsChangeMU() {
 	if (selectedShapes.length > 0) {
-		presentOverlayPush();
+		mapEditorHistory.presentOverlayPush ();
 	}
 }
@@ -309,9 +309,9 @@
 	google.maps.event.addListener(drawingManager, 'overlaycomplete', function (e) {
 		allowDeselect = true;
-		historyOverlayPush();
+		mapEditorHistory.historyOverlayPush();
 		overlays.push(e.overlay); // store reference to added overlay
 		var newShape = e.overlay;
 		newShape.type = e.type;
-		presentOverlayPush();
+		mapEditorHistory.presentOverlayPush();
 
 		if (e.type !== google.maps.drawing.OverlayType.MARKER) {
@@ -348,10 +348,11 @@
 	document.addEventListener('keydown', function () {
 		if (event.code == 'KeyY' && (event.ctrlKey || event.metaKey) || (event.code == 'KeyZ' && event.code == 'ShiftLeft' && (event.ctrlKey || event.metaKey))) {
-			redo();
+			mapEditorHistory.redo();
 		}
 		if (event.code == 'KeyZ' && (event.ctrlKey || event.metaKey)) {
 			if (shiftKeyPressed == false) {
-				undo();
-				mapEditorHistory.undo(overlays); // ***** when we only have MapEditorHistory as a class
+				//undo();
+				mapEditorHistory.undo();
+				//mapEditorHistory.undo(overlays, draggableState); // ***** when we only have MapEditorHistory as a class
 				//that.mapEditorHistory.undo(that.overlays); // ***** when we have both MapEditorHistory and MapEditor as classes
 				
@@ -436,5 +437,5 @@
 	google.maps.event.addListener(newShape, 'dragstart', function (e) {
 		beingDragged = true;
-		historyOverlayPush();
+		mapEditorHistory.historyOverlayPush();
 
 	});
@@ -442,5 +443,5 @@
 	google.maps.event.addListener(newShape, 'dragend', function () {
 		beingDragged = false;
-		presentOverlayPush();
+		mapEditorHistory.presentOverlayPush ();
 		allowDeselect = false;
 	});
@@ -458,5 +459,5 @@
 	google.maps.event.addListener(newShape, 'dragstart', function (e) {
 		allowDeselect = false;
-		historyOverlayPush();
+		mapEditorHistory.historyOverlayPush();
 	});
 
@@ -465,5 +466,5 @@
 	google.maps.event.addListener(newShape, 'dragend', function () {
 		beingDragged = false;
-		presentOverlayPush();
+		mapEditorHistory.presentOverlayPush ();
 		settingThePath();
 		
@@ -475,5 +476,5 @@
 	google.maps.event.addListener(newShape, 'bounds_changed', function (e) {
 		if (beingDragged == false) {
-			presentOverlayPush();
+			mapEditorHistory.presentOverlayPush ();
 		}
 	});
@@ -485,5 +486,5 @@
 		}
 		if (e.vertex !== undefined || e.edge !== undefined) {
-			historyOverlayPush()
+			mapEditorHistory.historyOverlayPush()
 		}
 		if (drawingManager.drawingMode == null) {
@@ -494,5 +495,5 @@
 	google.maps.event.addListener(newShape, 'mouseup', function (e) {
 		if (e.vertex !== undefined || e.edge !== undefined) {
-			presentOverlayPush()
+			mapEditorHistory.presentOverlayPush ()
 		} else {
 			//setSelection(newShape, e);
@@ -572,5 +573,5 @@
 function setSelectedThickness(sWeight) {
 	if (selectedShapes.length > 0) {
-		//historyOverlayPush();
+		//mapEditorHistory.historyOverlayPush();
 		for (var i = 0; i < selectedShapes.length; i++) {
 			selectedShapes[i].set('strokeWeight', sWeight);
@@ -636,7 +637,7 @@
 
 function printHistory() {
-	console.log("prev", prevOverlays);
-	console.log("present ", presentOverlays);
-	console.log("undone ", undoneOverlays);
+	console.log("prev", mapEditorHistory.prevOverlays);
+	console.log("present ", mapEditorHistory.presentOverlays);
+	console.log("undone ", mapEditorHistory.undoneOverlays);
 	console.log(mouseState);
 }
@@ -668,5 +669,5 @@
 function deleteSelectedShape() {
 	//console.log("this fires");
-	historyOverlayPush();
+	mapEditorHistory.historyOverlayPush();
 	for (var i = 0; i < selectedShapes.length; i++) {
 		selectedShapes[i].setMap(null);
@@ -680,5 +681,5 @@
 	selectedShapes = [];
 	//console.log("this fires");
-	presentOverlayPush();
+	mapEditorHistory.presentOverlayPush ();
 }
 
@@ -686,5 +687,5 @@
 	console.log(nId);
 	//console.log("this fires");
-	historyOverlayPush();
+	mapEditorHistory.historyOverlayPush();
 	for (var i = 0; i < overlays.length; i++) {
 		overlays[i].setMap(null);
@@ -692,4 +693,4 @@
 	overlays = [];
 	//console.log("this fires");
-	presentOverlayPush();
-}
+	mapEditorHistory.presentOverlayPush ();
+}
