move 4 global variables into Metamaps namespace

This commit is contained in:
Devin Howard 2016-02-23 19:04:30 +08:00
parent 59f84cfe20
commit 09ceb8ceec
2 changed files with 37 additions and 35 deletions

View file

@ -869,9 +869,9 @@ Metamaps.JIT = {
} }
// if it's a right click or holding down alt, start synapse creation ->third option is for firefox // if it's a right click or holding down alt, start synapse creation ->third option is for firefox
else if ((e.button == 2 || (e.button == 0 && e.altKey) || e.buttons == 2) && authorized) { else if ((e.button == 2 || (e.button == 0 && e.altKey) || e.buttons == 2) && authorized) {
if (tempInit == false) { if (Metamaps.tempInit == false) {
tempNode = node; Metamaps.tempNode = node;
tempInit = true; Metamaps.tempInit = true;
Metamaps.Create.newTopic.hide(); Metamaps.Create.newTopic.hide();
Metamaps.Create.newSynapse.hide(); Metamaps.Create.newSynapse.hide();
@ -887,8 +887,8 @@ Metamaps.JIT = {
} }
} else { } else {
Metamaps.Mouse.synapseStartCoordinates = [{ Metamaps.Mouse.synapseStartCoordinates = [{
x: tempNode.pos.getc().x, x: Metamaps.tempNode.pos.getc().x,
y: tempNode.pos.getc().y y: Metamaps.tempNode.pos.getc().y
}]; }];
} }
Metamaps.Mouse.synapseEndCoordinates = { Metamaps.Mouse.synapseEndCoordinates = {
@ -899,11 +899,11 @@ Metamaps.JIT = {
// //
temp = eventInfo.getNode(); temp = eventInfo.getNode();
if (temp != false && temp.id != node.id && Metamaps.Selected.Nodes.indexOf(temp) == -1) { // this means a Node has been returned if (temp != false && temp.id != node.id && Metamaps.Selected.Nodes.indexOf(temp) == -1) { // this means a Node has been returned
tempNode2 = temp; Metamaps.tempNode2 = temp;
Metamaps.Mouse.synapseEndCoordinates = { Metamaps.Mouse.synapseEndCoordinates = {
x: tempNode2.pos.getc().x, x: Metamaps.tempNode2.pos.getc().x,
y: tempNode2.pos.getc().y y: Metamaps.tempNode2.pos.getc().y
}; };
// before making the highlighted one bigger, make sure all the others are regular size // before making the highlighted one bigger, make sure all the others are regular size
@ -913,7 +913,7 @@ Metamaps.JIT = {
temp.setData('dim', 35, 'current'); temp.setData('dim', 35, 'current');
Metamaps.Visualize.mGraph.plot(); Metamaps.Visualize.mGraph.plot();
} else if (!temp) { } else if (!temp) {
tempNode2 = null; Metamaps.tempNode2 = null;
Metamaps.Visualize.mGraph.graph.eachNode(function (n) { Metamaps.Visualize.mGraph.graph.eachNode(function (n) {
n.setData('dim', 25, 'current'); n.setData('dim', 25, 'current');
}); });
@ -941,10 +941,10 @@ Metamaps.JIT = {
} }
}, // onDragMoveTopicHandler }, // onDragMoveTopicHandler
onDragCancelHandler: function (node, eventInfo, e) { onDragCancelHandler: function (node, eventInfo, e) {
tempNode = null; Metamaps.tempNode = null;
if (tempNode2) tempNode2.setData('dim', 25, 'current'); if (Metamaps.tempNode2) Metamaps.tempNode2.setData('dim', 25, 'current');
tempNode2 = null; Metamaps.tempNode2 = null;
tempInit = false; Metamaps.tempInit = false;
// reset the draw synapse positions to false // reset the draw synapse positions to false
Metamaps.Mouse.synapseStartCoordinates = []; Metamaps.Mouse.synapseStartCoordinates = [];
Metamaps.Mouse.synapseEndCoordinates = null; Metamaps.Mouse.synapseEndCoordinates = null;
@ -953,27 +953,27 @@ Metamaps.JIT = {
onDragEndTopicHandler: function (node, eventInfo, e) { onDragEndTopicHandler: function (node, eventInfo, e) {
var midpoint = {}, pixelPos, mapping; var midpoint = {}, pixelPos, mapping;
if (tempInit && tempNode2 == null) { if (Metamaps.tempInit && Metamaps.tempNode2 == null) {
// this means you want to add a new topic, and then a synapse // this means you want to add a new topic, and then a synapse
Metamaps.Create.newTopic.addSynapse = true; Metamaps.Create.newTopic.addSynapse = true;
Metamaps.Create.newTopic.open(); Metamaps.Create.newTopic.open();
} else if (tempInit && tempNode2 != null) { } else if (Metamaps.tempInit && Metamaps.tempNode2 != null) {
// this means you want to create a synapse between two existing topics // this means you want to create a synapse between two existing topics
Metamaps.Create.newTopic.addSynapse = false; Metamaps.Create.newTopic.addSynapse = false;
Metamaps.Create.newSynapse.topic1id = tempNode.getData('topic').id; Metamaps.Create.newSynapse.topic1id = Metamaps.tempNode.getData('topic').id;
Metamaps.Create.newSynapse.topic2id = tempNode2.getData('topic').id; Metamaps.Create.newSynapse.topic2id = Metamaps.tempNode2.getData('topic').id;
tempNode2.setData('dim', 25, 'current'); Metamaps.tempNode2.setData('dim', 25, 'current');
Metamaps.Visualize.mGraph.plot(); Metamaps.Visualize.mGraph.plot();
midpoint.x = tempNode.pos.getc().x + (tempNode2.pos.getc().x - tempNode.pos.getc().x) / 2; midpoint.x = Metamaps.tempNode.pos.getc().x + (Metamaps.tempNode2.pos.getc().x - Metamaps.tempNode.pos.getc().x) / 2;
midpoint.y = tempNode.pos.getc().y + (tempNode2.pos.getc().y - tempNode.pos.getc().y) / 2; midpoint.y = Metamaps.tempNode.pos.getc().y + (Metamaps.tempNode2.pos.getc().y - Metamaps.tempNode.pos.getc().y) / 2;
pixelPos = Metamaps.Util.coordsToPixels(midpoint); pixelPos = Metamaps.Util.coordsToPixels(midpoint);
$('#new_synapse').css('left', pixelPos.x + "px"); $('#new_synapse').css('left', pixelPos.x + "px");
$('#new_synapse').css('top', pixelPos.y + "px"); $('#new_synapse').css('top', pixelPos.y + "px");
Metamaps.Create.newSynapse.open(); Metamaps.Create.newSynapse.open();
tempNode = null; Metamaps.tempNode = null;
tempNode2 = null; Metamaps.tempNode2 = null;
tempInit = false; Metamaps.tempInit = false;
} else if (!tempInit && node && !node.nodeFrom) { } else if (!Metamaps.tempInit && node && !node.nodeFrom) {
// this means you dragged an existing node, autosave that to the database // this means you dragged an existing node, autosave that to the database
// check whether to save mappings // check whether to save mappings
@ -1052,9 +1052,9 @@ Metamaps.JIT = {
// reset the draw synapse positions to false // reset the draw synapse positions to false
Metamaps.Mouse.synapseStartCoordinates = []; Metamaps.Mouse.synapseStartCoordinates = [];
Metamaps.Mouse.synapseEndCoordinates = null; Metamaps.Mouse.synapseEndCoordinates = null;
tempInit = false; Metamaps.tempInit = false;
tempNode = null; Metamaps.tempNode = null;
tempNode2 = null; Metamaps.tempNode2 = null;
if (!e.ctrlKey && !e.shiftKey) { if (!e.ctrlKey && !e.shiftKey) {
Metamaps.Control.deselectAllEdges(); Metamaps.Control.deselectAllEdges();
Metamaps.Control.deselectAllNodes(); Metamaps.Control.deselectAllNodes();
@ -1693,8 +1693,8 @@ Metamaps.JIT = {
easing = 1; // frictional value easing = 1; // frictional value
easing = 1; easing = 1;
window.clearInterval(panningInt) window.clearInterval(Metamaps.panningInt)
panningInt = setInterval(function () { Metamaps.panningInt = setInterval(function () {
myTimer() myTimer()
}, 1); }, 1);
@ -1703,7 +1703,7 @@ Metamaps.JIT = {
$(document).trigger(Metamaps.JIT.events.pan); $(document).trigger(Metamaps.JIT.events.pan);
easing = easing * 0.75; easing = easing * 0.75;
if (easing < 0.1) window.clearInterval(panningInt); if (easing < 0.1) window.clearInterval(Metamaps.panningInt);
} }
}, // SmoothPanning }, // SmoothPanning
renderMidArrow: function (from, to, dim, swap, canvas, placement, newSynapse) { renderMidArrow: function (from, to, dim, swap, canvas, placement, newSynapse) {

View file

@ -14,11 +14,13 @@ var labelType, useGradients, nativeTextSupport, animate;
animate = !(iStuff || !nativeCanvasSupport); animate = !(iStuff || !nativeCanvasSupport);
})(); })();
// TODO eliminate these 4 global variables // TODO eliminate these 4 top-level variables
var panningInt; // this variable is used to store a 'setInterval' for the Metamaps.JIT.SmoothPanning() function, so that it can be cleared with window.clearInterval Metamaps = {
var tempNode = null, panningInt: null,
tempInit = false, tempNode: null,
tempNode2 = null; tempInit: false,
tempNode2: null
}
Metamaps.Settings = { Metamaps.Settings = {
embed: false, // indicates that the app is on a page that is optimized for embedding in iFrames on other web pages embed: false, // indicates that the app is on a page that is optimized for embedding in iFrames on other web pages