var student = {
name: "John",
getName: function() {
console.log("student " + this.name);
}
var employee = {
name: "Tom",
getName: function() {
console.log("employee " + this.name)
}
var run = student.getName.bind(employee);
run();
Category: javascript
Category Added in a WPeMatico Campaign
mozilla pdfjs text overlapped in specific situation
I’m facing a problem with mozilla pdfjs and after reading many github pages I’m here to seek some help.
There are two apps, one is a simple vue app(which I wrote for test), and another enterprise app using angular. In vue app, process of rendering PDF works just fine and scaling works, but in angular app texts are overlapping each other (before and after scale), while both are running on the exact same config (same OS and hardware) and result is same for every different PDF.
rendering result in vue
rendering result in angular
I know it is not a framework related issue, but I cannot figure out what causes this! fonts maybe? or some css property?
pdfjs version : 2.14.305
Not able to remove the list children using “onclick” event attached to ul parent [duplicate]
Something is missing in my code and my event.target keeps undefined. May be related with the argument section for the function provided for the inline onclick event?
<div>
<hr />
<div class="ex-wrapper">
<ul class="list-container" onclick="removeItem()">
<li class="weekday-item">Monday</li>
<li class="weekday-item">Tuesday</li>
<li class="weekday-item">Wednesday</li>
<li class="weekday-item">Thursday</li>
<li class="weekday-item">Friday</li>
</ul>
</div>
</div>
<script>
function removeItem(event) {
if (event.target.matches(".list-container"))
event.target.remove();
}
</script>
How to fix Type error cannot destructure property “app_Id” of undefined or null
Hi I’m using virgil security with firebase, and I have integrated it with cloud functions. When I register a user in my app, it’s suppose to trigger a user verification to register the user to virgil cloud, but instead I get this type error when I check the cloud functions console cannot destructure property “app_Id” of undefined or null. Meanwhile I have the .env from virgil security documentation in my root project.
This is the screenshot of the error on the console
React-Native: Can I pull QR code information from json with RestApi?
When I read the qr code in the QR Code Scanner application, I want to print the qr code information from the json.
scope is not updating in model when view is updated
hey guys I have coded the draggable & resigable text widget like below one Textarea(second) element where we can type text and resize it and another where we can drag it and add click events for Widget but when resized the Widget in View the second textarea scope is updating but the first Textarea width is fixed for some reason
<foreignObject width="{{textareawidth}}"
height="{{textareaheight}}"
x="{{shapeobjects[objind].left}}" y="{{shapeobjects[objind].top}}">
<body>
<textarea ng-dblclick="onRightClick(objind,$event)" ng-model="shapeobjects[objind].TextWidget" spy-styleheight="textareaheight"
spy-stylewidth="textareawidth" ng-right-click="ViewMode?ViewMode=true:onRightClick(objind,$event)" ng-hide="shapeobjects[objind].isactive"
data-index="{{objind}}" kendo-draggable k-dragstart="onDataDragStart"
ng-mouseup="ViewMode?ViewMode=true:textwidgetdragend(objind,$event)" k-drag="onDataDrag" class="pfdtexthtwidget{{objind}}" id="try"
style="height:{{shapeobjects[objind].height}}px;
width:{{shapeobjects[objind].width}}px;background:transparent;text-align:{{shapeobjects[objind].textalign}};
font-style:{{shapeobjects[objind].fontstyle?'italic':'normal'}};font-weight:{{shapeobjects[objind].fontweight?'bold':'normal'}};
text-decoration:{{shapeobjects[objind].fontline?'underline':'none'}};cursor:{{ViewMode?'default':'pointer'}};opacity:{{shapeobjects[objind].fillopacity}};
border:'2px dotted blue';color:{{shapeobjects[objind].textcolor}};font-size:{{shapeobjects[objind].textsize}}px;min-width:100px !important"
></textarea>
<textarea rows="1" cols="10" ng-show="shapeobjects[objind].isactive" spy-styleheight="textareaheight" spy-stylewidth="textareawidth"
class="k-input textwidget pfdactivetexthtwidget{{objind}}" data-index="{{objind}}" id="try1"
ng-dblclick="ViewMode?ViewMode=true:onRightClick(objind,$event)" ng-right-click="ViewMode?ViewMode=true:onRightClick(objind,$event)"
ng-model="shapeobjects[objind].TextWidget" style="height:{{shapeobjects[objind].height}}px;width:{{shapeobjects[objind].width}}px;
min-height:auto;background:transparent;text-align:{{shapeobjects[objind].textalign}};
font-style:{{shapeobjects[objind].fontstyle?'italic':'normal'}};font-weight:{{shapeobjects[objind].fontweight?'bold':'normal'}};
text-decoration:{{shapeobjects[objind].fontline?'underline':'none'}};opacity:{{shapeobjects[objind].fillopacity}};
border:'2px dotted blue';color:{{shapeobjects[objind].textcolor}};font-size:{{shapeobjects[objind].textsize}}px;min-width:100px !important"></textarea>
</body>
</foreignObject>
Create Flow Charts in React js using Fluent UI
Declaration of a class in a variable in javascript is undefined
so this is my first time using javascript. I made a Website which functions as a shop. The Error i am getting through the google inspect tool is:
> Uncaught TypeError: Cannot read properties of undefined (reading'innerText')
> at updatetotal (main.js:103:41)
> at HTMLElement.addCartClicked (main.js:68:3)
So this is the relevant Code:
var cartBoxContent = `
<img src="${productImg}" class="cart-img">
<div class="detail-box">
<div class="cart-product-title">${title}</div>
<div class="cart-price">${price}</div>
<input type="number" value="1" class="cart-quantity">
</div>
<i class="bx bx-trash-alt cart-remove"></i>`;
cartShopBox.innerHTML = cartBoxContent;
cartItems.append(cartShopBox);
cartShopBox.getElementsByClassName("cart-remove")[0].addEventListener("click", removeCartItem);
cartShopBox.getElementsByClassName("cart-quantity")[0].addEventListener("change", quantityChanged);
}
function updatetotal() {
var cartContent = document.getElementsByClassName("cart-content")[0];
var cartBoxes = cartContent.getElementsByClassName("cart-box");
var total = 0;
for (var i = 0; i < cartBoxes.length; i++){
var cartBox = cartBoxes[i];
var priceElement = cartBox.getElementsByClassName("cart-price")[0];
var quantityElement = cartBox.getElementsByClassName("cart-quantity")[0];
var price = parseFloat(priceElement.innerText.replace("$", ""));
var quantity = quantityElement.value;
total = total + price * quantity;
document.getElementsByClassName("total-price")[0].innerText = "$" + total;
}
}
So the Error is “priceElement” is undefined, but i defined with “cart-price” which is in the variable “cartBoxContent” with ${price}. If you need more Information comment what you need. Thanks
How do we put one time series on the left Y-axis and another on the right Y-axis?
How do we put one time series on the left Y-axis and another time series on the right Y-axis (so that we can use two separate scales)?
The code I have used to render the chart is:
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
var xValues = [8.8, 8.6, 9.0, 9.7, 9.5, 9.1, 9.0, 9.2, 9.0, 9.6];
var yValues = [31.0, 23.0, 23.0, 45.29, 44.21, 3.53, 83.0, 21.0, 80.0, 38.88]
var labels = ['W12', 'W13', 'W14', 'W15', 'W16', 'W17', 'W18', 'W1P', 'W2P', 'W3P'];
new Chart("id", {
type: "line",
data: {
labels: labels,
datasets: [{
data: xValues,
borderColor: "green",
fill: false,
label: "Salary"
}, {
data: yValues,
borderColor: "orange",
fill: false,
label: "Ownership",
}]
},
options: {
legend: {display: true},
title: {
display: true,
text: "Salary & Ownership"
},
}
});
Thank you.
out of multiple occurrences of item, remove only the second one
My array looks like this:
{"numb":1, "idSpec":55,}
{"numb":2, "idSpec":42,}
{"numb":3, "idSpec":96,}
{"numb":4, "idSpec":96,}
{"numb":5, "idSpec":96,}
{"numb":6, "idSpec":96,}
You can see that idSpec: 96 has multiple occurrences in my object.
This is my desired output
{"numb":1, "idSpec":55,}
{"numb":2, "idSpec":42,}
{"numb":3, "idSpec":96,}
{"numb":5, "idSpec":96,}
{"numb":6, "idSpec":96,}
How can I only remove idSpec‘s second occurrence?
Javascript/jQuery stop the countup timer
I have function countup.
Below is my code and demo.
Now I need to stop the countup but I don’t have any idea how to put and do that on function.
So the idea, I just call this: $("#a").countRunTime().stop() then it will stop the countup.
Any idea?
$.fn.countRunTime = function(fromDate){
var $el = this;
tick();
var options = $.extend({
callback: function() {}
}, arguments[0] || {});
options.callback.call(this);
function formatTime(distance) {
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
var value = (hours > 9 ? hours : '0' + hours) + ":" + (minutes > 9 ? minutes : '0' + minutes) + ":" + (seconds > 9 ? seconds : '0' + seconds);
return value;
}
function tick() {
var now = new Date().getTime();
if(fromDate > now) {
$el.html("Invalid");
}
else {
var remaining = now-fromDate;
$el.html(formatTime(remaining));
setTimeout(tick, 1000);
}
};
};
$("#a").countRunTime(new Date("20 Jul 2022 11:21:33").getTime());
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="a"></div>
Implementation ideas for authentication between two parties
I would like to implement an authentication between two parties (for example a user and a bank) but I stumbled upon a “design/implementation” doubt.
I need to do this steps:
- user to communicate his address [something related to my project]
encrypted with bank’s public key - bank decrypt address and send to that address some data encrypted
with user public key - user decrypt and use digital signature to sign that data and send it
back (like before and blablabla)
I’ve created the server [with nodejs->express] which provides endpoints for:
- registration of users/banks [or other requesters of authentication]
- encryption with pub key
- decryption with private key sent as a parameter
- digital signature
The question is:
Now, are banks that needs to call with the right sequence my endpoints to authenticate users or should I create a new Endpoint like /authenticate and in some way automatically retrieve the user+bank requests to my endpoints?
The first option seems more like an api service but I don’t know if it’s the only way to do it.
And for the second one i have no idea how to do it.
(Sorry for my bad english I’m Italian, I do only know pizza pasta peperoni language)
specfic npm package not working in node.js? issue: perl rules/compile-rules.pl ‘perl’ is not recognized as an internal or external command
this is the package https://github.com/davidpomerenke/scigen.js ,
https://www.npmjs.com/package/scigen
i have installed the package using the npm install command and then made sure my package.json has type: module for the import to work,in my code I have included
on their website it says they have a runtime compilation rule but I am not sure what they mean by that or what I have to do to get this package working on visual studio code ide with node.js
in my code I have included :
// hithere.js
import { scigen, scigenSave } from "scigen";
console.log("hi")
however I get this error after running node hithere.js in my terminal
C:UsersthreeaccDesktopmyprojects>perl rules/compile-rules.pl
'perl' is not recognized as an internal or external command,
operable program or batch file.
C:UsersthreeaccDesktopmyprojects>node perl rules/compile-rules.pl
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'C:UsersthreeaccDesktopmyprojectsperl'
←[90m at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:778:27)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)←[39m
←[90m at node:internal/main/run_main_module:17:47←[39m {
code: ←[32m'MODULE_NOT_FOUND'←[39m,
requireStack: []
}
C:UsersthreeaccDesktopmyprojects>node hithere.js
node:internal/modules/cjs/loader:933
const err = new Error(message);
^
Error: Cannot find module '../rules/rules-compiled/scirules.json'
Require stack:
- C:UsersthreeaccDesktopmyprojectsnode_modulesscigenlibscigen.js
- C:UsersthreeaccDesktopmyprojectsnode_modulesscigenlibindex.js
←[90m at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:778:27)←[39m
←[90m at Module.require (node:internal/modules/cjs/loader:1005:19)←[39m
←[90m at require (node:internal/modules/cjs/helpers:102:18)←[39m
at Object.<anonymous> (C:UsersthreeaccDesktopmyprojectsnode_modules←[4mscigen←[24mlibscigen.js:10:40)
←[90m at Module._compile (node:internal/modules/cjs/loader:1101:14)←[39m
←[90m at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)←[39m
←[90m at Module.load (node:internal/modules/cjs/loader:981:32)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:822:12)←[39m
←[90m at Module.require (node:internal/modules/cjs/loader:1005:19)←[39m {
code: ←[32m'MODULE_NOT_FOUND'←[39m,
requireStack: [
←[32m'C:\Users\threeacc\Desktop\myprojects\node_modules\scigen\lib\scigen.js'←[39m,
←[32m'C:\Users\threeacc\Desktop\myprojects\node_modules\scigen\lib\index.js'←[39m
]
}
Cannot redirect neither open new tab with javascript on iPhone Safari
I have this code, that used to create transaction and then redirect user to page with this transaction:
const { detect } = require('detect-browser')
const browser = detect()
...
async beginTransaction (data) {
this.submitError = false
if (!this.validateData()) return
this.$store.commit('SET_LOADER', 1)
try {
this.captchaCounter++
const clientOrigin = localStorage.getItem('cOrigin')
const result = await startTransaction({
...data
}, this.offerId, localStorage.getItem('market'))
localStorage.removeItem('cOrigin')
const route = this.$router.resolve({path: '/chat', query: { id: result.transactionId, pushNotifications: null, beCareful: null }})
if (browser.name.toLowerCase() === 'safari' || this.$browserDetect.isSafari) {
await this.$router.push(`/chat?id=${result.transactionId}&pushNotifications&beCareful`)
} else {
return window.open(route.href, '_blank')
}
} catch (e) {
console.log(e)
}
}
This code works perfectly fine with every other browser or device, but not on iPhone with Safari. I tried probably everything that could found, I was trying to use window reference, like here. I was also trying to do it using .then(() => {}) like here and even this, but nothing works.
What is the problem? Could it be problem in phone, not code? Because I have similar code that works, but it is bonded on button click:
async redirectToChat (id) {
if (browser.name.toLowerCase() === 'safari' || this.$browserDetect.isSafari) {
await this.$router.push(`/chat?id=${id}`)
} else {
const route = this.$router.resolve({path: '/chat', query: { id }})
return window.open(route.href, '_blank')
}
},
Is it possible to convert a double quoted string with template literal to tilde string to assign values? [duplicate]
I am trying to convert a double quoted string containing template literal into tilde string such that I can pass values inside the string.
Sample:
const email = "hello there ${user_name}"
const emailParser = (email)=>{
let user_name = "alex"
console.log(`${email}`)
console.log(`hello there ${user_name}`)
}
emailParser(email)
Result
hello there ${user_name}
hello there alex
I would like to know, if there is some method to achieve the result of first console log to be like that of second console log.
