初始化项目
This commit is contained in:
447
src/assets/static/common.js
Normal file
447
src/assets/static/common.js
Normal file
@@ -0,0 +1,447 @@
|
||||
var isMobile = isMobileWidth();
|
||||
var isPhone = isPhoneWidth();
|
||||
var wasMobile = isMobile;
|
||||
var wasDesktop = !isMobile;
|
||||
|
||||
var isMiniHeader = false;
|
||||
|
||||
var myLocationLat = null;
|
||||
var myLocationLong = null;
|
||||
|
||||
$(document).ready(function() {
|
||||
|
||||
initListeners();
|
||||
initHeader();
|
||||
initForms();
|
||||
initMobileMenu();
|
||||
adjustElementsForScreen();
|
||||
|
||||
});
|
||||
|
||||
//create trigger to resizeEnd event, called after event is finished
|
||||
$(window).resize(function() {
|
||||
if(this.resizeTO) clearTimeout(this.resizeTO);
|
||||
this.resizeTO = setTimeout(function() {
|
||||
$(this).trigger('resizeEnd');
|
||||
}, 100);
|
||||
});
|
||||
|
||||
//cdetermine scren type and call style functions after window resize is completed
|
||||
$(window).on('resizeEnd', function() {
|
||||
|
||||
adjustElementsForScreen();
|
||||
|
||||
});
|
||||
|
||||
$(window).scroll(function() {
|
||||
if($(window).scrollTop() > 200) {
|
||||
if(isMiniHeader === false && !isMobileWidth()) {
|
||||
$('.header').addClass('mini');
|
||||
isMiniHeader = true;
|
||||
}
|
||||
} else {
|
||||
if(isMiniHeader === true) {
|
||||
$('.header').removeClass('mini');
|
||||
isMiniHeader = false;
|
||||
}
|
||||
|
||||
}
|
||||
//var scroll = $(window).scrollTop();
|
||||
});
|
||||
|
||||
|
||||
function adjustElementsForScreen() {
|
||||
|
||||
isMobile = isMobileWidth();
|
||||
isPhone = isPhoneWidth();
|
||||
|
||||
if (!isMobileWidth()) {
|
||||
$(".mobileContent").hide();
|
||||
}
|
||||
|
||||
if (isMobile) wasMobile = true;
|
||||
if (!isMobile) wasDesktop = true;
|
||||
|
||||
if (wasDesktop && isMobile) {
|
||||
if (location.pathname.indexOf("index.php") === -1 && location.pathname.indexOf(".php") > -1) {
|
||||
handleActivePage();
|
||||
}
|
||||
}
|
||||
if (wasMobile && !isMobile) location.reload();
|
||||
|
||||
if (isMobile && isMiniHeader === true) {
|
||||
$('.header').removeClass('mini');
|
||||
isMiniHeader = false;
|
||||
}
|
||||
|
||||
//adjust 'find us' Google Maps links as user location not always located accurately on desktop
|
||||
if (isMobile) {
|
||||
$(".findUsSweden").attr("href", "https://www.google.com/maps/dir/?api=1&destination=Pythagoras+AB,+S%C3%B6der+M%C3%A4larstrand+27+B,+118+25+Stockholm");
|
||||
$(".findUsUK").attr("href", "https://www.google.com/maps/dir/?api=1&destination=180+Piccadilly,+St.+James's,+London+W1J+9HF,+UK");
|
||||
$(".findUsNorway").attr("href", "https://www.google.com/maps/dir/?api=1&destination=Skogliveien+4a,+3047+Drammen,+Norway");
|
||||
}else{
|
||||
$(".findUsSweden").attr("href", "https://www.google.com/maps/dir//Pythagoras+AB,+S%C3%B6der+M%C3%A4larstrand+27+B,+118+25+Stockholm");
|
||||
$(".findUsUK").attr("href", "https://www.google.com/maps/dir//180+Piccadilly,+St.+James's,+London+W1J+9HF,+UK");
|
||||
$(".findUsNorway").attr("href", "https://www.google.com/maps/dir//Skogliveien+4a,+3047+Drammen,+Norway");
|
||||
}
|
||||
|
||||
adjustContentBannersForScreen();
|
||||
|
||||
}
|
||||
|
||||
function initHeader() {
|
||||
|
||||
//go to main page if not there on logo click
|
||||
$(".logoCell .logo").on("click", function() {
|
||||
if (window.location.href.indexOf("index.php") === -1) {
|
||||
window.location.href = "index.php";
|
||||
}
|
||||
});
|
||||
|
||||
//show/hide main menu dropdowns on hover
|
||||
$(".mainMenu > tbody > tr > td")
|
||||
.on("mouseenter", function(e) {
|
||||
e.stopPropagation();
|
||||
$(".dropDown").hide();
|
||||
$("table.mainMenu > tbody > tr > td.selected").css("box-shadow", "none");
|
||||
$(this).find(".dropDown").addClass("droppedDown");
|
||||
$(this).find(".dropDown").slideDown();
|
||||
})
|
||||
.on("mouseleave", function(e) {
|
||||
e.stopPropagation();
|
||||
$(this).find(".dropDown").removeClass("droppedDown");
|
||||
$(this).find(".dropDown").hide();
|
||||
$("table.mainMenu > tbody > tr > td.selected").css("box-shadow", "0 -3px 0 #ff0000 inset");
|
||||
});
|
||||
|
||||
highlightHeaderCategory();
|
||||
|
||||
}
|
||||
|
||||
//highlight the appproprate main header meny category by examing url
|
||||
function highlightHeaderCategory() {
|
||||
|
||||
var myLocation = location.pathname;
|
||||
|
||||
//console.log("My location: " + myLocation);
|
||||
|
||||
if (myLocation.indexOf("index.php") !== -1) {
|
||||
$("#mainMenuGroup0").addClass("selected");
|
||||
}else if (
|
||||
myLocation.indexOf("/fm-") !== -1 ||
|
||||
myLocation.indexOf("/prs-") !== -1 ||
|
||||
myLocation.indexOf("/lvh-") !== -1 ||
|
||||
myLocation.indexOf("/fas-") !== -1 ||
|
||||
myLocation.indexOf("/sb-") !== -1 ||
|
||||
myLocation.indexOf("/tek-") !== -1) {
|
||||
$("#mainMenuGroup1").addClass("selected");
|
||||
}else if (
|
||||
myLocation.indexOf("/mobila-losningar.php") !== -1 ||
|
||||
myLocation.indexOf("/ifrs16.php") !== -1 ||
|
||||
myLocation.indexOf("/gdpr.php") !== -1) {
|
||||
$("#mainMenuGroup2").addClass("selected");
|
||||
}else if (
|
||||
myLocation.indexOf("/det-har-ar-pythagoras.php") !== -1 ||
|
||||
myLocation.indexOf("/kontakta-oss.php") !== -1 ||
|
||||
myLocation.indexOf("/jobba-hos-oss.php") !== -1) {
|
||||
$("#mainMenuGroup3").addClass("selected");
|
||||
}else if (myLocation.indexOf(".php") === -1){
|
||||
$("#mainMenuGroup0").addClass("selected");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//event listners for elements
|
||||
function initListeners() {
|
||||
|
||||
$("#hamburger").on("click", function() {
|
||||
|
||||
if ($("#mobileLanguageMenu").hasClass("showing")) {
|
||||
$("#mobileLanguageMenu").hide();
|
||||
$("#mobileLanguageMenu").removeClass("showing");
|
||||
}
|
||||
|
||||
if ($("#mobileMenu").hasClass("showing")) {
|
||||
hideMobileMenu();
|
||||
}else{
|
||||
showMobileMenu();
|
||||
}
|
||||
});
|
||||
|
||||
$("#mobileLanguage").on("click", function(e) {
|
||||
|
||||
if ($("#mobileMenu").hasClass("showing")) {
|
||||
$("#mobileMenu").hide();
|
||||
$("#mobileMenu").removeClass("showing");
|
||||
}
|
||||
|
||||
if ($("#mobileLanguageMenu").hasClass("showing")) {
|
||||
hideMobileLanguageMenu();
|
||||
}else{
|
||||
showMobileLanguageMenu();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$("#screenOverlayBehindHeader, .linkGoBack").on("click", function(e) {
|
||||
if ($("#mobileMenu").hasClass("showing")) {
|
||||
hideMobileMenu();
|
||||
}
|
||||
if ($("#mobileLanguageMenu").hasClass("showing")) {
|
||||
hideMobileLanguageMenu();
|
||||
}
|
||||
});
|
||||
|
||||
$("#mobileLanguageMenu a").on("click", function(e) {
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
//show support form
|
||||
$("a.linkSupport").on("click", function(e) {
|
||||
e.preventDefault();
|
||||
showForm("support");
|
||||
});
|
||||
|
||||
//show contact form
|
||||
$("a.linkContactUs").on("click", function(e) {
|
||||
e.preventDefault();
|
||||
showForm("contact");
|
||||
});
|
||||
|
||||
$("#scrollToBoxes").on("click", function(e){
|
||||
e.preventDefault();
|
||||
$.scrollToElement($("#pageBoxesContainer"));
|
||||
});
|
||||
|
||||
|
||||
$('.cookiesInfo').children('input[type=button]').on('click', function(){
|
||||
$(this).parent().remove();
|
||||
});
|
||||
|
||||
//location
|
||||
/*$("#ourLocationSweden").on("click", function(e) {
|
||||
e.preventDefault();
|
||||
navigateTo("sweden", $(this));
|
||||
});*/
|
||||
|
||||
}
|
||||
|
||||
function initMobileMenu() {
|
||||
$("#mobileMenu a").on("click", function(e) {
|
||||
|
||||
if ($(this).hasClass("hasSubmenu")) {
|
||||
e.preventDefault();
|
||||
$("#mobileMenu .subMenu").not($(this).siblings()).slideUp();
|
||||
$(".hasSubmenu").not($(this)).css("font-weight", "normal");
|
||||
$(this).css("font-weight", "bold");
|
||||
//$(this).parent().css("border-bottom", "none");
|
||||
$(this).parent().find(".subMenu").slideDown();
|
||||
|
||||
}else{
|
||||
hideMobileMenu();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function initForms() {
|
||||
|
||||
|
||||
$(".btnQuitForm").on("click", function() {
|
||||
$("#forms").hide();
|
||||
$("#screenOverlay").hide();
|
||||
$("#formContactContainer").hide();
|
||||
$("#formSupportContainer").hide();
|
||||
});
|
||||
|
||||
$("#formSupport").on("submit", function(e) {
|
||||
e.preventDefault();
|
||||
submitSupportForm($(this));
|
||||
});
|
||||
|
||||
$("#formContact").on("submit", function(e) {
|
||||
e.preventDefault();
|
||||
submitContactForm($(this));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function showForm(formName) {
|
||||
|
||||
$("#forms").show();
|
||||
$("#screenOverlay").show();
|
||||
|
||||
$(".contactTable").show();
|
||||
$(".formInputContainer").show();
|
||||
$(".formResultContainer").hide();
|
||||
|
||||
if (formName === "contact") {
|
||||
var $conCommentsTitle = $("label[for='conComments']");
|
||||
console.log($(".contentTableRight").find("[data-contact-link]").data("contact-link"));
|
||||
if ($(".contentTableRight").find("[data-contact-link]").length) {
|
||||
$conCommentsTitle.html("Berätta vad du vill veta mer om gällande " +
|
||||
$(".contentTableRight").find("[data-contact-link]").data("contact-link") + ": *");
|
||||
}else{
|
||||
$conCommentsTitle.html("Vad vill du veta mer om: ");
|
||||
}
|
||||
$("#formContactContainer").show();
|
||||
} else if (formName === "support") {
|
||||
$("#formSupportContainer").show();
|
||||
}
|
||||
|
||||
scrollToTop();
|
||||
|
||||
}
|
||||
|
||||
|
||||
function submitSupportForm(form) {
|
||||
|
||||
$.post("http://biz199.inmotionhosting.com/~rustyt6/pythagoras/php/submit_support_form.php",
|
||||
{
|
||||
subject: $("#supSubject").val(),
|
||||
company: $("#supCompany").val(),
|
||||
name: $("#supName").val(),
|
||||
email: $("#supEmail").val(),
|
||||
phone: $("#supPhone").val(),
|
||||
product: $("#supProduct").val(),
|
||||
comments: $("#supComments").val()
|
||||
},
|
||||
function(data) {
|
||||
console.log(data);
|
||||
}
|
||||
);
|
||||
|
||||
$(".formInputContainer").hide();
|
||||
$(".formResultContainer").show();
|
||||
scrollToTop();
|
||||
|
||||
$("#supSubject").val("");
|
||||
$("#supCompany").val("");
|
||||
$("#supName").val("");
|
||||
$("#supEmail").val("");
|
||||
$("#supPhone").val("");
|
||||
$("#supProduct").val("");
|
||||
$("#supComments").val("");
|
||||
}
|
||||
|
||||
function submitContactForm(form) {
|
||||
|
||||
$.post("http://biz199.inmotionhosting.com/~rustyt6/pythagoras/php/submit_contact_form.php",
|
||||
{
|
||||
name: $("#conName").val(),
|
||||
email: $("#conEmail").val(),
|
||||
phone: $("#conPhone").val(),
|
||||
comments: $("#conComments").val()
|
||||
},
|
||||
function(data) {
|
||||
console.log(data);
|
||||
}
|
||||
);
|
||||
|
||||
$(".contactTable").hide();
|
||||
$(".formResultContainer").show();
|
||||
scrollToTop();
|
||||
|
||||
$("#conName").val("");
|
||||
$("#conEmail").val("");
|
||||
$("#conPhone").val("");
|
||||
$("#conComments").val("");
|
||||
}
|
||||
|
||||
|
||||
function adjustContentBannersForScreen() {
|
||||
|
||||
if (isMobileWidth()) {
|
||||
$("#pageBannerImage1").attr("src", "images/banner_page_mobile_solutions_mobile.jpg");
|
||||
$("#pageBannerImage2").attr("src", "images/banner_page_ifrs16_mobile.jpg");
|
||||
$("#pageBannerImage3").attr("src", "images/banner_page_gdpr_mobile.jpg");
|
||||
}else{
|
||||
$("#pageBannerImage1").attr("src", "images/banner_page_mobile_solutions.jpg");
|
||||
$("#pageBannerImage2").attr("src", "images/banner_page_ifrs16.jpg");
|
||||
$("#pageBannerImage3").attr("src", "images/banner_page_gdpr.jpg");
|
||||
}
|
||||
}
|
||||
|
||||
/*function navigateTo(destination, $element) {
|
||||
|
||||
var baseAddress = "https://www.google.com/maps/dir/";
|
||||
|
||||
var addressSweden = "Pythagoras+AB,+S%C3%B6der+M%C3%A4larstrand+27+B,+118+25+Stockholm";
|
||||
|
||||
if (myLocationLat == null || myLocationLong == null) {
|
||||
getUserLocationForDirections();
|
||||
}else{
|
||||
if ($element.attr("href").length <= 1) {
|
||||
$element.attr("href", baseAddress + myLocationLat + "," + myLocationLong + "/" + addressSweden);
|
||||
}
|
||||
console.log($element.attr("href"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function getUserLocationForDirections() {
|
||||
$.post("https://www.googleapis.com/geolocation/v1/geolocate?key=AIzaSyB04D7_YYzWb3y3TDtVr-FR3rkBHSV6oOg",
|
||||
function(data){
|
||||
console.log(data);
|
||||
myLocationLat = data.location.lat;
|
||||
myLocationLong = data.location.lng;
|
||||
console.log(myLocationLat, myLocationLong);
|
||||
//setupDirections();
|
||||
//https://www.google.com/maps/dir/?api=1&destination=Pythagoras+AB,+S%C3%B6der+M%C3%A4larstrand+27+B,+118+25+Stockholm
|
||||
});
|
||||
}*/
|
||||
|
||||
function showMobileMenu() {
|
||||
$("#screenOverlayBehindHeader").show();
|
||||
|
||||
$("#mobileMenu").slideDown();
|
||||
$("#mobileMenu").addClass("showing");
|
||||
}
|
||||
|
||||
function hideMobileMenu() {
|
||||
$("#mobileMenu").slideUp(function(){
|
||||
$("#screenOverlayBehindHeader").hide();
|
||||
});
|
||||
$("#mobileMenu").removeClass("showing");
|
||||
}
|
||||
|
||||
function showMobileLanguageMenu() {
|
||||
$("#screenOverlayBehindHeader").show();
|
||||
|
||||
$("#mobileLanguageMenu").slideDown();
|
||||
$("#mobileLanguageMenu").addClass("showing");
|
||||
}
|
||||
|
||||
function hideMobileLanguageMenu() {
|
||||
$("#mobileLanguageMenu").slideUp(function(){
|
||||
$("#screenOverlayBehindHeader").hide();
|
||||
});
|
||||
$("#mobileLanguageMenu").removeClass("showing");
|
||||
}
|
||||
|
||||
$.scrollToElement = function($element){
|
||||
|
||||
var adjustment = 0;
|
||||
if (isMiniHeader) {
|
||||
adjustment = 35;
|
||||
}
|
||||
var $header = $('.header:first');
|
||||
$('html,body').animate({scrollTop: $element.offset().top-($header.length > 0 ? $header.height() : 0) - adjustment}, 'slow');
|
||||
};
|
||||
|
||||
//scroll page to top
|
||||
function scrollToTop() {
|
||||
$("body,html").animate({ scrollTop: 0 }, "slow");
|
||||
}
|
||||
|
||||
//is screen mobile? (<= 768 px)
|
||||
//#mobile_indicator is show/hidden via media query
|
||||
function isMobileWidth() {
|
||||
return $('#mobile_indicator').is(':visible');
|
||||
}
|
||||
|
||||
//is screen phone? (<= 480 px)
|
||||
//#mobile_indicator is show/hidden via media query
|
||||
function isPhoneWidth() {
|
||||
return $('#phone_indicator').is(':visible');
|
||||
}
|
||||
Reference in New Issue
Block a user