Incorporating YouTube links into calendar events for each specific date

Our team is currently developing an online class website where our client wants to incorporate recorded classes. These recorded classes will be uploaded to YouTube in unlisted format and then linked to specific calendar dates. I will share the code for the calendar below.

To view the code, please visit: https://codepen.io/internette/pen/YqJEjY

<div class="yellow">
  <div id="calendar">
    <div id="toolbar"></div>
    ... (code continues) ...
</div>
 

We are looking to create a feature where clicking on a date in the calendar will toggle a space displaying a link to the corresponding YouTube video. Exciting stuff!

Answer №1

To incorporate the anchor tag in a similar manner to the other elements, follow the modified code below which includes a link to YouTube:

var allMonths, dayArray = [],
  click = 0,
  dotw = [/Sun/gi, /Mon/gi, /Tue/gi, /Wed/gi, /Thu/gi, /Fri/gi, /Sat/gi];

function getAllDays(month, year) {
  var date = new Date(year, month, 1);
  var days = [];
  while (date.getMonth() === month) {
    var dayToPush = new Date(date);
    days.push(dayToPush);
    date.setDate(date.getDate() + 1);
  }
  return days;
}

function getYear() {
  var d = new Date();
  var curYear = d.getFullYear();
  return curYear;
}

function addElements(query, id) {
  //for onload, use activeIndex+1 as query value
  document.getElementById(id).innerHTML = '';
  var allDays = getAllDays((query), getYear());
  for (var i = 0; i < allDays.length; i++) {
    allDays[i] = allDays[i].toString();
  }
  var stopNow = false,
    counter = 0;
  for (var i = 0; i < dotw.length; i++) {
    if (allDays[0].match(dotw[i])) {
      stopNow = true;
    } else {
      if (!stopNow) {
        counter += 1;
      }
    }
  }
  for (var i = 0; i < counter; i++) {
    allDays.unshift(" ");
  }
  for (var i = 0; i < allDays.length; i++) {
    var singleDay = document.createElement('div');
    singleDay.className = 'day';
    singleDay.dataset.title = '';
    singleDay.dataset.location = '';
    //Parse Day
    if (allDays[i] !== " ") {
      var dayOTW = allDays[i].split(' ')[2];
      if (dayOTW.charAt(0) === "0") {
        allDays[i] = dayOTW.replace(/0/gi, '');
      } else {
        allDays[i] = dayOTW;
      }
    }
    singleDay.innerHTML = allDays[i];
    document.getElementById(id).appendChild(singleDay);
  }
  var allOfDays = document.querySelectorAll('#days .day');
  var dayArray = [];
  for (var i = 0; i < allOfDays.length; i++) {
    if (i === 6 || i === 13 || i === 20 || i === 27 || i === 34) {
      allOfDays[i].outerHTML += '<div class="day-details"><div id="input-arrow"></div><div class="input"><a href="https://www.youtube.com/watch?v=PkhPuH8G5Hg">CLICK ME</a></div></div>'
    }
  }
  document.getElementById(id).innerHTML += '<div class="day-details"><div id="input-arrow"></div><div class="input"><a href="https://www.youtube.com/watch?v=PkhPuH8G5Hg">CLICK ME</a></div><div style="clear:both"></div>';
}
//Thanks: http://stackoverflow.com/questions/4649699/is-it-possible-to-get-elements-numerical-index-in-its-parent-node-without-loopi
function whichChild(elem) {
  var i = 0;
  while ((elem = elem.previousSibling) != null) ++i;
  return i;
}
window.onload = function() {
  allMont...  
<link href="https://codepen.io/internette/pen/YqJEjY.css" rel="stylesheet" />
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.1/css/font-awesome.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.18.2/TweenMax.min.js"></script>
<div class="yellow">
  <div id="calendar">
    <div id="toolbar"></div>
    <div id="color-picker" class="show"></div>
    <div id="dates" class="show">
      <div id="lastMt">&lsaquo;</div>
      <div id="nextMt">&rsaquo;</div>
      <div id="months-cont">
        <div id="months">
          <span class="active month">January</span><span ... 

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Enter a keyword in the search bar to find what you're looking

I am working on a form where users can select their occupation from a list that is stored in a separate .js file. The list includes various occupations like 'AA Patrolman' and 'Abattoir Inspector'. var occupationSelect = "<select id ...

if and elsif JSON with Angular

Currently, I am working on completing a task within our project. To provide more context, I have a field with items that I must select. Once I choose an item, another field appears in which I must select additional elements. These elements need to be sen ...

Developing an interactive Vue component that is able to be modified using custom properties within the HTML code

I'm a VueJS beginner and I'm working on creating a custom ul component for a webpage. I want this component to be populated and updated using custom props in the HTML, allowing other developers to easily use, update, and add to the component with ...

Display a dynamic list of data fetched from an axios Get request in a React MUI dropdown menu

import { useEffect, useState } from "react"; import Box from "@mui/material/Box"; import FormControl from "@mui/material/FormControl"; import InputLabel from "@mui/material/InputLabel"; import MenuItem from "@m ...

Generate a new div element dynamicaly after every 10 elements are added

I am facing the following scenario: I need to dynamically add an UNKNOWN number of checkboxes to a layout component, arranged in columns with 10 checkboxes per layout item. Although I have successfully added all the checkboxes to a single div element, I ...

How come my FormData POST request isn't being blocked by CORS policy?

I am facing confusion with one query: why does my POST request, which sends form data from a frontend hosted on a different origin to a backend hosted on a different origin, not get blocked by CORS policy? My Node.js code includes the following: const exp ...

Creating an href link within a button that is contained within a collapse component

I am grappling with an issue where my collapsed model is displaying more information about clients; however, when I click on the button inside it, instead of getting the specific client's data, I end up retrieving information for all clients. <ion ...

Creating a personalized login function in LaravelWould you like to learn how to

Currently, I am in the process of creating an application that caters to two distinct user groups: sellers and buyers. Each group has their own unique set of pages and forms for registration. I have successfully implemented the registration logic for both ...

What are the steps to create two frames using Twitter Bootstrap?

I'm just starting to work with Twitter Bootstrap and I need some help. Can someone assist me in creating a two-column layout inside the HTML, where the menu in the header stays visible even when scrolled down? I've included my HTML code below. Th ...

There seems to be an issue with accessing the 'request' property of an undefined object

Currently, I am in the process of incorporating a base service into an Angular application. This service is designed to provide methods to other services for composing requests with default headers and options. However, I encounter an issue when attempting ...

Thymeleaf: Expression parsing error

I am working on a Thymeleaf template that includes pagination functionality. <ul class="results_perpage" > <li th:if="${previous != null}"><a th:href="javascript:movePage(`${previous}`);" class="results_menu" th:text="PREVIOUS">< ...

Node.js (npm) is still unable to locate python despite setting %PYTHON% beforehand

Trying to get Node.js to work is proving to be more challenging than expected! Despite having two versions of Python on my computer, it seems that Node.js only works with the older version, 2.7. When I encountered an error, it prompted me to set the path ...

What is the best way to style divs in this manner?

Imagine you have a div with specific height and width (as shown in the illustration as the innermost one), and you wish for the outer divs to encompass it, with an outer margin of 1 em. How could this be achieved? +--------+ | +-----+| | |+---+|| | || ...

Utilizing Nginx to Reverse Proxy to Node.js and Implement Rewrites

I have various applications running in the background behind an Nginx reverse proxy. One of these applications is a Node server using Express.js. I am forwarding domain.com/demo/app/<path> to localhost:7003/<path> through this Nginx configurati ...

Enhancing websites with CSS3 and VueJS for fluid and captivating background gradients transitions

After implementing a logic in the application, the gradient is now changing dynamically. <template> <div :style="`background-image: ${backgroundImage}`" class="background"> <snackbar /> <nuxt /> <default-footer /&g ...

Generate a Calendar Table using JavaScript in the Document Object Model (DOM

I have set up a table with 6 rows and 5 columns. The purpose of the table is to represent each month, which may have varying numbers of days. I want each column to display dates ranging from 1-30 or 1-31, depending on the specific month. Here's what ...

Ways to isolate AngularJS files without relying on the global scope

I came across a post on Stack Overflow discussing the best practices for declaring AngularJS modules. Despite reading it, I am still unsure about the most effective way to separate and declare angularJS files for modules, controllers, services, etc. I hav ...

Using Express for Managing Subdomains, Redirects, and Hosting Static Files

I am struggling to configure Express in a specific way and can't seem to get it right. Despite researching on various platforms like SO, I still can't figure it out. Hopefully, by explaining my intentions here, someone can guide me in the right d ...

React: When an array state is controlling my components, why aren't they re-rendering?

I am facing an issue with my app where the className of buttons is not updating correctly when clicked. It seems that only active buttons trigger a re-render, while non-active ones do not. This behavior is confusing to me. Here's the code snippet for ...

The scroll bar in the main window vanishes as the popup window expands in size

When the popup expands in size, the bottom portion becomes inaccessible even with a scrollbar present. Ideally, the scrollbar on the parent window should adjust automatically as the popup grows, allowing users to scroll and view the entire content. ...