'
}
]);
// 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 #222','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 #222','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','rgba(0,0,0,0.7)');
$('.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','rgba(0,0,0,0.7)');
$('.sidebarWandIcon').css('background-color','rgba(0,0,0,0.7)');
$('.sidebarAccountIcon').css('background-color','rgba(0,0,0,0.9)');
$('.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',
template: '
{{value}}
{{originator}}
',
remote: {
url: '/topics/autocomplete_topic?term=%QUERY'
},
engine: Hogan
}
]);
$('#topic_name').bind('typeahead:autocompleted', function (event, datum, dataset) {
event.preventDefault();
event.stopPropagation();
});
// 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);
$('.new_topic').submit();
event.preventDefault();
event.stopPropagation();
});
// 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();
var filterPosition = userid ? '-72px' : '-36px';
$('.sidebarFilterBox').hide().css({
position:'absolute',
top: '35px',
right: filterPosition
});
// 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_metacode').bind("ajax:success", function() {
var metacode = $(this).html();
//changing img alt, img src for top card (topic view page)
//and on-canvas card. Also changing image of node
$(this).parents('.CardOnGraph').find('img.icon').attr('alt', metacode);
$(this).parents('.CardOnGraph').find('img.icon').attr('src', imgArray[metacode].src);
});
$('.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);
});
$('.addMap').click(function(event) {
createNewMap();
});
// bind keyboard handlers
$('body').bind('keyup', function(e) {
switch(e.which) {
case 13: enterKeyHandler(); 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");
});
}
// this is to save the layout of a map
function saveLayoutAll() {
$('.wandSaveLayout').html('Saving...');
var coor = "";
if (gType == "arranged" || gType == "chaotic") {
Mconsole.graph.eachNode(function(n) {
coor = coor + n.getData("mappingid") + '/' + n.pos.x + '/' + n.pos.y + ',';
});
coor = coor.slice(0, -1);
$('#map_coordinates').val(coor);
$('#saveMapLayout').submit();
}
}
// this is to update the location coordinate of a single node on a map
function saveLayout(id) {
var n = Mconsole.graph.getNode(id);
$('#map_coordinates').val(n.getData("mappingid") + '/' + n.pos.x + '/' + n.pos.y);
$('#saveMapLayout').submit();
dragged = 0;
$('.wandSaveLayout').html('Saved!');
setTimeout(function(){$('.wandSaveLayout').html('Save Layout')},1500);
}
// this is to save your console to a map
function saveToMap() {
var nodes_data = "", synapses_data = "";
var synapses_array = new Array();
Mconsole.graph.eachNode(function(n) {
//don't add to the map if it was filtered out
if (categoryVisible[n.getData('metacode')] == false) {
return;
}
var x, y;
if (n.pos.x && n.pos.y) {
x = n.pos.x;
y = n.pos.y;
} else {
var x = Math.cos(n.pos.theta) * n.pos.rho;
var y = Math.sin(n.pos.theta) * n.pos.rho;
}
nodes_data += n.id + '/' + x + '/' + y + ',';
n.eachAdjacency(function(adj) {
synapses_array.push(adj.getData("id"));
});
});
//get unique values only
synapses_array = $.grep(synapses_array, function(value, key){
return $.inArray(value, synapses_array) === key;
});
synapses_data = synapses_array.join();
nodes_data = nodes_data.slice(0, -1);
$('#map_topicsToMap').val(nodes_data);
$('#map_synapsesToMap').val(synapses_data);
$('#fork_map').fadeIn('fast');
}
function createNewMap() {
$('#new_map').fadeIn('fast');
}
function fetchRelatives(node) {
var myA = $.ajax({
type: "Get",
url: "/topics/" + node.id + "?format=json",
success: function(data) {
if (gType == "centered") {
Mconsole.busy = true;
Mconsole.op.sum(data, {
type: 'fade',
duration: 500,
hideLabels: false
});
Mconsole.graph.eachNode(function (n) {
n.eachAdjacency(function (a) {
if (!a.getData('showDesc')) {
a.setData('alpha', 0.4, 'start');
a.setData('alpha', 0.4, 'current');
a.setData('alpha', 0.4, 'end');
}
});
});
Mconsole.busy = false;
}
else {
Mconsole.op.sum(data, {
type: 'nothing',
});
Mconsole.plot();
}
/*Mconsole.op.contract(node, {
type: 'replot'
});
Mconsole.op.expand(node, {
type: 'animate',
transition: $jit.Trans.Elastic.easeOut,
duration: 1000
});*/
},
error: function(){
alert('failure');
}
});
}
function MconsoleReset() {
var tX = Mconsole.canvas.translateOffsetX;
var tY = Mconsole.canvas.translateOffsetY;
Mconsole.canvas.translate(-tX,-tY);
var mX = Mconsole.canvas.scaleOffsetX;
var mY = Mconsole.canvas.scaleOffsetY;
Mconsole.canvas.scale((1/mX),(1/mY));
}
function openNodeShowcard(node) {
//populate the card that's about to show with the right topics data
populateShowCard(node);
$('.showcard').fadeIn('fast');
//node.setData('dim', 1, 'current');
MetamapsModel.showcardInUse = node.id;
}