ability to switch metacode sets from mapping page

This commit is contained in:
Connor Turland 2014-06-04 15:24:16 -04:00
parent c1de3abf28
commit a46d097da9
51 changed files with 4638 additions and 4460 deletions

View file

Before

Width:  |  Height:  |  Size: 180 B

After

Width:  |  Height:  |  Size: 180 B

View file

Before

Width:  |  Height:  |  Size: 178 B

After

Width:  |  Height:  |  Size: 178 B

View file

Before

Width:  |  Height:  |  Size: 120 B

After

Width:  |  Height:  |  Size: 120 B

View file

Before

Width:  |  Height:  |  Size: 105 B

After

Width:  |  Height:  |  Size: 105 B

View file

Before

Width:  |  Height:  |  Size: 111 B

After

Width:  |  Height:  |  Size: 111 B

View file

Before

Width:  |  Height:  |  Size: 110 B

After

Width:  |  Height:  |  Size: 110 B

View file

Before

Width:  |  Height:  |  Size: 119 B

After

Width:  |  Height:  |  Size: 119 B

View file

Before

Width:  |  Height:  |  Size: 101 B

After

Width:  |  Height:  |  Size: 101 B

View file

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

View file

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

View file

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

View file

Before

Width:  |  Height:  |  Size: 4.3 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 263 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

View file

@ -1,38 +1,38 @@
function selectEdgeOnClickHandler(adj, e) { function selectEdgeOnClickHandler(adj, e) {
if (Mconsole.busy) return; if (Mconsole.busy) return;
// catch right click on mac, which is often like ctrl+click // catch right click on mac, which is often like ctrl+click
if (navigator.platform.indexOf("Mac")!=-1 && e.ctrlKey) { if (navigator.platform.indexOf("Mac") != -1 && e.ctrlKey) {
selectEdgeOnRightClickHandler(adj, e) selectEdgeOnRightClickHandler(adj, e)
return; return;
} }
if (synapseWasDoubleClicked()) { if (synapseWasDoubleClicked()) {
synapseDoubleClickHandler(adj, e); synapseDoubleClickHandler(adj, e);
return; return;
} }
var edgeIsSelected = MetamapsModel.selectedEdges.indexOf(adj); var edgeIsSelected = MetamapsModel.selectedEdges.indexOf(adj);
if (edgeIsSelected == -1) edgeIsSelected = false; if (edgeIsSelected == -1) edgeIsSelected = false;
else if (edgeIsSelected != -1) edgeIsSelected = true; else if (edgeIsSelected != -1) edgeIsSelected = true;
if (edgeIsSelected && e.shiftKey) { if (edgeIsSelected && e.shiftKey) {
//deselecting an edge with shift //deselecting an edge with shift
deselectEdge(adj); deselectEdge(adj);
} else if (!edgeIsSelected && e.shiftKey) { } else if (!edgeIsSelected && e.shiftKey) {
//selecting an edge with shift //selecting an edge with shift
selectEdge(adj); selectEdge(adj);
} else if (edgeIsSelected && !e.shiftKey) { } else if (edgeIsSelected && !e.shiftKey) {
//deselecting an edge without shift - unselect all //deselecting an edge without shift - unselect all
deselectAllEdges(); deselectAllEdges();
} else if (!edgeIsSelected && !e.shiftKey) { } else if (!edgeIsSelected && !e.shiftKey) {
//selecting an edge without shift - unselect all but new one //selecting an edge without shift - unselect all but new one
deselectAllEdges(); deselectAllEdges();
selectEdge(adj); selectEdge(adj);
} }
Mconsole.plot(); Mconsole.plot();
}//selectEdgeOnClickHandler } //selectEdgeOnClickHandler
function selectEdgeOnRightClickHandler(adj, e) { function selectEdgeOnRightClickHandler(adj, e) {
// the 'node' variable is a JIT node, the one that was clicked on // the 'node' variable is a JIT node, the one that was clicked on
@ -58,12 +58,12 @@ function selectEdgeOnRightClickHandler(adj, e) {
if (mapid && userid != null) menustring += '<li class="rc-remove">Remove from map</li>'; if (mapid && userid != null) menustring += '<li class="rc-remove">Remove from map</li>';
menustring += '<li class="rc-hide">Hide until refresh</li>'; menustring += '<li class="rc-hide">Hide until refresh</li>';
if (userid) { if (userid) {
var options = '<ul><li class="changeP toCommons">commons</li> \ var options = '<ul><li class="changeP toCommons">commons</li> \
<li class="changeP toPublic">public</li> \ <li class="changeP toPublic">public</li> \
<li class="changeP toPrivate">private</li> \ <li class="changeP toPrivate">private</li> \
</ul>'; </ul>';
menustring += '<li class="rc-permission">Change permissions' + options + '</li>'; menustring += '<li class="rc-permission">Change permissions' + options + '</li>';
} }
menustring += '</ul>'; menustring += '</ul>';
@ -71,8 +71,8 @@ function selectEdgeOnRightClickHandler(adj, e) {
// position the menu where the click happened // position the menu where the click happened
$(rightclickmenu).css({ $(rightclickmenu).css({
left: e.clientX, left: e.clientX,
top: e.clientY top: e.clientY
}); });
//add the menu to the page //add the menu to the page
$('#center-container').append(rightclickmenu); $('#center-container').append(rightclickmenu);
@ -81,162 +81,162 @@ function selectEdgeOnRightClickHandler(adj, e) {
// attach events to clicks on the list items // attach events to clicks on the list items
// delete the selected things from the database // delete the selected things from the database
$('.rc-delete').click(function() { $('.rc-delete').click(function () {
$('.rightclickmenu').remove(); $('.rightclickmenu').remove();
var n = MetamapsModel.selectedNodes.length; var n = MetamapsModel.selectedNodes.length;
var e = MetamapsModel.selectedEdges.length; var e = MetamapsModel.selectedEdges.length;
var ntext = n == 1 ? "1 topic" : n + " topics"; var ntext = n == 1 ? "1 topic" : n + " topics";
var etext = e == 1 ? "1 synapse" : e + " synapses"; var etext = e == 1 ? "1 synapse" : e + " synapses";
var text = "You have " + ntext + " and " + etext + " selected. "; var text = "You have " + ntext + " and " + etext + " selected. ";
var r=confirm(text + "Are you sure you want to permanently delete them all? This will remove them from all maps they appear on."); var r = confirm(text + "Are you sure you want to permanently delete them all? This will remove them from all maps they appear on.");
if (r == true) { if (r == true) {
deleteSelectedEdges(); deleteSelectedEdges();
deleteSelectedNodes(); deleteSelectedNodes();
} }
}); });
// remove the selected things from the map // remove the selected things from the map
$('.rc-remove').click(function() { $('.rc-remove').click(function () {
$('.rightclickmenu').remove(); $('.rightclickmenu').remove();
removeSelectedEdges(); removeSelectedEdges();
removeSelectedNodes(); removeSelectedNodes();
}); });
// hide selected nodes and synapses until refresh // hide selected nodes and synapses until refresh
$('.rc-hide').click(function() { $('.rc-hide').click(function () {
$('.rightclickmenu').remove(); $('.rightclickmenu').remove();
hideSelectedEdges(); hideSelectedEdges();
hideSelectedNodes(); hideSelectedNodes();
}); });
// change the permission of all the selected nodes and synapses that you were the originator of // change the permission of all the selected nodes and synapses that you were the originator of
$('.rc-permission li').click(function() { $('.rc-permission li').click(function () {
$('.rightclickmenu').remove(); $('.rightclickmenu').remove();
// $(this).text() will be 'commons' 'public' or 'private' // $(this).text() will be 'commons' 'public' or 'private'
updateSelectedPermissions( $(this).text() ); updateSelectedPermissions($(this).text());
}); });
} //selectEdgeOnRightClickHandler } //selectEdgeOnRightClickHandler
function synapseDoubleClickHandler(adj, e) { function synapseDoubleClickHandler(adj, e) {
editEdge(adj, e); editEdge(adj, e);
} }
/* /*
* Returns a boolean saying if the synapse was double clicked in our understanding of the word * Returns a boolean saying if the synapse was double clicked in our understanding of the word
*/ */
function synapseWasDoubleClicked() { function synapseWasDoubleClicked() {
//grab the timestamp of the click //grab the timestamp of the click
var storedTime = MetamapsModel.lastSynapseClick; var storedTime = MetamapsModel.lastSynapseClick;
var now = Date.now(); //not compatible with IE8 FYI var now = Date.now(); //not compatible with IE8 FYI
MetamapsModel.lastSynapseClick = now; MetamapsModel.lastSynapseClick = now;
if (now - storedTime < MetamapsModel.DOUBLE_CLICK_TOLERANCE) { if (now - storedTime < MetamapsModel.DOUBLE_CLICK_TOLERANCE) {
return true; return true;
} else { } else {
return false; return false;
} }
}//synapseWasDoubleClicked; } //synapseWasDoubleClicked;
function nodeDoubleClickHandler(node, e) { function nodeDoubleClickHandler(node, e) {
openNodeShowcard(node); openNodeShowcard(node);
} }
function enterKeyHandler(event) { function enterKeyHandler(event) {
//var selectedNodesCopy = MetamapsModel.selectedNodes.slice(0); //var selectedNodesCopy = MetamapsModel.selectedNodes.slice(0);
//var len = selectedNodesCopy.length; //var len = selectedNodesCopy.length;
//for (var i = 0; i < len; i += 1) { //for (var i = 0; i < len; i += 1) {
// n = selectedNodesCopy[i]; // n = selectedNodesCopy[i];
// keepFromCommons(n); // keepFromCommons(n);
//}//for //}//for
//Mconsole.plot(); //Mconsole.plot();
}//enterKeyHandler } //enterKeyHandler
function escKeyHandler() { function escKeyHandler() {
deselectAllEdges(); deselectAllEdges();
deselectAllNodes(); deselectAllNodes();
}//escKeyHandler } //escKeyHandler
/* /*
* Make a node "in the commons" (with a green circle) lose its * Make a node "in the commons" (with a green circle) lose its
* green circle so it stays on the console/map/... * green circle so it stays on the console/map/...
*/ */
function keepFromCommons(event, id) { function keepFromCommons(event, id) {
if (userid == null) { if (userid == null) {
return; return;
} }
$('#topic_addSynapse').val("false"); $('#topic_addSynapse').val("false");
$('#topic_x').val(0); $('#topic_x').val(0);
$('#topic_y').val(0); $('#topic_y').val(0);
$('#topic_grabTopic').val(id); $('#topic_grabTopic').val(id);
$('.new_topic').submit(); $('.new_topic').submit();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
return false; return false;
}//doubleClickNodeHandler } //doubleClickNodeHandler
/* /*
* Returns a boolean saying if the node was double clicked in our understanding of the word * Returns a boolean saying if the node was double clicked in our understanding of the word
*/ */
function nodeWasDoubleClicked() { function nodeWasDoubleClicked() {
//grab the timestamp of the click //grab the timestamp of the click
var storedTime = MetamapsModel.lastNodeClick; var storedTime = MetamapsModel.lastNodeClick;
var now = Date.now(); //not compatible with IE8 FYI var now = Date.now(); //not compatible with IE8 FYI
MetamapsModel.lastNodeClick = now; MetamapsModel.lastNodeClick = now;
if (now - storedTime < MetamapsModel.DOUBLE_CLICK_TOLERANCE) { if (now - storedTime < MetamapsModel.DOUBLE_CLICK_TOLERANCE) {
return true; return true;
} else { } else {
return false; return false;
} }
}//nodeWasDoubleClicked; } //nodeWasDoubleClicked;
function selectNodeOnClickHandler(node, e) { function selectNodeOnClickHandler(node, e) {
if (Mconsole.busy) return; if (Mconsole.busy) return;
// catch right click on mac, which is often like ctrl+click // catch right click on mac, which is often like ctrl+click
if (navigator.platform.indexOf("Mac")!=-1 && e.ctrlKey) { if (navigator.platform.indexOf("Mac") != -1 && e.ctrlKey) {
selectNodeOnRightClickHandler(node, e) selectNodeOnRightClickHandler(node, e)
return; return;
} }
var check = nodeWasDoubleClicked(); var check = nodeWasDoubleClicked();
if (check) { if (check) {
nodeDoubleClickHandler(node, e); nodeDoubleClickHandler(node, e);
return; return;
} else { } else {
// wait a certain length of time, then check again, then run this code // wait a certain length of time, then check again, then run this code
setTimeout(function() { setTimeout(function () {
if (!nodeWasDoubleClicked()) { if (!nodeWasDoubleClicked()) {
if (!e.shiftKey) { if (!e.shiftKey) {
Mconsole.graph.eachNode(function (n) { Mconsole.graph.eachNode(function (n) {
if (n.id != node.id) { if (n.id != node.id) {
deselectNode(n); deselectNode(n);
} }
}); });
} }
if (node.selected) { if (node.selected) {
deselectNode(node); deselectNode(node);
} else { } else {
selectNode(node); selectNode(node);
} }
//trigger animation to final styles //trigger animation to final styles
Mconsole.fx.animate({ Mconsole.fx.animate({
modes: ['edge-property:lineWidth:color:alpha'], modes: ['edge-property:lineWidth:color:alpha'],
duration: 500 duration: 500
}); });
Mconsole.plot(); Mconsole.plot();
} }
}, MetamapsModel.DOUBLE_CLICK_TOLERANCE); }, MetamapsModel.DOUBLE_CLICK_TOLERANCE);
} }
}//selectNodeOnClickHandler } //selectNodeOnClickHandler
function selectNodeOnRightClickHandler(node, e) { function selectNodeOnRightClickHandler(node, e) {
// the 'node' variable is a JIT node, the one that was clicked on // the 'node' variable is a JIT node, the one that was clicked on
// the 'e' variable is the click event // the 'e' variable is the click event
@ -263,12 +263,12 @@ function selectNodeOnClickHandler(node, e) {
if (!mapid) menustring += '<li class="rc-center">Center this topic</li>'; if (!mapid) menustring += '<li class="rc-center">Center this topic</li>';
menustring += '<li class="rc-popout">Open in new tab</li>'; menustring += '<li class="rc-popout">Open in new tab</li>';
if (userid) { if (userid) {
var options = '<ul><li class="changeP toCommons">commons</li> \ var options = '<ul><li class="changeP toCommons">commons</li> \
<li class="changeP toPublic">public</li> \ <li class="changeP toPublic">public</li> \
<li class="changeP toPrivate">private</li> \ <li class="changeP toPrivate">private</li> \
</ul>'; </ul>';
menustring += '<li class="rc-permission">Change permissions' + options + '</li>'; menustring += '<li class="rc-permission">Change permissions' + options + '</li>';
} }
menustring += '</ul>'; menustring += '</ul>';
@ -276,8 +276,8 @@ function selectNodeOnClickHandler(node, e) {
// position the menu where the click happened // position the menu where the click happened
$(rightclickmenu).css({ $(rightclickmenu).css({
left: e.clientX, left: e.clientX,
top: e.clientY top: e.clientY
}); });
//add the menu to the page //add the menu to the page
$('#center-container').append(rightclickmenu); $('#center-container').append(rightclickmenu);
@ -286,259 +286,258 @@ function selectNodeOnClickHandler(node, e) {
// attach events to clicks on the list items // attach events to clicks on the list items
// delete the selected things from the database // delete the selected things from the database
$('.rc-delete').click(function() { $('.rc-delete').click(function () {
$('.rightclickmenu').remove(); $('.rightclickmenu').remove();
var n = MetamapsModel.selectedNodes.length; var n = MetamapsModel.selectedNodes.length;
var e = MetamapsModel.selectedEdges.length; var e = MetamapsModel.selectedEdges.length;
var ntext = n == 1 ? "1 topic" : n + " topics"; var ntext = n == 1 ? "1 topic" : n + " topics";
var etext = e == 1 ? "1 synapse" : e + " synapses"; var etext = e == 1 ? "1 synapse" : e + " synapses";
var text = "You have " + ntext + " and " + etext + " selected. "; var text = "You have " + ntext + " and " + etext + " selected. ";
var r=confirm(text + "Are you sure you want to permanently delete them all? This will remove them from all maps they appear on."); var r = confirm(text + "Are you sure you want to permanently delete them all? This will remove them from all maps they appear on.");
if (r == true) { if (r == true) {
deleteSelectedEdges(); deleteSelectedEdges();
deleteSelectedNodes(); deleteSelectedNodes();
} }
}); });
// remove the selected things from the map // remove the selected things from the map
$('.rc-remove').click(function() { $('.rc-remove').click(function () {
$('.rightclickmenu').remove(); $('.rightclickmenu').remove();
removeSelectedEdges(); removeSelectedEdges();
removeSelectedNodes(); removeSelectedNodes();
}); });
// hide selected nodes and synapses until refresh // hide selected nodes and synapses until refresh
$('.rc-hide').click(function() { $('.rc-hide').click(function () {
$('.rightclickmenu').remove(); $('.rightclickmenu').remove();
hideSelectedEdges(); hideSelectedEdges();
hideSelectedNodes(); hideSelectedNodes();
}); });
// when in radial, center on the topic you picked // when in radial, center on the topic you picked
$('.rc-center').click(function() { $('.rc-center').click(function () {
$('.rightclickmenu').remove(); $('.rightclickmenu').remove();
centerOn(node.id); centerOn(node.id);
}); });
// open the entity in a new tab // open the entity in a new tab
$('.rc-popout').click(function() { $('.rc-popout').click(function () {
$('.rightclickmenu').remove(); $('.rightclickmenu').remove();
var win=window.open('/topics/' + node.id, '_blank'); var win = window.open('/topics/' + node.id, '_blank');
win.focus(); win.focus();
}); });
// change the permission of all the selected nodes and synapses that you were the originator of // change the permission of all the selected nodes and synapses that you were the originator of
$('.rc-permission li').click(function() { $('.rc-permission li').click(function () {
$('.rightclickmenu').remove(); $('.rightclickmenu').remove();
// $(this).text() will be 'commons' 'public' or 'private' // $(this).text() will be 'commons' 'public' or 'private'
updateSelectedPermissions( $(this).text() ); updateSelectedPermissions($(this).text());
}); });
} //selectNodeOnRightClickHandler } //selectNodeOnRightClickHandler
function canvasDoubleClickHandler(canvasLoc,e) { function canvasDoubleClickHandler(canvasLoc, e) {
//grab the location and timestamp of the click //grab the location and timestamp of the click
var storedTime = MetamapsModel.lastCanvasClick; var storedTime = MetamapsModel.lastCanvasClick;
var now = Date.now(); //not compatible with IE8 FYI var now = Date.now(); //not compatible with IE8 FYI
MetamapsModel.lastCanvasClick = now; MetamapsModel.lastCanvasClick = now;
// if on a public map, disable topic creation // if on a public map, disable topic creation
if (userid && (mapperm || !mapid) ) { if (userid && (mapperm || !mapid)) {
if (now - storedTime < MetamapsModel.DOUBLE_CLICK_TOLERANCE) { if (now - storedTime < MetamapsModel.DOUBLE_CLICK_TOLERANCE) {
//pop up node creation :) //pop up node creation :)
$('#topic_grabTopic').val("null"); $('#topic_grabTopic').val("null");
$('#topic_addSynapse').val("false"); $('#topic_addSynapse').val("false");
$('#new_topic').css('left', e.clientX + "px"); $('#new_topic').css('left', e.clientX + "px");
$('#new_topic').css('top', e.clientY + "px"); $('#new_topic').css('top', e.clientY + "px");
$('#topic_x').val(canvasLoc.x); $('#topic_x').val(canvasLoc.x);
$('#topic_y').val(canvasLoc.y); $('#topic_y').val(canvasLoc.y);
$('#new_topic').fadeIn('fast'); $('#new_topic').fadeIn('fast');
$('#topic_name').typeahead('setQuery','').focus(); $('#topic_name').typeahead('setQuery', '').focus();
return; return;
} }
} }
if (!MetamapsModel.didPan) { if (!MetamapsModel.didPan) {
$('#new_topic').fadeOut('fast'); $('#new_topic').fadeOut('fast');
$('#new_synapse').fadeOut('fast'); $('#new_synapse').fadeOut('fast');
$('.rightclickmenu').remove(); $('.rightclickmenu').remove();
// reset the draw synapse positions to false // reset the draw synapse positions to false
MetamapsModel.synapseStartCoord = false; MetamapsModel.synapseStartCoord = false;
MetamapsModel.synapseEndCoord = false; MetamapsModel.synapseEndCoord = false;
deselectAllNodes(); deselectAllNodes();
tempInit = false; tempInit = false;
tempNode = null; tempNode = null;
tempNode2 = null; tempNode2 = null;
Mconsole.plot(); Mconsole.plot();
} }
}//canvasDoubleClickHandler } //canvasDoubleClickHandler
function handleSelectionBeforeDragging(node, e) { function handleSelectionBeforeDragging(node, e) {
// four cases: // four cases:
// 1 nothing is selected, so pretend you aren't selecting // 1 nothing is selected, so pretend you aren't selecting
// 2 others are selected only and shift, so additionally select this one // 2 others are selected only and shift, so additionally select this one
// 3 others are selected only, no shift: drag only this one // 3 others are selected only, no shift: drag only this one
// 4 this node and others were selected, so drag them (just return false) // 4 this node and others were selected, so drag them (just return false)
//return value: deselect node again after? //return value: deselect node again after?
if (MetamapsModel.selectedNodes.length == 0) { if (MetamapsModel.selectedNodes.length == 0) {
selectNode(node); selectNode(node);
return 'deselect'; return 'deselect';
}
if (MetamapsModel.selectedNodes.indexOf(node) == -1) {
if (e.shiftKey) {
selectNode(node);
return 'nothing';
} else {
return 'only-drag-this-one';
} }
} if (MetamapsModel.selectedNodes.indexOf(node) == -1) {
return 'nothing'; //case 4? if (e.shiftKey) {
selectNode(node);
return 'nothing';
} else {
return 'only-drag-this-one';
}
}
return 'nothing'; //case 4?
} }
function onDragMoveTopicHandler(node, eventInfo, e) { function onDragMoveTopicHandler(node, eventInfo, e) {
if (node && !node.nodeFrom) { if (node && !node.nodeFrom) {
$('#new_synapse').fadeOut('fast'); $('#new_synapse').fadeOut('fast');
$('#new_topic').fadeOut('fast'); $('#new_topic').fadeOut('fast');
var pos = eventInfo.getPos(); var pos = eventInfo.getPos();
// if it's a left click, or a touch, move the node var newPosComplex = new $jit.Complex(pos.x, pos.y);
if ( e.touches || (e.button == 0 && !e.altKey && (e.buttons == 0 || e.buttons == 1 || e.buttons == undefined))) { // if it's a left click, or a touch, move the node
//if the node dragged isn't already selected, select it if (e.touches || (e.button == 0 && !e.altKey && (e.buttons == 0 || e.buttons == 1 || e.buttons == undefined))) {
var whatToDo = handleSelectionBeforeDragging(node, e); //if the node dragged isn't already selected, select it
if (whatToDo == 'only-drag-this-one' || whatToDo == 'deselect') { var whatToDo = handleSelectionBeforeDragging(node, e);
if (gType == "centered") { if (whatToDo == 'only-drag-this-one' || whatToDo == 'deselect') {
var rho = Math.sqrt(pos.x * pos.x + pos.y * pos.y); if (gType == "centered") {
var theta = Math.atan2(pos.y, pos.x); var rho = Math.sqrt(pos.x * pos.x + pos.y * pos.y);
node.pos.setp(theta, rho); var theta = Math.atan2(pos.y, pos.x);
} node.pos.setp(theta, rho);
else { } else {
node.pos.setc(pos.x,pos.y); node.setPos(newPosComplex, 'start');
node.setData('xloc', pos.x); node.setPos(newPosComplex, 'current');
node.setData('yloc', pos.y); node.setPos(newPosComplex, 'end');
} node.setData('xloc', pos.x);
} else { node.setData('yloc', pos.y);
var len = MetamapsModel.selectedNodes.length; }
} else {
var len = MetamapsModel.selectedNodes.length;
//first define offset for each node //first define offset for each node
var xOffset = new Array(); var xOffset = new Array();
var yOffset = new Array(); var yOffset = new Array();
for (var i = 0; i < len; i += 1) { for (var i = 0; i < len; i += 1) {
var n = MetamapsModel.selectedNodes[i]; var n = MetamapsModel.selectedNodes[i];
if (gType == "centered") { if (gType == "centered") {
xOffset[i] = n.pos.toComplex().x - node.pos.toComplex().x; xOffset[i] = n.pos.toComplex().x - node.pos.toComplex().x;
yOffset[i] = n.pos.toComplex().y - node.pos.toComplex().y; yOffset[i] = n.pos.toComplex().y - node.pos.toComplex().y;
} } else {
else { xOffset[i] = n.pos.x - node.pos.x;
xOffset[i] = n.pos.x - node.pos.x; yOffset[i] = n.pos.y - node.pos.y;
yOffset[i] = n.pos.y - node.pos.y; }
} } //for
}//for
for (var i = 0; i < len; i += 1) { for (var i = 0; i < len; i += 1) {
var n = MetamapsModel.selectedNodes[i]; var n = MetamapsModel.selectedNodes[i];
if (gType == "centered") { if (gType == "centered") {
var x = pos.x + xOffset[i]; var x = pos.x + xOffset[i];
var y = pos.y + yOffset[i]; var y = pos.y + yOffset[i];
var rho = Math.sqrt(x * x + y * y); var rho = Math.sqrt(x * x + y * y);
var theta = Math.atan2(y, x); var theta = Math.atan2(y, x);
n.pos.setp(theta, rho); n.pos.setp(theta, rho);
} } else {
else { newPosComplex = new $jit.Complex(pos.x + xOffset[i], pos.y + yOffset[i]);
var x = pos.x + xOffset[i]; n.setPos(newPosComplex, 'start');
var y = pos.y + yOffset[i]; n.setPos(newPosComplex, 'current');
n.pos.setc(x,y); n.setPos(newPosComplex, 'end');
n.setData('xloc', pos.x); n.setData('xloc', pos.x + xOffset[i]);
n.setData('yloc', pos.y); n.setData('yloc', pos.y + yOffset[i]);
} }
n.setData('xloc', x); } //for
n.setData('yloc', y); } //if
}//for
}//if
if (whatToDo == 'deselect') { if (whatToDo == 'deselect') {
deselectNode(node); deselectNode(node);
} }
dragged = node.id; dragged = node.id;
Mconsole.plot(); Mconsole.plot();
} }
// 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) && userid != null) { else if ((e.button == 2 || (e.button == 0 && e.altKey) || e.buttons == 2) && userid != null) {
// if on a public map, disable synapse creation // if on a public map, disable synapse creation
if (mapid && !mapperm) return; if (mapid && !mapperm) return;
if (tempInit == false) { if (tempInit == false) {
tempNode = node; tempNode = node;
tempInit = true; tempInit = true;
// set the draw synapse start position // set the draw synapse start position
MetamapsModel.synapseStartCoord = { MetamapsModel.synapseStartCoord = {
x: node.pos.getc().x, x: node.pos.getc().x,
y: node.pos.getc().y y: node.pos.getc().y
}; };
} }
// //
temp = eventInfo.getNode(); temp = eventInfo.getNode();
if (temp != false && temp.id != node.id) { // this means a Node has been returned if (temp != false && temp.id != node.id) { // this means a Node has been returned
tempNode2 = temp; tempNode2 = temp;
// set the draw synapse end position // set the draw synapse end position
MetamapsModel.synapseEndCoord = { MetamapsModel.synapseEndCoord = {
x: temp.pos.getc().x, x: temp.pos.getc().x,
y: temp.pos.getc().y y: temp.pos.getc().y
}; };
Mconsole.plot(); Mconsole.plot();
// 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
Mconsole.graph.eachNode(function (n) { Mconsole.graph.eachNode(function (n) {
n.setData('dim', 25, 'current'); n.setData('dim', 25, 'current');
}); });
temp.setData('dim',35,'current'); temp.setData('dim', 35, 'current');
Mconsole.fx.plotNode(tempNode, Mconsole.canvas); Mconsole.fx.plotNode(tempNode, Mconsole.canvas);
Mconsole.fx.plotNode(temp, Mconsole.canvas); Mconsole.fx.plotNode(temp, Mconsole.canvas);
} else if (!temp) { } else if (!temp) {
tempNode2 = null; tempNode2 = null;
Mconsole.graph.eachNode(function (n) { Mconsole.graph.eachNode(function (n) {
n.setData('dim', 25, 'current'); n.setData('dim', 25, 'current');
}); });
//pop up node creation :) //pop up node creation :)
$('#topic_grabTopic').val("null"); $('#topic_grabTopic').val("null");
var myX = e.clientX - 110; var myX = e.clientX - 110;
var myY = e.clientY - 30; var myY = e.clientY - 30;
$('#new_topic').css('left',myX + "px"); $('#new_topic').css('left', myX + "px");
$('#new_topic').css('top',myY + "px"); $('#new_topic').css('top', myY + "px");
$('#new_synapse').css('left',myX + "px"); $('#new_synapse').css('left', myX + "px");
$('#new_synapse').css('top',myY + "px"); $('#new_synapse').css('top', myY + "px");
$('#topic_x').val(eventInfo.getPos().x); $('#topic_x').val(eventInfo.getPos().x);
$('#topic_y').val(eventInfo.getPos().y); $('#topic_y').val(eventInfo.getPos().y);
// set the draw synapse end position // set the draw synapse end position
MetamapsModel.synapseEndCoord = { MetamapsModel.synapseEndCoord = {
x: eventInfo.getPos().x, x: eventInfo.getPos().x,
y: eventInfo.getPos().y y: eventInfo.getPos().y
}; };
Mconsole.plot(); Mconsole.plot();
Mconsole.fx.plotNode(tempNode, Mconsole.canvas); Mconsole.fx.plotNode(tempNode, Mconsole.canvas);
} }
} }
} }
} }
var lastDist = 0; var lastDist = 0;
function getDistance(p1, p2) { function getDistance(p1, p2) {
return Math.sqrt(Math.pow((p2.x - p1.x), 2) + Math.pow((p2.y - p1.y), 2)); return Math.sqrt(Math.pow((p2.x - p1.x), 2) + Math.pow((p2.y - p1.y), 2));
} }
function touchPanZoomHandler(eventInfo, e) { function touchPanZoomHandler(eventInfo, e) {
if (e.touches.length == 1) { if (e.touches.length == 1) {
var thispos = touchPos, var thispos = touchPos,
currentPos = eventInfo.getPos(), currentPos = eventInfo.getPos(),
canvas = Mconsole.canvas, canvas = Mconsole.canvas,
ox = canvas.translateOffsetX, ox = canvas.translateOffsetX,
oy = canvas.translateOffsetY, oy = canvas.translateOffsetY,
sx = canvas.scaleOffsetX, sx = canvas.scaleOffsetX,
sy = canvas.scaleOffsetY; sy = canvas.scaleOffsetY;
currentPos.x *= sx; currentPos.x *= sx;
currentPos.y *= sy; currentPos.y *= sy;
currentPos.x += ox; currentPos.x += ox;
@ -548,38 +547,36 @@ function touchPanZoomHandler(eventInfo, e) {
var x = currentPos.x - thispos.x, var x = currentPos.x - thispos.x,
y = currentPos.y - thispos.y; y = currentPos.y - thispos.y;
touchPos = currentPos; touchPos = currentPos;
Mconsole.canvas.translate(x * 1/sx, y * 1/sy); Mconsole.canvas.translate(x * 1 / sx, y * 1 / sy);
} } else if (e.touches.length == 2) {
else if (e.touches.length == 2) {
var touch1 = e.touches[0]; var touch1 = e.touches[0];
var touch2 = e.touches[1]; var touch2 = e.touches[1];
var dist = getDistance({ var dist = getDistance({
x: touch1.clientX, x: touch1.clientX,
y: touch1.clientY y: touch1.clientY
}, { }, {
x: touch2.clientX, x: touch2.clientX,
y: touch2.clientY y: touch2.clientY
}); });
if(!lastDist) { if (!lastDist) {
lastDist = dist; lastDist = dist;
} }
var scale = dist / lastDist; var scale = dist / lastDist;
console.log(scale); console.log(scale);
if (8 >= Mconsole.canvas.scaleOffsetX*scale && Mconsole.canvas.scaleOffsetX*scale >= 1) { if (8 >= Mconsole.canvas.scaleOffsetX * scale && Mconsole.canvas.scaleOffsetX * scale >= 1) {
Mconsole.canvas.scale(scale, scale); Mconsole.canvas.scale(scale, scale);
} }
if (Mconsole.canvas.scaleOffsetX < 0.5) { if (Mconsole.canvas.scaleOffsetX < 0.5) {
Mconsole.canvas.viz.labels.hideLabels(true); Mconsole.canvas.viz.labels.hideLabels(true);
} } else if (Mconsole.canvas.scaleOffsetX > 0.5) {
else if (Mconsole.canvas.scaleOffsetX > 0.5) { Mconsole.canvas.viz.labels.hideLabels(false);
Mconsole.canvas.viz.labels.hideLabels(false); }
} lastDist = dist;
lastDist = dist;
} }
} }
@ -587,41 +584,42 @@ function touchPanZoomHandler(eventInfo, e) {
function updateSelectedPermissions(permission) { function updateSelectedPermissions(permission) {
if ( $('.notice.metamaps').length == 0 ) { if ($('.notice.metamaps').length == 0) {
$('body').prepend('<div class="notice metamaps" />'); $('body').prepend('<div class="notice metamaps" />');
}
$('.notice.metamaps').hide().html('Working...').fadeIn('fast');
// variables to keep track of how many nodes and synapses you had the ability to change the permission of
var nCount = 0, sCount = 0;
// change the permission of the selected synapses, if logged in user is the original creator
var l = MetamapsModel.selectedEdges.length;
for (var i = l-1; i >= 0; i -= 1) {
var edge = MetamapsModel.selectedEdges[i];
if (edge.getData('userid') == userid) {
updateSynapsePermission(edge,permission);
sCount++;
} }
} $('.notice.metamaps').hide().html('Working...').fadeIn('fast');
// change the permission of the selected topics, if logged in user is the original creator // variables to keep track of how many nodes and synapses you had the ability to change the permission of
var l = MetamapsModel.selectedNodes.length; var nCount = 0,
for (var i = l-1; i >= 0; i -= 1) { sCount = 0;
var node = MetamapsModel.selectedNodes[i];
if (node.getData('userid') == userid) { // change the permission of the selected synapses, if logged in user is the original creator
updateTopicPermission(node,permission); var l = MetamapsModel.selectedEdges.length;
nCount++; for (var i = l - 1; i >= 0; i -= 1) {
var edge = MetamapsModel.selectedEdges[i];
if (edge.getData('userid') == userid) {
updateSynapsePermission(edge, permission);
sCount++;
}
} }
}
var nString = nCount == 1 ? (nCount.toString() + ' topic and ') : (nCount.toString() + ' topics and '); // change the permission of the selected topics, if logged in user is the original creator
var sString = sCount == 1 ? (sCount.toString() + ' synapse') : (sCount.toString() + ' synapses'); var l = MetamapsModel.selectedNodes.length;
for (var i = l - 1; i >= 0; i -= 1) {
var node = MetamapsModel.selectedNodes[i];
$('.notice.metamaps').html(nString + sString + ' you created updated to ' + permission) if (node.getData('userid') == userid) {
setTimeout( function() { updateTopicPermission(node, permission);
$('.notice.metamaps').fadeOut('fast'); nCount++;
}, 8000); }
}
var nString = nCount == 1 ? (nCount.toString() + ' topic and ') : (nCount.toString() + ' topics and ');
var sString = sCount == 1 ? (sCount.toString() + ' synapse') : (sCount.toString() + ' synapses');
$('.notice.metamaps').html(nString + sString + ' you created updated to ' + permission)
setTimeout(function () {
$('.notice.metamaps').fadeOut('fast');
}, 8000);
} }

View file

@ -9,6 +9,18 @@ var MetamapsModel = new Object();
MetamapsModel.embed = false; MetamapsModel.embed = false;
MetamapsModel.metacodeScrollerInit = false; // indicates whether the scrollbar in the custom metacode set space has been init
MetamapsModel.selectedMetacodeSet = null;
MetamapsModel.selectedMetacodeSetIndex = null;
MetamapsModel.selectedMetacodeNames = new Array();
MetamapsModel.newSelectedMetacodeNames = new Array();
MetamapsModel.selectedMetacodes = new Array();
MetamapsModel.newSelectedMetacodes = new Array();
//array of all selected edges, same for nodes //array of all selected edges, same for nodes
MetamapsModel.selectedEdges = new Array(); MetamapsModel.selectedEdges = new Array();
MetamapsModel.selectedNodes = new Array(); MetamapsModel.selectedNodes = new Array();

File diff suppressed because it is too large Load diff

View file

@ -1,302 +0,0 @@
/*
* @file
* There is a lot of code that goes into creating the "label" of a node
* This includes editable cards with all node details, and some controls
* onCreateLabelHandler is the main function of this file, and the file
* also contains a bunch of helper functions
*
* html and littleHTML are potentially confusing variables
* html is the contents of the card shown when you click on a node's label.
* littleHTML creates little controls for removing/hiding nodes from the canvas
*
* This function features PHP-style variable substitution because the strings
* are so damn long. Values are identified by $_id_$, and then a regular
* expression is substituted in later (for html, in a separate function).
*/
function generateShowcardHTML() {
return ' \
<div class="CardOnGraph" \
id="topic_$_id_$"> \
<span class="title"> \
<span class="best_in_place best_in_place_name" \
data-url="/topics/$_id_$" \
data-object="topic" \
data-attribute="name" \
data-type="input">$_name_$</span> \
</span> \
<div class="links"> \
<div \
class="linkItem icon"> \
<div class="metacodeTitle">$_metacode_$</div> \
<div class="metacodeImage" \
style="background-image:url($_imgsrc_$);" \
title="click and drag to move card"></div> \
</div> \
<div class="linkItem contributor hoverForTip"> \
<div class="tip">Created by $_username_$ on $_date_$</div> \
</div> \
<a href="/maps/topics/$_id_$" class="linkItem mapCount hoverForTip" \
title="Click to see which maps topic appears on" target="_blank"> \
$_map_count_$ \
</a> \
<div class="linkItem synapseCount">$_synapse_count_$</div> \
<div class="linkItem mapPerm $_mk_permission_$"></div> \
<a href="/topics/$_id_$" class="linkItem topicPopout" title="Open topic in new tab" target="_blank"></a>\
<div class="clearfloat"></div> \
</div> \
<div class="metacodeSelect">$_metacode_select_$</div> \
<div class="scroll"> \
<div class="desc"> \
<span class="best_in_place best_in_place_desc" \
data-url="/topics/$_id_$" \
data-object="topic" \
data-nil="$_desc_nil_$" \
data-attribute="desc" \
data-type="textarea">$_desc_$</span> \
<div class="clearfloat"></div> \
</div> \
</div> \
<div class="link"> \
$_a_tag_$<span class="best_in_place best_in_place_link" \
data-url="/topics/$_id_$" \
data-object="topic" \
data-nil="$_link_nil_$" \
data-attribute="link" \
data-type="input">$_link_$</span>$_close_a_tag_$ \
$_go_link_$ \
</div> \
<div class="clearfloat"></div> \
</div>';
}//generateShowcardHTML
function replaceVariables(html, node) {
//link is rendered differently if user is logged out or in
var go_link, a_tag, close_a_tag;
if (! authorizeToEdit(node)) {
go_link = '';
if (node.getData("link") != "") {
a_tag = '<a href="' + node.getData("link") + '" target="_blank">';
close_a_tag = '</a>';
}
else {
a_tag = '';
close_a_tag = '';
}
} else {
go_link = '<a href="' + node.getData("link") + '" ' +
' class="go-link" target="_blank"></a>';
a_tag = '';
close_a_tag = '';
}
var desc_nil = "<span class='gray'>Click to add description...</span>";
var link_nil = "<span class='gray'>Click to add link...</span>";
var edit_perm = '';
if (userid == node.getData("userid")) {
edit_perm = ' \
<div class="permActivator"> \
<div class="editSettings"> \
<span>Permissions:&nbsp;</span> \
<span title="Click to Edit"> \
<span class="best_in_place best_in_place_permission" \
id="best_in_place_topic_$_id_$_permission" \
data-url="/topics/$_id_$" \
data-object="topic" \
data-collection=$_permission_choices_$ \
data-attribute="permission" \
data-type="select" \
data-value="$_permission_$"> \
$_permission_$ \
</span> \
</span> \
<div class="clearfloat"></div> \
</div> \
</div>';
}
var permissions = ['commons','public','private'];
var permission_choices = "'[";
for (var i in permissions) {
permission_choices += '["' + permissions[i] + '","' + permissions[i] + '"],';
}
//remove trailing comma and add ]
permission_choices = permission_choices.slice(0, -1);
permission_choices += "]'";
edit_perm = edit_perm.replace(/\$_permission_choices_\$/g, permission_choices);
html = html.replace(/\$_edit_permission_\$/g, edit_perm);
html = html.replace(/\$_permission_\$/g, node.getData("permission"));
html = html.replace(/\$_mk_permission_\$/g, mk_permission(node));
html = html.replace(/\$_map_count_\$/g, node.getData("inmaps").length);
html = html.replace(/\$_synapse_count_\$/g, node.getData("synapseCount"));
html = html.replace(/\$_id_\$/g, node.id);
html = html.replace(/\$_metacode_\$/g, node.getData("metacode"));
html = html.replace(/\$_imgsrc_\$/g, imgArray[node.getData("metacode")].src);
html = html.replace(/\$_name_\$/g, node.name);
html = html.replace(/\$_userid_\$/g, node.getData("userid"));
html = html.replace(/\$_username_\$/g, node.getData("username"));
html = html.replace(/\$_date_\$/g, node.getData("date"));
html = html.replace(/\$_metacode_select_\$/g, $('#metacodeOptions').html());
html = html.replace(/\$_go_link_\$/g, go_link);
html = html.replace(/\$_a_tag_\$/g, a_tag);
html = html.replace(/\$_close_a_tag_\$/g, close_a_tag);
html = html.replace(/\$_link_nil_\$/g, link_nil);
if (node.getData("link") == "" && authorizeToEdit(node)) {
html = html.replace(/\$_link_\$/g, link_nil);
} else {
html = html.replace(/\$_link_\$/g, node.getData("link"));
}
html = html.replace(/\$_desc_nil_\$/g, desc_nil);
if (node.getData("desc") == "" && authorizeToEdit(node)) {
//logged in but desc isn't there so it's invisible
html = html.replace(/\$_desc_\$/g, desc_nil);
} else {
//html = html.replace(/\$_desc_\$/g, node.getData("desc").replace(/\n/g, '<br />'));
html = html.replace(/\$_desc_\$/g, node.getData("desc"));
}
return html;
}
function hideCurrentCard() {
if (MetamapsModel.showcardInUse) {
var node = Mconsole.graph.getNode(MetamapsModel.showcardInUse);
hideCard(node);
}
}
function hideCard(node) {
var card = '.showcard';
$(card).fadeOut('fast', function(){
//node.setData('dim', 25, 'current');
Mconsole.plot();
});
MetamapsModel.showcardInUse = null;
}
function populateShowCard(node) {
var showCard = document.getElementById('showcard');
$(showCard).find('.permission').remove();
var html = generateShowcardHTML();
html = replaceVariables(html, node);
if (authorizeToEdit(node)) {
var perm = document.createElement('div');
var string = 'permission canEdit';
if (userid == node.data.$userid) string += ' yourTopic';
perm.className = string;
perm.innerHTML = html;
showCard.appendChild(perm);
} else {
var perm = document.createElement('div');
perm.className = 'permission cannotEdit';
perm.innerHTML = html;
showCard.appendChild(perm);
}
var selectingMetacode = false;
// attach the listener that shows the metacode title when you hover over the image
$('.showcard .metacodeImage').mouseenter(function(){
$('.showcard .icon').css('z-index','4');
$('.showcard .metacodeTitle').show();
});
$('.showcard .linkItem.icon').mouseleave(function() {
if ( !selectingMetacode ) {
$('.showcard .metacodeTitle').hide();
$('.showcard .icon').css('z-index','1');
}
});
$('.showcard .metacodeTitle').click(function() {
if (!selectingMetacode) {
selectingMetacode = true;
$(this).addClass('minimize'); // this line flips the drop down arrow to a pull up arrow
$('.metacodeSelect').show();
// add the scroll bar to the list of metacode select options if it isn't already there
if ( !$('.metacodeSelect ul').hasClass('mCustomScrollbar') ) {
$('.metacodeSelect ul').mCustomScrollbar();
$('.metacodeSelect li').click(function() {
selectingMetacode = false;
var metacodeName = $(this).find('.mSelectName').text();
updateMetacode(node, metacodeName);
});
}
} else {
selectingMetacode = false;
$(this).removeClass('minimize'); // this line flips the pull up arrow to a drop down arrow
$('.metacodeSelect').hide();
}
});
// ability to change permission
var selectingPermission = false;
if (userid == node.data.$userid ) {
$('.showcard .yourTopic .mapPerm').click(function() {
if (!selectingPermission) {
selectingPermission = true;
$(this).addClass('minimize'); // this line flips the drop down arrow to a pull up arrow
if ( $(this).hasClass('co') ) {
$(this).append('<ul class="permissionSelect"><li class="public"></li><li class="private"></li></ul>');
} else if ( $(this).hasClass('pu') ) {
$(this).append('<ul class="permissionSelect"><li class="commons"></li><li class="private"></li></ul>');
} else if ( $(this).hasClass('pr') ) {
$(this).append('<ul class="permissionSelect"><li class="commons"></li><li class="public"></li></ul>');
}
$('.permissionSelect li').click(function(event) {
selectingPermission = false;
var permission = $(this).attr('class');
updateTopicPermission(node, permission);
event.stopPropagation();
});
} else {
selectingPermission = false;
$(this).removeClass('minimize'); // this line flips the pull up arrow to a drop down arrow
$('.permissionSelect').remove();
}
});
}
// when you're typing a description, resize the scroll box to have space
$('.best_in_place_desc textarea').bind('keyup', function() {
var s = $('.showcard').find('.scroll');
s.height( s.height() ).mCustomScrollbar('update');
console.log('working');
});
//bind best_in_place ajax callbacks
$(showCard).find('.best_in_place_name').bind("ajax:success", function() {
var s = $('.showcard').find('.scroll');
s.height( s.height() ).mCustomScrollbar('update');
var name = $(this).html();
node.name = decodeEntities(name);
Mconsole.plot();
});
$(showCard).find('.best_in_place_desc').bind("ajax:success", function() {
this.innerHTML = this.innerHTML.replace(/\r/g, '')
var s = $('.showcard').find('.scroll');
s.height( s.height() ).mCustomScrollbar('update');
var desc = $(this).html();
node.setData("desc", desc);
});
$(showCard).find('.best_in_place_link').bind("ajax:success", function() {
var link = $(this).html();
$(showCard).find('.go-link').attr('href', link);
node.setData("link", link);
});
}

View file

@ -1,18 +1,18 @@
function centerOn(nodeid) { function centerOn(nodeid) {
if (!Mconsole.busy) { if (!Mconsole.busy) {
var node = Mconsole.graph.getNode(nodeid); var node = Mconsole.graph.getNode(nodeid);
$('div.index img').attr('src', imgArray[node.getData('metacode')].src); $('div.index img').attr('src', imgArray[node.getData('metacode')].src);
$('div.index .mapName').html(node.name); $('div.index .mapName').html(node.name);
$(document).attr('title', node.name + ' | Metamaps'); $(document).attr('title', node.name + ' | Metamaps');
window.history.pushState(node.name, "Metamaps", "/topics/" + node.id); window.history.pushState(node.name, "Metamaps", "/topics/" + node.id);
Mconsole.onClick(node.id, { Mconsole.onClick(node.id, {
hideLabels: false, hideLabels: false,
duration: 1000, duration: 1000,
onComplete: function() { onComplete: function () {
fetchRelatives(node); fetchRelatives(node);
} }
}); });
} }
} }
function editEdge(edge, e) { function editEdge(edge, e) {
@ -29,10 +29,10 @@ function editEdge(edge, e) {
var edit_div = document.createElement('div'); var edit_div = document.createElement('div');
edit_div.setAttribute('id', 'edit_synapse'); edit_div.setAttribute('id', 'edit_synapse');
if (authorizeToEdit(edge)) { if (authorizeToEdit(edge)) {
edit_div.className = 'permission canEdit'; edit_div.className = 'permission canEdit';
edit_div.className += edge.getData('userid') === userid ? ' yourEdge' : ''; edit_div.className += edge.getData('userid') === userid ? ' yourEdge' : '';
} else { } else {
edit_div.className = 'permission cannotEdit'; edit_div.className = 'permission cannotEdit';
} }
$('.main .wrapper').append(edit_div); $('.main .wrapper').append(edit_div);
@ -41,12 +41,11 @@ function editEdge(edge, e) {
//drop it in the right spot, activate it //drop it in the right spot, activate it
$('#edit_synapse').css('position', 'absolute'); $('#edit_synapse').css('position', 'absolute');
if (e) { if (e) {
$('#edit_synapse').css('left', e.clientX); $('#edit_synapse').css('left', e.clientX);
$('#edit_synapse').css('top', e.clientY); $('#edit_synapse').css('top', e.clientY);
} } else {
else { $('#edit_synapse').css('left', myX);
$('#edit_synapse').css('left', myX); $('#edit_synapse').css('top', myY);
$('#edit_synapse').css('top', myY);
} }
//$('#edit_synapse_name').click(); //required in case name is empty //$('#edit_synapse_name').click(); //required in case name is empty
//$('#edit_synapse_name input').focus(); //$('#edit_synapse_name input').focus();
@ -56,407 +55,385 @@ function editEdge(edge, e) {
} }
function populateEditEdgeForm(edge) { function populateEditEdgeForm(edge) {
add_name_form(edge); add_name_form(edge);
add_user_info(edge); add_user_info(edge);
add_perms_form(edge); add_perms_form(edge);
if (authorizeToEdit(edge)) { if (authorizeToEdit(edge)) {
add_direction_form(edge); add_direction_form(edge);
} }
} }
function add_name_form(edge) { function add_name_form(edge) {
var data_nil = '<span class="gray">Click to add description.</span>'; var data_nil = '<span class="gray">Click to add description.</span>';
//name editing form //name editing form
$('#edit_synapse').append('<div id="edit_synapse_name"></div>'); $('#edit_synapse').append('<div id="edit_synapse_name"></div>');
$('#edit_synapse_name').attr('class', 'best_in_place best_in_place_desc'); $('#edit_synapse_name').attr('class', 'best_in_place best_in_place_desc');
$('#edit_synapse_name').attr('data-object', 'synapse'); $('#edit_synapse_name').attr('data-object', 'synapse');
$('#edit_synapse_name').attr('data-attribute', 'desc'); $('#edit_synapse_name').attr('data-attribute', 'desc');
$('#edit_synapse_name').attr('data-type', 'textarea'); $('#edit_synapse_name').attr('data-type', 'textarea');
$('#edit_synapse_name').attr('data-nil', data_nil); $('#edit_synapse_name').attr('data-nil', data_nil);
$('#edit_synapse_name').attr('data-url', '/synapses/' + edge.getData("id")); $('#edit_synapse_name').attr('data-url', '/synapses/' + edge.getData("id"));
$('#edit_synapse_name').html(edge.getData("desc")); $('#edit_synapse_name').html(edge.getData("desc"));
//if edge data is blank or just whitespace, populate it with data_nil //if edge data is blank or just whitespace, populate it with data_nil
if ($('#edit_synapse_name').html().trim() == '') { if ($('#edit_synapse_name').html().trim() == '') {
$('#edit_synapse_name').html(data_nil); $('#edit_synapse_name').html(data_nil);
}
$('#edit_synapse_name').bind("ajax:success", function() {
var desc = $(this).html();
if (desc == data_nil) {
edge.setData("desc", '');
} else {
edge.setData("desc", desc);
} }
selectEdge(edge);
Mconsole.plot(); $('#edit_synapse_name').bind("ajax:success", function () {
}); var desc = $(this).html();
if (desc == data_nil) {
edge.setData("desc", '');
} else {
edge.setData("desc", desc);
}
selectEdge(edge);
Mconsole.plot();
});
} }
function add_user_info(edge) { function add_user_info(edge) {
$('#edit_synapse').append('<div id="edgeUser" class="hoverForTip"><div class="tip">Created by ' + edge.getData("username") + '</div></div>'); $('#edit_synapse').append('<div id="edgeUser" class="hoverForTip"><div class="tip">Created by ' + edge.getData("username") + '</div></div>');
} }
function add_perms_form(edge) { function add_perms_form(edge) {
//permissions - if owner, also allow permission editing //permissions - if owner, also allow permission editing
$('#edit_synapse').append('<div class="mapPerm ' + mk_permission(edge) + '"></div>'); $('#edit_synapse').append('<div class="mapPerm ' + mk_permission(edge) + '"></div>');
// ability to change permission // ability to change permission
var selectingPermission = false; var selectingPermission = false;
if (userid == edge.getData('userid')) { if (userid == edge.getData('userid')) {
$('#edit_synapse.yourEdge .mapPerm').click(function() { $('#edit_synapse.yourEdge .mapPerm').click(function () {
if (!selectingPermission) { if (!selectingPermission) {
selectingPermission = true; selectingPermission = true;
$(this).addClass('minimize'); // this line flips the drop down arrow to a pull up arrow $(this).addClass('minimize'); // this line flips the drop down arrow to a pull up arrow
if ( $(this).hasClass('co') ) { if ($(this).hasClass('co')) {
$(this).append('<ul class="permissionSelect"><li class="public"></li><li class="private"></li></ul>'); $(this).append('<ul class="permissionSelect"><li class="public"></li><li class="private"></li></ul>');
} else if ( $(this).hasClass('pu') ) { } else if ($(this).hasClass('pu')) {
$(this).append('<ul class="permissionSelect"><li class="commons"></li><li class="private"></li></ul>'); $(this).append('<ul class="permissionSelect"><li class="commons"></li><li class="private"></li></ul>');
} else if ( $(this).hasClass('pr') ) { } else if ($(this).hasClass('pr')) {
$(this).append('<ul class="permissionSelect"><li class="commons"></li><li class="public"></li></ul>'); $(this).append('<ul class="permissionSelect"><li class="commons"></li><li class="public"></li></ul>');
} }
$('#edit_synapse .permissionSelect li').click(function(event) { $('#edit_synapse .permissionSelect li').click(function (event) {
selectingPermission = false; selectingPermission = false;
var permission = $(this).attr('class'); var permission = $(this).attr('class');
updateSynapsePermission(edge, permission); updateSynapsePermission(edge, permission);
event.stopPropagation(); event.stopPropagation();
}); });
} else { } else {
selectingPermission = false; selectingPermission = false;
$(this).removeClass('minimize'); // this line flips the pull up arrow to a drop down arrow $(this).removeClass('minimize'); // this line flips the pull up arrow to a drop down arrow
$('#edit_synapse .permissionSelect').remove(); $('#edit_synapse .permissionSelect').remove();
}
});
} }
}); } //add_perms_form
}
}//add_perms_form
function add_direction_form(edge) { function add_direction_form(edge) {
//directionality checkboxes //directionality checkboxes
$('#edit_synapse').append('<input type="checkbox" id="edit_synapse_left">'); $('#edit_synapse').append('<input type="checkbox" id="edit_synapse_left">');
$('#edit_synapse').append('<label class="left">&lt;</label>'); $('#edit_synapse').append('<label class="left">&lt;</label>');
$('#edit_synapse').append('<input type="checkbox" id="edit_synapse_right">'); $('#edit_synapse').append('<input type="checkbox" id="edit_synapse_right">');
$('#edit_synapse').append('<label class="right">&gt;</label>'); $('#edit_synapse').append('<label class="right">&gt;</label>');
//determine which node is to the left and the right //determine which node is to the left and the right
//if directly in a line, top is left //if directly in a line, top is left
if (edge.nodeFrom.pos.x < edge.nodeTo.pos.x || if (edge.nodeFrom.pos.x < edge.nodeTo.pos.x ||
edge.nodeFrom.pos.x == edge.nodeTo.pos.x && edge.nodeFrom.pos.x == edge.nodeTo.pos.x &&
edge.nodeFrom.pos.y < edge.nodeTo.pos.y) { edge.nodeFrom.pos.y < edge.nodeTo.pos.y) {
var left = edge.nodeTo; var left = edge.nodeTo;
var right = edge.nodeFrom; var right = edge.nodeFrom;
} else {
var left = edge.nodeFrom;
var right = edge.nodeTo;
}
/*
* One node is actually on the left onscreen. Call it left, & the other right.
* If category is from-to, and that node is first, check the 'right' checkbox.
* Else check the 'left' checkbox since the arrow is incoming.
*/
var directionCat = edge.getData('category'); //both, none, from-to
if (directionCat == 'from-to') {
var from_to = edge.getData('direction');
if (from_to[0] == left.id) {
//check left checkbox
$('#edit_synapse_left').prop('checked', true);
} else { } else {
//check right checkbox var left = edge.nodeFrom;
$('#edit_synapse_right').prop('checked', true); var right = edge.nodeTo;
} }
} else if (directionCat == 'both') {
//check both checkboxes
$('#edit_synapse_left').prop('checked', true);
$('#edit_synapse_right').prop('checked', true);
}
$('#edit_synapse_left, #edit_synapse_right').click(function() {
var leftChecked = $('#edit_synapse_left').is(':checked');
var rightChecked = $('#edit_synapse_right').is(':checked');
var dir = edge.getData('direction'); /*
var dirCat = 'none'; * One node is actually on the left onscreen. Call it left, & the other right.
if (leftChecked && rightChecked) { * If category is from-to, and that node is first, check the 'right' checkbox.
dirCat = 'both'; * Else check the 'left' checkbox since the arrow is incoming.
} else if (!leftChecked && rightChecked) { */
dirCat = 'from-to';
dir = [right.id, left.id]; var directionCat = edge.getData('category'); //both, none, from-to
} else if (leftChecked && !rightChecked) { if (directionCat == 'from-to') {
dirCat = 'from-to'; var from_to = edge.getData('direction');
dir = [left.id, right.id]; if (from_to[0] == left.id) {
} //check left checkbox
$.ajax({ $('#edit_synapse_left').prop('checked', true);
'type': 'PUT', } else {
'url': '/synapses/' + edge.getData('id'), //check right checkbox
'data': { $('#edit_synapse_right').prop('checked', true);
synapse: {
category:dirCat
},
node1_id: {
node1: dir[0]
},
node2_id: {
node2: dir[1]
} }
}, } else if (directionCat == 'both') {
'success': function(data) { //check both checkboxes
updateEdgeDisplay(edge, dir, dirCat); $('#edit_synapse_left').prop('checked', true);
} $('#edit_synapse_right').prop('checked', true);
}
$('#edit_synapse_left, #edit_synapse_right').click(function () {
var leftChecked = $('#edit_synapse_left').is(':checked');
var rightChecked = $('#edit_synapse_right').is(':checked');
var dir = edge.getData('direction');
var dirCat = 'none';
if (leftChecked && rightChecked) {
dirCat = 'both';
} else if (!leftChecked && rightChecked) {
dirCat = 'from-to';
dir = [right.id, left.id];
} else if (leftChecked && !rightChecked) {
dirCat = 'from-to';
dir = [left.id, right.id];
}
$.ajax({
'type': 'PUT',
'url': '/synapses/' + edge.getData('id'),
'data': {
synapse: {
category: dirCat
},
node1_id: {
node1: dir[0]
},
node2_id: {
node2: dir[1]
}
},
'success': function (data) {
updateEdgeDisplay(edge, dir, dirCat);
}
});
}); });
}); } //add_direction_form
}//add_direction_form
function updateEdgeDisplay(edge, dir, dirCat) { function updateEdgeDisplay(edge, dir, dirCat) {
edge.setData('category', dirCat); edge.setData('category', dirCat);
edge.setData('direction', dir); edge.setData('direction', dir);
//render mid arrow //render mid arrow
//renderEdgeArrows(Mconsole.fx.edgeHelper, edge); //renderEdgeArrows(Mconsole.fx.edgeHelper, edge);
Mconsole.plot(); Mconsole.plot();
} }
function best_in_place_perms(edge) {
var output =
'<span class="best_in_place best_in_place_permission" \
id="best_in_place_topic_$_id_$_permission" \
data-url="/synapses/$_id_$" \
data-object="synapse" \
data-collection=$_permission_choices_$ \
data-attribute="permission" \
data-type="select" \
data-value="$_current_$">$_perm_$</span>';
var permission_choices = "'[";
permission_choices += '["commons","commons"],';
permission_choices += '["public","public"],';
permission_choices += '["private","private"]';
permission_choices += "]'";
output = output.replace(/\$_permission_choices_\$/g, permission_choices);
output = output.replace(/\$_id_\$/g, edge.getData('id'));
output = output.replace(/\$_current_$\$/g, edge.getData('permission'));
output = output.replace(/\$_perm_\$/g, edge.getData('permission'));
return output;
}//best_in_place_perms
function deselectAllEdges() { function deselectAllEdges() {
var l = MetamapsModel.selectedEdges.length; var l = MetamapsModel.selectedEdges.length;
for (var i = l-1; i >= 0; i -= 1) { for (var i = l - 1; i >= 0; i -= 1) {
var edge = MetamapsModel.selectedEdges[i]; var edge = MetamapsModel.selectedEdges[i];
deselectEdge(edge); deselectEdge(edge);
} }
} }
function deselectAllNodes() { function deselectAllNodes() {
var l = MetamapsModel.selectedNodes.length; var l = MetamapsModel.selectedNodes.length;
for (var i = l-1; i >= 0; i -= 1) { for (var i = l - 1; i >= 0; i -= 1) {
var node = MetamapsModel.selectedNodes[i]; var node = MetamapsModel.selectedNodes[i];
deselectNode(node); deselectNode(node);
} }
} }
// this is for hiding one topic from your canvas // this is for hiding one topic from your canvas
function removeEdge(edge) { function removeEdge(edge) {
var id = edge.getData("id"); var id = edge.getData("id");
$.ajax({ $.ajax({
type: "DELETE", type: "DELETE",
url: "/synapses/" + id, url: "/synapses/" + id,
success: function(){ success: function () {
hideEdge(edge); hideEdge(edge);
}, },
}); });
} }
function hideEdge(edge) { function hideEdge(edge) {
var from = edge.nodeFrom.id; var from = edge.nodeFrom.id;
var to = edge.nodeTo.id; var to = edge.nodeTo.id;
edge.setData('alpha', 0, 'end'); edge.setData('alpha', 0, 'end');
Mconsole.fx.animate({ Mconsole.fx.animate({
modes: ['edge-property:alpha'], modes: ['edge-property:alpha'],
duration: 1000 duration: 1000
}); });
Mconsole.graph.removeAdjacence(from, to); Mconsole.graph.removeAdjacence(from, to);
Mconsole.plot(); Mconsole.plot();
} }
function hideSelectedEdges() { function hideSelectedEdges() {
var l = MetamapsModel.selectedEdges.length; var l = MetamapsModel.selectedEdges.length;
for (var i = l-1; i >= 0; i -= 1) { for (var i = l - 1; i >= 0; i -= 1) {
var edge = MetamapsModel.selectedEdges[i]; var edge = MetamapsModel.selectedEdges[i];
hideEdge(edge); hideEdge(edge);
} }
MetamapsModel.selectedEdges = new Array(); MetamapsModel.selectedEdges = new Array();
} }
function removeSelectedEdges() { function removeSelectedEdges() {
var l = MetamapsModel.selectedEdges.length; var l = MetamapsModel.selectedEdges.length;
for (var i = l-1; i >= 0; i -= 1) { for (var i = l - 1; i >= 0; i -= 1) {
if (mapid != null) { if (mapid != null) {
var edge = MetamapsModel.selectedEdges[i]; var edge = MetamapsModel.selectedEdges[i];
var id = edge.getData("id"); var id = edge.getData("id");
//delete mapping of id mapid //delete mapping of id mapid
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "/synapses/" + mapid + "/" + id + "/removefrommap", url: "/synapses/" + mapid + "/" + id + "/removefrommap",
}); });
}
hideEdge(edge);
} }
hideEdge(edge); MetamapsModel.selectedEdges = new Array();
}
MetamapsModel.selectedEdges = new Array();
} }
function deleteSelectedEdges() { function deleteSelectedEdges() {
var l = MetamapsModel.selectedEdges.length; var l = MetamapsModel.selectedEdges.length;
for (var i = l-1; i >= 0; i -= 1) { for (var i = l - 1; i >= 0; i -= 1) {
var edge = MetamapsModel.selectedEdges[i]; var edge = MetamapsModel.selectedEdges[i];
var id = edge.getData("id"); var id = edge.getData("id");
$.ajax({ $.ajax({
type: "DELETE", type: "DELETE",
url: "/synapses/" + id, url: "/synapses/" + id,
}); });
hideEdge(edge); hideEdge(edge);
} }
MetamapsModel.selectedEdges = new Array(); MetamapsModel.selectedEdges = new Array();
} }
function selectNode(node) { function selectNode(node) {
if (MetamapsModel.selectedNodes.indexOf(node) != -1) return; if (MetamapsModel.selectedNodes.indexOf(node) != -1) return;
node.selected = true; node.selected = true;
node.setData('dim', 30, 'current'); node.setData('dim', 30, 'current');
node.setData('whiteCircle',true); node.setData('whiteCircle', true);
node.eachAdjacency(function (adj) { node.eachAdjacency(function (adj) {
selectEdge(adj); selectEdge(adj);
}); });
MetamapsModel.selectedNodes.push(node); MetamapsModel.selectedNodes.push(node);
} }
function deselectNode(node) { function deselectNode(node) {
delete node.selected; delete node.selected;
node.setData('whiteCircle', false); node.setData('whiteCircle', false);
node.eachAdjacency(function(adj) { node.eachAdjacency(function (adj) {
deselectEdge(adj); deselectEdge(adj);
}); });
node.setData('dim', 25, 'current'); node.setData('dim', 25, 'current');
//remove the node //remove the node
MetamapsModel.selectedNodes.splice( MetamapsModel.selectedNodes.splice(
MetamapsModel.selectedNodes.indexOf(node), 1); MetamapsModel.selectedNodes.indexOf(node), 1);
} }
function selectEdge(edge) { function selectEdge(edge) {
if (MetamapsModel.selectedEdges.indexOf(edge) != -1) return; if (MetamapsModel.selectedEdges.indexOf(edge) != -1) return;
edge.setData('showDesc', true, 'current'); edge.setData('showDesc', true, 'current');
if ( ! MetamapsModel.embed) { if (!MetamapsModel.embed) {
edge.setDataset('end', { edge.setDataset('end', {
lineWidth: 4, lineWidth: 4,
color: '#FFFFFF', color: '#FFFFFF',
alpha: 1 alpha: 1
});
} else if (MetamapsModel.embed) {
edge.setDataset('end', {
lineWidth: 4,
color: '#999',
alpha: 1
});
}
Mconsole.fx.animate({
modes: ['edge-property:lineWidth:color:alpha'],
duration: 100
}); });
} else if (MetamapsModel.embed) { MetamapsModel.selectedEdges.push(edge);
edge.setDataset('end', {
lineWidth: 4,
color: '#999',
alpha: 1
});
}
Mconsole.fx.animate({
modes: ['edge-property:lineWidth:color:alpha'],
duration: 100
});
MetamapsModel.selectedEdges.push(edge);
} }
function deselectEdge(edge) { function deselectEdge(edge) {
edge.setData('showDesc', false, 'current'); edge.setData('showDesc', false, 'current');
edge.setDataset('end', {
lineWidth: 2,
color: '#222222',
alpha: 0.4
});
if (MetamapsModel.edgeHoveringOver == edge) {
edge.setData('showDesc', true, 'current');
edge.setDataset('end', { edge.setDataset('end', {
lineWidth: 4, lineWidth: 2,
color: '#222222', color: '#222222',
alpha: 1 alpha: 0.4
}); });
}
Mconsole.fx.animate({ if (MetamapsModel.edgeHoveringOver == edge) {
modes: ['edge-property:lineWidth:color:alpha'], edge.setData('showDesc', true, 'current');
duration: 100 edge.setDataset('end', {
}); lineWidth: 4,
color: '#222222',
alpha: 1
});
}
//remove the edge Mconsole.fx.animate({
MetamapsModel.selectedEdges.splice( modes: ['edge-property:lineWidth:color:alpha'],
MetamapsModel.selectedEdges.indexOf(edge), 1); duration: 100
});
//remove the edge
MetamapsModel.selectedEdges.splice(
MetamapsModel.selectedEdges.indexOf(edge), 1);
} }
// this is for hiding one topic from your canvas // this is for hiding one topic from your canvas
function hideNode(nodeid) { function hideNode(nodeid) {
var node = Mconsole.graph.getNode(nodeid); var node = Mconsole.graph.getNode(nodeid);
if (nodeid == Mconsole.root && gType == "centered") { if (nodeid == Mconsole.root && gType == "centered") {
alert("You can't hide this topic, it is the root of your graph."); alert("You can't hide this topic, it is the root of your graph.");
return; return;
} }
deselectNode(node); deselectNode(node);
node.setData('alpha', 0, 'end'); node.setData('alpha', 0, 'end');
node.eachAdjacency(function(adj) { node.eachAdjacency(function (adj) {
adj.setData('alpha', 0, 'end'); adj.setData('alpha', 0, 'end');
}); });
Mconsole.fx.animate({ Mconsole.fx.animate({
modes: ['node-property:alpha', modes: ['node-property:alpha',
'edge-property:alpha'], 'edge-property:alpha'],
duration: 1000 duration: 1000
}); });
Mconsole.graph.removeNode(nodeid); Mconsole.graph.removeNode(nodeid);
} }
function hideSelectedNodes() { function hideSelectedNodes() {
var l = MetamapsModel.selectedNodes.length; var l = MetamapsModel.selectedNodes.length;
for (var i = l-1; i >= 0; i -= 1) { for (var i = l - 1; i >= 0; i -= 1) {
var node = MetamapsModel.selectedNodes[i]; var node = MetamapsModel.selectedNodes[i];
hideNode(node.id); hideNode(node.id);
} }
} }
function removeNode(nodeid) { function removeNode(nodeid) {
var node = Mconsole.graph.getNode(nodeid); var node = Mconsole.graph.getNode(nodeid);
deselectNode(node); deselectNode(node);
if (mapperm) { if (mapperm) {
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "/topics/" + mapid + "/" + nodeid + "/removefrommap", url: "/topics/" + mapid + "/" + nodeid + "/removefrommap",
}); });
} }
} }
function removeSelectedNodes() {
if (mapperm) { function removeSelectedNodes() {
var l = MetamapsModel.selectedNodes.length; if (mapperm) {
for (var i = l-1; i >= 0; i -= 1) { var l = MetamapsModel.selectedNodes.length;
var node = MetamapsModel.selectedNodes[i]; for (var i = l - 1; i >= 0; i -= 1) {
removeNode(node.id); var node = MetamapsModel.selectedNodes[i];
removeNode(node.id);
}
} }
}
} }
function deleteNode(nodeid) { function deleteNode(nodeid) {
if (nodeid == Mconsole.root && gType == "centered") { if (nodeid == Mconsole.root && gType == "centered") {
alert("You can't delete this topic, it is the root of your graph."); alert("You can't delete this topic, it is the root of your graph.");
return; return;
} }
$.ajax({ $.ajax({
type: "DELETE", type: "DELETE",
url: "/topics/" + nodeid, url: "/topics/" + nodeid,
}); });
} }
function deleteSelectedNodes() { function deleteSelectedNodes() {
var l = MetamapsModel.selectedNodes.length; var l = MetamapsModel.selectedNodes.length;
for (var i = l-1; i >= 0; i -= 1) { for (var i = l - 1; i >= 0; i -= 1) {
var node = MetamapsModel.selectedNodes[i]; var node = MetamapsModel.selectedNodes[i];
deleteNode(node.id); deleteNode(node.id);
} }
} }

View file

View file

@ -0,0 +1,207 @@
/*
* @file
* There is a lot of code that goes into creating the "label" of a node
* This includes editable cards with all node details, and some controls
* onCreateLabelHandler is the main function of this file, and the file
* also contains a bunch of helper functions
*
* html and littleHTML are potentially confusing variables
* html is the contents of the card shown when you click on a node's label.
* littleHTML creates little controls for removing/hiding nodes from the canvas
*
* This function features PHP-style variable substitution because the strings
* are so damn long. Values are identified by $_id_$, and then a regular
* expression is substituted in later (for html, in a separate function).
*/
function buildCardWithHogan(node) {
var nodeValues = {};
var authorized = authorizeToEdit(node);
//link is rendered differently if user is logged out or in
var go_link, a_tag, close_a_tag;
if (!authorized) {
go_link = '';
if (node.getData("link") != "") {
a_tag = '<a href="' + node.getData("link") + '" target="_blank">';
close_a_tag = '</a>';
} else {
a_tag = '';
close_a_tag = '';
}
} else {
go_link = '<a href="' + node.getData("link") + '" ' +
' class="go-link" target="_blank"></a>';
a_tag = '';
close_a_tag = '';
}
var desc_nil = "Click to add description...";
var link_nil = "Click to add link...";
nodeValues.permission = node.getData("permission");
nodeValues.mk_permission = mk_permission(node);
nodeValues.map_count = node.getData("inmaps").length;
nodeValues.synapse_count = node.getData("synapseCount");
nodeValues.id = node.id;
nodeValues.metacode = node.getData("metacode");
nodeValues.imgsrc = imgArray[node.getData("metacode")].src;
nodeValues.name = node.name;
nodeValues.userid = node.getData("userid");
nodeValues.username = node.getData("username");
nodeValues.date = node.getData("date");
// the code for this is stored in /views/main/_metacodeOptions.html.erb
nodeValues.metacode_select = $('#metacodeOptions').html();
nodeValues.go_link = go_link;
nodeValues.a_tag = a_tag;
nodeValues.close_a_tag = close_a_tag;
nodeValues.link_nil = link_nil;
nodeValues.link = (node.getData("link") == "" && authorized) ? link_nil : node.getData("link");
nodeValues.desc_nil = desc_nil;
nodeValues.desc = (node.getData("desc") == "" && authorized) ? desc_nil : node.getData("desc");
// the code for the template is stored in /views/layouts/_templates.html.erb
var hoganTemplate = Hogan.compile($('#topicCardTemplate').html());
return hoganTemplate.render(nodeValues);
}
function hideCurrentCard() {
if (MetamapsModel.showcardInUse) {
var node = Mconsole.graph.getNode(MetamapsModel.showcardInUse);
hideCard(node);
}
}
function hideCard(node) {
var card = '.showcard';
$(card).fadeOut('fast', function () {
//node.setData('dim', 25, 'current');
Mconsole.plot();
});
MetamapsModel.showcardInUse = null;
}
function populateShowCard(node) {
var showCard = document.getElementById('showcard');
$(showCard).find('.permission').remove();
var html = buildCardWithHogan(node);
if (authorizeToEdit(node)) {
var perm = document.createElement('div');
var string = 'permission canEdit';
if (userid == node.data.$userid) string += ' yourTopic';
perm.className = string;
perm.innerHTML = html;
showCard.appendChild(perm);
} else {
var perm = document.createElement('div');
perm.className = 'permission cannotEdit';
perm.innerHTML = html;
showCard.appendChild(perm);
}
var selectingMetacode = false;
// attach the listener that shows the metacode title when you hover over the image
$('.showcard .metacodeImage').mouseenter(function () {
$('.showcard .icon').css('z-index', '4');
$('.showcard .metacodeTitle').show();
});
$('.showcard .linkItem.icon').mouseleave(function () {
if (!selectingMetacode) {
$('.showcard .metacodeTitle').hide();
$('.showcard .icon').css('z-index', '1');
}
});
$('.showcard .metacodeTitle').click(function () {
if (!selectingMetacode) {
selectingMetacode = true;
$(this).addClass('minimize'); // this line flips the drop down arrow to a pull up arrow
$('.metacodeSelect').show();
// add the scroll bar to the list of metacode select options if it isn't already there
if (!$('.metacodeSelect ul').hasClass('mCustomScrollbar')) {
$('.metacodeSelect ul').mCustomScrollbar();
$('.metacodeSelect li').click(function () {
selectingMetacode = false;
var metacodeName = $(this).find('.mSelectName').text();
updateMetacode(node, metacodeName);
});
}
} else {
selectingMetacode = false;
$(this).removeClass('minimize'); // this line flips the pull up arrow to a drop down arrow
$('.metacodeSelect').hide();
}
});
// ability to change permission
var selectingPermission = false;
if (userid == node.data.$userid) {
$('.showcard .yourTopic .mapPerm').click(function () {
if (!selectingPermission) {
selectingPermission = true;
$(this).addClass('minimize'); // this line flips the drop down arrow to a pull up arrow
if ($(this).hasClass('co')) {
$(this).append('<ul class="permissionSelect"><li class="public"></li><li class="private"></li></ul>');
} else if ($(this).hasClass('pu')) {
$(this).append('<ul class="permissionSelect"><li class="commons"></li><li class="private"></li></ul>');
} else if ($(this).hasClass('pr')) {
$(this).append('<ul class="permissionSelect"><li class="commons"></li><li class="public"></li></ul>');
}
$('.permissionSelect li').click(function (event) {
selectingPermission = false;
var permission = $(this).attr('class');
updateTopicPermission(node, permission);
event.stopPropagation();
});
} else {
selectingPermission = false;
$(this).removeClass('minimize'); // this line flips the pull up arrow to a drop down arrow
$('.permissionSelect').remove();
}
});
}
// when you're typing a description, resize the scroll box to have space
$('.best_in_place_desc textarea').bind('keyup', function () {
var s = $('.showcard').find('.scroll');
s.height(s.height()).mCustomScrollbar('update');
console.log('working');
});
//bind best_in_place ajax callbacks
$(showCard).find('.best_in_place_name').bind("ajax:success", function () {
var s = $('.showcard').find('.scroll');
s.height(s.height()).mCustomScrollbar('update');
var name = $(this).html();
node.name = decodeEntities(name);
Mconsole.plot();
});
$(showCard).find('.best_in_place_desc').bind("ajax:success", function () {
this.innerHTML = this.innerHTML.replace(/\r/g, '')
var s = $('.showcard').find('.scroll');
s.height(s.height()).mCustomScrollbar('update');
var desc = $(this).html();
node.setData("desc", desc);
});
$(showCard).find('.best_in_place_link').bind("ajax:success", function () {
var link = $(this).html();
$(showCard).find('.go-link').attr('href', link);
node.setData("link", link);
});
}

View file

@ -35,594 +35,6 @@ var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null,
mapperm = false, mapperm = false,
touchPos, touchDragNode, mouseIsDown = false; touchPos, touchDragNode, mouseIsDown = false;
$(document).ready(function () {
function bindMainMenuHover() {
var menuIsOpen = false
// controls the sliding hover of the bottom left menu
var sliding1 = false;
var lT;
var closeMenu = function () {
lT = setTimeout(function () {
if (!sliding1) {
sliding1 = true;
// $('.footer .menu').animate({
// height: '0px'
// }, 300, function() {
// sliding1 = false;
// menuIsOpen = false;
// });
$('.footer').css('border-top-right-radius', '5px');
$('.logo').animate({
'background-position-x': '-10px'
}, 200);
$('.footer .menu').fadeOut(200, function () {
sliding1 = false;
menuIsOpen = false;
});
}
}, 500);
}
var openMenu = function () {
clearTimeout(lT);
if (!sliding1) {
sliding1 = true;
// $('.footer .menu').animate({
// height: listLength + 'px'
// }, 300, function() {
// sliding1 = false;
// });
$('.footer').css('border-top-right-radius', '0');
$('.logo').animate({
'background-position-x': '-7px'
}, 200);
$('.footer .menu').fadeIn(200, function () {
sliding1 = false;
});
}
}
// bind the hover events
$(".logo").hover(openMenu, closeMenu);
// when on touch screen, make touching on the logo do what hovering does on desktop
$("#mainTitle a").bind('touchend', function (evt) {
if (!menuIsOpen) {
openMenu();
evt.preventDefault();
evt.stopPropagation();
}
});
}
function bindSearchHover() {
var searchIsOpen = false
// controls the sliding hover of the search
var sliding1 = false;
var lT;
var openSearch = function () {
clearTimeout(lT);
if (!sliding1 && !searchIsOpen) {
hideCards();
sliding1 = true;
$('.sidebarSearch .twitter-typeahead, .sidebarSearch .tt-hint, .sidebarSearchField').animate({
width: '200px'
}, 200, function () {
$('.sidebarSearchField, .sidebarSearch .tt-hint').css({
padding: '5px 10px',
width: '180px'
});
$('.sidebarSearchField').focus();
sliding1 = false
searchIsOpen = true;
});
}
}
var closeSearch = function (closeAfter) {
lT = setTimeout(function () {
if (!sliding1 && searchIsOpen && $('.sidebarSearchField').val() == '') {
sliding1 = true;
$('.sidebarSearchField, .sidebarSearch .tt-hint').css({
padding: '5px 0',
width: '200px'
});
$('.sidebarSearch .twitter-typeahead, .sidebarSearch .tt-hint, .sidebarSearchField').animate({
width: '0'
}, 200, function () {
$('.sidebarSearchField').typeahead('setQuery', '');
sliding1 = false;
searchIsOpen = false;
});
}
}, closeAfter);
}
// bind the hover events
$(".sidebarSearch").hover(function () {
openSearch()
}, function () {
closeSearch(800)
});
$('.sidebarSearchIcon').click(function (e) {
$('.sidebarSearchField').focus();
});
$('.sidebarSearch').click(function (e) {
e.stopPropagation();
});
$('body').click(function (e) {
closeSearch(0);
});
// if the search is closed and user hits SHIFT+S
$('body').bind('keydown', function (e) {
switch (e.which) {
case 191:
if (e.ctrlKey && !searchIsOpen) {
openSearch();
}
break;
default:
break; //console.log(e.which);
}
});
// initialize the search box autocomplete results
var mapheader = userid ? '<h3 class="search-header">Maps</h3><input type="checkbox" class="limitToMe" id="limitMapsToMe"></input><label for="limitMapsToMe" class="limitToMeLabel">added by me</label><div class="minimizeResults minimizeMapResults"></div><div class="clearfloat"></div>' : '<h3 class="search-header">Maps</h3><div class="minimizeResults minimizeMapResults"></div><div class="clearfloat"></div>';
var topicheader = userid ? '<h3 class="search-header">Topics</h3><input type="checkbox" class="limitToMe" id="limitTopicsToMe"></input><label for="limitTopicsToMe" class="limitToMeLabel">added by me</label><div class="minimizeResults minimizeTopicResults"></div><div class="clearfloat"></div>' : '<h3 class="search-header">Topics</h3><div class="minimizeResults minimizeTopicResults"></div><div class="clearfloat"></div>';
$('.sidebarSearchField').typeahead([
{
name: 'topics',
dupChecker: function (datum1, datum2) {
return false;
},
template: $('.topicTemplate').html(),
remote: {
url: '/search/topics?term=%QUERY',
replace: function () {
var q = '/search/topics?term=' + $('.sidebarSearchField').val();
if ($("#limitTopicsToMe").is(':checked')) {
q += "&user=" + userid.toString();
}
return q;
},
filter: function (dataset) {
if (dataset.length == 0) {
dataset.push({
value: "No results",
label: "No results",
typeImageURL: "/assets/icons/wildcard.png",
rtype: "noresult"
});
}
return dataset;
}
},
engine: Hogan,
header: topicheader
},
{
name: 'maps',
dupChecker: function (datum1, datum2) {
return false;
},
template: $('.mapTemplate').html(),
remote: {
url: '/search/maps?term=%QUERY',
replace: function () {
var q = '/search/maps?term=' + $('.sidebarSearchField').val();
if ($("#limitMapsToMe").is(':checked')) {
q += "&user=" + userid.toString();
}
return q;
},
filter: function (dataset) {
if (dataset.length == 0) {
dataset.push({
value: "No results",
label: "No results",
rtype: "noresult"
});
}
return dataset;
}
},
engine: Hogan,
header: mapheader
},
{
name: 'mappers',
dupChecker: function (datum1, datum2) {
return false;
},
template: $('.mapperTemplate').html(),
remote: {
url: '/search/mappers?term=%QUERY',
filter: function (dataset) {
if (dataset.length == 0) {
dataset.push({
value: "No results",
label: "No results",
rtype: "noresult"
});
}
return dataset;
}
},
engine: Hogan,
header: '<h3 class="search-header">Mappers</h3><div class="minimizeResults minimizeMapperResults"></div><div class="clearfloat"></div>'
}
]);
// tell the autocomplete to launch a new tab with the topic, map, or mapper you clicked on
$('.sidebarSearchField').bind('typeahead:selected', function (event, datum, dataset) {
console.log(event);
if (datum.rtype != "noresult") {
var win;
if (dataset == "topics") {
win = window.open('/topics/' + datum.id, '_blank');
} else if (dataset == "maps") {
win = window.open('/maps/' + datum.id, '_blank');
} else if (dataset == "mappers") {
win = window.open('/maps/mappers/' + datum.id, '_blank');
}
win.focus();
closeSearch(0);
}
});
var checkboxChangeInit = false,
minimizeInit = false;
$('.sidebarSearchField').bind('keyup', function () {
// when the user selects 'added by me' resend the query with their userid attached
if (!checkboxChangeInit) {
$('.limitToMe').bind("change", function (e) {
// set the value of the search equal to itself to retrigger the autocomplete event
searchIsOpen = false;
$('.sidebarSearchField').typeahead('setQuery', $('.sidebarSearchField').val());
setTimeout(function () {
searchIsOpen = true;
}, 2000);
});
checkboxChangeInit = true;
}
// when the user clicks minimize section, hide the results for that section
if (!minimizeInit) {
$('.minimizeMapperResults').click(function (e) {
var s = $('.tt-dataset-mappers .tt-suggestions');
console.log(s.css('height'));
if (s.css('height') == '0px') {
$('.tt-dataset-mappers .tt-suggestions').css({
'height': 'auto',
'overflow': 'visible'
});
$(this).removeClass('maximizeResults').addClass('minimizeResults');
} else {
$('.tt-dataset-mappers .tt-suggestions').css({
'height': '0',
'overflow': 'hidden'
});
$(this).removeClass('minimizeResults').addClass('maximizeResults');
}
});
$('.minimizeTopicResults').click(function (e) {
var s = $('.tt-dataset-topics .tt-suggestions');
console.log(s.css('height'));
if (s.css('height') == '0px') {
s.css({
'height': 'auto',
'border-top': 'none',
'overflow': 'visible'
});
$(this).removeClass('maximizeResults').addClass('minimizeResults');
} else {
s.css({
'height': '0',
'border-top': '1px solid rgb(56, 56, 56)',
'overflow': 'hidden'
});
$(this).removeClass('minimizeResults').addClass('maximizeResults');
}
});
$('.minimizeMapResults').click(function (e) {
var s = $('.tt-dataset-maps .tt-suggestions');
console.log(s.css('height'));
if (s.css('height') == '0px') {
s.css({
'height': 'auto',
'border-top': 'none',
'overflow': 'visible'
});
$(this).removeClass('maximizeResults').addClass('minimizeResults');
} else {
s.css({
'height': '0',
'border-top': '1px solid rgb(56, 56, 56)',
'overflow': 'hidden'
});
$(this).removeClass('minimizeResults').addClass('maximizeResults');
}
});
minimizeInit = true;
}
});
//
$('.sidebarSearch button.addToMap').click(function (event) {
event.stopPropagation();
});
} // end bindSearchHover
function bindAccountHover() {
var accountIsOpen = false
// controls the sliding hover of the bottom left menu
var sliding1 = false;
var lT;
var closeAccount = function () {
lT = setTimeout(function () {
if (!sliding1) {
sliding1 = true;
$('.sidebarAccountIcon').css('background-color', '#0F1519');
$('.sidebarAccountBox').fadeOut(200, function () {
sliding1 = false;
accountIsOpen = false;
});
}
}, 300);
}
var openAccount = function () {
clearTimeout(lT);
if (!sliding1) {
sliding1 = true;
// hide the other two
$('.sidebarFilterBox').hide();
$('.sidebarWandBox').hide();
$('.sidebarFilterIcon').css('background-color', '#0F1519');
$('.sidebarWandIcon').css('background-color', '#0F1519');
$('.sidebarAccountIcon').css('background-color', '#000');
$('.sidebarAccountBox').fadeIn(200, function () {
sliding1 = false;
accountIsOpen = true;
});
}
}
// bind the hover events
$(".sidebarAccount").hover(openAccount, closeAccount);
} // end bindAccountHover
// bind hover events
bindMainMenuHover();
bindSearchHover();
bindAccountHover();
// disable right click events on the new topic and new synapse input fields
$('#new_topic, #new_synapse').bind('contextmenu', function (e) {
return false;
});
// initialize the autocomplete results for the metacode spinner
$('#topic_name').typeahead([
{
name: 'topic_autocomplete',
limit: 8,
template: '<img class="autocompleteSection topicType" width="22" height="22" src="{{typeImageURL}}" alt="{{type}}" title="{{type}}"/><p class="autocompleteSection topicTitle">{{label}}</p><div class="autocompleteSection topicPermission {{permission}}"></div><div class="autocompleteSection topicOriginatorIcon hoverForTip"><span class="tip topicOriginator">{{originator}}</span></div><div class="clearfloat"></div>',
remote: {
url: '/topics/autocomplete_topic?term=%QUERY'
},
engine: Hogan
}
]);
// tell the autocomplete to submit the form with the topic you clicked on if you pick from the autocomplete
$('#topic_name').bind('typeahead:selected', function (event, datum, dataset) {
$('#topic_grabTopic').val(datum.id);
event.preventDefault();
event.stopPropagation();
});
// bind keyboard handlers
$('#topic_name').bind('keyup', function (e) {
switch (e.which) {
case 13:
$('.new_topic').submit();
break;
default:
break;
}
});
// initialize the autocomplete results for the metacode spinner
$('#synapse_desc').typeahead([
{
name: 'synapse_autocomplete',
template: "{{label}}",
remote: {
url: '/search/synapses?term=%QUERY'
},
engine: Hogan
},
{
name: 'existing_synapses',
limit: 50,
template: $('.synapseTemplate').html(),
remote: {
url: '/search/synapses',
replace: function () {
var q = '/search/synapses?topic1id=' + $('#synapse_topic1id').val() + '&topic2id=' + $('#synapse_topic2id').val();
return q;
}
},
engine: Hogan,
header: "<h3>Existing Synapses</h3>"
},
]);
// tell the autocomplete to submit the form with the topic you clicked on if you pick from the autocomplete
$('#synapse_desc').bind('typeahead:selected', function (event, datum, dataset) {
if (datum.id) { // if they clicked on an existing synapse get it
$('#synapse_grabSynapse').val(datum.id);
}
event.preventDefault();
event.stopPropagation();
});
// bind keyboard handlers
$('#synapse_desc').bind('keyup', function (e) {
switch (e.which) {
case 13:
$('.new_synapse').submit();
break;
default:
break;
}
});
// when either form submits, don't leave the page
$('.new_topic, .new_synapse').bind('submit', function (event, data) {
event.preventDefault();
});
//$(".scroll").mCustomScrollbar();
// initialize scroll bar for filter by metacode, then hide it and position it correctly again
$("#filter_by_metacode").mCustomScrollbar({
advanced: {
updateOnContentResize: true
}
});
$('.sidebarFilterBox').hide().css({
position: 'absolute',
top: '35px',
right: '-36px'
});
// initialize metacode spinner and then hide it
$("#metacodeImg").CloudCarousel({
titleBox: $('#metacodeImgTitle'),
yRadius: 40,
xPos: 150,
yPos: 40,
speed: 0.3,
mouseWheel: true,
bringToFront: true
});
$('.new_topic').hide();
$('.notice.metamaps').delay(10000).fadeOut('fast');
$('.alert.metamaps').delay(10000).fadeOut('fast');
$('#center-container').bind('contextmenu', function (e) {
return false;
});
addHoverForSettings();
//bind best_in_place ajax callbacks
$('.best_in_place_desc').bind("ajax:success", function () {
$(this).parents('.CardOnGraph').find('.scroll').mCustomScrollbar("update");
});
$('.best_in_place_link').bind("ajax:success", function () {
var link = $(this).html();
$(this).parents('.CardOnGraph').find('.go-link').attr('href', link);
});
//bind lightbox clicks
$('.openLightbox').click(function (event) {
openLightbox($(this).attr('data-open'));
event.preventDefault();
return false;
});
// bind permission changer events
$('.permIcon').click(function () {
$(this).siblings('#map_permission').val($(this).attr('data-permission'));
$(this).siblings('.permIcon').find('.mapPermIcon').removeClass('selected');
$(this).find('.mapPermIcon').addClass('selected');
});
// bind keyboard handlers
$('body').bind('keyup', function (e) {
switch (e.which) {
case 13:
enterKeyHandler(e);
break;
case 27:
escKeyHandler();
break;
default:
break; //console.log(e.which);
}
});
}); // end document.ready
function addHoverForSettings() {
// controls the sliding hover of the settings for cards
$(".permActivator").unbind('mouseover');
$(".permActivator").unbind('mouseout');
var sliding2 = false;
var lT1, lT2;
$(".permActivator").bind('mouseover',
function () {
clearTimeout(lT2);
that = this;
lT1 = setTimeout(function () {
if (!sliding2) {
sliding2 = true;
$(that).animate({
width: '203px',
height: '37px'
}, 300, function () {
sliding2 = false;
});
}
}, 300);
});
$(".permActivator").bind('mouseout',
function () {
clearTimeout(lT1);
that = this;
lT2 = setTimeout(function () {
if (!sliding2) {
sliding2 = true;
$(that).animate({
height: '16px',
width: '16px'
}, 300, function () {
sliding2 = false;
});
}
}, 800);
}
);
$('.best_in_place_permission').unbind("ajax:success");
//bind best_in_place ajax callbacks
$('.best_in_place_permission').bind("ajax:success", function () {
var permission = $(this).html();
var el = $(this).parents('.cardSettings').find('.mapPerm');
el.attr('title', permission);
if (permission == "commons") el.html("co");
else if (permission == "public") el.html("pu");
else if (permission == "private") el.html("pr");
});
} // end addHoverForSettings
// this is to save the layout of a map // this is to save the layout of a map
function saveLayoutAll() { function saveLayoutAll() {
@ -714,14 +126,6 @@ function fetchRelatives(node) {
}); });
Mconsole.plot(); Mconsole.plot();
} }
/*Mconsole.op.contract(node, {
type: 'replot'
});
Mconsole.op.expand(node, {
type: 'animate',
transition: $jit.Trans.Elastic.easeOut,
duration: 1000
});*/
}, },
error: function () { error: function () {
alert('failure'); alert('failure');
@ -825,6 +229,98 @@ function updateMapPermission(mapid, permission) {
}); });
} }
function updateMetacodeSet(set, index, custom) {
if (custom && MetamapsModel.newSelectedMetacodes.length == 0) {
alert('Please select at least one metacode to use!');
return false;
}
var codesToSwitchTo;
MetamapsModel.selectedMetacodeSetIndex = index;
MetamapsModel.selectedMetacodeSet = "metacodeset-" + set;
if (!custom) {
codesToSwitchTo = $('#metacodeSwitchTabs' + set).attr('data-metacodes').split(',');
$('.customMetacodeList li').addClass('toggledOff');
MetamapsModel.selectedMetacodes = [];
MetamapsModel.selectedMetacodeNames = [];
MetamapsModel.newSelectedMetacodes = [];
MetamapsModel.newSelectedMetacodeNames = [];
}
if (custom) {
// uses .slice to avoid setting the two arrays to the same actual array
MetamapsModel.selectedMetacodes = MetamapsModel.newSelectedMetacodes.slice(0);
MetamapsModel.selectedMetacodeNames = MetamapsModel.newSelectedMetacodeNames.slice(0);
codesToSwitchTo = MetamapsModel.selectedMetacodeNames.slice(0);
}
// sort by name
codesToSwitchTo.sort();
codesToSwitchTo.reverse();
$('#metacodeImg, #metacodeImgTitle').empty();
$('#metacodeImg').removeData('cloudcarousel');
var newMetacodes = "";
for (var i = 0; i < codesToSwitchTo.length; i++) {
newMetacodes += '<img class="cloudcarousel" width="40" height="40" src="' + imgArray[codesToSwitchTo[i]].src + '" title="' + codesToSwitchTo[i] + '"/>';
};
$('#metacodeImg').empty().append(newMetacodes).CloudCarousel({
titleBox: $('#metacodeImgTitle'),
yRadius: 40,
xPos: 150,
yPos: 40,
speed: 0.15,
mouseWheel: true,
bringToFront: true
});
$('#lightbox_overlay').hide();
var mdata = {
"metacodes": {
"value": custom ? MetamapsModel.selectedMetacodes.toString() : MetamapsModel.selectedMetacodeSet
}
};
$.ajax({
type: "POST",
dataType: 'json',
url: "/user/updatemetacodes",
data: mdata,
success: function (data) {
console.log('success updating metacodes');
//setTimeout(function () {
// $('.metacodeTitle').hide();
// $('.showcard .icon').css('z-index', '1');
//}, 500);
},
error: function () {
alert('failed to update metacodes');
}
});
}
function cancelMetacodeSetSwitch() {
if (MetamapsModel.selectedMetacodeSet != "metacodeset-custom") {
$('.customMetacodeList li').addClass('toggledOff');
MetamapsModel.selectedMetacodes = [];
MetamapsModel.selectedMetacodeNames = [];
MetamapsModel.newSelectedMetacodes = [];
MetamapsModel.newSelectedMetacodeNames = [];
}
else { // custom set is selected
// reset it to the current actual selection
$('.customMetacodeList li').addClass('toggledOff');
for (var i = 0; i < MetamapsModel.selectedMetacodes.length; i++) {
$('#' + MetamapsModel.selectedMetacodes[i]).removeClass('toggledOff');
};
// uses .slice to avoid setting the two arrays to the same actual array
MetamapsModel.newSelectedMetacodeNames = MetamapsModel.selectedMetacodeNames.slice(0);
MetamapsModel.newSelectedMetacodes = MetamapsModel.selectedMetacodes.slice(0);
}
$('#metacodeSwitchTabs').tabs("select", MetamapsModel.selectedMetacodeSetIndex);
}
function MconsoleReset() { function MconsoleReset() {
var tX = Mconsole.canvas.translateOffsetX; var tX = Mconsole.canvas.translateOffsetX;
@ -843,7 +339,6 @@ function openNodeShowcard(node) {
$('.showcard').fadeIn('fast'); $('.showcard').fadeIn('fast');
var s = $('.showcard').find('.scroll'); var s = $('.showcard').find('.scroll');
s.height(s.height()).mCustomScrollbar(); s.height(s.height()).mCustomScrollbar();
//node.setData('dim', 1, 'current');
MetamapsModel.showcardInUse = node.id; MetamapsModel.showcardInUse = node.id;
} }
@ -853,6 +348,13 @@ function openLightbox(which) {
$('#lightbox_overlay').show(); $('#lightbox_overlay').show();
$('#lightbox_main').css('margin-top', '-' + ($('#lightbox_main').height() / 2) + 'px'); $('#lightbox_main').css('margin-top', '-' + ($('#lightbox_main').height() / 2) + 'px');
//if (MetamapsModel.selectedMetacodeSet == "metacodeset-custom" && !MetamapsModel.metacodeScrollerInit) {
if (!MetamapsModel.metacodeScrollerInit) {
//$('.customMetacodeList').mCustomScrollbar();
$('.customMetacodeList, .metacodeSetList').mCustomScrollbar({advanced: { updateOnContentResize: true }});
MetamapsModel.metacodeScrollerInit = true;
}
} }
function cancelMapCreate(id) { function cancelMapCreate(id) {

View file

@ -0,0 +1,93 @@
/* AllMappingPages means:
1. being logged in or logged out and,
2. either
a. being on a Map page, or
b. being on a Topic page
*/
$(document).ready(function () {
// initialize topic card draggability and resizability
$('.showcard').draggable({
handle: ".metacodeImage"
});
$('#showcard').resizable({
maxHeight: 500,
maxWidth: 500,
minHeight: 320,
minWidth: 226,
resize: function (event, ui) {
var p = $('#showcard').find('.scroll');
p.height(p.height()).mCustomScrollbar('update');
}
}).css({
display: 'none',
top: '300px',
left: '100px'
});
function bindFilterHover() {
var filterIsOpen = false;
// controls the sliding hover of the bottom left menu
var sliding1 = false;
var lT;
var closeFilter = function () {
lT = setTimeout(function () {
if (!sliding1) {
sliding1 = true;
$('.sidebarFilterIcon').css('background-color', '#0F1519');
$('.sidebarFilterBox').fadeOut(200, function () {
sliding1 = false;
filterIsOpen = false;
});
}
}, 300);
}
var openFilter = function () {
clearTimeout(lT);
if (!sliding1) {
sliding1 = true;
// hide the other two
$('.sidebarAccountBox').hide();
$('.sidebarWandBox').hide();
$('.sidebarAccountIcon').css('background-color', '#0F1519');
$('.sidebarWandIcon').css('background-color', '#0F1519');
$('.sidebarFilterIcon').css('background-color', '#000');
$('.sidebarFilterBox').fadeIn(200, function () {
sliding1 = false;
filterIsOpen = true;
});
}
}
// bind the hover events
$(".sidebarFilter").hover(openFilter, closeFilter);
} // end bindFilterHover
bindFilterHover();
// initialize scroll bar for filter by metacode, then hide it and position it correctly again
$("#filter_by_metacode").mCustomScrollbar({
advanced: {
updateOnContentResize: true
}
});
$('.sidebarFilterBox').hide().css({
position: 'absolute',
top: '35px',
right: '-36px'
});
// prevent right clicks on the main canvas, so as to not get in the way of our right clicks
$('#center-container').bind('contextmenu', function (e) {
return false;
});
}); // end document.ready

View file

@ -0,0 +1,19 @@
/* AuthAllMappingPages means:
1. being logged in and,
2. either
a. being on a Map page, or
b. being on a Topic page
*/
$(document).ready(function () {
$('.sidebarFork').click(function () {
saveToMap();
});
// initialize best_in_place editing
$('.authenticated div.permission.canEdit .best_in_place').best_in_place();
}); // end document.ready

View file

@ -0,0 +1,32 @@
/* authCanEditMapPage means:
1. being logged in and,
2. being on a Map page and having edit permissions (your map, or commons map)
*/
$(document).ready(function () {
// because anyone who can edit the map can collaborate on it in realtime
$(".sidebarCollaborateIcon").click(function (event) {
if (!goRealtime) {
$('.sidebarCollaborate .tip').html('Stop Realtime Collaboration');
} else {
$('.sidebarCollaborate .tip').html('Start Realtime Collaboration');
}
goRealtime = !goRealtime;
$(".sidebarCollaborateIcon").toggleClass("blue");
});
// because anyone who can edit the map can save a new map layout
$('.sidebarSave').click(function () {
saveLayoutAll();
});
// because anyone who can edit the map can change the map title
$('.mapInfoName .best_in_place_name').bind("ajax:success", function () {
var name = $(this).html();
$('.mapName').html(name);
});
}); // end document.ready

View file

@ -0,0 +1,156 @@
/* authCanEditMappingPages means:
1. being logged in and,
2. either
a. being on a Map page and having edit permissions (your map, or commons map) or,
b. being on a Topic page
this code adds required jQuery for creating, or pulling in, topics and synapses
*/
$(document).ready(function () {
//////
//////
//// TOPIC CREATION
// initialize the autocomplete results for the metacode spinner
$('#topic_name').typeahead([
{
name: 'topic_autocomplete',
limit: 8,
template: $('#topicAutocompleteTemplate').html(),
remote: {
url: '/topics/autocomplete_topic?term=%QUERY'
},
engine: Hogan
}
]);
// tell the autocomplete to submit the form with the topic you clicked on if you pick from the autocomplete
$('#topic_name').bind('typeahead:selected', function (event, datum, dataset) {
$('#topic_grabTopic').val(datum.id);
event.preventDefault();
event.stopPropagation();
});
// bind keyboard handlers
$('#topic_name').bind('keyup', function (e) {
switch (e.which) {
case 13:
$('.new_topic').submit();
break;
default:
break;
}
});
// initialize metacode spinner and then hide it
$("#metacodeImg").CloudCarousel({
titleBox: $('#metacodeImgTitle'),
yRadius: 40,
xPos: 150,
yPos: 40,
speed: 0.3,
mouseWheel: true,
bringToFront: true
});
$('.new_topic').hide();
//////
//////
//// SYNAPSE CREATION
// initialize the autocomplete results for synapse creation
$('#synapse_desc').typeahead([
{
name: 'synapse_autocomplete',
template: "{{label}}",
remote: {
url: '/search/synapses?term=%QUERY'
},
engine: Hogan
},
{
name: 'existing_synapses',
limit: 50,
template: $('#synapseAutocompleteTemplate').html(),
remote: {
url: '/search/synapses',
replace: function () {
var q = '/search/synapses?topic1id=' + $('#synapse_topic1id').val() + '&topic2id=' + $('#synapse_topic2id').val();
return q;
}
},
engine: Hogan,
header: "<h3>Existing Synapses</h3>"
},
]);
// tell the autocomplete to submit the form with the topic you clicked on if you pick from the autocomplete
$('#synapse_desc').bind('typeahead:selected', function (event, datum, dataset) {
if (datum.id) { // if they clicked on an existing synapse get it
$('#synapse_grabSynapse').val(datum.id);
}
event.preventDefault();
event.stopPropagation();
});
// bind keyboard handlers
$('#synapse_desc').bind('keyup', function (e) {
switch (e.which) {
case 13:
$('.new_synapse').submit();
break;
default:
break;
}
});
//////
//////
//// TOPIC AND SYNAPSE CREATION
// when either form submits, don't leave the page
$('.new_topic, .new_synapse').bind('submit', function (event, data) {
event.preventDefault();
});
// disable right click events on the new topic and new synapse input fields
$('#new_topic, #new_synapse').bind('contextmenu', function (e) {
return false;
});
//////
//////
//// SWITCHING METACODE SETS
$('#metacodeSwitchTabs').tabs({
selected: MetamapsModel.selectedMetacodeSetIndex
}).addClass("ui-tabs-vertical ui-helper-clearfix");
$("#metacodeSwitchTabs .ui-tabs-nav li").removeClass("ui-corner-top").addClass("ui-corner-left");
$("#metacodeSwitchTabs .ui-tabs-nav li a").click(function(){
// recenter the lightbox when you switch tabs
$('#lightbox_main').css('margin-top', '-' + ($('#lightbox_main').height() / 2) + 'px');
});
/*$("#metacodeSetCustom").click(function () {
if (!MetamapsModel.metacodeScrollerInit) {
$('.customMetacodeList, .metacodeSetList').mCustomScrollbar({advanced: { updateOnContentResize: true }});
MetamapsModel.metacodeScrollerInit = true;
}
});*/
$('.customMetacodeList li').click(function () {
if ($(this).attr('class') != 'toggledOff') {
$(this).addClass('toggledOff');
var value_to_remove = $(this).attr('id');
var name_to_remove = $(this).attr('data-name');
MetamapsModel.newSelectedMetacodes.splice(MetamapsModel.newSelectedMetacodes.indexOf(value_to_remove), 1);
MetamapsModel.newSelectedMetacodeNames.splice(MetamapsModel.newSelectedMetacodeNames.indexOf(name_to_remove), 1);
} else if ($(this).attr('class') == 'toggledOff') {
$(this).removeClass('toggledOff');
MetamapsModel.newSelectedMetacodes.push($(this).attr('id'));
MetamapsModel.newSelectedMetacodeNames.push($(this).attr('data-name'));
}
});
}); // end document.ready

View file

@ -0,0 +1,16 @@
/* authEveryPage means:
1. being logged in and on any page on metamaps
this code adds required jQuery for the create map lightBox that can be used from any page on metamaps
*/
$(document).ready(function () {
// bind permission changer events on the createMap form
$('.permIcon').click(function () {
$(this).siblings('#map_permission').val($(this).attr('data-permission'));
$(this).siblings('.permIcon').find('.mapPermIcon').removeClass('selected');
$(this).find('.mapPermIcon').addClass('selected');
});
}); // end document.ready

View file

@ -0,0 +1,36 @@
/* AuthMapCreatorMapPage means:
1. being on a Map page
2. being the original creator of that map
*/
$(document).ready(function () {
// ability to change permission of the map
var selectingPermission = false;
$('.yourMap .mapPermission').click(function () {
if (!selectingPermission) {
selectingPermission = true;
$(this).addClass('minimize'); // this line flips the drop down arrow to a pull up arrow
if ($(this).hasClass('commons')) {
$(this).append('<ul class="permissionSelect"><li class="public"></li><li class="private"></li></ul>');
} else if ($(this).hasClass('public')) {
$(this).append('<ul class="permissionSelect"><li class="commons"></li><li class="private"></li></ul>');
} else if ($(this).hasClass('private')) {
$(this).append('<ul class="permissionSelect"><li class="commons"></li><li class="public"></li></ul>');
}
$('.mapPermission .permissionSelect li').click(function (event) {
selectingPermission = false;
var permission = $(this).attr('class');
updateMapPermission(mapid, permission);
event.stopPropagation();
});
} else {
selectingPermission = false;
$(this).removeClass('minimize'); // this line flips the pull up arrow to a drop down arrow
$('.mapPermission .permissionSelect').remove();
}
});
}); // end document.ready

View file

@ -0,0 +1,404 @@
// everything in this document.ready function is here because it is needed on every single page on metamaps
$(document).ready(function () {
function bindMainMenuHover() {
var menuIsOpen = false
// controls the sliding hover of the bottom left menu
var sliding1 = false;
var lT;
var closeMenu = function () {
lT = setTimeout(function () {
if (!sliding1) {
sliding1 = true;
// $('.footer .menu').animate({
// height: '0px'
// }, 300, function() {
// sliding1 = false;
// menuIsOpen = false;
// });
$('.footer').css('border-top-right-radius', '5px');
$('.logo').animate({
'background-position-x': '-10px'
}, 200);
$('.footer .menu').fadeOut(200, function () {
sliding1 = false;
menuIsOpen = false;
});
}
}, 500);
}
var openMenu = function () {
clearTimeout(lT);
if (!sliding1) {
sliding1 = true;
// $('.footer .menu').animate({
// height: listLength + 'px'
// }, 300, function() {
// sliding1 = false;
// });
$('.footer').css('border-top-right-radius', '0');
$('.logo').animate({
'background-position-x': '-7px'
}, 200);
$('.footer .menu').fadeIn(200, function () {
sliding1 = false;
});
}
}
// bind the hover events
$(".logo").hover(openMenu, closeMenu);
// when on touch screen, make touching on the logo do what hovering does on desktop
$("#mainTitle a").bind('touchend', function (evt) {
if (!menuIsOpen) {
openMenu();
evt.preventDefault();
evt.stopPropagation();
}
});
}
function bindSearchHover() {
var searchIsOpen = false
// controls the sliding hover of the search
var sliding1 = false;
var lT;
var openSearch = function () {
clearTimeout(lT);
if (!sliding1 && !searchIsOpen) {
hideCards();
sliding1 = true;
$('.sidebarSearch .twitter-typeahead, .sidebarSearch .tt-hint, .sidebarSearchField').animate({
width: '200px'
}, 200, function () {
$('.sidebarSearchField, .sidebarSearch .tt-hint').css({
padding: '5px 10px',
width: '180px'
});
$('.sidebarSearchField').focus();
sliding1 = false
searchIsOpen = true;
});
}
}
var closeSearch = function (closeAfter) {
lT = setTimeout(function () {
if (!sliding1 && searchIsOpen && $('.sidebarSearchField').val() == '') {
sliding1 = true;
$('.sidebarSearchField, .sidebarSearch .tt-hint').css({
padding: '5px 0',
width: '200px'
});
$('.sidebarSearch .twitter-typeahead, .sidebarSearch .tt-hint, .sidebarSearchField').animate({
width: '0'
}, 200, function () {
$('.sidebarSearchField').typeahead('setQuery', '');
sliding1 = false;
searchIsOpen = false;
});
}
}, closeAfter);
}
// bind the hover events
$(".sidebarSearch").hover(function () {
openSearch()
}, function () {
closeSearch(800)
});
$('.sidebarSearchIcon').click(function (e) {
$('.sidebarSearchField').focus();
});
$('.sidebarSearch').click(function (e) {
e.stopPropagation();
});
$('body').click(function (e) {
closeSearch(0);
});
// if the search is closed and user hits SHIFT+S
$('body').bind('keydown', function (e) {
switch (e.which) {
case 191:
if (e.ctrlKey && !searchIsOpen) {
openSearch();
}
break;
default:
break; //console.log(e.which);
}
});
// initialize the search box autocomplete results
var mapheader = userid ? '<h3 class="search-header">Maps</h3><input type="checkbox" class="limitToMe" id="limitMapsToMe"></input><label for="limitMapsToMe" class="limitToMeLabel">added by me</label><div class="minimizeResults minimizeMapResults"></div><div class="clearfloat"></div>' : '<h3 class="search-header">Maps</h3><div class="minimizeResults minimizeMapResults"></div><div class="clearfloat"></div>';
var topicheader = userid ? '<h3 class="search-header">Topics</h3><input type="checkbox" class="limitToMe" id="limitTopicsToMe"></input><label for="limitTopicsToMe" class="limitToMeLabel">added by me</label><div class="minimizeResults minimizeTopicResults"></div><div class="clearfloat"></div>' : '<h3 class="search-header">Topics</h3><div class="minimizeResults minimizeTopicResults"></div><div class="clearfloat"></div>';
$('.sidebarSearchField').typeahead([
{
name: 'topics',
dupChecker: function (datum1, datum2) {
return false;
},
template: $('#topicSearchTemplate').html(),
remote: {
url: '/search/topics?term=%QUERY',
replace: function () {
var q = '/search/topics?term=' + $('.sidebarSearchField').val();
if ($("#limitTopicsToMe").is(':checked')) {
q += "&user=" + userid.toString();
}
return q;
},
filter: function (dataset) {
if (dataset.length == 0) {
dataset.push({
value: "No results",
label: "No results",
typeImageURL: "/assets/icons/wildcard.png",
rtype: "noresult"
});
}
return dataset;
}
},
engine: Hogan,
header: topicheader
},
{
name: 'maps',
dupChecker: function (datum1, datum2) {
return false;
},
template: $('#mapSearchTemplate').html(),
remote: {
url: '/search/maps?term=%QUERY',
replace: function () {
var q = '/search/maps?term=' + $('.sidebarSearchField').val();
if ($("#limitMapsToMe").is(':checked')) {
q += "&user=" + userid.toString();
}
return q;
},
filter: function (dataset) {
if (dataset.length == 0) {
dataset.push({
value: "No results",
label: "No results",
rtype: "noresult"
});
}
return dataset;
}
},
engine: Hogan,
header: mapheader
},
{
name: 'mappers',
dupChecker: function (datum1, datum2) {
return false;
},
template: $('#mapperSearchTemplate').html(),
remote: {
url: '/search/mappers?term=%QUERY',
filter: function (dataset) {
if (dataset.length == 0) {
dataset.push({
value: "No results",
label: "No results",
rtype: "noresult"
});
}
return dataset;
}
},
engine: Hogan,
header: '<h3 class="search-header">Mappers</h3><div class="minimizeResults minimizeMapperResults"></div><div class="clearfloat"></div>'
}
]);
// tell the autocomplete to launch a new tab with the topic, map, or mapper you clicked on
$('.sidebarSearchField').bind('typeahead:selected', function (event, datum, dataset) {
console.log(event);
if (datum.rtype != "noresult") {
var win;
if (dataset == "topics") {
win = window.open('/topics/' + datum.id, '_blank');
} else if (dataset == "maps") {
win = window.open('/maps/' + datum.id, '_blank');
} else if (dataset == "mappers") {
win = window.open('/maps/mappers/' + datum.id, '_blank');
}
win.focus();
closeSearch(0);
}
});
var checkboxChangeInit = false,
minimizeInit = false;
$('.sidebarSearchField').bind('keyup', function () {
// when the user selects 'added by me' resend the query with their userid attached
if (!checkboxChangeInit) {
$('.limitToMe').bind("change", function (e) {
// set the value of the search equal to itself to retrigger the autocomplete event
searchIsOpen = false;
$('.sidebarSearchField').typeahead('setQuery', $('.sidebarSearchField').val());
setTimeout(function () {
searchIsOpen = true;
}, 2000);
});
checkboxChangeInit = true;
}
// when the user clicks minimize section, hide the results for that section
if (!minimizeInit) {
$('.minimizeMapperResults').click(function (e) {
var s = $('.tt-dataset-mappers .tt-suggestions');
console.log(s.css('height'));
if (s.css('height') == '0px') {
$('.tt-dataset-mappers .tt-suggestions').css({
'height': 'auto',
'overflow': 'visible'
});
$(this).removeClass('maximizeResults').addClass('minimizeResults');
} else {
$('.tt-dataset-mappers .tt-suggestions').css({
'height': '0',
'overflow': 'hidden'
});
$(this).removeClass('minimizeResults').addClass('maximizeResults');
}
});
$('.minimizeTopicResults').click(function (e) {
var s = $('.tt-dataset-topics .tt-suggestions');
console.log(s.css('height'));
if (s.css('height') == '0px') {
s.css({
'height': 'auto',
'border-top': 'none',
'overflow': 'visible'
});
$(this).removeClass('maximizeResults').addClass('minimizeResults');
} else {
s.css({
'height': '0',
'border-top': '1px solid rgb(56, 56, 56)',
'overflow': 'hidden'
});
$(this).removeClass('minimizeResults').addClass('maximizeResults');
}
});
$('.minimizeMapResults').click(function (e) {
var s = $('.tt-dataset-maps .tt-suggestions');
console.log(s.css('height'));
if (s.css('height') == '0px') {
s.css({
'height': 'auto',
'border-top': 'none',
'overflow': 'visible'
});
$(this).removeClass('maximizeResults').addClass('minimizeResults');
} else {
s.css({
'height': '0',
'border-top': '1px solid rgb(56, 56, 56)',
'overflow': 'hidden'
});
$(this).removeClass('minimizeResults').addClass('maximizeResults');
}
});
minimizeInit = true;
}
});
//
$('.sidebarSearch button.addToMap').click(function (event) {
event.stopPropagation();
});
} // end bindSearchHover
function bindAccountHover() {
var accountIsOpen = false
// controls the sliding hover of the bottom left menu
var sliding1 = false;
var lT;
var closeAccount = function () {
lT = setTimeout(function () {
if (!sliding1) {
sliding1 = true;
$('.sidebarAccountIcon').css('background-color', '#0F1519');
$('.sidebarAccountBox').fadeOut(200, function () {
sliding1 = false;
accountIsOpen = false;
});
}
}, 300);
}
var openAccount = function () {
clearTimeout(lT);
if (!sliding1) {
sliding1 = true;
// hide the other two
$('.sidebarFilterBox').hide();
$('.sidebarWandBox').hide();
$('.sidebarFilterIcon').css('background-color', '#0F1519');
$('.sidebarWandIcon').css('background-color', '#0F1519');
$('.sidebarAccountIcon').css('background-color', '#000');
$('.sidebarAccountBox').fadeIn(200, function () {
sliding1 = false;
accountIsOpen = true;
});
}
}
// bind the hover events
$(".sidebarAccount").hover(openAccount, closeAccount);
} // end bindAccountHover
// bind hover events
bindMainMenuHover();
bindSearchHover();
bindAccountHover();
// hide notices after 10 seconds
$('.notice.metamaps').delay(10000).fadeOut('fast');
$('.alert.metamaps').delay(10000).fadeOut('fast');
//bind lightbox clicks
$('.openLightbox').click(function (event) {
openLightbox($(this).attr('data-open'));
event.preventDefault();
return false;
});
// bind keyboard handlers
$('body').bind('keyup', function (e) {
switch (e.which) {
case 13:
enterKeyHandler(e);
break;
case 27:
escKeyHandler();
break;
default:
break; //console.log(e.which);
}
});
}); // end document.ready

View file

@ -0,0 +1,48 @@
/* MapPage means:
1. being on a Map page
*/
$(document).ready(function () {
function bindInfoHover() {
var infoIsOpen = false;
// controls the sliding hover of the bottom left menu
var sliding1 = false;
var lT;
var closeInfo = function () {
lT = setTimeout(function () {
if (!sliding1) {
sliding1 = true;
$('.mapInfoBox').fadeOut(200, function () {
sliding1 = false;
infoIsOpen = false;
});
}
}, 300);
}
var openInfo = function (event) {
clearTimeout(lT);
if (!sliding1 && event.target.className != "openCheatsheet openLightbox") {
sliding1 = true;
$('.mapInfoBox').fadeIn(200, function () {
sliding1 = false;
infoIsOpen = true;
});
}
}
// bind the hover events
$("div.index").hover(openInfo, closeInfo);
} // end bindInfoHover
bindInfoHover();
}); // end document.ready

View file

@ -1,75 +1,166 @@
window.realtime = {}; window.realtime = {};
window.realtime.addTopicToMap = function(topic) { window.realtime.notifyTimeOut = null;
var newPos, tempForT; window.realtime.notifyUser = function (message) {
Mconsole.graph.addNode(topic); if ($('.notice.metamaps').length == 0) {
tempForT = Mconsole.graph.getNode(topic.id); $('body').prepend('<div class="notice metamaps" />');
tempForT.setData('dim', 1, 'start'); }
tempForT.setData('dim', 25, 'end'); $('.notice.metamaps').hide().html(message).fadeIn('fast');
newPos = new $jit.Complex();
newPos.x = tempForT.data.$xloc; clearTimeout(window.realtime.notifyTimeOut);
newPos.y = tempForT.data.$yloc; window.realtime.notifyTimeOut = setTimeout(function () {
tempForT.setPos(newPos, 'start'); $('.notice.metamaps').fadeOut('fast');
tempForT.setPos(newPos, 'current'); }, 8000);
tempForT.setPos(newPos, 'end');
Mconsole.fx.plotNode(tempForT, Mconsole.canvas);
return Mconsole.labels.plotLabel(Mconsole.canvas, tempForT, Mconsole.config);
}; };
window.realtime.updateTopicOnMap = function(topic) { window.realtime.setupSocket = function () {
var newPos, tempForT; var socket = window.realtime.socket;
tempForT = Mconsole.graph.getNode(topic.id);
tempForT.data = topic.data; socket.emit('newMapperNotify', {
tempForT.name = topic.name; userid: userid,
if (MetamapsModel.showcardInUse === topic.id) { username: username,
populateShowCard(tempForT); mapid: mapid
} });
newPos = new $jit.Complex();
newPos.x = tempForT.data.$xloc; // if you're the 'new guy' update your list with who's already online
newPos.y = tempForT.data.$yloc; socket.on(userid + '-' + mapid + '-UpdateMapperList', function (data) {
tempForT.setPos(newPos, 'start'); // data.userid
tempForT.setPos(newPos, 'current'); // data.username
tempForT.setPos(newPos, 'end'); //alert(data.username + ' is already online');
return Mconsole.fx.animate({ });
modes: ['linear', 'node-property:dim', 'edge-property:lineWidth'],
transition: $jit.Trans.Quad.easeInOut, // receive word that there's a new mapper on the map
duration: 500 socket.on('maps-' + mapid + '-newmapper', function (data) {
}); // data.userid
// data.username
window.realtime.notifyUser(data.username + ' just came online');
// send this new mapper back your details, and the awareness that you're online
var update = {
userToNotify: data.userid,
username: username,
userid: userid,
mapid: mapid
};
socket.emit('updateNewMapperList', update);
});
socket.on('maps-' + mapid + '-lostmapper', function (data) {
// data.userid
// data.username
window.realtime.notifyUser(data.username + ' just went offline');
});
socket.on('maps-' + mapid, function (data) {
//as long as you weren't the origin of the changes, update your map
if (data.origin != userid && goRealtime) {
if (data.resource == 'Topic') {
topic = $.parseJSON(data.obj);
if (data.action == 'create') {
window.realtime.addTopicToMap(topic);
} else if (data.action == 'update' && Mconsole.graph.getNode(topic.id) != 'undefined') {
window.realtime.updateTopicOnMap(topic);
} else if (data.action == 'destroy' && Mconsole.graph.getNode(topic.id) != 'undefined') {
hideNode(topic.id)
}
return;
} else if (data.resource == 'Synapse') {
synapse = $.parseJSON(data.obj);
if (data.action == 'create') {
window.realtime.addSynapseToMap(synapse);
} else if (data.action == 'update' &&
Mconsole.graph.getAdjacence(synapse.data.$direction['0'], synapse.data.$direction['1']) != 'undefined') {
window.realtime.updateSynapseOnMap(synapse);
} else if (data.action == 'destroy' &&
Mconsole.graph.getAdjacence(synapse.data.$direction['0'], synapse.data.$direction['1']) != 'undefined') {
var edge = Mconsole.graph.getAdjacence(synapse.data.$direction['0'], synapse.data.$direction['1']);
hideEdge(edge);
}
return;
}
}
});
}; };
window.realtime.addSynapseToMap = function(synapse) { window.realtime.addTopicToMap = function (topic) {
var Node1, Node2, tempForS; var newPos, tempForT;
Node1 = Mconsole.graph.getNode(synapse.data.$direction[0]); Mconsole.graph.addNode(topic);
Node2 = Mconsole.graph.getNode(synapse.data.$direction[1]); tempForT = Mconsole.graph.getNode(topic.id);
Mconsole.graph.addAdjacence(Node1, Node2, {}); tempForT.setData('dim', 1, 'start');
tempForS = Mconsole.graph.getAdjacence(Node1.id, Node2.id); tempForT.setData('dim', 25, 'end');
tempForS.setDataset('start', { newPos = new $jit.Complex();
lineWidth: 0.4 newPos.x = tempForT.data.$xloc;
}); newPos.y = tempForT.data.$yloc;
tempForS.setDataset('end', { tempForT.setPos(newPos, 'start');
lineWidth: 2 tempForT.setPos(newPos, 'current');
}); tempForT.setPos(newPos, 'end');
tempForS.data = synapse.data; Mconsole.fx.plotNode(tempForT, Mconsole.canvas);
Mconsole.fx.plotLine(tempForS, Mconsole.canvas); return Mconsole.labels.plotLabel(Mconsole.canvas, tempForT, Mconsole.config);
return Mconsole.fx.animate({
modes: ['linear', 'node-property:dim', 'edge-property:lineWidth'],
transition: $jit.Trans.Quad.easeInOut,
duration: 500
});
}; };
window.realtime.updateSynapseOnMap = function(synapse) { window.realtime.updateTopicOnMap = function (topic) {
var k, tempForS, v, wasShowDesc, _ref; var newPos, tempForT;
tempForS = Mconsole.graph.getAdjacence(synapse.data.$direction[0], synapse.data.$direction[1]); tempForT = Mconsole.graph.getNode(topic.id);
wasShowDesc = tempForS.data.$showDesc; tempForT.data = topic.data;
_ref = synapse.data; tempForT.name = topic.name;
for (k in _ref) { if (MetamapsModel.showcardInUse === topic.id) {
v = _ref[k]; populateShowCard(tempForT);
tempForS.data[k] = v; }
} newPos = new $jit.Complex();
tempForS.data.$showDesc = wasShowDesc; newPos.x = tempForT.data.$xloc;
if (MetamapsModel.edgecardInUse === synapse.data.$id) { newPos.y = tempForT.data.$yloc;
editEdge(tempForS, false); tempForT.setPos(newPos, 'start');
} tempForT.setPos(newPos, 'current');
return Mconsole.plot(); tempForT.setPos(newPos, 'end');
return Mconsole.fx.animate({
modes: ['linear', 'node-property:dim', 'edge-property:lineWidth'],
transition: $jit.Trans.Quad.easeInOut,
duration: 500
});
};
window.realtime.addSynapseToMap = function (synapse) {
var Node1, Node2, tempForS;
Node1 = Mconsole.graph.getNode(synapse.data.$direction[0]);
Node2 = Mconsole.graph.getNode(synapse.data.$direction[1]);
Mconsole.graph.addAdjacence(Node1, Node2, {});
tempForS = Mconsole.graph.getAdjacence(Node1.id, Node2.id);
tempForS.setDataset('start', {
lineWidth: 0.4
});
tempForS.setDataset('end', {
lineWidth: 2
});
tempForS.data = synapse.data;
Mconsole.fx.plotLine(tempForS, Mconsole.canvas);
return Mconsole.fx.animate({
modes: ['linear', 'node-property:dim', 'edge-property:lineWidth'],
transition: $jit.Trans.Quad.easeInOut,
duration: 500
});
};
window.realtime.updateSynapseOnMap = function (synapse) {
var k, tempForS, v, wasShowDesc, _ref;
tempForS = Mconsole.graph.getAdjacence(synapse.data.$direction[0], synapse.data.$direction[1]);
wasShowDesc = tempForS.data.$showDesc;
_ref = synapse.data;
for (k in _ref) {
v = _ref[k];
tempForS.data[k] = v;
}
tempForS.data.$showDesc = wasShowDesc;
if (MetamapsModel.edgecardInUse === synapse.data.$id) {
editEdge(tempForS, false);
}
return Mconsole.plot();
}; };

File diff suppressed because it is too large Load diff

View file

@ -103,7 +103,7 @@
} }
.best_in_place_name input{ .best_in_place_name textarea, .best_in_place_name input {
height: 15px; height: 15px;
padding: 5px 0; padding: 5px 0;
width: 100%; width: 100%;

View file

@ -27,4 +27,18 @@ class UsersController < ApplicationController
end end
end end
# PUT /user/updatemetacodes
def updatemetacodes
@user = current_user
@m = params[:metacodes][:value]
@user.settings.metacodes=@m.split(',')
@user.save
respond_to do |format|
format.json { render json: @user }
end
end
end end

View file

@ -8,7 +8,7 @@
<h3 class="accountHeader">Hello <%= account.name.split[0...1][0] %>!</h3> <h3 class="accountHeader">Hello <%= account.name.split[0...1][0] %>!</h3>
<ul> <ul>
<li class="accountIcon accountMaps"><a href="/maps/mappers/<%= account.id %>">My Maps</a></li> <li class="accountIcon accountMaps"><a href="/maps/mappers/<%= account.id %>">My Maps</a></li>
<li class="accountIcon accountSettings"><%= link_to "Settings", edit_user_url(account) %></li> <li class="accountIcon accountSettings"><%= link_to "Account", edit_user_url(account) %></li>
<% if account.admin %> <% if account.admin %>
<li class="accountIcon accountSettings"><%= link_to "Admin", metacodes_path %></li> <li class="accountIcon accountSettings"><%= link_to "Admin", metacodes_path %></li>
<% end %> <% end %>

View file

@ -6,7 +6,7 @@
<div id="lightbox_overlay"> <div id="lightbox_overlay">
<div id="lightbox_main"> <div id="lightbox_main">
<a id="lightbox_close" onclick="cancelMapCreate('fork_map');cancelMapCreate('new_map');return false;" href="#"></a> <a id="lightbox_close" onclick="cancelMetacodeSetSwitch();cancelMapCreate('fork_map');cancelMapCreate('new_map');return false;" href="#"></a>
<div id="lightbox_content"> <div id="lightbox_content">
<div class="lightboxContent" id="about"> <div class="lightboxContent" id="about">
@ -58,11 +58,15 @@
<div class="lightboxContent" id="forkmap"> <div class="lightboxContent" id="forkmap">
<%= render :partial => 'maps/fork' %> <%= render :partial => 'maps/fork' %>
</div> </div>
<div class="lightboxContent" id="switchMetacodes">
<%= render :partial => 'layouts/switchmetacodes' %>
</div>
<% end %> <% end %>
<% end %> <% end %>
</div> </div>
</div> </div>
<div id="lightbox_screen" onclick="cancelMapCreate('fork_map');cancelMapCreate('new_map');return false;" style="height: 100%;"></div> <div id="lightbox_screen" onclick="cancelMetacodeSetSwitch();cancelMapCreate('fork_map');cancelMapCreate('new_map');return false;" style="height: 100%;"></div>
</div> </div>

View file

@ -1,108 +0,0 @@
<%#
# @file
# templates for the upper right autocomplete results
#%>
<div class="templates">
<script type="text/template" class="topicTemplate">
<div class="result{{rtype}}">
<div class="topicMetacode">
<img src="{{typeImageURL}}" class="topicIcon" />
<span class="metacodeTip">{{type}}</span>
</div>
<div class="resultText">
<p class="resultTitle">{{label}}</p>
<p class="resultDesc">{{description}}</p>
</div>
<div class="autoOptions">
<% if controller_name == 'maps' && action_name == 'show' && authenticated? && @map.authorize_to_edit(@current) %>
<button class="addToMap hoverForTip" onclick="return keepFromCommons(event, {{id}})">
<span class="tip">add to map</span>
</button>
<% end %>
<a href="/topics/{{id}}" target="_blank" class="goTo hoverForTip">
<span class="tip">open in new tab</span>
</a>
<div class="mapCount hoverForTip">
<span class="tip">appears on this # of maps</span>
{{mapCount}}
</div>
<div class="synapseCount hoverForTip">
<span class="tip"> has this # of synapses</span>
{{synapseCount}}
</div>
<div class="topicOriginatorIcon hoverForTip">
<span class="tip topicOriginator">created by {{originator}}</span>
</div>
<div class="topicPermission {{permission}} hoverForTip">
<span class="tip">topic is {{permission}}</span>
</div>
</div>
<div class="clearfloat"></div>
</div>
</script>
<script type="text/template" class="mapTemplate">
<div class="result{{rtype}}">
<img class="icon" src="/assets/map.png">
<div class="resultText">
<p class="resultTitle">{{label}}</p>
<p class="resultDesc">{{description}}</p>
</div>
<div class="autoOptions">
<a href="/maps/{{id}}" target="_blank" class="goTo hoverForTip">
<span class="tip">open in new tab</span>
</a>
<div class="topicCount hoverForTip">
<span class="tip">has this # of topics</span>
{{topicCount}}
</div>
<div class="synapseCount hoverForTip">
<span class="tip">has this # of synapses</span>
{{synapseCount}}
</div>
<div class="mapContributorsIcon hoverForTip">
<span class="tip mapContributors">{{contributorList}}</span>
{{contributorCount}}
</div>
<div class="mapPermission {{permission}} hoverForTip">
<span class="tip">map is {{permission}}</span>
</div>
</div>
<div class="clearfloat"></div>
</div>
</script>
<script type="text/template" class="mapperTemplate">
<div class="result{{rtype}}">
<img class="icon" width="28" height="28" src="/assets/MMCCicon_mapper.png">
<div class="resultText">
<p class="resultTitle">{{label}}</p>
</div>
<div class="autoOptions">
<a href="/maps/mappers/{{id}}" target="_blank" class="goTo hoverForTip">
<span class="tip">open in new tab</span>
</a>
<div class="mapCount hoverForTip">
<span class="tip">created this # of maps</span>
{{mapCount}}
</div>
</div>
<div class="clearfloat"></div>
</div>
</script>
<script type="text/template" class="synapseTemplate">
<div class="result{{rtype}}">
<p class="autocompleteSection synapseDesc">{{label}}</p>
<div class="autocompleteSection synapsePermission {{permission}}"></div>
<div class="autocompleteSection synapseOriginatorIcon hoverForTip">
<span class="tip synapseOriginator">{{originator}}</span>
</div>
<div class="clearfloat"></div>
</div>
</script>
</div>

View file

@ -0,0 +1,69 @@
<%#
# @file
# The inner HTML for switching your metacode set
#%>
<% metacodes = current_user.settings.metacodes %>
<% selectedSet = metacodes[0].include?("metacodeset") ? metacodes[0].sub("metacodeset-","") : "custom" %>
<% allMetacodeSets = MetacodeSet.order("name").all %>
<% if selectedSet == "custom"
index = allMetacodeSets.length
else
set = MetacodeSet.find(selectedSet.to_i)
index = allMetacodeSets.index(set)
end %>
<h3>Switch Metacode Set</h3>
<div id="metacodeSwitchTabs">
<ul>
<% allMetacodeSets.each do |m| %>
<li><a href="#metacodeSwitchTabs<%= m.id %>" data-set-id="<%= m.id %>"><%= m.name %></a></li>
<% end %>
<li><a href="#metacodeSwitchTabsCustom" data-set-id="custom" id="metacodeSetCustom">Custom</a></li>
</ul>
<% allMetacodeSets.each_with_index do |m, localindex| %>
<div id="metacodeSwitchTabs<%= m.id %>"
data-metacodes="<%= m.metacodes.map(&:name).join(',') %>">
<p class="setTitle"><%= m.name %></p>
<p><%= m.desc %></p>
<% @list = '' %>
<% m.metacodes.sort{|x,y| x.name <=> y.name }.each_with_index do |m, index| %>
<% @list += '<li><img src="' + m.icon + '" alt="' + m.name + '" /><p>' + m.name.downcase + '</p><div class="clearfloat"></div></li>' %>
<% end %>
<div class="metacodeSetList">
<ul>
<%= @list.html_safe %>
</ul>
<div class="clearfloat"></div>
</div>
<button class="button" onclick="updateMetacodeSet(<%= m.id %>, <%= localindex %>, false);">Switch to Set</button>
</div>
<% end %>
<div id="metacodeSwitchTabsCustom">
<p>Pick Your Own Metacodes</p>
<% @list = '' %>
<% Metacode.order("name").all.each_with_index do |m, index| %>
<% if selectedSet == "custom" %>
<% mClass = metacodes.index(m.id.to_s) == nil ? "toggledOff" : "" %>
<% else %>
<% mClass = "toggledOff" %>
<% end %>
<% @list += '<li id="' + m.id.to_s + '" data-name="' + m.name + '" class="' + mClass + '"><img src="' + m.icon + '" alt="' + m.name + '" /><p>' + m.name.downcase + '</p><div class="clearfloat"></div></li>' %>
<% end %>
<div class="customMetacodeList">
<ul>
<%= @list.html_safe %>
</ul>
<div class="clearfloat"></div>
</div>
<button class="button" onclick="updateMetacodeSet('custom', <%= allMetacodeSets.length %>, true);">Switch to Custom Set</button>
</div>
</div>
<div class="clearfloat"></div>
<script>
MetamapsModel.selectedMetacodeSet = "metacodeset-<%= selectedSet %>";
MetamapsModel.selectedMetacodeSetIndex = <%= index %>;
</script>

View file

@ -0,0 +1,157 @@
<%#
# @file
# templates for the upper right autocomplete results
#%>
<div class="templates">
<script type="text/template" id="topicSearchTemplate">
<div class="result{{rtype}}">
<div class="topicMetacode">
<img src="{{typeImageURL}}" class="topicIcon" />
<span class="metacodeTip">{{type}}</span>
</div>
<div class="resultText">
<p class="resultTitle">{{label}}</p>
<p class="resultDesc">{{description}}</p>
</div>
<div class="autoOptions">
<% if controller_name == 'maps' && action_name == 'show' && authenticated? && @map.authorize_to_edit(@current) %>
<button class="addToMap hoverForTip" onclick="return keepFromCommons(event, {{id}})">
<span class="tip">add to map</span>
</button>
<% end %>
<div class="goTo hoverForTip">
<span class="tip">open in new tab</span>
</div>
<div class="mapCount hoverForTip">
<span class="tip">appears on this # of maps</span>
{{mapCount}}
</div>
<div class="synapseCount hoverForTip">
<span class="tip"> has this # of synapses</span>
{{synapseCount}}
</div>
<div class="topicOriginatorIcon hoverForTip">
<span class="tip topicOriginator">created by {{originator}}</span>
</div>
<div class="topicPermission {{permission}} hoverForTip">
<span class="tip">topic is {{permission}}</span>
</div>
</div>
<div class="clearfloat"></div>
</div>
</script>
<script type="text/template" id="mapSearchTemplate">
<div class="result{{rtype}}">
<img class="icon" src="/assets/map.png">
<div class="resultText">
<p class="resultTitle">{{label}}</p>
<p class="resultDesc">{{description}}</p>
</div>
<div class="autoOptions">
<div class="goTo hoverForTip">
<span class="tip">open in new tab</span>
</div>
<div class="topicCount hoverForTip">
<span class="tip">has this # of topics</span>
{{topicCount}}
</div>
<div class="synapseCount hoverForTip">
<span class="tip">has this # of synapses</span>
{{synapseCount}}
</div>
<div class="mapContributorsIcon hoverForTip">
<span class="tip mapContributors">{{contributorList}}</span>
{{contributorCount}}
</div>
<div class="mapPermission {{permission}} hoverForTip">
<span class="tip">map is {{permission}}</span>
</div>
</div>
<div class="clearfloat"></div>
</div>
</script>
<script type="text/template" id="mapperSearchTemplate">
<div class="result{{rtype}}">
<img class="icon" width="28" height="28" src="/assets/MMCCicon_mapper.png">
<div class="resultText">
<p class="resultTitle">{{label}}</p>
</div>
<div class="autoOptions">
<div class="goTo hoverForTip">
<span class="tip">open in new tab</span>
</div>
<div class="mapCount hoverForTip">
<span class="tip">created this # of maps</span>
{{mapCount}}
</div>
</div>
<div class="clearfloat"></div>
</div>
</script>
<script type="text/template" id="synapseAutocompleteTemplate">
<div class="result{{rtype}}">
<p class="autocompleteSection synapseDesc">{{label}}</p>
<div class="autocompleteSection synapsePermission {{permission}}"></div>
<div class="autocompleteSection synapseOriginatorIcon hoverForTip">
<span class="tip synapseOriginator">{{originator}}</span>
</div>
<div class="clearfloat"></div>
</div>
</script>
<script type="text/template" id="topicAutocompleteTemplate">
<img class="autocompleteSection topicType" width="22" height="22" src="{{typeImageURL}}" alt="{{type}}" title="{{type}}" />
<p class="autocompleteSection topicTitle">{{label}}</p>
<div class="autocompleteSection topicPermission {{permission}}"></div>
<div class="autocompleteSection topicOriginatorIcon hoverForTip">
<span class="tip topicOriginator">{{originator}}</span>
</div>
<div class="clearfloat"></div>
</script>
<script type="text/template" id="topicCardTemplate">
<div class="CardOnGraph" id="topic_{{id}}">
<span class="title">
<span class="best_in_place best_in_place_name"
data-url="/topics/{{id}}"
data-object="topic"
data-attribute="name"
data-type="textarea">{{name}}</span>
</span>
<div class="links">
<div class="linkItem icon">
<div class="metacodeTitle">{{metacode}}</div>
<div class="metacodeImage" style="background-image:url({{imgsrc}});" title="click and drag to move card"></div>
</div>
<div class="linkItem contributor hoverForTip">
<div class="tip">Created by {{username}} on {{date}}</div>
</div>
<a href="/maps/topics/{{id}}" class="linkItem mapCount hoverForTip" title="Click to see which maps topic appears on" target="_blank">
{{map_count}}
</a>
<div class="linkItem synapseCount">{{synapse_count}}</div>
<div class="linkItem mapPerm {{mk_permission}}"></div>
<a href="/topics/{{id}}" class="linkItem topicPopout" title="Open topic in new tab" target="_blank"></a>
<div class="clearfloat"></div>
</div>
<div class="metacodeSelect">{{{metacode_select}}}</div>
<div class="scroll">
<div class="desc">
<span class="best_in_place best_in_place_desc" data-url="/topics/{{id}}" data-object="topic" data-nil="{{desc_nil}}" data-attribute="desc" data-type="textarea">{{desc}}</span>
<div class="clearfloat"></div>
</div>
</div>
<div class="link">
{{a_tag}}<span class="best_in_place best_in_place_link" data-url="/topics/{{id}}" data-object="topic" data-nil="{{link_nil}}" data-attribute="link" data-type="input">{{link}}</span>{{close_a_tag}} {{{go_link}}}
</div>
<div class="clearfloat"></div>
</div>
</script>
</div>

View file

@ -51,7 +51,7 @@
<div class="sidebarSearchIcon"></div> <div class="sidebarSearchIcon"></div>
<input type="text" class="sidebarSearchField"></input> <input type="text" class="sidebarSearchField"></input>
<div class="clearfloat"></div> <div class="clearfloat"></div>
<%= render :partial => 'layouts/searchtemplates' %> <%= render :partial => 'layouts/templates' %>
</div> </div>
<div class="sidebarAccount"> <div class="sidebarAccount">
<div class="sidebarAccountIcon"></div> <div class="sidebarAccountIcon"></div>

View file

@ -8,7 +8,7 @@
<div class="mapCard"> <div class="mapCard">
<span class="title"> <span class="title">
<%= best_in_place map, :name, :type => :input, :classes => 'best_in_place_name' %> <%= best_in_place map, :name, :type => :textarea, :classes => 'best_in_place_name' %>
</span> </span>
<div class="links"> <div class="links">
<div class="linkItem icon"> <div class="linkItem icon">
@ -25,7 +25,7 @@
</div> </div>
<div class="scroll"> <div class="scroll">
<div class="desc"> <div class="desc">
<%= best_in_place map, :desc, :type => :textarea, :nil => "<span class='gray'>Click to add description.</span>", :classes => 'best_in_place_desc' %> <%= best_in_place map, :desc, :type => :textarea, :nil => "Click to add description.", :classes => 'best_in_place_desc' %>
<div class="clearfloat"></div> <div class="clearfloat"></div>
</div> </div>
</div> </div>

View file

@ -35,7 +35,7 @@
<% if (authenticated? && @map.authorize_to_edit(user)) || (!authenticated? && @map.desc != "" && @map.desc != nil )%> <% if (authenticated? && @map.authorize_to_edit(user)) || (!authenticated? && @map.desc != "" && @map.desc != nil )%>
<div class="mapInfoDesc"> <div class="mapInfoDesc">
<%= best_in_place @map, :desc, :type => :textarea, :nil => "<span class='gray'>Click to add description.</span>", :classes => 'best_in_place_desc' %> <%= best_in_place @map, :desc, :type => :textarea, :nil => "Click to add description.", :classes => 'best_in_place_desc' %>
</div> </div>
<% end %> <% end %>

View file

@ -4,11 +4,17 @@
#%> #%>
<div class="anypage"> <div class="anypage">
<%= form_for Topic.new, url: topics_url, remote: true do |form| %> <%= form_for Topic.new, url: topics_url, remote: true do |form| %>
<div class="openMetacodeSwitcher openLightbox" data-open="switchMetacodes"></div>
<div id="metacodeImg"> <div id="metacodeImg">
<% @m = user.settings.metacodes %> <% @m = user.settings.metacodes %>
<% @metacodes = [] %> <% set = @m[0].include?("metacodeset") ? MetacodeSet.find(@m[0].sub("metacodeset-","").to_i) : false %>
<% @m.each do |m| %> <% if set %>
<% @metacodes.push(Metacode.find(m.to_i)) %> <% @metacodes = set.metacodes %>
<% else %>
<% @metacodes = [] %>
<% @m.each do |m| %>
<% @metacodes.push(Metacode.find(m.to_i)) %>
<% end %>
<% end %> <% end %>
<% @metacodes.sort! {|m1,m2| m2.name.downcase <=> m1.name.downcase }.rotate!(-1) %> <% @metacodes.sort! {|m1,m2| m2.name.downcase <=> m1.name.downcase }.rotate!(-1) %>
<% @metacodes.each do |metacode| %> <% @metacodes.each do |metacode| %>
@ -26,5 +32,15 @@
<%= form.hidden_field :addSynapse, :value => false %> <%= form.hidden_field :addSynapse, :value => false %>
<div id="metacodeImgTitle"></div> <div id="metacodeImgTitle"></div>
<div class="clearfloat"></div> <div class="clearfloat"></div>
<script>
<% @metacodes.each do |metacode| %>
<% if !set %>
MetamapsModel.selectedMetacodes.push("<%= metacode.id %>");
MetamapsModel.newSelectedMetacodes.push("<%= metacode.id %>");
MetamapsModel.selectedMetacodeNames.push("<%= metacode.name %>");
MetamapsModel.newSelectedMetacodeNames.push("<%= metacode.name %>");
<% end %>
<% end %>
</script>
<% end %> <% end %>
</div> </div>

View file

@ -59,247 +59,63 @@
<div class="clearfloat"></div> <div class="clearfloat"></div>
<% if authenticated? %> <% if authenticated? %>
<% # add these if you have edit permissions on the map %>
<% if @map.permission == "commons" || @map.user == user %> <% if @map.permission == "commons" || @map.user == user %>
<% # for creating and pulling in topics and synapses %>
<%= render :partial => 'newtopic' %> <%= render :partial => 'newtopic' %>
<%= render :partial => 'newsynapse' %> <%= render :partial => 'newsynapse' %>
<% end %>
<%= render :partial => 'main/metacodeoptions' %>
<% # for saving layouts %> <% # for saving the layout of the map %>
<% if @map.permission == "commons" || @map.user == user %> <%= form_for @map, :url => savelayout_path(@map), :html => { :class => "saveMapLayout", :id => "saveMapLayout"}, remote: true do |form| %>
<%= form_for @map, :url => savelayout_path(@map), :html => { :class => "saveMapLayout", :id => "saveMapLayout"}, remote: true do |form| %>
<%= form.hidden_field "coordinates", :value => "" %> <%= form.hidden_field "coordinates", :value => "" %>
<% end %>
<% end %>
<% end %>
<script>
$(document).ready(function() {
function bindFilterHover() {
var filterIsOpen = false;
// controls the sliding hover of the bottom left menu
var sliding1 = false;
var lT;
var closeFilter = function() {
lT = setTimeout(function() {
if (! sliding1) {
sliding1 = true;
$('.sidebarFilterIcon').css('background-color','#0F1519');
$('.sidebarFilterBox').fadeOut(200, function() {
sliding1 = false;
filterIsOpen = false;
});
}
},300);
}
var openFilter = function() {
clearTimeout(lT);
if (! sliding1) {
sliding1 = true;
// hide the other two
$('.sidebarAccountBox').hide();
$('.sidebarWandBox').hide();
$('.sidebarAccountIcon').css('background-color','#0F1519');
$('.sidebarWandIcon').css('background-color','#0F1519');
$('.sidebarFilterIcon').css('background-color','#000');
$('.sidebarFilterBox').fadeIn(200, function() {
sliding1 = false;
filterIsOpen = true;
});
}
}
// bind the hover events
$(".sidebarFilter").hover(openFilter, closeFilter);
} // end bindFilterHover
function bindInfoHover() {
var infoIsOpen = false;
// controls the sliding hover of the bottom left menu
var sliding1 = false;
var lT;
var closeInfo = function() {
lT = setTimeout(function() {
if (! sliding1) {
sliding1 = true;
$('.mapInfoBox').fadeOut(200, function() {
sliding1 = false;
infoIsOpen = false;
});
}
},300);
}
var openInfo = function(event) {
clearTimeout(lT);
if (! sliding1 && event.target.className != "openCheatsheet openLightbox") {
sliding1 = true;
$('.mapInfoBox').fadeIn(200, function() {
sliding1 = false;
infoIsOpen = true;
});
}
}
// bind the hover events
$("div.index").hover(openInfo, closeInfo);
} // end bindInfoHover
bindFilterHover();
bindInfoHover();
$('.sidebarSave').click(function() {
saveLayoutAll();
});
$('.sidebarFork').click(function() {
saveToMap();
});
$(".sidebarCollaborateIcon").click(function(event) {
if (!goRealtime) {
$('.sidebarCollaborate .tip').html('Stop Realtime Collaboration');
} else {
$('.sidebarCollaborate .tip').html('Start Realtime Collaboration');
}
goRealtime = !goRealtime;
$(".sidebarCollaborateIcon").toggleClass("blue");
});
// initialize best_in_place editing
$('.authenticated div.permission.canEdit .best_in_place').best_in_place();
<% if @map.user == user %>
// ability to change permission
var selectingPermission = false;
$('.yourMap .mapPermission').click(function() {
if (!selectingPermission) {
selectingPermission = true;
$(this).addClass('minimize'); // this line flips the drop down arrow to a pull up arrow
if ( $(this).hasClass('commons') ) {
$(this).append('<ul class="permissionSelect"><li class="public"></li><li class="private"></li></ul>');
} else if ( $(this).hasClass('public') ) {
$(this).append('<ul class="permissionSelect"><li class="commons"></li><li class="private"></li></ul>');
} else if ( $(this).hasClass('private') ) {
$(this).append('<ul class="permissionSelect"><li class="commons"></li><li class="public"></li></ul>');
}
$('.mapPermission .permissionSelect li').click(function(event) {
selectingPermission = false;
var permission = $(this).attr('class');
updateMapPermission(mapid, permission);
event.stopPropagation();
});
} else {
selectingPermission = false;
$(this).removeClass('minimize'); // this line flips the pull up arrow to a drop down arrow
$('.mapPermission .permissionSelect').remove();
}
});
<% end %> <% end %>
//bind best_in_place ajax callbacks
$('.mapInfoName .best_in_place_name').bind("ajax:success", function() {
var name = $(this).html();
$('.mapName').html(name);
});
$('.showcard').draggable({ handle: ".metacodeImage" });
$('#showcard').resizable({
maxHeight: 500,
maxWidth: 500,
minHeight: 320,
minWidth: 226,
resize: function( event, ui ) {
var p = $('#showcard').find('.scroll');
p.height( p.height() ).mCustomScrollbar('update');
}
}).css({
display: 'none',
top: '300px',
left: '100px'
});
});
var dragged = 0;
mapid = <%= @map.id %>;
<% if (@map.permission == "commons" && authenticated?) || @map.user == user %>
mapperm = true;
<% end %> <% end %>
viewMode = "graph"; <% # for populating the change metacode list on the topic card %>
json = <%= @mapjson %>; <%= render :partial => 'main/metacodeoptions' %>
if (json.length > 0) { <% end %>
$(window).load(function() {
<% if (@map.arranged) %>
initialize("arranged");
<% else %>
initialize("chaotic");
<% end %>
});
}
else {
$(window).load(function() {
initialize("chaotic", true);
});
}
//window.realtime.socket = io.connect('http://gentle-savannah-1303.herokuapp.com'); // this is for the heroku staging environment
//window.realtime.socket = io.connect('http://metamaps.cc:5001'); // this is for metamaps.cc
window.realtime.socket = io.connect('http://localhost:5001'); // this is for localhost development
window.realtime.socket.on('connect', function() {
subscribeToRooms();
console.log('socket connected');
});
function subscribeToRooms() {
window.realtime.socket.on('maps-' + mapid, function(data) {
//as long as you weren't the origin of the changes, update your map
if (data.origin != userid && goRealtime) {
if (data.resource == 'Topic') {
topic = $.parseJSON(data.obj);
if (data.action == 'create') { <script>
window.realtime.addTopicToMap(topic); var dragged = 0;
} mapid = <%= @map.id %>;
else if (data.action == 'update' && Mconsole.graph.getNode(topic.id) != 'undefined') { <% if (@map.permission == "commons" && authenticated? ) || @map.user == user %>
window.realtime.updateTopicOnMap(topic); mapperm = true;
} <% end %>
else if (data.action == 'destroy' && Mconsole.graph.getNode(topic.id) != 'undefined') {
hideNode(topic.id)
}
return; viewMode = "graph";
} json = <%= @mapjson %>;
else if (data.resource == 'Synapse') { if (json.length > 0) {
synapse = $.parseJSON(data.obj); $(window).load(function () {
<% if (@map.arranged) %>
if (data.action == 'create') { initialize("arranged");
window.realtime.addSynapseToMap(synapse); <% else %>
} initialize("chaotic");
else if (data.action == 'update' && <% end %>
Mconsole.graph.getAdjacence(synapse.data.$direction['0'], synapse.data.$direction['1']) != 'undefined') {
window.realtime.updateSynapseOnMap(synapse);
}
else if (data.action == 'destroy' &&
Mconsole.graph.getAdjacence(synapse.data.$direction['0'], synapse.data.$direction['1']) != 'undefined') {
var edge = Mconsole.graph.getAdjacence(synapse.data.$direction['0'], synapse.data.$direction['1']);
hideEdge(edge);
}
return;
}
}
}); });
} } else {
$(window).load(function () {
initialize("chaotic", true);
});
}
<% if authenticated? && (@map.permission == "commons" || @map.user == user) %>
// this is for the heroku staging environment
//window.realtime.socket = io.connect('http://gentle-savannah-1303.herokuapp.com');
// this is for metamaps.cc
//window.realtime.socket = io.connect('http://metamaps.cc:5001');
// this is for localhost development
window.realtime.socket = io.connect('http://localhost:5001');
window.realtime.socket.on('connect', function () {
console.log('socket connected');
window.realtime.setupSocket();
});
<% end %>
</script> </script>

View file

@ -20,7 +20,6 @@ $(document).ready(function() {
$('#metacodes_value').val(selectMetacodes.toString()); $('#metacodes_value').val(selectMetacodes.toString());
$('.editMetacodes li').click(function() { $('.editMetacodes li').click(function() {
console.log($(this).attr('class'));
if ($(this).attr('class') != 'toggledOff') { if ($(this).attr('class') != 'toggledOff') {
$(this).addClass('toggledOff'); $(this).addClass('toggledOff');
var value_to_remove = $(this).attr('id'); var value_to_remove = $(this).attr('id');

View file

@ -35,7 +35,7 @@
<div class="index"> <div class="index">
<div class="openCheatsheet openLightbox" data-open="cheatsheet"></div> <div class="openCheatsheet openLightbox" data-open="cheatsheet"></div>
<span><img width="35" height="35" src="/assets/<%= @topic.metacode.icon %>"></span> <span><img width="35" height="35" src="<%= @topic.metacode.icon %>"></span>
<span class="mapName"><%= @topic.name %></span> <span class="mapName"><%= @topic.name %></span>
<div class="clearfloat"></div> <div class="clearfloat"></div>
</div> </div>
@ -55,76 +55,7 @@
<% end %> <% end %>
<script> <script>
$(document).ready(function() { json = <%= @relatives %>;
function bindFilterHover() {
var filterIsOpen = false
// controls the sliding hover of the bottom left menu
var sliding1 = false;
var lT;
var closeFilter = function() {
lT = setTimeout(function() {
if (! sliding1) {
sliding1 = true;
$('.sidebarFilterIcon').css('background-color','#0F1519');
$('.sidebarFilterBox').fadeOut(200, function() {
sliding1 = false;
filterIsOpen = false;
});
}
},300);
}
var openFilter = function() {
clearTimeout(lT);
if (! sliding1) {
sliding1 = true;
// hide the other two
$('.sidebarAccountBox').hide();
$('.sidebarWandBox').hide();
$('.sidebarAccountIcon').css('background-color','#0F1519');
$('.sidebarWandIcon').css('background-color','#0F1519');
$('.sidebarFilterIcon').css('background-color','#000');
$('.sidebarFilterBox').fadeIn(200, function() {
sliding1 = false;
filterIsOpen = true;
});
}
}
// bind the hover events
$(".sidebarFilter").hover(openFilter, closeFilter);
} // end bindFilterHover
bindFilterHover();
$('.sidebarFork').click(function() {
saveToMap();
});
// initialize best_in_place editing
$('.authenticated div.permission.canEdit .best_in_place').best_in_place();
$('.showcard').draggable({ handle: ".icon" });
$('#showcard').resizable({
maxHeight: 500,
maxWidth: 500,
minHeight: 320,
minWidth: 226
}).css({
display: 'none',
top: '300px',
left: '100px'
});
});
json = <%= @relatives %>;
$(window).load(function() { $(window).load(function() {
initialize("centered"); initialize("centered");
}); });

View file

@ -41,6 +41,7 @@ ISSAD::Application.routes.draw do
devise_scope :user do devise_scope :user do
get "sign_out", :to => "devise/sessions#destroy" get "sign_out", :to => "devise/sessions#destroy"
end end
match 'user/updatemetacodes', to: 'users#updatemetacodes', via: :post, as: :updatemetacodes
resources :users, except: [:show, :index] resources :users, except: [:show, :index]

View file

@ -30,14 +30,48 @@ function start() {
redis.subscribe('maps'); redis.subscribe('maps');
io.on('connection', function(socket){ io.on('connection', function(socket){
// this will ping everyone on a map with updates to the map
redis.on('message', function(channel, message){ redis.on('message', function(channel, message){
console.log(message); console.log(message);
var m = JSON.parse(message); var m = JSON.parse(message);
var room; var room = 'maps-' + m.mapid;
room = 'maps-' + m.mapid;
socket.emit(room, m); socket.emit(room, m);
}); });
// this will ping a new person with awareness of who's already on the map
socket.on('updateNewMapperList', function(data) {
var existingUser = { userid: data.userid, username: data.username };
socket.broadcast.emit(data.userToNotify + '-' + data.mapid + '-UpdateMapperList', existingUser);
});
// this will ping everyone on a map that there's a person just joined the map
socket.on('newMapperNotify', function (data) {
socket.set('mapid', data.mapid);
socket.set('userid', data.userid);
socket.set('username', data.username);
var newUser = { userid: data.userid, username: data.username };
socket.broadcast.emit('maps-' + data.mapid + '-newmapper', newUser);
});
// this will ping everyone on a map that there's a person just left the map
socket.on('disconnect', function () {
var socketUserName, socketUserID;
socket.get('userid', function (err, id) {
socketUserID = id;
});
socket.get('username', function (err, name) {
socketUserName = name;
});
var data = { username: socketUserName, userid: socketUserID };
socket.get('mapid', function (err, mapid) {
socket.broadcast.emit('maps-' + mapid + '-lostmapper', data);
});
});
}); });
} }

File diff suppressed because one or more lines are too long