here is my dependencies
“dependencies”: {
“axios”: “^0.25.0”,
“bootstrap”: “^5.1.3”,
“bootstrap-vue”: “^2.21.2”,
“core-js”: “^3.20.3”,
“vue”: “^2.6.11”,
“vue-router”: “^4.0.12”
},
“devDependencies”: {
“@vue/cli-plugin-babel”: “~4.5.0”,
“@vue/cli-plugin-eslint”: “~4.5.0”,
“@vue/cli-service”: “~4.5.0”,
“babel-eslint”: “^10.1.0”,
“eslint”: “^6.7.2”,
“eslint-plugin-vue”: “^6.2.2”,
“node-sass”: “^7.0.1”,
“sass-loader”: “^12.4.0”,
“vue-template-compiler”: “^2.6.11”
},
Category: javascript
Category Added in a WPeMatico Campaign
javascript – unable to get response from promise.all()
I find that I cannot get the response when using promise.all
.
The orders
below should be an array
Promise.all(promises).then(function (orders) {
console.log(orders); // nothing logged
});
Full code
let promises = markets.map(async (mkt) => {
return new Promise(async function (resolve, reject) {
return functionA(paramA)
.then(resA => {
return res.functionB()
.then((resB) => {
if (resB.length > 0) {
return functionC()
.then(resC => {
console.log(resC); // successfully logged
return resC;
});
}
});
})
.catch(err => console.log(err));
});
});
Promise.all(promises).then(function (orders) {
console.log(orders); // nothing logged
});
How can I fix?
Run This Script On Every Tab Except “Main” Tab
I have this script working well, but I’m uncertain how to make it run on every tab not labeled “Main”. Thanks in advance!
function hideRows() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var s = ss.getSheetByName("Dude"); // Enter sheet name
var row = s.getRange('A2:A').getValues(); // Enter column letter that has the text "hide" and "unhide"
var cell = s.getRange('A1').getValue();
s.showRows(1, s.getMaxRows());
for(var i=0; i < row.length; i++){ if(row[i] != cell) { s.hideRows(i+2, 1); } // Value to hide
}
}
Jerome
i want to click on next button Using Java script Function
Hello i want to click on next button Using Java script Function
https://www3.wipo.int/branddb/en/#
enter image description here
EXCEL custom functions can use ajax?
What do I want to achieve:
I want to call the interface in a custom function,Use the data returned by the interface to calculate.
actual result:
Custom functions cannot compute the correct result,always get 0.
This is my function.js code:
function add(first, second) {
ajax_web({
api: API_ENTITY.LOGIN,
data: {
domain: '01',
user: 'dev',
pass: 'shijinimda',
},
}).then(function (data) {
return first + second;
})
}
Did I do something wrong?If you need more documents, please ask me.
thanks a lot
How to export a JavaScript function that gets the results from an eventListenerClick?
I have a javascript file where I let the user set some values as an exported function looks something like this setValues(1,'test')
. In this set call I set an eventlistener on a button to call a function document.querySelector('#spinner').addEventListener('click', spin);
this calls the function spin(). I would like to get the results back from this and have the user be able to call getResults()
and the user would be able to view the results from spin().
I am aiming to export both setValues()
and getResults()
so the user can import the module and use the functions. How can I get it so getResults will properly show the user the values?
How to Map Dropdown Values with the below object to textarea when onChange method is triggering using react
Below is my object
const carModel = {
Volvo: '2015 model',
Toyota: '2016 model',
Benz: '2017 model',
Tesla: '2021 model'
}
i need to populate All the car model For Eg. Volvo, Toyota, Benz, tesla
into a Dropdown and Corresponding values into Textarea in React. Can someone help in resolving this?
Load a react component on button onClick
I have the following code for a button in my ReactApp to open a new window with specific size:
<button
type="button"
style={{ height: '20px', width: '50px' }}
className="btn btn-primary"
onClick={() => {
window.open(
"",
"Popup",
"width=975, height=92, top=30"
);
}}
/>
I want to load another component when user clicks on the button. How can I achieve that? I have tried to load the component and then use it like the following, but didn’t work:
import component from "./component"
<button
type="button"
style={{ height: '20px', width: '50px' }}
className="btn btn-primary"
onClick={() => {
window.open(
"{<component />}",
"Popup",
"width=975, height=92, top=30"
);
}}
/>
What would be the best way to do this?
Puppeteer dynamically add event listeners to page object
I’m writing some utility functions for puppeteer to speed up workflow. I want to assign callback functions to dynamically created event listeners. Here’s my code so far —
const puppeteer = require('puppeteer');
const listeners = {
'console': function(consoleObj) {
console.log(consoleObj.text());
},
'dialog': function(dialog) {
console.log(dialog.message());
}
};
(async () => {
const browser = await puppeteer.launch({headless: false});
const page = await browser.newPage();
for (var l in listeners) {
page.on(l, obj => {
listeners[l](obj)
});
}
var el = await page.evaluate(_ => {
console.log('page console operational!')
});
})();
For some reason the page.on() function won’t accept dynamically input listener types. Whereas if I input the listener type manually it works (obviously this is not useful because it will just continuously overwrite the ‘console’ listener) —
for (var l in listeners) {
page.on('console', obj => {
listeners[l](obj)
});
}
How can I go about dynamically creating event listeners with Puppeteer?
How are canvas games/advanced animations animated? Is clearRect the only way?
I know this is a very generic and possibly well-explained question but I have trouble understanding this topic.
As far as I know HTML <canvas>
requires to clear the canvas or parts of it during animation using clearRect. According to Mozilla there’s no other way
And this is where my mind is blown, because it sounds like a great approach for simple animations, with a lot of static stuff, but only for those. What if I have 10,000 objects on a canvas but I want to animate only one? Also clearRect
does not clear objects, but pixels so it’s incredibly easy to remove excessive content, especially if your object is not a rectangle!
Example no. 1 – clearRect removes too much:
Here’s a simple example. The blue ball is supposed to follow your pointer. The point is, in the very first frame I’m running a function called drawRandomRectangles
that renders 50 random rectangles. Have you noticed? Nope, because they instantly got removed from the canvas on rerender, because ctx.clearRect(0,0, canvas.width, canvas.height);
clears everything, excepting what’s being drawn in the next frame!
See here: https://jsfiddle.net/4kf6xdeL/
Example no. 2 – clearRect removes less (still bad):
I know what was the problem in the first example! The clearRect should affect only the ball, as the ball is only animated when you move the pointer. Replacing ctx.clearRect(0,0, canvas.width, canvas.height)
with ctx.clearRect(e.clientX, e.clientY, 25, 25)
should solve all my problems!
See here: https://jsfiddle.net/4kf6xdeL/2/
Nope, it does not help! It even creates more issues.
Here’s a gif from a fairly simple RTS based game I used to play:
Note how much is going on there! It renders +800 units at once and every single unit can have separate animation. How does it work? I’ve looked trough the code and I don’t see many clearRect
s, also I think it would be nearly impossible to do clearRect here, correct? How are complex animations or games done?
NOTE: I don’t want to use any libs, trying to at least grasp low-level canvas 🙂
Also the game from the gif uses unminified source code, but after examining it I still don’t really get how it renders it all… Note layers of multiple canvases aren’t the answer here as all the games I know, agar.io etc. use just only one canvas as different canvases can’t affect each other.
Thanks for any hints, explanations or just fixing my examples 🙂
Hide images in between rotation (Javascript)
I’ve created a timer that switches and loops between images.
I’m looking to create a pause in between the images in which nothing is shown.
So logo1 on for 15 seconds
hide images for 30 seconds
logo2 on for 15 seconds
and so on
This is what I’ve got so far.
Ideally, the hide would hide both DIVS
<head>
<style>
.box1 {
background-color: rgba(0,0,0,0);
color: #fff;
opacity: 1;
align-content: safe;
}
.brandlogo {
background-color: rgba(0,0,0,0);
position: absolute;
top: 500;
left: 1100;
}
.box2 {
background-color: rgba(0,0,0,0);
color: #545454;
position: absolute;
top: 400;
left: 1000;
}
</style>
</head>
<BODY>
<div class="wrapper">
<div class="box box1" id="art" ><img class="brandlogo" id="image" src="logo1.png" width="100"></div>
<div class="box box2" id="frameart"><img class="brandframe" id="frame" src="adframe2.png" width="300"></div>
</div>
<script type = "text/javascript">
var image = document.getElementById("image");
var currentPos = 0;
var images = ["logo1.png", "logo2.png", "logo3.png"]
function timercount() {
if (++currentPos >= images.length)
currentPos = 0;
image.src = images[currentPos];
}
setInterval(timercount, 3000);
$("#art").show();
setTimeout(function() { $("#art").hide(); }, 500);
</script>
</BODY>
</HTML>```
Regex for matching a sequence of incrementing numbers wihtin a given string of numbers
I have a javascript regex that matches an incrementing numerical value using look ahead however, I feel this can be simplified.
I currently am using /^(?=[1-5]{5}$)(?=(?=.*([1]))(?=.*([2]))(?=.*([3]))(?=.*([4]))|(?=.*([2]))(?=.*([3]))(?=.*([4]))(?=.*([5])))d+$/gm
to identify if at least 4 digits in a 5 digit string have values that increment by 1.
Rules:
- Can only contain numbers 1-5 and there must only be 5 characters in the string =
(?=[1-5]{5}$)
- 4 of the 5 numbers must increment by 1, they do not have to be grouped together.
- Here I have entered 4 literal groups for each potential incrementing 4 digit string
(?=.*([1]))(?=.*([2]))(?=.*([3]))(?=.*([4]))
and(?=.*([2]))(?=.*([3]))(?=.*([4]))(?=.*([5]))
. These are inside a look ahead with anor
separator.
Here is an example of strings that match the regex:
12343
– 4 numbers increment in order starting at the 1
32142
– 4 numbers increment, but not in order starting with the 1
23451
– 4 numbers increment in order starting at the 2
52345
– 4 numbers increment in order starting at the 2
34152
– 4 numbers increment out of order, here we have 2 matches that are not in order, only one match is required
12345
– 4 numbers increment in order, here we have 2 matches that are both in order, only one match is required
My regex seems to work with my tests, however I just feel there is a more dynamic and cleaner approach to this that I am just not privy to as my regex skills are below par to say the least.
Targeting specific Lottie animations on hover with lottie-web in React
How to target with hover a specific animation when I have multiple lottie animations on the same page in React using lottie-web
. lottie-web documentation states that in the lottie.play()
I can insert a name parameter to target a specific animation, so I did this lottie.play(container)
, but it didn’t work.
import React, { useEffect, useRef } from "react";
import lottie from "lottie-web";
function App() {
const containerOne = useRef(null);
const containerTwo = useRef(null);
useEffect(() => {
lottie.loadAnimation({
container: containerOne.current,
renderer: "svg",
loop: true,
autoplay: false,
animationData: require("./office.json")
});
lottie.loadAnimation({
container: containerTwo.current,
renderer: "svg",
loop: true,
autoplay: false,
animationData: require("./office.json")
});
return () => {
lottie.destroy();
};
}, []);
return (
<div className="App">
<h1>React Lottie Demo</h1>
{/* First lottie */}
<div
ref={containerOne}
onMouseEnter={() => lottie.play()}
onMouseLeave={() => lottie.pause()}
/>
{/* Second lottie */}
<div
ref={containerTwo}
onMouseEnter={() => lottie.play()}
onMouseLeave={() => lottie.pause()}
/>
</div>
);
}
export default App;
The result on my code is that no matter which animation I hover on both animations will play.
Here is a codesandbox link.
Website is not loading the script, CSS, or Three.js
Let me start out by saying that i have very little experience with html, javascript and overall website creation and hosting, so sorry in advance if the information i am providing is lacking.
I am trying to make a website by using a 3d object from three.js, however nothing is loading in the ‘live server’ (when i upload the entire website to cpanel), however when i use visual studio code to run it through my local server (through the command npm run dev) the website is showing as intended. I have screenshotted the pages:
When i open element inspect on the broken page, i get the following error through the console:
Failed to load module script: Expected a JavaScript module script but the server responded with a
MIME type of “text/css”. Strict MIME type checking is enforced for
module scripts per HTML spec.
and
Uncaught SyntaxError: Cannot use import statement outside a module
i have the following code in my script.js:
import './style.css'
import * as THREE from '../node_modules/three/build/three.module.js'
import { OrbitControls } from '../node_modules/three/examples/jsm/controls/OrbitControls.js'
import { GLTFLoader } from '../node_modules/three/examples/jsm/loaders/GLTFLoader.js'
import { HemisphereLight, Sphere, SRGB8_ALPHA8_ASTC_12x12_Format, sRGBEncoding, Texture, TextureEncoding } from '../node_modules/three/build/three.module.js'
import gsap from '../node_modules/gsap/all.js'
var gltfLoader = new GLTFLoader()
let tl = gsap.timeline()
var diamond = null
I am also using this to call the script in the index.html, however i am uncertain if this is the correct way of calling the script.
<script type=module src="script.js"></script>
How would i be able to fix this? any help would be appreciated!
Array index out of bounds – How to check if it is out of bounds [closed]
Basically I’m trying to get it to not do what’s in the loop if it’s out of bounds. However, it still goes through the loop anyways. I’m not really sure how I’d do this correctly. Game is an array, and basically there’s a loop outside of this one that goes through all rows and collumns
if(row >= 0 && row < game.length)
{
if(game[row - 1][col].equals("X"))
{
numNbrs += 1;
}
}