Collapsible rows in table without using any IDs

I have created a table in which whenever a user clicks the row it expands its next hidden row. to do that I have used the below script in which the next element of the class row-details is targeted as a hidden element. The issue here is to use an id or class to target each div inside the row.

If I use normal div elements then the script can use this.nextElementSibling; to identify the next div element which can be hidden and when the first div is clicked it will expand.

var tableRow = document.getElementsByClassName('row');

for (var i = 0; i < tableRow.length; i++) {
    tableRow[i].addEventListener('click', function () {
        var tableContent = document.querySelector('.row-details');
        if (tableContent.style.maxHeight) {
            tableContent.style.maxHeight = null;
        } else {
            tableContent.style.maxHeight = tableContent.scrollHeight + 'px';
        }
    });
}

In the below code there are 2 rows each with a hidden row containing details. I have used the same class for both hidden rows. What I am trying to achieve is to expand the hidden row without defining any Id or class. min-height property is not working on tr tags.


var tableRow = document.getElementsByClassName('row');

for (var i = 0; i < tableRow.length; i++) {
    tableRow[i].addEventListener('click', function () {
        var tableContent = this.nextElementSibling;
        if (tableContent.style.maxHeight) {
            tableContent.style.maxHeight = null;
        } else {
            tableContent.style.maxHeight = tableContent.scrollHeight + 'px';
        }
    });
}
.row-details{
  max-height: 0;
  overflow: hidden;
  transition: all 300ms ease;
}

table {
  border-collapse: unset;
}
<table>
  <tr>
    <th>Date</th>
    <th>Data-1</th>
    <th>Data-2</th>
  </tr>
  <tr class="row">
    <td>Lorem</td>
    <td>ipsum</td>
    <td>dolor sit amet.</td>
  </tr>
  <tr>
    <td colspan="3">
      <div class="row-details">
        <span>Lorem, ipsum.</span>
      </div>
    </td>
  </tr>
  <tr class="row">
    <td>Lorem</td>
    <td>ipsum</td>
    <td>dolor sit amet.</td>
  </tr>
  <tr>
    <td colspan="3">
      <div class="row-details">
        <span>Lorem, ipsum.</span>
      </div>
    </td>
  </tr>
</table>

DiviAreas : Could not find an area with the ID: landing-popup

Created a Divi Popup which loads the main page when it first appears but disappears when the page is refreshed. In the below code, the else part doesn’t render. It throws an error: [DiviAreas] Could not find an area with the ID: landing-popup

jQuery(document).ready(function ($) {
  if (localStorage.getItem("btnClassName") == null) {
    if (document.cookie.indexOf("modal_shown") < 1) {
      setTimeout(function () {
        DiviArea.show("landing-popup");
        document.cookie =
          "modal_shown=seen; sameSite=Strict; Secure; max-age= 60 * 60 * 24 * 365 ";
        $(".first-button").on("click", function () {
          localStorage.setItem("btnClassName", "first-button");
        });
        $(".second-button").on("click", function () {
          localStorage.setItem("btnClassName", "second-button");
        });
      }, 500);
    } else if (
      document.cookie.indexOf("modal_shown") > 1 &&
      localStorage.getItem("btnClassName") == null
    ) {
      DiviArea.show("landing-popup");
    }
  } else if (localStorage.getItem("btnClassName") == "second-button") {
    window.location.href =
      "https://example.com/second-homepage/";
  } else if (localStorage.getItem("btnClassName") == "first-button") {
    window.location.href =
      "https://example.com/first-homepage/";
  } else {
    console.error("Invalid State of selection");
  }
});
</script>

writing else part again separately for better understanding.

else if (
      document.cookie.indexOf("modal_shown") > 1 &&
      localStorage.getItem("btnClassName") == null
    ) {
      DiviArea.show("landing-popup");
    }

What I tried

DiviArea.addAction("ready", function($)  {
      if (localStorage.getItem("btnClassName") == null) {
    if (document.cookie.indexOf("modal_shown") < 1) {
      setTimeout(function () {
        DiviArea.show("landing-popup");
        document.cookie =
          "modal_shown=seen; sameSite=Strict; Secure; max-age= 60 * 60 * 24 * 365 ";
        $(".first-button").on("click", function () {
          localStorage.setItem("btnClassName", "first-button");
        });
        $(".second-button").on("click", function () {
          localStorage.setItem("btnClassName", "second-button");
        });
      }, 500);
    } else if (
      document.cookie.indexOf("modal_shown") > 1 &&
      localStorage.getItem("btnClassName") == null
    ) {
      DiviArea.show("landing-popup");
    }
  } else if (localStorage.getItem("btnClassName") == "second-button") {
    window.location.href =
      "https://example.com/second-homepage/";
  } else if (localStorage.getItem("btnClassName") == "first-button") {
    window.location.href =
      "https://example.com/first-homepage/";
  } else {
    console.error("Invalid State of selection");
  }
});

In this case, I’m getting a popup every time I refresh but it doesn’t render cookies or localstorage. Since it is not triggering inside if-else cases.

How to disable `ReactIntlTelInput` component from `react-intl-tel-input-v2`?

I have successfully integrate react-intl-tel-input-v2 for international phone number input. Here is the code

class App extends Component {
  constructor() {
    super();
    this.state = {
      name: 'React',
      value: { iso2: 'cn', dialCode: '86', phone: '12345678901' },
    };
  }

  onChange = (value) =>
    this.setState({ value }, () => console.log(this.state.value));

  render() {
    return (
      <div>
        <Hello name={this.state.name} />

        <ReactIntlTelInput
          value={this.state.value}
          onChange={this.onChange}
        />

        <h4>{JSON.stringify(this.state.value)}</h4>
      </div>
    );
  }
}

Now my problem is I want to disable this component. I didn’t find any proper documentation how to disable it. I also check different props but not succeed.
You can also check the code stackblitz

Dropzone component is working normally if we use it directly in the component. But it’s not working if we keep that component in the Material Dialog

import React from 'react';
import 'react-dropzone-uploader/dist/styles.css';
import { Dialog, DialogActions, DialogContent, DialogTitle,} from "@material-ui/core";

import Dropzone from 'react-dropzone-uploader';
import { getDroppedOrSelectedFiles } from 'html5-file-selector'

const Preview = ({ meta }) => {
const { name, percent, status } = meta
return (
  <span style={{ alignSelf: 'flex-start', margin: '10px 3%', fontFamily: 'Helvetica' 
}}>
    {name}, {Math.round(percent)}%, {status}
    <progress value={Math.round(percent)} max="100"></progress>
  </span>
)
}
const FileUploadComponent = () => {
const fileParams = ({ meta }) => {
    return { url: 'https://httpbin.org/post' }
}
const onFileChange = ({ meta, file }, status) => { 
    console.log(status, meta, file) 
}
const onSubmit = (files, allFiles) => {
    allFiles.forEach(f => f.remove())
}
const getFilesFromEvent = e => {
    return new Promise(resolve => {
        getDroppedOrSelectedFiles(e).then(chosenFiles => {
            resolve(chosenFiles.map(f => f.fileObject))
        })
    })
}
const selectFileInput = ({ accept, onFiles, files, getFilesFromEvent }) => {
    const textMsg = files.length > 0 ? 'Upload Again' : 'Select Files'
    return (
        <label className="btn btn-danger mt-4">
            {textMsg}
            <input
                style={{ display: 'none' }}
                type="file"
                accept={accept}
                multiple
                onChange={e => {
                    getFilesFromEvent(e).then(chosenFiles => {
                        onFiles(chosenFiles)
                    })
                }}
            />
        </label>
    )
}
return (
    <div>
            <div className="bodycontent">
            <Dropzone
            onSubmit={onSubmit}
            onChangeStatus={onFileChange}
            InputComponent={selectFileInput}
            PreviewComponent={Preview}
            getUploadParams={fileParams}
            getFilesFromEvent={getFilesFromEvent}
            accept=".pdf"
            maxFiles={1}
            inputContent="Drop A File"
            />
            <div>
    </div>
    <Dialog>
        <DialogTitle>
            Upload..... 
        </DialogTitle>
        <DialogContent dividers>
            <Dropzone
                onSubmit={onSubmit}
                onChangeStatus={onFileChange}
                InputComponent={selectFileInput}
                PreviewComponent={Preview}
                getUploadParams={fileParams}
                getFilesFromEvent={getFilesFromEvent}
                accept=".pdf"
                maxFiles={1}
                inputContent="Drop A File"
            />
        </DialogContent> 
    </Dialog>
  );
};


export default FileUploadComponent;
enter code here

If I keep “Dropzone” component out side the material “Dialog” it is working in first click as expected. But if I keep “Dropzone” component in the, inside “Dialog” it’s not working on fisrst click. From the second click onwards it’s working as expected. i.e “onFileChange” is calling only from second click onwards. it’s not calling on first click. any suggestion please.

