inside out project STEP-104 to STEP-105 JavaScript Code Changes
29 removals
Words removed | 5 |
Total words | 131 |
Words removed (%) | 3.82 |
79 lines
32 additions
Words added | 76 |
Total words | 202 |
Words added (%) | 37.62 |
83 lines
// JavaScript Document
// inside out project STEP-105
window.onload = init();
window.onload = init();
function init() {
function init() {
window.addEventListener('scroll', function(e) {
window.addEventListener('scroll', function(e) {
var distanceY = window.pageYOffset || document.documentElement.scrollTop,
var distanceY = window.pageYOffset || document.documentElement.scrollTop,
shrinkOn = 300,
shrinkOn = 300,
header = document.querySelector("header");
header = document.querySelector("header");
if (distanceY > shrinkOn) {
if (distanceY > shrinkOn) {
classie.add(header, "smaller");
classie.add(header, "smaller");
} else {
} else {
if (classie.has(header, "smaller")) {
if (classie.has(header, "smaller")) {
classie.remove(header, "smaller");
classie.remove(header, "smaller");
}
}
}
}
});
});
$.ajax({
$.ajax({
method: 'GET',
method: 'GET',
url: 'https://me.inside-out-project.com/wp-json/wp-api-menus/v2/menus/3',
url: 'https://me.inside-out-project.com/wp-json/wp-api-menus/v2/menus/3',
dataType: 'json',
dataType: 'json',
success: function(data) {
success: function(data) {
$('nav').hide();
$('nav').hide();
var menu = menuBuilder(data.items);
var menu = menuBuilder(data.items);
$('nav').html(menu).slideDown();
$('nav').html(menu).slideDown();
$('nav li a').click(function() {
// $('nav').append(menu);
getPage($(this).data("pgid"));
});
getPage(314);
$("#loaderDiv").fadeOut("slow");
$("#loaderDiv").fadeOut("slow");
},
},
error: function() {
error: function() {
console.log('all is not good');
console.log('all is not good');
}
}
});
});
}
}
function menuBuilder(obj) {
function menuBuilder(obj) {
var theMenu = '';
var theMenu = '';
if (obj.length > 0) {
if (obj.length > 0) {
theMenu = theMenu + '<ul>';
theMenu = theMenu + '<ul>';
obj.forEach(function(item) {
obj.forEach(function(item) {
theMenu = theMenu + '<li><a href="#" data-pgid="' + item.object_id + '">' + item.title + '</a>';
theMenu = theMenu + '<li><a href="#">' + item.title + '</a>';
if (item.children) {
if (item.children) {
theMenu = theMenu + menuBuilder(item.children);
theMenu = theMenu + menuBuilder(item.children);
}
}
theMenu = theMenu + '</li>';
theMenu = theMenu + '</li>';
});
});
theMenu = theMenu + '</ul>';
theMenu = theMenu + '</ul>';
} else {
} else {
console.log('no data');
console.log('no data');
}
}
return theMenu;
return theMenu;
}
}
function getPage(obj) {
$("#loaderDiv").fadeIn("slow");
$.ajax({
method: 'GET',
url: 'https://me.inside-out-project.com/wp-json/wp/v2/pages/' + obj,
dataType: 'json',
success: function(data) {
var pgbuild = '';
pgbuild = '<section><div class="container">' + data.content.rendered + '</div></section>';
$("#content").fadeOut(function() {
$('html').animate({
scrollTop: 0
}, 'slow'); //IE, FF
$('body').animate({
scrollTop: 0
}, 'slow'); //chrome, don't know if Safari works
$(this).html(pgbuild).fadeIn();
$("#loaderDiv").fadeOut("slow");
});
},
error: function() {
console.log('bad');
}
});
}