Whenever i click on my right left button images are going downward

I have made a project in which Firstly i import card component using bootstrap and put some images there. Give them a center tag. In script.js I give button to function like whenever i click on right button it switch to next and vice verse. But when ever i amclicking on any button images are going downward instead of staying up there in a fixed position. Problem is that whenever i click the images it goes downward and again downward.

https://codepen.io/mohit-04/pen/abWPwPq

When you click the button images go down and if again then even more down I want to keep up in centre between the button

INDEX

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
      integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
      crossorigin="anonymous"
    />
    <link rel="stylesheet" href="style.css" />
    <script src="script.js" defer></script>
  </head>
  <body>
    <center>
      <h1>Hello</h1>
      <br />
      <br />
      <div class="carousel" data-carousel>
        <button
          class="carousel-button next"
          data-carousel-button="next"
          data-carousel-button
        >
          &#8669;
        </button>
        <button
          class="carousel-button prev"
          data-carousel-button="prev"
          data-carousel-button
        >
          &#8668;
        </button>

        <ul data-slides>
          <li class="slide" data-active>
            <div class="card" style="width: 18rem">
              <img
                class="card-img-top"
                src="https://images.unsplash.com/photo-1644982647531-daff2c7383f3?crop=entropy&cs=tinysrgb&fm=jpg&ixlib=rb-1.2.1&q=60&raw_url=true&ixid=MnwxMjA3fDF8MHxlZGl0b3JpYWwtZmVlZHwxfHx8ZW58MHx8fHw%3D&auto=format&fit=crop&w=600"
                alt="Card image cap"
              />
              <div class="card-body">
                <h5 class="card-title">Card title</h5>
                <p class="card-text">
                  Some quick example text to build on the card title and make up
                  the bulk of the card's content.
                </p>
                <a href="#" class="btn btn-primary">Go somewhere</a>
              </div>
            </div>
          </li>
          <li class="slide">
            <div class="card" style="width: 18rem">
              <img
                class="card-img-top"
                src="https://images.unsplash.com/photo-1653491888857-6cb8c8f0264c?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwxOHx8fGVufDB8fHx8&auto=format&fit=crop&w=600&q=60"
                alt="Card image cap"
              />
              <div class="card-body">
                <h5 class="card-title">Card title</h5>
                <p class="card-text">
                  Some quick example text to build on the card title and make up
                  the bulk of the card's content.
                </p>
                <a href="#" class="btn btn-primary">Go somewhere</a>
              </div>
            </div>
          </li>
          <li class="slide">
            <div class="card" style="width: 18rem">
              <img
                class="card-img-top"
                src="https://images.unsplash.com/photo-1625215081436-85323ed5042c?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwyNHx8fGVufDB8fHx8&auto=format&fit=crop&w=600&q=60"
                alt="Card image cap"
              />
              <div class="card-body">
                <h5 class="card-title">Card title</h5>
                <p class="card-text">
                  Some quick example text to build on the card title and make up
                  the bulk of the card's content.
                </p>
                <a href="#" class="btn btn-primary">Go somewhere</a>
              </div>
            </div>
          </li>
          <li class="slide">
            <div class="card" style="width: 18rem">
              <img
                class="card-img-top"
                src="https://images.unsplash.com/photo-1653597859079-bc6d0e9101de?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHwzNHx8fGVufDB8fHx8&auto=format&fit=crop&w=600&q=60"
                alt="Card image cap"
              />
              <div class="card-body">
                <h5 class="card-title">Card title</h5>
                <p class="card-text">
                  Some quick example text to build on the card title and make up
                  the bulk of the card's content.
                </p>
                <a href="#" class="btn btn-primary">Go somewhere</a>
              </div>
            </div>
          </li>
          <li class="slide">
            <div class="card" style="width: 18rem">
              <img
                class="card-img-top"
                src="https://images.unsplash.com/photo-1653604212161-b50f445f7987?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxlZGl0b3JpYWwtZmVlZHw0M3x8fGVufDB8fHx8&auto=format&fit=crop&w=600&q=60"
                alt="Card image cap"
              />
              <div class="card-body">
                <h5 class="card-title">Card title</h5>
                <p class="card-text">
                  Some quick example text to build on the card title and make up
                  the bulk of the card's content.
                </p>
                <a href="#" class="btn btn-primary">Go somewhere</a>
              </div>
            </div>
          </li>
        </ul>
      </div>
    </center>
  </body>
