Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <title>Bootstrap demo</title>
- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"
- integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
- <style>
- </style>
- </head>
- <body>
- <nav class="navbar navbar-expand-lg navbar-light bg-light">
- <div class="container-fluid">
- <a class="navbar-brand" href="#">Navbar</a>
- <button class="navbar-toggler" type="button" data-bs-toggle="collapse"
- data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false"
- aria-label="Toggle navigation">
- <span class="navbar-toggler-icon"></span>
- </button>
- <div class="collapse navbar-collapse" id="navbarSupportedContent">
- <ul class="navbar-nav me-auto mb-2 mb-lg-0">
- <li class="nav-item">
- <a class="nav-link active" aria-current="page" href="index.html">Home</a>
- </li>
- <li class="nav-item">
- <a class="nav-link" href="#" id="popular_movies">Popular Movies</a>
- </li>
- <li class="nav-item dropdown">
- <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button"
- data-bs-toggle="dropdown" aria-expanded="false">
- Dropdown
- </a>
- <ul class="dropdown-menu" aria-labelledby="navbarDropdown">
- <li><a class="dropdown-item" href="#">Action</a></li>
- <li><a class="dropdown-item" href="#">Another action</a></li>
- <li>
- <hr class="dropdown-divider">
- </li>
- <li><a class="dropdown-item" href="#">Something else here</a></li>
- </ul>
- </li>
- <li class="nav-item">
- <button type="button" id="joke" class="btn btn-primary" data-bs-toggle="modal"
- data-bs-target="#exampleModal">
- tell me a joke
- </button>
- </li>
- </ul>
- <form class="d-flex">
- <input class="form-control me-2" type="search" placeholder="Search" aria-label="Search" id="search">
- <button class="btn btn-outline-success" type="submit" id="submit">Search</button>
- </form>
- </div>
- </div>
- </nav>
- <div class="container-fluid">
- <h1 id="movielist_title"></h1>
- <div id="movielist"></div>
- </div>
- <!-- Button trigger modal -->
- <!-- Modal -->
- <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
- <div class="modal-dialog">
- <div class="modal-content">
- <div class="modal-header">
- <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
- <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
- </div>
- <div class="modal-body">
- <span id="punchline"></span>
- </div>
- <div class="modal-footer">
- <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
- </div>
- </div>
- </div>
- </div>
- <script src="https://code.jquery.com/jquery-3.7.0.min.js"
- integrity="sha256-2Pmvv0kuTBOenSvLm6bvfBSSHrUJ+3A7x6P5Ebd07/g=" crossorigin="anonymous"></script>
- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"
- integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz"
- crossorigin="anonymous"></script>
- <script>
- $(function () {
- // function to load popular movies from TMDB
- $("#popular_movies").click(function () {
- // clear any existing data so it doesn't keep stacking up
- $("#movielist_title").empty();
- $("#movielist").empty();
- var api_key = "ce283f8ff68c019530c5f5ccf045de2d"; //TODO insert your unique API KEY here
- var api_url = "https://api.themoviedb.org/3/movie/popular?api_key=" + api_key;
- $.getJSON(api_url, function (data) {
- $.each(data.results, function (i, item) {
- console.log(item);
- var posterFullUrl = "https://image.tmdb.org/t/p/w185//" + item.poster_path;
- var img = "<img src='" + posterFullUrl + "' title='" + item.title + " (" + item.release_date.substring(0, 4) + ")'/>";
- $("#movielist").append(img);
- $("#movielist_title").text("Popular Movies");
- });
- });
- });
- $("form").submit(function(e) {
- e.preventDefault();
- // $("#submit").click();
- });
- // joke api
- $("#joke").click(function () {
- console.log("testing joke api");
- var joke_url = "https://official-joke-api.appspot.com/random_joke";
- $.getJSON(joke_url, function (data) {
- $("#exampleModalLabel").text(data.setup);
- $("#punchline").text(data.punchline);
- console.log(data);
- });
- });
- // function to search for movies
- $("#submit").click(function (e) {
- $("#movielist").empty();
- var search_string = $("#search").val().replace("/ /g", "+");
- // zj: ^^^ this is weird, we're using a "regular expression" to replace *ALL* occurrences of space in that value
- var api_key = "ce283f8ff68c019530c5f5ccf045de2d"; //TODO insert your unique API KEY here
- var movie_search_url = "https://api.themoviedb.org/3/search/movie?api_key=" + api_key + "&query=" + search_string;
- $.getJSON(movie_search_url, function (data) {
- $.each(data.results, function (i, item) {
- console.log(item);
- var posterFullUrl = "https://image.tmdb.org/t/p/w185//" + item.poster_path;
- var img = "<img src='" + posterFullUrl + "' title='" + item.title + " (" + item.release_date.substring(0, 4) + ")'/>";
- $("#movielist").append(img);
- $("#movielist_title").text("Search results for '" + search_string + "':");
- });
- });
- });
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement