Category: javascript
Category Added in a WPeMatico Campaign
Is there any way to do a callback with staggered animatons in Anime.js?
I want to do something whenever animation of each separate element begins. However, the begin callback only triggers on the animation of first element and not each element in the list. Here is an example:
anime({
targets: 'ul li',
background: '#000',
delay: anime.stagger(500),
begin: function(anim) {
console.log('changed');
},
});
The above code only logs changed once but there are 8 different list elements whose background changes to black with a delay of 500ms.
What is the proper way of tiggering a callback for each such element?
Thanks.
How to add custom Javascript on export button in Amcharts
I am working on amcharts. while exporting chart image the chart is taking too much time like 3 to 4 seconds , I need to show the loader during waiting time , Is there any functionality related to amcharts version 4.
Demo Code for chart (The below chart is not taking too much time because it is just a demo code)
/**
* ---------------------------------------
* This demo was created using amCharts 4.
*
* For more information visit:
* https://www.amcharts.com/
*
* Documentation is available at:
* https://www.amcharts.com/docs/v4/
* ---------------------------------------
*/
// Create chart instance
var chart = am4core.create("chartdiv", am4charts.XYChart);
// Add data
chart.data = [{
"category": "Research & Development",
"value": 3.5
}, {
"category": "Marketing",
"value": 6
}, {
"category": "Distribution",
"value": 4.2
}];
// Create axes
let categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.dataFields.category = "category";
let valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
// Create series
var series = chart.series.push(new am4charts.ColumnSeries());
series.dataFields.valueY = "value";
series.dataFields.categoryX = "category";
series.name = "Sales";
// Enable export
chart.exporting.menu = new am4core.ExportMenu();
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
}
#chartdiv {
width: 100%;
height: 300px;
}
<script src="//www.amcharts.com/lib/4/core.js"></script>
<script src="//www.amcharts.com/lib/4/charts.js"></script>
<div id="chartdiv"></div>
In the following example I need to show the loader when user export the chart in to image or excel e.t.c …
I’ve tried to add javascript by using class name but unable to detect click event on export button.
How to get the URL Link “” from Div Section Tag “” with help of selecting multiple elements in JSOUP Android Method
I am using Jsoup in android studio to extract the URL of a webpage. The href attribute of those URL’s are relative like:
Java Code in Android Studio:
Elements downloadElementDataLINK = doc.getElementsByClass(“list-inline gmr-download-list clearfix“).select(“li“).select(“a[href]“);
Is it possible in Jsoup to get fetched the URL Link “” from Div Section “” with selecting multiple elements in Jsoup method.
If yes, then how can we implement it in the android studio project?
Below’s mentioned image and its code.
Website UI Part: I want to fetch or get a URL Link from this Download Element.
Pic from this URL: https://111.90.159.132/comedy/phir-hera-pheri/
HTML Code Part: Here is the actual code, I want to fetch URL Link “” from Div Section with using ID/CLASS of DIV Tag”“.
Pic from this CODE: https://111.90.159.132/comedy/phir-hera-pheri/
——————————————-
How can we implement it in the android studio project? we’ve tried with JSOUP Android Library. here is the sample code.
// Android Studio Code with Using JSOUP Library
public void DownloadEmbedMOV(Source source){
try {
Toast.makeText(this, "Please Wait, Link is Fetching..", Toast.LENGTH_LONG).show();
Intent intent = new Intent(MovieActivity.this, DownloadEmbedActivity.class);
doc = Jsoup.connect(source.getUrl()).get();
Elements downloadElementDataLINK = doc.getElementsByClass("list-inline gmr-download-list clearfix").select("li").select("a[href]");
String ddLinkFile = downloadElementDataLINK.get(0).absUrl("href");
Toast.makeText(this, "LINK Fetched: " + downloadElementDataLINK.attr("abs:href"), Toast.LENGTH_LONG).show();
intent.putExtra("url", source.getUrl());
intent.putExtra("url",downloadElementDataLINK.first().absUrl("href"));
intent.putExtra("name", poster.getTitle());
startActivity(intent);
}
catch (IOException e) {
e.printStackTrace();
}
}
This code isn’t working in the right way, whenever we use
Elements downloadElementDataLINK = doc.getElementsByClass(“list-inline gmr-download-list clearfix“).select(“li“).select(“a[href]“);
to get the absolute URL like http://example.com/text, it is not working. How can I get the absolute URL with using JSOUP Android Library; use it with multiple select elements in HTML CODE PART?
Please, Please, Help me to get rid of this coding trouble. Is there any better coding way to solve this problem?
Sort date a list of tags that contain a date along with other non-date text?
This is the HTML containing a list of <a> tags containing the date within the .caption2 class. By default the list of these episodes are NOT sorted by date. How can I sort them by date with oldest being on top of the list and latest at the end of the list?
<div class="pure-u-1 pure-u-sm-3-5">
<h2 class="separatorbar">All Episodes</h2>
<a class="episodecell" href="/+R7DU820ug">
<img
class="art"
src="https://example.com/1174581"
/>
<div class="cellcontent">
<div class="titlestack">
<div class="title singleline">
489: Very Inappropriate Thoughts About This Computer
</div>
<div class="caption2 singleline">Jun 30 • 114 min</div>
</div>
</div>
</a>
<a class="episodecell" href="/+QCwmMHIhs">
<img
class="art"
src="https://example.com/1051401"
/>
<div class="cellcontent">
<div class="titlestack">
<div class="title singleline">
Priest and Joe Illidge on crafting new villain Entropy without any
rules
</div>
<div class="caption2 singleline">Jun 26 • 87 min left</div>
</div>
</div>
</a>
<a class="episodecell" href="/+QwxKgVw_o">
<img
class="art"
src="https://example.com/1098514"
/>
<div class="cellcontent">
<div class="titlestack">
<div class="title singleline">Ep. 647: Best Sci Fi Beach Reading</div>
<div class="caption2 singleline">Jun 27 • 27 min</div>
</div>
</div>
</a>
<a class="episodecell" href="/+HdT7S_15E">
<img
class="art"
src="https://example.com/488766"
/>
<div class="cellcontent">
<div class="titlestack">
<div class="title singleline">Filosofía de coyote</div>
<div class="caption2 singleline">Jun 29 • 25 min</div>
</div>
</div>
</a>
</div>
I have a two options with radio button and two forms in that options one radio Button form to submit using formik
I have two Options with radio Buttons when i click on first radio Button i need to submit the form Using button… Note: One buton Only for two forms what to do how to solve using formik
How to fix Unexpected end of file (kaboom.js)
I’m getting an error saying unexpected end of file.
Any idea on how to fix this?
Chrome extension content loads only for a split second
I’m developing a chrome extension that involves adding a column to a table, however aside from the header the changes only load for a second before they get overridden. My changes also activate after a button within the website is pressed to load the table, but the changes always only ever take place the 2nd time the button is pressed, but never the first.
manifest.json
"name": "Better Registration",
"description": "Registration Page",
"version": "1.0",
"manifest_version": 3,
"content_scripts": [
{
"matches": ["*://*.registrationssb.ucr.edu/*"],
"js": ["content.js"],
"run_at": "document_end"
}
]
}
content.js
var run = document.getElementById("search-go");
if(run){
run.addEventListener("click", load);
}
function load(){
console.log("LOAD PAGE");
var table = document.getElementById("table1");
if(table != null){
var row = table.rows[0];
var cell = row.insertCell(9);
cell.innerHTML = "PLACEMENT HEADER";
for(let i = 1; i < table.rows.length; i++){
var cell = table.rows[i].insertCell(9);
cell.innerHTML = "PLACEMENT TEXT";
}
}
}
how to use window.onload=function with multiple jQuery click events
I have two different buttons in the navigation menu, they are anchor links to a tab switcher on the home page, which has two tabs. I need the navigation buttons to change the active tab, when clicked. It should be a simple code, but I am a newbie in JS.
I need this to call the functions after the page loads, this way, it will work from other pages too, not just from the home page.
The first function works in itself as it should. The function also works when the button is clicked on a different page. It calls the homepage, then changes the active tab after page load:
add_action( 'wp_footer', function () { ?>
<script>
jQuery('#menu-item-15507 a').on('click', window.onload=function myfunction_1() {
jQuery( '#one-to-one a' ).click();
return true;
});
</script>
<?php } );
But when I add the second event and function, the tabs are not changing on pageload. It works on the same page (home page), but not when fired from a different page:
add_action( 'wp_footer', function () { ?>
<script>
jQuery('#menu-item-15507 a').on('click', window.onload=function myfunction_1() {
jQuery( '#one-to-one a' ).click();
return true;
});
jQuery('#menu-item-16848 a').on('click', window.onload=function myfunction_2() {
jQuery( '#courses a' ).click();
return true;
});
</script>
<?php } );
How am I supposed to change the code to get both functions to work on page load as well?
Can Optional Chaining be alternative of ‘in’ operator in Javascript
I often saw in operator in some library of Javascript.
but I think in operator has risk of causing human errors.
because we have to write property name as string type.
I think optional chaining could be alternative of in operator and It looks more safe.
we can get help of intelligence of IDE during writing code.
what is the benefit of using in keywords instead of Optional Chaining?
Require a class/variable for other files
I have this constructer class that creates a new Client, I would like to require this into other files so I am able to utilize the properties and methods. The issue is that the constructer is static so I cannot call exports or module.exports to export to the class.
const fc = new fnbr.Client({
auth: { deviceAuth: JSON.parse(fs.readFileSync('./deviceAuth.json', 'utf8')),}
})
If I attempt to use module.exports, I receive a circular dependency error.
Any ideas?
Webpack: How to configure webpack to keep last 3 build files
My webpack is configured to generate new js files every time when content changes [name][contenthash].js. But it creating problems in runtime when using lazy loading of chunks.
After new build old files are deleted and new ones are created with new hashes. If user in this time tries to open new page, app.[hash].js file fails to load product.[contenthash].js file, because its name has already changed after build. User have to reload the page to load it and they can loose some filled data.
Is there any way to configure webpack clean to keep last versions of build files?
loading videos using fetchAPI
i’m trying to download complete videos, making blob links for them before actually playing them or adding them to DOM, here the bit of my code that does that
const init = {method: 'GET',mode: 'no-cors',cache: 'default'};
const request = new Request(mp4Url);
fetch(request, init)
.then((response) => response.blob())
.then(data=>
{
let vid = URL.createObjectURL(data)
let htmlString =`
<video id="video-${id}" class="video_player" src="${vid}" autoplay muted loop>
</video>`
let videoElem = parser.parseFromString(htmlString, "text/html");
videoRoot.appendChild(videoElem.firstChild.children[1].firstChild)
}
);
i’m getting
blob:http://127.0.0.1:5501/b62d9895-a432-487e-b1bc-4c670fe4b30c
net::ERR_REQUEST_RANGE_NOT_SATISFIABLE
from chrome and this from firefox
HTTP “Content-Type” of “application/x-unknown-content-type” is not supported. Load of media resource blob:http://127.0.0.1:5501/b62d9895-a432-487e-b1bc-4c670fe4b30c failed.
is something like this really possible?
dispatching ClipboardEvent on textarea element does not work
I wont to simulate paste event trough javascript as shown on snipped below
<!DOCTYPE html>
<html>
<body>
<div class="col-xs-10 col-md-9 col-lg-8 form-field input_controls">
<textarea rows="8"cols="60" id="short_description" name="short_description"></textarea>
</div>
<script>
const transfer = new window.DataTransfer();
transfer.setData('text/plain', 'I LOVE YOU');
const element = document.querySelector('[name="short_description"]');
element.dispatchEvent(new ClipboardEvent('paste', {
bubbles: true,
cancelable: true,
clipboardData: transfer
}));
</script>
</body>
</html>
Unfortunately I get no text filled on the textarea above? Any idea why this does not work?
Get distance between two SVG paths javascript
I have two SVG paths, a and b, that I want to find the distance between. Distance varies along each point, so in my case, I want to find the smallest distance between these two paths. Is there a way to do this using javascript?
path {
fill: none;
}
<svg xmlns="http://www.w3.org/2000/svg">
<path d="M0,0 Q30,30,0,60" stroke="black"></path>
<path d="M70,0 Q30,30,70,60" stroke="black"></path>
<path d="M15,30 L50,30" stroke="red"></path>
</svg>
In this example, I define the longest path to be the red line.
As an addition, is there any way to find the direction that this is pointing? For example, if the distance method is path1.distance(path2), could i get the distance as represented by a vector from the point on path1, to the point on path2? If this is not in the scope of your answer, that is fine.
