ResultManager/script/main.js

204 lines
5.6 KiB
JavaScript
Raw Normal View History

2019-08-08 13:58:29 +00:00
/**
* /script/main.js
* @version 1.4
* @desc Main javascript file
* @author Fándly Gergő Zoltán (fandlygergo@gmail.hu, systemtest.tk)
* @copy 2017 Fándly Gergő Zoltán
* License:
Result Manager for managing results of students in bilingual school systems.
Copyright (C) 2017 Fándly Gergő Zoltán
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
**/
var Site="";
function disposeMessageOverlay(){
$("#messageOverlay").html("");
$("#messageOverlay").fadeOut();
}
function showMessage(html){
$("#messageOverlay").html(html);
$("#messageOverlay").fadeIn();
setTimeout(function(){
disposeMessageOverlay()
}, 5000);
}
function loadMessages(){
$.ajax({
url: "./subs/msg.php",
type: "GET",
success: function(response){
if(response!=""){
showMessage(response);
}
}
});
}
function smoothScroll(selector){
$('html, body').stop().animate({
scrollTop: $(selector).offset().top
}, 500);
}
function goTo(site, pop=false){
Site=site;
//slide up
$("#content").slideUp(function(){
//load part
$.ajax({
url: "./subs/loader.php",
type: "GET",
data: {"load": site},
success: function(response){
$("#content").html(response);
if(!pop){
window.history.pushState({"site": site}, null, "./"+site);
}
},
complete: function(){
$("#content").slideDown(function(){
//load script
$.getScript("./script/js.php?load="+site);
//prepare site
prepareSite();
});
}
});
});
}
function prepareSite(){
//smooth scroll
$('a[href^="#"]').on('click', function(event) {
var target = $(this.getAttribute('href'));
if( target.length ) {
event.preventDefault();
$('html, body').stop().animate({
scrollTop: target.offset().top
}, 500);
}
});
//disable ajax forms submit
$(".ajaxform").submit(function(e){
e.preventDefault(); //prevent classic submit
});
}
function toggleDropdown(content, img){
if($(content).css("display")=="none"){
$(content).slideDown();
$(img).attr("src", "./res/minus.png");
}
else{
$(content).slideUp();
$(img).attr("src", "./res/plus.png");
}
}
function footableRemoveElem(elem){
//delete from table
var button=$(elem);
var current=button.parents("tr:first");
var remove;
//if we in the detail row or not
if(current.hasClass("footable-detail-row")){
//get the previous row and add it with the current row to be removed later
remove = current.add(current.prev());
}
else{
//get the next row after the current row and check if it's a detail row
var next = current.next();
//if the next row is a detail row or not
if (next.hasClass("footable-detail-row")){
//get the next row and add it with the current row to be removed later
remove = current.add(next);
}
else{
//we can't find a detail row so just remove the current row later
remove = current;
}
}
remove.fadeOut(function(){
remove.remove();
});
}
function search(field, list){
$(list).children("li").each(function(){
if($(this).children("label").text().toLowerCase().indexOf($(field).val().toLowerCase())!=-1){
$(this).css("display", "block");
}
else{
$(this).css("display", "none");
}
});
}
function toggleRequiredFormElement(container, to=-1){
if(to==-1){
if($(container).css("display")=="none"){
$(container).children("input").attr("required", true);
$(container).slideDown();
}
else{
$(container).slideUp();
$(container).children("input").attr("required", false);
}
}
else{
if(to==1){
$(container).children("input").attr("required", true);
$(container).slideDown();
}
else{
$(container).slideUp();
$(container).children("input").attr("required", false);
}
}
}
/*
* RUN
*/
jQuery(function($){
//get correct site
Site=window.location.pathname.substring(window.location.pathname.lastIndexOf("/")+1);
$.getScript("./script/js.php?load="+Site);
prepareSite();
//ajax loading functions
$(document).ajaxStart(function(){
$("#loadingOverlay").css("display", "block");
});
$(document).ajaxComplete(function(){
$("#loadingOverlay").css("display", "none");
});
//go back in history
window.addEventListener("popstate", function(e){
if(e.state!=null){
goTo(e.state["site"], true);
}
else{
goTo("", true);
}
});
});