2014-06-04 19:24:16 +00:00
|
|
|
/* 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 () {
|
|
|
|
|
2014-06-11 20:47:46 +00:00
|
|
|
function bindForkHover() {
|
|
|
|
var closeFork = function () {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var openFork = function () {
|
|
|
|
// hide the other three
|
|
|
|
$('.sidebarFilterBox, .sidebarAccountBox, .sidebarCollaborateBox').hide();
|
|
|
|
$('.sidebarFilterIcon, .sidebarAccountIcon, .sidebarCollaborateIcon').css('background-color', '#0F1519');
|
|
|
|
}
|
|
|
|
// bind the hover events
|
|
|
|
$(".sidebarFork").hover(openFork, closeFork);
|
|
|
|
} // end bindForkHover
|
|
|
|
|
|
|
|
// bind hover events
|
|
|
|
bindForkHover();
|
|
|
|
|
2014-06-04 19:24:16 +00:00
|
|
|
//////
|
|
|
|
//////
|
|
|
|
//// 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
|
|
|
|
}
|
|
|
|
]);
|
2014-06-09 17:36:23 +00:00
|
|
|
|
|
|
|
var topicTypeahead = false;
|
2014-06-04 19:24:16 +00:00
|
|
|
// 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();
|
2014-06-09 17:36:23 +00:00
|
|
|
$('.new_topic').submit();
|
|
|
|
topicTypeahead = true;
|
|
|
|
});
|
|
|
|
$('#topic_name').bind('typeahead:opened', function () {
|
|
|
|
topicTypeahead = false;
|
2014-06-04 19:24:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// bind keyboard handlers
|
|
|
|
$('#topic_name').bind('keyup', function (e) {
|
|
|
|
switch (e.which) {
|
|
|
|
case 13:
|
2014-06-09 17:36:23 +00:00
|
|
|
if (!topicTypeahead) $('.new_topic').submit();
|
2014-06-04 19:24:16 +00:00
|
|
|
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',
|
2014-06-09 17:36:23 +00:00
|
|
|
template: "<div>{{label}}</div>",
|
2014-06-04 19:24:16 +00:00
|
|
|
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>"
|
|
|
|
},
|
|
|
|
]);
|
2014-06-09 17:36:23 +00:00
|
|
|
|
|
|
|
var synapseTypeahead = false;
|
2014-06-04 19:24:16 +00:00
|
|
|
// 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();
|
2014-06-09 17:36:23 +00:00
|
|
|
$('.new_synapse').submit();
|
|
|
|
synapseTypeahead = true;
|
|
|
|
});
|
|
|
|
$('#synapse_desc').bind('typeahead:opened', function () {
|
|
|
|
synapseTypeahead = false;
|
2014-06-04 19:24:16 +00:00
|
|
|
});
|
|
|
|
// bind keyboard handlers
|
|
|
|
$('#synapse_desc').bind('keyup', function (e) {
|
|
|
|
switch (e.which) {
|
|
|
|
case 13:
|
2014-06-09 17:36:23 +00:00
|
|
|
if (!synapseTypeahead) $('.new_synapse').submit();
|
2014-06-04 19:24:16 +00:00
|
|
|
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");
|
|
|
|
$('.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
|