</html>

STYLE

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  background-image: url("a.avif");

  background-repeat: no-repeat;
  background-size: cover;
}

.carousel {
  width: 100vw;
  height: 100vh;
  position: relative;
}

.slide {
  /* position: absolute; */
  inset: 0;
  opacity: 0;
}

.slide > img {
  display: block;
  height: 100%;
  width: 100%;
  object-fit: cover;
}

.carousel > ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

.slide[data-active] {
  opacity: 1;
}

.carousel-button {
  position: absolute;
  z-index: 2;
  background: none;
  border: none;
  font-size: 4rem;
  top: 50%;
  transform: translateY(-50%);
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  border-radius: 0.25rem;
  padding: 0 0.5rem;
  background-color: rgba(0, 0, 0, 0.1);
}

.carousel-button:hover,
.carousel-button:focus {
  color: purple;
  background-color: rgba(0, 0, 0, 0.2);
}

.carousel-button:focus {
  outline: 1px solid black;
}

.carousel-button.prev {
  left: 24rem;
}

.carousel-button.next {
  right: 24rem;
}

SCRIPT

// taking ids
const button = document.querySelectorAll("[data-carousel-button]");

// looping though next and prev button means
// ** LOGIC **

// storing all the images in array and then if we click the
// left arrow then it will go to -1 and if right then +1
//through this it will navigate through each images using index of images
button.forEach((button) => {
  // function which check which button is gonna be clicked
  button.addEventListener("click", () => {
    const offset = button.dataset.carouselButton === "next" ? 1 : -1;
    // to navigate closest parent element making a loop in ul tag to navigate each li
    const slides = button
      .closest("[data-carousel]")
      .querySelector("[data-slides]");

    // just checking which slide means li has data active tag
    const activeSlide = slides.querySelector("[data-active]");
    // extracting all the li in array
    // getting the active slide and + offset means what we have to do means either +1 or -1
    let newIndex = [...slides.children].indexOf(activeSlide) + offset;

    // if it comes to last element and again user click left then it automatically goes to last element
    if (newIndex < 0) newIndex = slides.children.length - 1;
    if (newIndex >= slides.children.length) newIndex = 0;

    // adding .active to that slide and removeing data-active to the previous one
    slides.children[newIndex].dataset.active = true;
    delete activeSlide.dataset.active;
  });
});

Is there a simpler way to restructure an array of objects?

I am trying to organize a fetch api request into a sidebar UL list but need to restructure the object backwards. Is there a way a less complicated way to approach this without having to use a bunch of foreach statements? I do have the option of a second api endpoint I can use to maybe help.

API ENTRYPOINT 1 (Topics)

"topics": [
    {
        "name": "TOPIC_NAME",
        "subcategories": [
            {
                "name": "SUBCATEGORY_NAME",
                "category": "CATEGORY_NAME"
            },
            {
                "name": "SUBCATEGORY_NAME",
                "category": "CATEGORY_NAME"
            }
        ]
    },
    {
        "name": "TOPIC_NAME",
        "subcategories": [
            {
                "name": "SUBCATEGORY_NAME",
                "category": "CATEGORY_NAME"
            },
            {
                "name": "SUBCATEGORY_NAME",
                "category": "CATEGORY_NAME"
            }
        ]
    }
]

API ENTRY POINT 2 (Cateogries)

"categories": [
    {
        "name": "CATEGORY_NAME"
        "subcategories": [
            {
                "name": "SUBCATEGORY_NAME"
                "category": "CATEGORY_NAME"
            }
        ]
    }
]

To become a sidebar UL List like this

CATEGORY_NAME
 - SUBCATEGORY_NAME
    - TOPIC_NAME
    - TOPIC_NAME
 - SUBCATEGORY_NAME
    - TOPIC_NAME
CATEGORY_NAME
 - SUBCATEGORY_NAME
    - TOPIC_NAME
    - TOPIC_NAME
 - SUBCATEGORY_NAME
    - TOPIC_NAME

Since I am using Vue I am looking for something similar to this

<ul
    v-for="(category, i) in categories"
    :key="i"
>
    <ul
        v-for="(subcategories, j) in subcategories"
    >
        <li
            v-for="(topic, k) in topics"
        >
            <a v-if="subcategories[j].includes(topic.subcategories[n?].name) ">{{ topic.name }}</a>
        </li>
    </ul>
</ul>

How to auto suggest texts retrieved from Mysql Database in PHP

I have use following method to get autosuggest texts from mysql tables.

<div id="add_data_Modal" class="modal fade">
 <div class="modal-dialog">
  <div class="modal-content">
   <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
    <h4 class="modal-title">Issue a new Book</h4>
   </div>
   <div class="modal-body">
    <form method="post" id="insert_form">
    <label>Enter Book Name</label>
     <input type="text" name="book_name" id="book_name" class="form-control" />
     <br />
     <input type="submit" name="insert" id="insert" value="Insert" class="btn btn-success" />

    </form>
   </div>
   <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
   </div>
  </div>
 </div>
</div>

<div id="dataModal" class="modal fade">
 <div class="modal-dialog">
  <div class="modal-content">
   <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">&times;</button>
    <h4 class="modal-title">Employee Details</h4>
   </div>
   <div class="modal-body" id="employee_detail">

   </div>
   <div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
   </div>
  </div>
 </div>
</div>

<script type="text/javascript">
  $(function() {
     $( "#book_name" ).autocomplete({
       source: 'bookname-search.php',
     });
  });
</script>

But the issue is suggested texts are not showing on top of popup container but behind on it. Can someone help me to solve this issue?

Unable to change notification title in Firebase Cloud Messaging

I am now able to implement push notifications with Firebase Cloud Messaging, and the push notifications themselves are delivered, but I am having trouble changing their content.

The default title is “This site has been updated in the background”, but I changed it to any text.

  • Environment

    • Vue CLI
    • TypeScript
  • main.ts

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './registerServiceWorker'
import firebase from 'firebase/compat/app';
import { getMessaging, getToken } from "firebase/messaging";

const firebaseConfig = {
  apiKey: "xxx",
  authDomain: "xxx",
  projectId: "xxx",
  storageBucket: "xxx",
  messagingSenderId: "xxx",
  appId: "xxx",
  measurementId: "xxx"
};

const firebaseApp = firebase.initializeApp(firebaseConfig);
const app = createApp(App)
installElementPlus(app)

app
  .use(store)
  .use(router)
  .component('MqResponsive', Vue3Mq.MqResponsive)
  .mount('#app')

const messaging = getMessaging(firebaseApp);
const vapidKey = {
  vapidKey:
    "xxx",
};
// Messaging
getToken(messaging, { vapidKey: 'xxx' }).then((currentToken) => {
  if (currentToken) {
    // Send the token to your server and update the UI if necessary
    console.log("currentToken : ", currentToken);
    // ...
  } else {
    // Show permission request UI
    console.log('No registration token available. Request permission to generate one.');
    // ...
  }
}).catch((err) => {
  console.log('An error occurred while retrieving token. ', err);
  // ...
});
  • firebase-messaging-sw.js
import firebase from 'firebase/compat/app';
import { onBackgroundMessage } from "firebase/messaging/sw";
import { getMessaging, getToken, onMessage } from "firebase/messaging";

