metamaps--metamaps/app/assets/javascripts/application.js

329 lines
9.9 KiB
JavaScript
Raw Normal View History

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// the compiled file.
//
// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
// GO AFTER THE REQUIRES BELOW.
//
//= require jquery
2012-12-14 07:16:17 +00:00
//= require jquery-ui
2012-12-31 03:56:05 +00:00
//= require jquery.purr
//= require best_in_place
2012-12-14 07:16:17 +00:00
//= require autocomplete-rails-uncompressed
//= require jquery_ujs
//= require_tree .
// other options are 'graph'
var viewMode = "list";
2012-10-22 01:10:43 +00:00
2013-03-29 06:38:13 +00:00
var labelType, useGradients, nativeTextSupport, animate, json, Mconsole = null, gType, tempNode = null, tempInit = false, tempNode2 = null, metacodeIMGinit = false, findOpen = false, analyzeOpen = false, organizeOpen = false, goRealtime = false, mapid = null, mapperm = false, touchPos, touchDragNode, mouseIsDown = false;
$(document).ready(function() {
2012-12-16 20:00:43 +00:00
$('#new_topic, #new_synapse').bind('contextmenu', function(e){
2012-12-21 00:24:27 +00:00
return false;
});
/// this is for the topic creation autocomplete field
$('#topic_name').bind('railsAutocomplete.select', function(event, data){
2012-12-16 20:00:43 +00:00
if (data.item.id != undefined) {
$('#topic_grabTopic').val(data.item.id);
$('.new_topic').submit();
2012-12-14 07:16:17 +00:00
}
});
2012-12-16 20:00:43 +00:00
$('.new_topic').bind('submit', function(event, data){
event.preventDefault();
});
$(".scroll").mCustomScrollbar();
2013-07-10 18:02:38 +00:00
$('.headertop').draggable();
var positionLeft = $(window).width() - $('.headertop').width() - 50;
$('.headertop').css('left', positionLeft + 'px');
$('.notice.metamaps').delay(10000).fadeOut('fast');
$('.alert.metamaps').delay(10000).fadeOut('fast');
2013-01-06 23:40:48 +00:00
//$('.nodemargin').css('padding-top',$('.focus').css('height'));
2012-12-16 20:00:43 +00:00
// controls the sliding hover of the menus at the top
var sliding1 = false;
var lT;
$(".logo").hover(
function () {
2013-12-02 01:47:28 +00:00
$('.menuflag').hide();
clearTimeout(lT);
if (! sliding1) {
2013-02-03 18:04:01 +00:00
sliding1 = true;
var listLength = $('.logo .menu li').length * 28;
$('.footer .menu').animate({
2013-02-03 18:04:01 +00:00
height: listLength + 'px'
}, 300, function() {
sliding1 = false;
});
}
},
function () {
lT = setTimeout(function() {
if (! sliding1) {
sliding1 = true;
$('.footer .menu').animate({
height: '0px'
}, 300, function() {
sliding1 = false;
menuIsOpen = false;
});
}
},800);
}
);
var menuIsOpen = false;
$("#mainTitle a").bind('touchend', function(evt) {
if (!menuIsOpen) {
menuIsOpen = true;
var listLength = $('.logo .menu li').length * 28;
$('.footer .menu').animate({
height: listLength + 'px'
}, 300);
evt.preventDefault();
evt.stopPropogation();
}
});
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);
});
// this is to save the layout of maps when you're on a map page
$("#saveLayout").click(function(event) {
event.preventDefault();
saveLayoutAll();
});
}); // 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() {
var coor = "";
if (gType == "arranged" || gType == "chaotic") {
Mconsole.graph.eachNode(function(n) {
2013-02-11 01:22:18 +00:00
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);
2013-02-11 01:22:18 +00:00
$('#map_coordinates').val(n.getData("mappingid") + '/' + n.pos.x + '/' + n.pos.y);
$('#saveMapLayout').submit();
dragged = 0;
2013-01-25 05:47:32 +00:00
$('#saveLayout').attr('value','Saved!');
setTimeout(function(){$('#saveLayout').attr('value','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);
$('#new_map').fadeIn('fast');
}
function addMetacode() {
// code from http://www.professorcloud.com/mainsite/carousel-integration.htm
//mouseWheel:true,
if (!metacodeIMGinit) {
$("#metacodeImg").CloudCarousel( {
titleBox: $('#metacodeImgTitle'),
yRadius:40,
xPos: 150,
yPos: 40,
speed:0.15,
mouseWheel:true,
bringToFront: true
});
metacodeIMGinit = true;
}
}
2013-01-25 05:47:32 +00:00
function fetchRelatives(node) {
var myA = $.ajax({
type: "Get",
url: "/topics/" + node.id + "?format=json",
success: function(data) {
if (gType == "centered") {
Mconsole.busy = true;
2013-01-25 05:47:32 +00:00
Mconsole.op.sum(data, {
type: 'fade',
duration: 500,
hideLabels: false
2013-01-25 05:47:32 +00:00
});
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;
2013-01-25 05:47:32 +00:00
}
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');
}
});
}
2013-01-06 04:03:05 +00:00
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 hideLabels() {
if (Mconsole.labels.labelsHidden) {
Mconsole.labels.hideLabels();
2013-07-10 18:02:38 +00:00
$('.hidelabels').html('Hide Labels');
}
else if (!Mconsole.labels.labelsHidden) {
Mconsole.labels.hideLabels(true);
2013-07-10 18:02:38 +00:00
$('.hidelabels').html('Show Labels');
}
}
$('*').keypress(function(e) {
2013-03-28 22:56:34 +00:00
switch(e.which) {
case 13: enterKeyHandler(); break;
case 27: escKeyHandler(); break;
default: //alert(e.which); break;
}
});