Access to XMLHttpRequest has been blocked by CORS policy: value of the ‘Access-Control-Allow-Origin’ header in response must not be the wildcard ‘*’

I would like to use this API(https://www.collectapi.com/api/gasPrice/gas-prices-api?tab=pricing) to get gas prices. I copied the example request from their page, but I keep getting:

Access to XMLHttpRequest at ‘https://api.collectapi.com/gasPrice/turkeyGasoline?district=kadikoy&city=istanbul’ from origin ‘http://127.0.0.1:5500’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: The value of the ‘Access-Control-Allow-Origin’ header in the response must not be the wildcard ‘*’ when the request’s credentials mode is ‘include’. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.

This is the code:

var data = null;

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "https://api.collectapi.com/gasPrice/turkeyGasoline?district=kadikoy&city=istanbul");
xhr.setRequestHeader("content-type", "application/json");
xhr.setRequestHeader("authorization", "apikey your_token");

xhr.send(data);

Could someone please tell me why is this happening and how could I fix it?

Why my div is overlapping even I used white-space in my javascript slider

I don’t understand why the div is overlapping. I want my div to be exact I as I click next or back pages. Here is my code

    <style>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }
        body {
            padding: 0;
            margin: 0;
        }
        .slider-wrap {
            position: relative;
            width: 100%;
            height: 200px;
            overflow: hidden;
            background: black;

        }
        .slider-main {
            white-space: nowrap;
            transition: ease 1000ms;
            position: absolute;
            width: 100%;
            height: 200px;
        }
        .item {
            width: 100%;
            height: 200px;
            background: red;
            display: inline-flex;
            position: relative;
        }
        .text {
            position: absolute;
            background: gray;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
            color: white;
            font-size: 25px;
        }
        .btn {
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .slider-prev,.slider-next {
            padding: 10px;
            font-size: 25px;
            cursor: pointer;
        }
    </style>
</head>
<body>

    <section class="product">
        <div class="container-fluid">
            <div class="slider-wrap">
                <div class="slider-main">
                    <div class="item">
                        <div class="text">1</div>
                    </div>
                    <div class="item">
                        <div class="text">2</div>
                    </div>
                    <div class="item">
                        <div class="text">3</div>
                    </div>
                    <div class="item">
                        <div class="text">4</div>
                    </div>
                    <div class="item">
                        <div class="text">5</div>
                    </div>
                    <div class="item">
                        <div class="text">6</div>
                    </div>
                </div>

            </div>
        </div>
    </section>
    <div class="btn">
        <button class="slider-prev" > Prev </button>
        <button class="slider-next" > Next </button>
    </div>
    
    <script>
        let sliderMain  = document.querySelector('.slider-main')
        let sliderPrev = document.querySelector('.slider-prev')
        let sliderNext = document.querySelector('.slider-next')
        let slidesLength = sliderMain.querySelectorAll('.item').length
        console.log(slidesLength)
        let activeSlideIndex = 0;
        sliderMain.style.left = `-${(slidesLength - 6) * 100}%`

        sliderPrev.addEventListener('click',() => changeSlide('prev'));
        sliderNext.addEventListener('click',() => changeSlide('next'));

        const changeSlide = dir => {
            // console.log(dir)
            if (dir == 'next') {
                activeSlideIndex--;
                if (activeSlideIndex < -slidesLength + 1) {
                    activeSlideIndex = 0;
                } 
            } else if (dir == "prev") {
                activeSlideIndex++;
                if (activeSlideIndex > 0) {
                    activeSlideIndex = -slidesLength + 1
                }
            }
            console.log(activeSlideIndex)
            sliderMain.style.left = `-${(slidesLength - 6 - activeSlideIndex) * 100}%`
        }

    </script>

My problem is that everythings alright in my javascript and html function but I don’t know what’s wrong with my css. I don’t know if this is the result of my white-space: no-wrap which is giving a little space so that it will make increase the div margins. So anyone can help me about this? I want it to be normal with no overlapping in each click I do.

Is it possible to prevent getDisplayMedia from changing focus?

When I use navigator.mediaDevices.getDisplayMedia() it will give the user a selection of windows and tabs to choose from media stream API selection choice
When the use makes a selection chrome will navigate to the tab/screen/window the user selected to share with the getDisplayMidia()

Is there a way for the user to select the screen to share without chrome navigating to it but rather staying on the same webpage?

Thank you!

Error using jquery trigger with multi section file input

I have a sample html

<form class="upload_section">
<input type="button" value="Choose file(s)" class="do_uploadFile">
<input type="file" name="uploadFile[]" class="uploadFile" multiple="multiple">
</form>

<form class="upload_section">
<input type="button" value="Choose file(s)" class="do_uploadFile">
<input type="file" name="uploadFile[]" class="uploadFile" multiple="multiple">
</form>

<form class="upload_section">
<input type="button" value="Choose file(s)" class="do_uploadFile">
<input type="file" name="uploadFile[]" class="uploadFile" multiple="multiple">
</form>

And script

$('.do_uploadFile').click(function () {
    $(this).closest(".upload_section").find(".uploadFile").click();
});
$('.uploadFile').on('change', function () {
    // ... code upload file
});

When I click Choose file(s), it’s work for first upload_section, not work for 2nd, 3rd,…how to fix it

Convert HH:mm to UTC date time in JavaScript using date-fns

I’m working on an appointment booking React app where a teacher can set their virtual office hours in the form of a time slot.

let availability = ["09:00", "17:00"]; // from 9 AM to 5 PM local time

Since this time is local to the teacher, I’d like to store it in UTC format so that if a student is in a different region, it will show this time in their appropriate timezone.

I tried using the parse function from [email protected] like this

parse('09:00', 'HH:mm', new Date()); // => Wed Jan 01 0020 00:00:00 GMT-0456 (Eastern Daylight Time)

But, this didn’t return the time in my timezone (Central Standard Time).

Is there a way to convert the local time slot to a UTC format?

How to hide menu while on pagehome page in vuejs?

I’m working on the code in vuejs… When I enter the interface, it takes me to the homepage page with the option to log in to admin or staff..
Now I want when I’m on pagehome and haven’t selected either admin and staff the menu will be hidden. In mounted() of homepage.vue I have called dataFunc function in navigation/vertical/index.js and I pass url to dataFunc function and check if homepage path exists then give it 1 into a null data array.
Now my problem is that the code is being processed asynchronously.. It hasn’t processed the dataFunc function to get the data array then export default data runs. Please show me this part. Thank you

I have a page Homepage :

enter image description here

Code : pagehome.vue

<template>
  <b-col md="8" offset-md="2">
    <div class="hompage-card" style="margin-top: 150px;">
      <b-row>
        <b-col md="5" sm="6">
          <b-card
            class="icon-card cursor-pointer text-center mb-2 mx-50"
          >
            <div class="icon-wrapper">
              <b-avatar
                class="mb-1"
                :variant="`light-warning`"
                size="45"
              >
                <feather-icon
                  size="24"
                  icon="BookmarkIcon"
                />
              </b-avatar>
            </div>
            <b-card-text class="icon-name text-truncate mb-0 mt-1">
              <strong>Admin</strong>
            </b-card-text>
          </b-card>
        </b-col>

        <b-col md="5" sm="6">
          <b-card
            v-b-tooltip.hover.top="'Staff'"
            class="icon-card cursor-pointer text-center mb-2 mx-50"
          >
            <div class="icon-wrapper">
              <b-avatar
                class="mb-1"
                :variant="`light-warning`"
                size="45"
              >
                <feather-icon
                  size="24"
                  icon="HomeIcon"
                />
              </b-avatar>
            </div>
            <b-card-text class="icon-name text-truncate mb-0 mt-1">
              <strong>Staff</strong>
            </b-card-text>
          </b-card>
        </b-col>
      </b-row>
    </div>
  </b-col>
</template>



<script>
import { dataFunc } from "../../navigation/vertical/index";
export default {
 mounted() {
    let route = this.$route.path;
    dataFunc(route);
  },
},
</script>

In file navigation/vertical/index.js

import dashboard from './dashboard'
import tables from './tables'
import billing from './billing'

var data = [...dashboard, ...tables, ...billing]
function dataFunc(value) {
    let searchString = value.includes('homepage');
    if (searchString) {
        data = [];
    }
}
export { dataFunc };
export default data;

I would expect it to be like this:

enter image description here

Why doesn’t yarn outdated list all outdated packages?

I’ve been using yarn outdated for a while now, it conveniently shows which packages are out of date. Then I either use yarn upgrade or yarn upgrade-interactive to upgrade all backward-compatible packages. It generally shows a bunch of packages so I never questioned it.

But then I realized some packages never show they’re outdated, but if I mouse over the listing in package.json in vscode, I see that some packages are way out of date. Below is an example, though not the only package by far. What is going on?

Here's an example, this is not the only package