const firebaseConfig = {
  apiKey: "xxx",
  authDomain: "xxx",
  projectId: "xxx",
  storageBucket: "xxx",
  messagingSenderId: "xxx",
  appId: "xxx",
  measurementId: "xxx"
};

const firebaseApp = firebase.initializeApp(firebaseConfig);

const messaging = getMessaging(firebaseApp);
const vapidKey = {
  vapidKey:
    "xxx",
};

// Messaging
getToken(messaging, { vapidKey: 'xxx' }).then((currentToken) => {
  if (currentToken) {
    // Send the token to your server and update the UI if necessary
    console.log("currentToken : ", currentToken);
    // ...
  } else {
    // Show permission request UI
    console.log('No registration token available. Request permission to generate one.');
    // ...
  }
}).catch((err) => {
  console.log('An error occurred while retrieving token. ', err);
  // ...
});

onMessage(messaging, (payload) => {
  console.log('Message received. ', payload);
  // ...
});

onBackgroundMessage(messaging, (payload) => {
  console.log('[firebase-messaging-sw.js] Received background message ', payload);

  self.addEventListener('push', async function (event) {
    event.waitUntil(
      self.registration.showNotification('title', {
        body: 'body'
      })
    );
  });
});

The image is localhost, but deploying to the web did not change the result.
I also tested on Firebase Messaging and downloaded as a PWA and again the results did not change.

What is the problem??

enter image description here

Thank you in advance!

Replacing text in an input box of a webpage (with defined ID)

I am trying to fill up all the input fields of a webpage (having input IDs ending with txtValue) which are filled with the word ‘dog’ to be replaced with the word ‘cat’.
I have tried this code, but it isn’t working. Kindly help me to solve this. Thank you in advance.

const ta = document.querySelectorAll("[id$='txtValue']");

const str = ta.value.replace("dog","cat");
ta.value = str
console.log(ta.value,"change to" ,str)

extendscript after effects listbox if statement not working well

i have listbox item_1 and item_2 and more but for the sake of it this is enough.

this is my code
when listbox item_1 is selected and item string is item_1 then fire the code for that only.

listBox.onDoubleClick = function () {

//alert (listBox.selection);

 if (listBox.selection = "item_1") {

    listBox_pressed()
    }
else

    }

issue am having is executing code even when i click other list items.

full code

// ScriptUI Listboxes
    var counter = 0;

    var window = new Window("palette", "Listbox", undefined);
    window.orientation = "column";
    
    var listBox = window.add("listbox", undefined, []);
    listBox.selection = 0;
    listBox.size = [200, 100];

    var buttonGroup = window.add("group", undefined, "buttonGroup");
    buttonGroup.orientation = "row";
    var addButton = buttonGroup.add("button", undefined, "+");
    addButton.size = [30, 30];
    var minusButton = buttonGroup.add("button", undefined, "-");
    minusButton.size = [30, 30];
    
    addButton.onClick = function () {
            counter++;
            listBox.add("item", "Item_"+counter.toString());
       
        }
     

    minusButton.onClick = function() {
            if(listBox.selection != null) {
            counter--;
            listBox.remove(listBox.selection);
                }
        }

/////////////////////////////////////======================================================================================================
listBox.onDoubleClick = function () {



//alert (listBox.selection);

 if (listBox.selection = "item_1") {

    listBox_pressed()
    }
else

    }
    
    

/////////////////////////////////////======================================================================================================



function listBox_pressed(){ // main function
        myComp = app.project.activeItem;
mySolid = myComp.layers.addSolid([0,0,0], "Solid", myComp.width, myComp.height,1);
        }
    
    window.center();
    window.show();

sir when the script starts when i click button it adds items to list like this
item_1
item_2
item_3 and so on
now based on each item string i want to fire my custom code and not by item index.

so if item_1 is double clicked then fire my custom code use
listBox_pressed()

can you just show me one seperate code for listbox item_1 when double clicked my custom code should fire using if statement.

if listbox

so this code ##

if (listBox.selection = "item_1") {

    listBox_pressed()
    }
else

    } 

