This repository has been archived on 2022-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
IcyNet.eu/src/script/main.js

133 lines
3.8 KiB
JavaScript
Raw Normal View History

2017-08-02 21:24:01 +00:00
window.$ = require('jquery')
$(document).ready(function () {
2017-08-24 16:23:03 +00:00
function pwcheck (e) {
var pw = $('#password').val()
var pwa = $('#password_repeat').val()
if (pwa !== pw) {
$('#password_repeat').addClass('invalid')
$('#repeatcheck').show()
$('#repeatcheck').html('<span class="error">The passwords do not match.</span>')
} else {
$('#password_repeat').removeClass('invalid')
$('#repeatcheck').hide()
$('#repeatcheck').html('')
}
}
2017-08-23 21:42:55 +00:00
if (window.location.hash) {
2017-08-24 16:23:03 +00:00
var locha = window.location.hash
2017-08-24 10:52:12 +00:00
if ($(locha).length) {
$(window).scrollTop($(locha).offset().top - $('.navigator').innerHeight() * 2)
2017-08-23 21:42:55 +00:00
}
}
2017-08-24 16:23:03 +00:00
$(window).on('scroll', function () {
if ($(window).scrollTop() >= $('.banner').innerHeight()) {
2017-08-02 21:24:01 +00:00
$('.anchor').css('height', $('.navigator').innerHeight() + 'px')
$('#navlogo').removeClass('hidden')
$('.navigator').addClass('fix')
} else {
$('#navlogo').addClass('hidden')
$('.navigator').removeClass('fix')
$('.anchor').css('height', '0px')
}
})
2017-08-24 16:23:03 +00:00
if ($(window).scrollTop() >= $('.banner').innerHeight()) {
2017-08-02 21:24:01 +00:00
$('#navlogo').removeClass('hidden')
$('.navigator').addClass('fix')
$('.anchor').css('height', $('.navigator').innerHeight() + 'px')
}
$('a[href*=\\#]').on('click', function (e) {
if (!$(this.hash).length) return
e.preventDefault()
2017-08-24 10:52:12 +00:00
var dest = 0
2017-08-02 21:24:01 +00:00
if ($(this.hash).offset().top > $(document).height() - $(window).height()) {
2017-08-24 16:23:03 +00:00
dest = $(document).height() - $(window).height()
2017-08-02 21:24:01 +00:00
} else {
2017-08-24 16:23:03 +00:00
dest = $(this.hash).offset().top
2017-08-02 21:24:01 +00:00
}
$('html,body').animate({
2017-08-24 16:23:03 +00:00
scrollTop: dest - $('.navigator').innerHeight()
2017-08-02 21:24:01 +00:00
}, 1000, 'swing')
})
2017-08-23 21:42:55 +00:00
$('#mobile').click(function (e) {
e.preventDefault()
$('.flexview').toggleClass('extended')
})
2017-08-24 16:23:03 +00:00
$('body').click(function (e) {
2017-08-23 21:42:55 +00:00
if (!$(e.target).is('#mobile') && !$(e.target).is('#mobile i') && $('.flexview').hasClass('extended')) {
$('.flexview').removeClass('extended')
}
})
if ($('#repeatcheck').length) {
$('#password_repeat').on('keyup', pwcheck)
$('#password').on('keyup', function (e) {
if ($('#password_repeat').val()) {
pwcheck(e)
}
})
}
2017-08-24 10:52:12 +00:00
if ($('.newsfeed').length) {
$.ajax({
type: 'get',
url: '/api/news',
dataType: 'json',
success: function (data) {
if (!data.length) {
return $('.newsfeed').html('There is nothing to show at this moment.')
}
var html = ''
for (var i in data) {
var article = data[i]
html += '<div class="prvarticle">'
html += '<a class="title" href="/news/' + article.id + '-' + article.slug + '">' + article.title + '</a>'
html += '<span class="timestamp">Published at ' + new Date(article.created_at) + '</span>'
html += '<div class="prvcontent">' + article.content + '</div>'
html += '<a href="/news/' + article.id + '-' + article.slug + '">Read More</a>'
html += '</div>'
}
$('.newsfeed').html(html)
}
})
}
window.checkLoginState = function () {
2017-08-24 16:23:03 +00:00
var FB = window.FB
FB.getLoginStatus(function (response) {
$.ajax({
type: 'post',
url: '/api/external/facebook/callback',
dataType: 'json',
data: response,
2017-08-24 10:52:12 +00:00
success: function (data) {
console.log(data)
if (data.error) {
$('.message').addClass('error')
$('.message span').text(data.error)
return
}
if (data.redirect) {
2017-08-24 16:23:03 +00:00
window.location.href = data.redirect
return
}
window.location.reload()
}
2017-08-24 16:23:03 +00:00
}).fail(function () {
$('.message').addClass('error')
$('.message span').text('An error occured.')
})
})
}
2017-08-02 21:24:01 +00:00
})