This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous"> | |
<script src="https://kit.fontawesome.com/6b773fe9e4.js" crossorigin="anonymous"></script> | |
<title>Ajax Template</title> | |
<style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
if(!isset($_SESSION['favorites'])) { $_SESSION['favorites'] = []; } | |
function is_ajax_request() { | |
return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && | |
$_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.addEventListener('DOMContentLoaded', () => { | |
const observer = new IntersectionObserver(entries => { | |
entries.forEach(entry => { | |
const id = entry.target.getAttribute('id'); | |
if (entry.intersectionRatio > 0) { | |
document.querySelector(`nav li a[href="#${id}"]`).parentElement.classList.add('active'); | |
} else { | |
document.querySelector(`nav li a[href="#${id}"]`).parentElement.classList.remove('active'); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Not my work - edited for my use --> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<!-- Required meta tags --> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<!-- Bootstrap CSS --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge" /> | |
<link rel="stylesheet" href="style.css" /> | |
<script defer src="script.js"></script> | |
<script defer src="assignments.js"></script> | |
<title>Asynchronous JavaScript</title> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const imgTargets = document.querySelectorAll('img[data-src]'); | |
const loadImg = function (entries, observer) { | |
const [entry] = entries; | |
if (!entry.isIntersecting) return; | |
entry.target.src = entry.target.dataset.src; | |
entry.target.addEventListener('load', function () { | |
entry.target.classList.remove('lazy-img'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const header = document.querySelector('.header'); | |
const navHeight = nav.getBoundingClientRect().height; | |
const stickyNav = function (entries) { | |
const [entry] = entries; | |
if (!entry.isIntersecting) nav.classList.add('sticky'); | |
else nav.classList.remove('sticky'); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const formatCurrency = function (value, locale, currency) { | |
new Intl.NumberFormat(locale, { | |
style: 'currency', | |
currency: currency, | |
}).format(value); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const randomInt = (min, max) => Math.floor(Math.random() * (max - min) + 1) + min; | |
console.log(randomInt(10, 20)); | |
// Used floor instead of trunc so negative numbers can be used |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.body.append(document.createElement('textarea')); | |
document.body.append(document.createElement('button')); | |
document.querySelector('button').addEventListener('click', function () { | |
const text = document.querySelector('textarea').value; | |
const rows = text.split('\n'); | |
for (const [i, row] of rows.entries()) { | |
const [first, second] = row.toLowerCase().trim().split('_'); | |
const output = `${first}${second.replace(second[0], second[0].toUpperCase())}`; |
NewerOlder