executes on any item rather than just item_1 only

How to create incremental counter across multiple browser windows?

I’ve tried to use localStorage to sync a counter across multiple windows and I’ve found that since localStorage doesn’t have a lock it is possible to have racing issue.

const root = document.getElementById('root');
let thisCounter = 0;
const interval = setInterval(() => {
  const counter = parseInt(localStorage.getItem('counter') || 0, 10);
  localStorage.setItem('counter', `${counter + 1}`);
  ++thisCounter;
  root.innerHTML = `global: ${counter + 1}, this: ${thisCounter}`;
  if (thisCounter >= 500) {
    clearInterval(interval);
  }
}, 100);

And when I open three Chrome browser windows (having separated threads) it appears that the counter would eventually run to 1498 or 1497 instead of 1500.

enter image description here

React Numeric Input Sum Calculator

the following code is a dynamic sum calculator made in ReactDOM
extracted from codepen https://codepen.io/tfbrown/pen/zjXvZy

class NumericInput extends React.Component {
  constructor(props) {
    super(props);
    this.state = { 
      num1: 0,
      num2: 0,
      result: 0
    };
    this._changeNum1 = this._changeNum1.bind(this);
    this._changeNum2 = this._changeNum2.bind(this);
  }
  
  _changeNum1(e) {
    if (e.target.validity.valid) {
      var newNum1 = +(e.target.value)
      this.setState({
          num1: newNum1,
          result: newNum1 + this.state.num2
        }); 
    }
  }
  
    _changeNum2(e) {
    if (e.target.validity.valid) {
      var newNum2 = +(e.target.value)
      this.setState({
          num2: newNum2,
          result: this.state.num1 + newNum2
        }); 
    }
  }

  render() {
    return (
      <div>
        <div>
          <p>first number:</p>
          <input type="number" value={this.state.num1} onChange={this._changeNum1} step="any" />
        </div>
        <div>
          <p>second number:</p>
          <input type="number" value={this.state.num2} onChange={this._changeNum2} step="any" />
        </div>
        <p>Result: {this.state.result}</p>
      </div>
    )
  }  
}  

// The following is boilderplate JavaScript
ReactDOM.render(<NumericInput />, document.getElementById("main"));

the problem is that I want to use this code but my project is made in Next.js and I would like to make this code functional in the .js file without the need for an html DOM making it functional in this index.js file.

import { useWeb3React } from "@web3-react/core"
import { useEffect } from "react"
import { injected } from "../components/wallet/Connectors"
import Web3 from 'web3'
import { Icon } from '@iconify/react';
import React, { useState } from "react";

export default function Home() {
 
    return (

  
    )

}

How to make the browser play a local mp3 when a span displays on the page?

When we accidentally scan a duplicate, Red text appears in the browser:

<span id="lblMessage" style="color:Red;font-weight:bold;">
    Duplicate serial number found.
</span> 

Can you please show javascript that we can add to a plugin like tampermonkey or chrome extension like “Edit – User JavaScript and CSS” that would play a local audio alert with error.mp3.

I have error.mp3 on local drive.

Thank you!

I have two different div coded using vue.js3 composition and v-if is not working correctly?

I’m trying to show or hide section of the app using Vue.js 3 composition using v-if. I was able to get this working using vue.js 2 API option, but recently started using vue.js 3 API Composition.

It looks like screenMode is being updated when displaying value using console.log, but the section is not hiding. Any idea?

<script setup>
  
  import { ref, onMounted } from 'vue'

  let screenMode = 'screenA'; 

  console.log('screenMode = ' + screenMode)

  function test(recordDate) {
    screenMode = 'screenB'
    console.log("screenMode =" + screenMode)
  }


  onMounted(() => {
    screenMode.value
  })

</script>



