Commit 6f2819ac authored by tmeyrick's avatar tmeyrick
Browse files

Added leaflet images

parents 3ed66b98 bf5cbab8
Pipeline #4049 passed with stage
in 2 seconds
......@@ -218,44 +218,41 @@ var Validator = (function () {
messages = [];
errorHTML = "";
// Validate Address Details
checkAddress(document.getElementById("deliveryAddress1").value, messages);
checkName(document.getElementById("deliveryName").value, messages);
checkEmail(document.getElementById("deliveryEmail").value, messages);
checkAddress($("#deliveryAddress1").val(), messages);
checkName($("#deliveryName").val(), messages);
checkEmail($("#deliveryEmail").val(), messages);
// TO BE ADDED
// Validate Credit Card Details
// This depends a bit on the type of card, so get that first
cardType = document.getElementById("cardType").value;
cardType = $("#cardType").val();
// Credit card number validation
cardNumber = document.getElementById("cardNumber").value;
cardNumber = $("#cardNumber").val();
checkCreditCardNumber(cardType, cardNumber, messages);
// Expiry date validation
cardMonth = document.getElementById("cardMonth").value;
cardYear = document.getElementById("cardYear").value;
cardMonth = $("#cardMonth").val();
cardYear = $("#cardYear").val();
checkCreditCardDate(cardMonth, cardYear, messages);
// CVC validation
cardValidation = document.getElementById("cardValidation").value;
cardValidation = $("#cardValidation").val();
checkCreditCardValidation(cardType, cardValidation, messages);
if (messages.length === 0) {
// Checkout successful, clear the cart
window.sessionStorage.clear();
document.getElementById("errorMsgs").innerHTML = "<p>Your order has been submitted</p>";
$("#errorMsgs").innerHTML = "<p>Your order has been submitted</p>";
} else {
errorHTML = "<ul>";
for (i = 0; i < messages.length; i++) {
errorHTML += "<li>" + messages[i] + "</li>";
}
errorHTML += "</ul>";
document.getElementById("errorMsgs").innerHTML = errorHTML;
$("#errorMsgs").innerHTML = errorHTML;
}
// Stop the form from submitting, which would trigger a page load
......@@ -277,6 +274,9 @@ var Validator = (function () {
document.getElementById("cardNumber").onkeypress = checkKeyIsDigit;
document.getElementById("cardValidation").onkeypress = checkKeyIsDigit;
document.getElementById("deliveryPostcode").onkeypress = checkKeyIsDigit;
$("#cardNumber").onkeypress = checkKeyIsDigit;
$("#cardValidation").onkeypress = checkKeyIsDigit;
$("#deliveryPostcode").onkeypress = checkKeyIsDigit;
};
// Expose public interface
......@@ -284,10 +284,4 @@ var Validator = (function () {
}());
// The usual onload event handling to call SampleValidator.setup
if (window.addEventListener) {
window.addEventListener('load', Validator.setup);
} else if (window.attachEvent) {
window.attachEvent('onload', Validator.setup);
} else {
alert("Could not attach 'Validator.setup' to the 'window.onload' event");
}
\ No newline at end of file
$(document).ready(Validator.setup);
\ No newline at end of file
......@@ -6,6 +6,7 @@
<title>Classic Cinema</title>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<script src="jquery.min.js"></script>
</head>
......
......@@ -4,14 +4,12 @@ var Cart = (function() {
function addToCart() {
var cartlist = [];
var movie = this.parentNode.parentNode;
var titleOfMovie = movie.getElementsByTagName("h3")[0].innerHTML;
var priceOfMovie = movie.getElementsByClassName("price")[0].innerHTML;
var titleOfMovie = $(this).parent().siblings("h3")[0].innerHTML;
var priceOfMovie = $(this).siblings(".price")[0].innerHTML;
var myObject = {title: titleOfMovie, price: priceOfMovie};
if (window.sessionStorage.getItem("cartlist") != null) {
cartlist = JSON.parse(window.sessionStorage.getItem("cartlist"));
cartlist = $.parseJSON(window.sessionStorage.getItem("cartlist"));
cartlist.push(myObject);
window.sessionStorage.setItem("cartlist", JSON.stringify(cartlist));
} else {
......@@ -21,15 +19,16 @@ var Cart = (function() {
}
pub.setup = function() {
var buttons = document.getElementsByClassName("buy");
var buttons = $(".buy");
// var buttons = document.getElementsByClassName("buy");
for (let button of buttons) {
button.onclick = addToCart;
$(button).click(addToCart);
}
};
/*let
/*
When the 'add to cart' button is pushed, create an object with
two data fields - a title and a price.
......@@ -40,11 +39,7 @@ var Cart = (function() {
}());
if (window.addEventListener) {
window.addEventListener('load', Cart.setup);
} else if (window.attachEvent) {
window.attachEvent('onload', Cart.setup);
}
$(document).ready(Cart.setup);
......@@ -6,6 +6,7 @@
<title>Classic Cinema</title>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<script src="jquery.min.js"></script>
</head>
<body>
......@@ -38,6 +39,7 @@
<li> <a href="scifi.html">Sci&nbsp;Fi</a>
<li> <a href="hitchcock.html">Hitchcock</a>
<li><a href="contact.html">Contact</a></li>
<li><a href="cart.html">Cart</a></li>
</ul>
</nav>
</header>
......
......@@ -42,6 +42,7 @@
<li><a href="scifi.html">Sci&nbsp;Fi</a>
<li><a href="hitchcock.html">Hitchcock</a>
<li>Contact</li>
<li><a href="cart.html">Cart</a></li>
</ul>
......
......@@ -6,6 +6,7 @@
<title>Classic Cinema</title>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<script src="jquery.min.js"></script>
</head>
<body>
......@@ -39,6 +40,7 @@
<li> <a href="scifi.html">Sci&nbsp;Fi</a>
<li> Hitchcock
<li><a href="contact.html">Contact</a></li>
<li><a href="cart.html">Cart</a></li>
</ul>
</nav>
......
......@@ -39,6 +39,7 @@
<li> <a href="scifi.html">Sci&nbsp;Fi</a>
<li> <a href="hitchcock.html">Hitchcock</a>
<li><a href="contact.html">Contact</a></li>
<li><a href="cart.html">Cart</a></li>
</ul>
</nav>
......
This diff is collapsed.
......@@ -3,56 +3,45 @@ var PrintCart = (function() {
var pub = {};
pub.setup = function() {
var div = document.getElementById("cart");
var form = document.getElementById("checkoutForm");
var div = $("#cart");
var form = $("#checkoutForm");
/*
If the cart list cookie is empty, print an empty message
Otherwise print out a list of cart items
*/
if (window.sessionStorage.getItem("cartlist") == null) {
div.innerHTML = "<p>There are currently no items in your cart.</p>";
form.style.display = "none";
$(form).css("display", "none");
} else {
/* Make a heading */
var heading = document.createElement("h2");
var headingTxt = document.createTextNode("My Cart");
heading.appendChild(headingTxt);
div.appendChild(heading);
heading.style.marginBottom = "10px";
var heading = "<h2>My Cart</h2>";
$(div).append(heading);
$(heading).css("marginBottom", "10px");
/* Create the list of cart items */
var ul = document.createElement("ul");
var cartlist = JSON.parse(window.sessionStorage.getItem("cartlist"));
var ul = "<ul></ul>";
var cartlist = $.parseJSON(window.sessionStorage.getItem("cartlist"));
var total = 0;
$(div).append(ul);
/* Loop through cart list from cookies and print out a li for each */
for (let cartitem of cartlist) {
var li = document.createElement("li");
var txt = document.createTextNode(cartitem.title + " - $" + cartitem.price);
li.appendChild(txt);
li.style.fontSize = '1.2em';
li.style.marginBottom = '10px';
ul.appendChild(li);
var li = "<li>" + cartitem.title + " - $" + cartitem.price + "</li>";
$("#cart ul").append(li);
$(li).css({"fontSize": "1.2em", "marginBottom": "10px"});
total += parseFloat(cartitem.price);
}
div.appendChild(ul);
ul.style.listStyle = 'none';
$("#cart ul").css("listStyle", "none");
/* Print out the total price */
var totalP = document.createElement("p");
var innerP = document.createTextNode("Total Price: $" + total.toFixed(2));
totalP.appendChild(innerP);
totalP.style.fontSize = '1.3em';
totalP.style.color = 'green';
div.appendChild(totalP);
var totalP = "<p>Total Price: $" + total.toFixed(2) + "</p>";
$(div).append(totalP);
$("#cart p").css({"fontSize": "1.3em", "color": "green"});
}
};
return pub;
}());
if (window.addEventListener) {
window.addEventListener('load', PrintCart.setup);
} else if (window.attachEvent) {
window.attachEvent('onload', PrintCart.setup);
}
\ No newline at end of file
$(document).ready(PrintCart.setup);
\ No newline at end of file
......@@ -6,6 +6,7 @@
<title>Classic Cinema</title>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<script src="jquery.min.js"></script>
</head>
<body>
......@@ -38,6 +39,7 @@
<li> Sci&nbsp;Fi
<li> <a href="hitchcock.html">Hitchcock</a>
<li><a href="contact.html">Contact</a></li>
<li><a href="cart.html">Cart</a></li>
</ul>
</nav>
</header>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment