103 lines
3.8 KiB
JavaScript
103 lines
3.8 KiB
JavaScript
/* jshint esversion: 6 */
|
|
import {
|
|
Template
|
|
} from 'meteor/templating';
|
|
|
|
Template.profile.helpers({
|
|
schoolgradenext() {
|
|
if(_.contains([null, undefined, ""], Meteor.user().profile.school ||
|
|
_.contains([null, undefined, ""], Meteor.user().profile.grade))) {
|
|
return "";
|
|
} else {
|
|
return "disabled";
|
|
}
|
|
}
|
|
});
|
|
|
|
Template.profile.events({
|
|
'click' (event) { // Closes respective divs when clicking outside of them. Order matters.
|
|
var e = event.target.className;
|
|
|
|
if(modifyingInput !== null && event.target !== document.getElementById(modifyingInput)) {
|
|
console.log("hia");
|
|
if (!(e.includes("optionHolder") || e.includes("optionText"))) {
|
|
console.log("hi");
|
|
toggleOptionMenu(false, modifyingInput);
|
|
modifyingInput = null;
|
|
}
|
|
}
|
|
},
|
|
'click #schoolnext' () {
|
|
// Animation to display class section
|
|
},
|
|
// HANDLING INPUT CHANGING
|
|
'focus .clickModify' (event) {
|
|
$(".optionHolder")
|
|
.fadeOut(100);
|
|
|
|
if(modifyingInput !== null) {
|
|
if(!$("#"+modifyingInput)[0].className.includes("dropdown")) closeInput(modifyingInput);
|
|
}
|
|
modifyingInput = event.target.id;
|
|
if(!$("#"+modifyingInput)[0].className.includes("dropdown")) {
|
|
event.target.select();
|
|
event.target.style.cursor = "text";
|
|
}
|
|
},
|
|
'keydown .dropdown' (event) {
|
|
var first = $("#"+modifyingInput).next().children("p:first-child");
|
|
var last = $("#"+modifyingInput).next().children("p:last-child");
|
|
var next = $(".selectedOption").next();
|
|
var prev = $(".selectedOption").prev();
|
|
var lastSel = $(".selectedOption");
|
|
|
|
if (event.keyCode === 38) {
|
|
event.preventDefault();
|
|
if (lastSel === undefined) {
|
|
last.addClass("selectedOption");
|
|
} else {
|
|
if (prev.length === 0) {
|
|
last.addClass("selectedOption");
|
|
lastSel.removeClass("selectedOption");
|
|
} else {
|
|
prev.addClass("selectedOption");
|
|
lastSel.removeClass("selectedOption");
|
|
}
|
|
}
|
|
} else if (event.keyCode === 40) {
|
|
event.preventDefault();
|
|
if (lastSel === undefined) {
|
|
first.addClass("selectedOption");
|
|
last.removeClass("selectedOption");
|
|
} else {
|
|
if (next.length === 0) {
|
|
first.addClass("selectedOption");
|
|
lastSel.removeClass("selectedOption");
|
|
} else {
|
|
next.addClass("selectedOption");
|
|
lastSel.removeClass("selectedOption");
|
|
}
|
|
}
|
|
} else if (event.keyCode === 13) {
|
|
lastSel[0].click();
|
|
$("#"+modifyingInput)[0].focus();
|
|
}
|
|
},
|
|
'click .dropdown, focus .dropdown' (event) {
|
|
if(clickDisabled) return;
|
|
clickDisabled = true;
|
|
if(event.target.id === optionOpen[0] && optionOpen[1]) {
|
|
toggleOptionMenu(false, event.target.id);
|
|
} else {
|
|
toggleOptionMenu(true, event.target.id);
|
|
}
|
|
setTimeout(function(){clickDisabled = false;},130); // Prevents spamming and handles extra click events.
|
|
},
|
|
'click .optionText' (event) { // Click each preferences setting.
|
|
var option = event.target.childNodes[0].nodeValue;
|
|
document.getElementById(modifyingInput).value = option;
|
|
toggleOptionMenu(false, modifyingInput);
|
|
$(".selectedOption").removeClass("selectedOption");
|
|
},
|
|
});
|