<template>
    <p class="screenTitle" >Calendar</p>

    <div class="container" v-if="screenMode === 'screenA'">    
      <table class="table table-striped">
        <thead>
          <tr>
            <th scope="col"></th>
            <th scope="col">Date</th>
            <th scope="col">Total</th>
          </tr>
        </thead>
        <tbody>
          <tr id="row1" @click="test('5/26/2022')">
            <th scope="row"></th>
            <td>5/26/2022</td>
            <td>52</td>
          </tr>
          <tr>
            <th scope="row"></th>
            <td>5/27/2022</td>
            <td>4</td>
          </tr>
          <tr>
            <th scope="row"></th>
            <td>5/28/2022</td>
            <td>90</td>
          </tr>        
        </tbody>
      </table>
  </div>

  <div class="container" v-if="screenMode === 'screenB'">    
    <table class="table table-striped">
      <thead>
        <tr>
          <th scope="col">#</th>
          <th scope="col">First</th>
          <th scope="col">Last</th>
          <th scope="col">Handle</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <th scope="row">1</th>
          <td>Mark</td>
          <td>Otto</td>
          <td>@mdo</td>
        </tr>
        <tr>
          <th scope="row">2</th>
          <td>Jacob</td>
          <td>Thornton</td>
          <td>@fat</td>
        </tr>
        <tr>
          <th scope="row">3</th>
          <td colspan="2">Larry the Bird</td>
          <td>@twitter</td>
        </tr>
      </tbody>
    </table>
  </div>


</template>

<style>

.screenTitle{
  color: blueviolet;
  margin-left: 10px;
  margin-top: 25px;
}

</style>

<!-- <style>
@media (min-width: 1024px) {
  .about {
    min-height: 100vh;
    display: flex;
    align-items: center;
  }
}
</style> -->



I am getting “Uncaught SyntaxError: Cannot use import statement outside a module” although i have script type=”module” in my html file [duplicate]

I am getting “Uncaught SyntaxError: Cannot use import statement outside a module” error when i am trying to import another javascript files from my javascript & html file. I added script type=”module” in html but didnt make any other changes as these are only vanilla js files. What is wrong with my import?

Thanks in advance

My html file

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8"/>
        <link rel="stylesheet" href="./css/cizim.css" />
        <title>Line</title>
        
    </head>
    <body>
<table align="center" width="1200" border="0">
  <tbody>
    <tr>
      <td width="500"><div align="center"><canvas width ="400" height="400" id="canvas" style="border:1px solid #d3d3d3;">Your browser does not support the HTML5 canvas tag.
          
        </canvas>
    <script type="module" src="canvas.js"></script>  
          </td>
      <td><table>
          <tbody>
              <tr>
                <td><label for="fname">Başlangıç Mesneti:</label></td>
                <td>
                    <input type="radio" id="msm" name="first" value="msm" checked="checked">
                    <label for="css">Mafsallı Sabit Mesnet</label>
                    <input type="radio" id="mhm" name="first" value="mhm">
                    <label for="javascript">Mafsallı Hareketli Mesnet</label>
                    <input type="radio" id="ank" name="first" value="ank">
                    <label for="html">Ankastre Mesnet</label>
                </td>
              </tr>
                <tr>
                <td><label for="fname">Bitiş Mesneti:</label></td>
                <td>
                    <input type="radio" id="msm" name="second" value="msm" checked="checked">
                    <label for="css">Mafsallı Sabit Mesnet</label>
                    <input type="radio" id="mhm" name="second" value="mhm">
                    <label for="javascript">Mafsallı Hareketli Mesnet</label>
                    <input type="radio" id="ank" name="second" value="ank">
                    <label for="html">Ankastre Mesnet</label>
                </td>
                </td>
              </tr>
              <tr>
                <td><label for="fname">Başlangıç:</label></td>
                <td><input type="text" id="start" name="fname"></td>
              </tr>
              <tr>
                <td><label for="fname">Bitiş:</label></td>
                <td><input type="text" id="end" name="sname"></td>
              </tr>
                <tr>
                <td><label for="fname">Başlangıç Yükü:</label></td>
                <td><input type="text" id="byuk" name="sname"></td>
              </tr>
                  </tr>
                <tr>
                <td><label for="fname">Bitiş Yükü:</label></td>
                <td><input type="text" id="syuk" name="sname"></td>
              </tr>
              <tr>
                <td>&nbsp;</td>
                <td><button id="myBtn" onclick="updateCanvas()">Hesapla</button></td>
              </tr>
          
          
          
          </tbody>
          </table>
    </td>
    </tr>
  </tbody>
</table>


        <div align="center">

            
<script src="canvas.js"></script>
        </div>
        
        
    </body>
</html>

My main .js file (canvas.js)

import Draw from "./draw.js";
import Values from "./values.js";

Other 2 js files i want to import through canvas.js

export default class Values {
  constructor() {
    this.first = document.querySelector('input[name="first"]:checked').value;
    this.second = document.querySelector('input[name="second"]:checked').value;
    this.canvas = document.getElementById("canvas");
    this.start = parseInt(document.getElementById("start").value);
    this.end = parseInt(document.getElementById("end").value);
    this.byuk = parseInt(document.getElementById("byuk").value);
    this.syuk = parseInt(document.getElementById("syuk").value);
    this.canvasWidth = canvas.width;
    this.canvasHeight = canvas.height;
    this.ctx = canvas.getContext("2d"); 
    this.canvasData = ctx.getImageData(0, 0, canvasWidth, canvasHeight);
  }
}
export default class Draw {
  constructor(startx, starty,endX, endY,canvasData,ctx) {
    this.startx = startx;
    this.starty = starty;
    this.endX = endX;
    this.endY = endY;
    this.canvasData = canvasData;
    this.ctx = ctx;
  }
  drawMyLine(startx, starty,endX, endY){
    ctx.beginPath();
    ctx.lineWidth = 1;
    ctx.strokeStyle = 'red';
    ctx.moveTo(startx, starty);
    ctx.lineTo(endX,endY);
    ctx.stroke();
  }
  drawPixel (x, y, r, g, b, a) {
    var index = (x + y * canvasWidth) * 4;
    //pixelDensity(1);
    canvasData.data[index + 0] = r;
    canvasData.data[index + 1] = g;
    canvasData.data[index + 2] = b;
    canvasData.data[index + 3] = a;
  }
}

innostudio fileuploader doesen’t shows thumbnails in bs-stepper

I built innostudio fileuploader into bs-stepper in a sub step.
Uploads and previews work correctly. The problem is showing the thumbnails when files are already called using “Preload Files”.
The preload files are correctly linked, but only a “no-image-icon” is shown.
I suspect that a lazy-loader is not running and I don’t know how to start it when calling the corresponding step.
I can execute a Javascript function by clicking on this step… but what should this function contain so that the lazyload is executed afterwards?

I’ve tried the following on click-statement on the last step-button before showing fileuploader:

function preloadImages(){
    $('input[name="filesUploadV2"]').fileuploader();
}

Image gallery innostudio fileuploader

React – Protocol “https:” not supported. Expected “http:”

Yeah, I saw this post, however I do not have such file where I can edit to use https and my backend is ASP.NET MVC Core 3.1.

So when my React application sends API calls to ASP.NET MVC application, then it throws an error:

TypeError [ERR_INVALID_PROTOCOL]: Protocol "https:" not supported. Expected "http:"
    at new NodeError (node:internal/errors:371:5)
    at new ClientRequest (node:_http_client:158:11)
    at Object.request (node:https:353:10)
    at Array.stream (C:My Files\Scriptsreactnode_moduleshttp-proxylibhttp-proxypassesweb-incoming.js:126:74)
    at ProxyServer.<anonymous> (C:My Files\Scriptsreactnode_moduleshttp-proxylibhttp-proxyindex.js:81:21)
    at middleware (C:My Files\Scriptsreactnode_moduleshttp-proxy-middlewarelibindex.js:46:13)
    at handle (C:My Files\Scriptsreactnode_moduleswebpack-dev-serverlibServer.js:322:18)
    at C:My Files\Scriptsreactnode_moduleswebpack-dev-serverlibServer.js:330:47
    at Layer.handle_error (C:My Files\Scriptsreactnode_modulesexpresslibrouterlayer.js:71:5)
    at trim_prefix (C:My Files\Scriptsreactnode_modulesexpresslibrouterindex.js:315:13)

the url looks like this:

http://localhost:3030/api/foo/bar

Our development config file dev.js looks like this:

// development config
const package = require('../../package.json')
const { merge } = require('webpack-merge')
const webpack = require('webpack')
const commonConfig = require('./common')
const agent = require('agentkeepalive')

module.exports = (webpackConfigEnv, argv) => {
    return merge(commonConfig(argv), {
        mode: 'development',
        entry: [
            'react-hot-loader/patch', // activate HMR for React
            'webpack-dev-server/client?http://localhost:3030', // 
            'webpack/hot/only-dev-server', // bundle the client for hot reloading
            './index.tsx', // the entry point of our app
        ],
        devServer: {
            port: 3030,
            hot: true, // enable HMR on the server
            historyApiFallback: true, //
            proxy: {
                '/api/*': {
                    target: argv.env.mock ? '' : 'https://localhost:43000',
                    secure: false,
                    changeOrigin: true,
                    agent: new agent({
                        maxSockets: 100,
                        keepAlive: true,
                        maxFreeSockets: 10,
                        keepAliveMsecs: 100000,
                        timeout: 6000000,
                        freeSocketTimeout: 90000, // free socket keepalive for 90 seconds
                    }),
                    onProxyRes: (proxyRes) => {
                        var key = 'www-authenticate'
                        proxyRes.headers[key] =
                            proxyRes.headers[key] && proxyRes.headers[key].split(',')
                    },
                },
            },
        },
        devtool: 'cheap-module-source-map',
        plugins: [
            new webpack.HotModuleReplacementPlugin(), // enable HMR globally
            new webpack.DefinePlugin({
                'process.env.appVersion': JSON.stringify(package.version),
                'process.env.isMockMode': JSON.stringify(argv?.env?.mock),
                'process.env.isDevelopment': true,
            }),
        ],
    })
}

How can I solve this issue? I cannot use http://localhost:43000 because my backend uses SSL.
Ahy help would be greatly appreciated!

js equivalent of str.replace(.., replacerFunction()) in rust

I am currently try to learn rust by transpiling some scripts from js to wasm.

In js there is this function:

string.prototype.replace(substr, replacerFunction())

I am searching a rust function for this case. I know there is also a string.replace func, but I think I cant pass there a custom replacerFunction to it.

I have this snippet in js:

const sentence = 'This is a sentence';
modifiedSentence = sentence.replace(/p{L}+/gu, (word) => {

      // imaging some heavily transformation on `word` here, based on its type like (verb, object or subject).

      return word;
});

Maybe a regex only solution would somehow be possible, but not for me 🙂

Thanks for any hints !

How to simulate receiving message from Server to Client in order to unit test SignalR client/manager with react-testing-library and jest?

I have a working SignalR manager with a connection: HubConnection that is already built with .build().
Check the following quick example:

const connection: HubConnection = new HubConnectionBuilder().withUrl(...).build();
connection.start().then(() => {
  console.log('connected');
  ...
  connection.on('PushNewMessage', (message) => addNewMessageToReduxStore(message));
  connection.on('DeleteMessage', (messageId) => deleteMessageFromStoreWithId(messageId));
  ...
});

Server sends message ‘PushNewMessage’ with an object with string text and number id. This triggers the addNewMessageToReduxStore(message) which is tracked for changes and trigger more Redux changes.

I want to write a unit test that starts with “Server sending a message” and compares the final Redux store state after 5 seconds since the message was received from the server to match an expected store state – then the test will pass.

So how to simulate receiving a message from the server in that exact web socket managed by the HubConnection used in the unit test initialization?