How to redirect to an image while click on test or id in word addin using office js?

please view the attached image for output

this is the code I have written in js

Office.context.document.addHandlerAsync(
        Office.EventType.DocumentSelectionChanged,
        (result: any) => {
          let bookmark = localStorage.getItem("bookmark")
          let bookmarkParse = JSON.parse(bookmark);
          console.log("bookmarkParse",bookmarkParse)
          bookmarkParse.map((item: any) => {
          Word.run(async (context) => {
            console.log("result", result);
            const range = context.document.getSelection();
            console.log("getRange",range)
            return context.sync().then(async function ()
            {
              context.load(range);
              await context.sync();
              let text = range.text
              console.log("item", item.ImageId, text);
              
  
              if (item.ImageId == text) {
                console.log("item bookmark",item.bookmark)
                range.hyperlink = "#" + item.bookmark;
                console.log("range.hyperlink",range.hyperlink)
                console.log(item.bookmark,"range matched");
              } else {
                console.log("range not matched");
              }
              await context.sync();
            });

here is the my code for redirected to image when clicking on the test.

onDidSaveTextDocument causes infinite loop

I’m trying to create an extension that runs two formatters in succession to format a file on save.

The idea comes from this answer, so I assume it must be possible.

My extension’s code looks like this:

import * as vscode from "vscode";

export function activate(context: vscode.ExtensionContext) {

    vscode.workspace.onDidSaveTextDocument(() => {
        vscode.window.showInformationMessage('Hello World from mojo.formatter!');
        const config = vscode.workspace.getConfiguration(
          "editor",
          vscode.window.activeTextEditor?.document
        );
        const formatters = ["esbenp.prettier-vscode", "dbaeumer.vscode-eslint"];
        formatters.forEach(async (formatter) => {
          await config.update("defaultFormatter", formatter);
          await vscode.commands.executeCommand("editor.action.formatDocument");
        });
    });

}

I’ve also added the following to my package.json:

  "activationEvents": [
    "*"
  ],

Everything else is the same as it comes in the Hello world extension example.

When I save a document, the formatters run but the extension seems to create an infinite loop of

  • Saving
  • Formatting
  • Saving again
  • Formatting

And so on…

Any idea what the issue could be?

match and assign value from array and objects

I have a datasource data which is an array of object and it has Column. How do we match it to the tempValues object and get the tempValues values that matches the column on dataSource.

The finalOuput is provided below on how the final ouput should look like . Thanks.

#Data Source

dataSouce = [
    {
        "name": "NVB",
        "value": 0,
        "financeValue": 0,
        "column": "nvb",
        "isEdit": false
    },
    {
        "name": "ROU",
        "value": 0,
        "financeValue": 0,
        "column": "rou",
        "isEdit": false
    },
    {
        "name": "Net Present Value",
        "value": 0,
        "financeValue": 0,
        "column": "netPresentValue",
        "isEdit": false
    },
]

#tempValues

tempValues = {
    "transactionId": 20,
    "nvb": 20,
    "rou": 100,
    "netPresentValue": 50,
}

#FinalOutput

= [
    {
        "name": "NVB",
        "value": 20,
        "financeValue": 0,
        "column": "nvb",
        "isEdit": false
    },
    {
        "name": "ROU",
        "value": 100,
        "financeValue": 0,
        "column": "rou",
        "isEdit": false
    },
    {
        "name": "Net Present Value",
        "value": 50,
        "financeValue": 0,
        "column": "netPresentValue",
        "isEdit": false
    },
]

How can I match on value and then add value to object?

Uncaught TypeError: Cannot read properties of undefined (reading ‘$wire’) at Livewire.value (VM951 livewire.js:13:145634)

I have error with google map when it put Marker it get this error
I do not know what the error is when I click on save it outputs that the data is field is required. in the map it selects the place but when I click on the place this error comes out at the bottom

VM951 livewire.js:13 Uncaught TypeError: Cannot read properties of undefined (reading '$wire')
    at Livewire.value (VM951 livewire.js:13:145634)
    at placeMarkerAndPanTo (make:2811:27)
    at make:2792:11
    at geocoder.js:6:1385
    at geocoder.js:3:420
    at bza (geocoder.js:2:218)
    at gia.e [as m] (geocoder.js:3:339)
    at Object.c [as _yj5gms] (common.js:123:253)
    at GeocodeService.Search?5m2&1d24.745676471010597&2d46.7278229712639&9sen-US&callback=_xdc_._yj5gms&key=AIzaSyDy4tKkS30XU9DJsUA5cqLzg-jtynKS18s&token=45746:1:28

I do not know what the error is when I click on save it outputs that the data is field is required. in the map it selects the place but when I click on the place this error comes out at

this is my code

@section('scripts')

<script src="https://maps.googleapis.com/maps/api/js?key={{env("GOOGLE_KEY")}}&libraries=places&v=weekly"> </script>


<script src="{{ asset('dashboard/assets/js/pages/crud/forms/widgets/select2.js') }}"></script>

<script>
  $(document).ready(function() {
    $('#kt_select2_3').select2({
      placeholder: '',
    }).on('change', function() {
      @this.properties = $(this).val();
    });
  });

  function mapLocation() {
    var directionsDisplay;
    var directionsService = new google.maps.DirectionsService();
    var map;

    var lat, lng;
    var markers = [];
    var gmarkers = [];

    function initialize() {
      directionsDisplay = new google.maps.DirectionsRenderer();
      var riyad = new google.maps.LatLng(24.729518, 46.723341);
      var mapOptions = {
        zoom: 13,
        center: riyad,
        mapTypeId: google.maps.MapTypeId.ROADMAP

      };
      map = new google.maps.Map(document.getElementById('map'), mapOptions);


      map.addListener('click', function(e) {

        var geocoder = geocoder = new google.maps.Geocoder();
        geocoder.geocode({
          'latLng': e.latLng
        }, function(results, status) {
          if (status == google.maps.GeocoderStatus.OK) {
            //alert(results[1].formatted_address);
            if (results[1]) {

              //results = results[1];
              //var result12 = results[1].formatted_address;
              // //document.getElementById("address_pickUp").innerHTML = results[1].formatted_address;
              // // alert(document.getElementById("address_pickUp").innerHTML.length)
              // if(document.getElementById("address_pickUp").innerHTML.length == 0){
              //   document.getElementById("address_pickUp").innerHTML = results[1].formatted_address;
              // }else{
              //   document.getElementById("address_dropOff").innerHTML = results[1].formatted_address;
              // }
              //@this.address = results[1].formatted_address;

              // alert("Location: " + results[1].formatted_address + "rnLatitude: " + e.latLng.lat() + "rnLongitude: " + e.latLng.lng());
              //alert(result12);

            }
          }


          placeMarkerAndPanTo(e.latLng, map, results[1].formatted_address);
        });
      });
      var marker = new google.maps.Marker({
        // position: markers[0],
        position: markers,
        map: map
      });

      function placeMarkerAndPanTo(latLng, map, results) {

        if (document.getElementById("pickup_lat").value.length == 0) {
          document.getElementById("pickup_lat").value = latLng.lat();
          document.getElementById("pickup_lng").value = latLng.lng();
          document.getElementById("address_pickUp").value = results;

          marker.setPosition(latLng);
          map.panTo(latLng);
          @this.pickup_lat = latLng.lat();
          @this.pickup_lng = latLng.lng();

        } else {
          document.getElementById("dropoff_lat").value = latLng.lat();
          document.getElementById("dropoff_lng").value = latLng.lng();
          document.getElementById("address_dropOff").value = results;
          marker.setPosition(latLng);
          map.panTo(latLng);
          @this.dropoff_lat = latLng.lat();
          @this.dropoff_lng = latLng.lng();

        }
      }
      directionsDisplay.setMap(map);
      google.maps.event.addDomListener(document.getElementById('routebtn'), 'click', calcRoute);

      // Create the search box and link it to the UI element.
      var input = document.getElementById('pac-input');
      var searchBox = new google.maps.places.SearchBox(input);
      map.controls[google.maps.ControlPosition.TOP_LEFT].push(input);

      // Bias the SearchBox results towards current map's viewport.
      map.addListener('bounds_changed', function() {
        searchBox.setBounds(map.getBounds());
      });

      var markers = [];
      // [START region_getplaces]
      // Listen for the event fired when the user selects a prediction and retrieve
      // more details for that place.
      searchBox.addListener('places_changed', function() {
        var places = searchBox.getPlaces();
        if (places.length == 0) {
          return;
        }
        // Clear out the old markers.
        markers.forEach(function(marker) {
          marker.setMap(null);
        });
        markers = [];

        // For each place, get the icon, name and location.
        var bounds = new google.maps.LatLngBounds();
        places.forEach(function(place) {
          var icon = {
            url: place.icon,
            size: new google.maps.Size(71, 71),
            origin: new google.maps.Point(0, 0),
            anchor: new google.maps.Point(17, 34),
            scaledSize: new google.maps.Size(25, 25)
          };

          console.log("latitude: " + place.geometry.location.lat() + ", longitude: " + place.geometry.location.lng());

          /*if (document.getElementById("pickup_lat").value.length == 0) {
            document.getElementById("pickup_lat").value = place.geometry.location.lat();
            document.getElementById("pickup_lng").value = place.geometry.location.lng();
            // marker.setPosition(latLng);
            // map.panTo(latLng);
            //@this.pickup_lat = place.geometry.location.lat();
            //@this.pickup_lng = place.geometry.location.lng();
          } else {
            document.getElementById("dropoff_lat").value = place.geometry.location.lat();
            document.getElementById("dropoff_lng").value = place.geometry.location.lng();
          }*/
          // Create a marker for each place.
          markers.push(new google.maps.Marker({
            map: map,
            icon: icon,
            title: place.name,
            position: place.geometry.location

          }));

          if (place.geometry.viewport) {
            // Only geocodes have viewport.
            bounds.union(place.geometry.viewport);
          } else {
            bounds.extend(place.geometry.location);
          }
        });
        map.fitBounds(bounds);
      });
    }

@endsection


make-trip.blade.php

<div class="col-lg-12" wire:ignore>
  <div class="col-lg-3">
    <x-input type="text" field="map" style="margin: 10px; z-index: 0; position: absolute; cursor: pointer; left: 0px; top: 0px;width:350px" placeholder="Search Box" id="pac-input"></x-input>
  </div>

I do no now what is the error 

How can I change the content of a clicked DOM ELement via JS condition?

I use a filter in a WordPress installation, I copy the name of the filter point (the respective category) over the result list in the DOM.

My question is, how can I catch the first filter point (All) via JavaScript and paste another name (All Facilities) to the place in the DOM?

My current JS code unfortunately only transfers the existing categories.

$(document).ready(function() {
// setze erst einmal den Titel für alle
$(“.einrichtungen”).append(‘Alle Einrichtungen’);

// reagiere auf die Klicks des Filters
$(".post-filter [href]").click(function() {
    $(".einrichtungen a.categorie-title").remove();
    $(this).clone().after().appendTo(".module-post").addClass('categorie-title text-center');
});

});

Can anyone give me a tip on how to implement this via JS?

Many thanks to all of you
m.orange

VSCode extension Activity Bar custom behaviour

I’m creating an vs-code-extension and I’m tring to add a button into the Activity Bar, which will not trigger the sidebar, and will open/close a webview.

Anynody knows if it’s that possible?

I’ve triend adding the button and mapit to a custom command that will open the web view, but without any luck. It didn’t worked.

collapsing function and variables name

Here is the fact in Head first js,

when the browser evaluates a function declaration, it creates a function as well as a variable with the same name as the function, and stores the function reference in the variable.

my question is, what if we also created a variable named just as same as the function.

I really confused, also some one please can suggest me a text book to understand these type of things?!

I know it is a little stupid, so, be kind please!

I tried this,

var sayHello = 2;
function sayHello() {
    console.log("Hello");
};

sayHello();

I expect that at first it makes a reference for “2”, after declaring a function, it reassign it to the function, though, it raised and error saying that “sayHello” is not a function, is there any priority or something?!

Don’t open image in browser when dropped into a window

When I drag an image and drop it into an open browser window, the browser will (provided I didn’t drop the image into an input field) open this image in the browser. The address bar shows something like file:///Users/paul/Desktop/test_image.png.

Is there any way with e.g. HTML, CSS or JS to simply ignore this and not to open the image in the window?

I want to reach this behavior for specific sites I’m hosting. Not as general browser setting.

Resolve promise ethersJs

I have here this code but whenever a new pair is being detected i get back
[object promise]

function main(){
    console.log('Starting...')
   contractBsc.on('PairCreated', (token0, token1, pair) =>{
        var erc20COntract0 = new ethers.Contract(token0, erc20Abi, provider) 
        var erc20COntract1 = new ethers.Contract(token1, erc20Abi, provider)  
        let name0 =  erc20COntract0.name()
        var name1 =  erc20COntract1.name()
        var symbol0 = erc20COntract0.symbol()
        var symbol1 = erc20COntract1.symbol()    
        console.log(`Token0: ${name0}, Symbol: ${symbol0}nToken1: ${name1}, Symbol: ${symbol1}`)
       // return name0,name1,symbol0,symbol1
    }) 
    
  
}
main()

How can I resolve the promise and than use the variables name1, name0 etc in my script

How to force log out after session expired?

Currently if the session token is expired, there’s no way for the application to know. We have to wait until they make any request after that to know their session has timed out, and redirect them to login again. Is there a way to check for the expiration in the background, and if the token is expired, force them out immediately? I was thinking about setTimeout, but could not really come up with an implementation yet.

Why set HTML element state in data object in typescript (angular)

I have been studying angular animation lately and found that there is no way to set element state in HTML other than setting the state in data object.
for example I have to animate single element withing the list of elements then there is no other way.

 export const listAnimation = trigger('listAnimation',
[

     state('before', style({
     opacity: .5
     })),
        transition('before <=> after', animate(1000)),
 ])



export class SubjectcontentComponent implements OnInit {
selectedItem:any;

subjects= [
{ id: 12, name: 'PHP', state:'before ' },
{ id: 13, name: 'Javascript' , state:'before '  },
{ id: 14, name: 'Css', state:'before '  },
{ id: 15, name: 'Angular' , state:'before '  },
{ id: 16, name: 'Laravel' , state:'before ' },
{ id: 17, name: 'java', state:'before ' },
{ id: 18, name: 'asp' , state:'before ' },
{ id: 19, name: 'python' , state:'before ' },
{ id: 20, name: 'database'  , state:'before ' }
];
 state: string='small';
 i=0;
 constructor( private subjectcontentService: SubjectcontentsService ) { }

ngOnInit(): void {
  this.subjects=this.subjects.map((subject)=> {
  subject.state='before';
  return subject;
 })
}
 toggle(subject:any){
 if(subject.state=='before')
  {
   subject.state='after';
  }
   else{
   subject.state='before';
  }


 }

}

Is there any benefit to storing the state of element in the data of regular object.

I want to use javascript to make a snow effect on my website but I only want to use it 50% high on the website. Can anyone help me tidy up my code?

I want to use javascript to make a snow effect on my website but I only want to use it 50% high on the website. Can anyone help me tidy up my code?

javascript

window.requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
window.cancelAnimationFrame = window.cancelAnimationFrame || window.mozCancelAnimationFrame || window.webkitCancelAnimationFrame || window.msCancelAnimationFrame;

var no = 80;var delai = 10;
var dx = new Array(), xp = new Array(), yp = new Array();
var am = new Array(), stx = new Array(), sty = new Array();
var i;
larg_fenetre = (document.body.offsetWidth<window.innerWidth)? window.innerWidth:document.body.offsetWidth;
haut_fenetre = (document.body.offsetHeight<window.innerHeight)? window.innerHeight:document.body.offsetHeight;

for (i = 0; i < no; i++) { 
    dx[i] = 0;
    xp[i] = Math.random()*(larg_fenetre-40);
    yp[i] = Math.random()*(haut_fenetre-30);
    am[i] = Math.random()*20;
    stx[i] = 0.02 + Math.random()/10;
    sty[i] = 0.4 + Math.random();
    
    obj = document.getElementsByTagName('body')[0];
    para = document.createElement("img");
    para.setAttribute("src","https://i.ibb.co/94kRvYD/snowww.webp");
    para.setAttribute("id","dot" + i);
    para.style.position = "fixed";
    para.style.width="10px";
    para.style.height="10px";
    para.style.zIndex = "-1";
    obj.appendChild(para);
}

function neige() {
    for (i = 0; i < no; i++) {
        dx[i] += stx[i];
        yp[i] += sty[i];
        if (yp[i] > haut_fenetre-50) {
            xp[i] = Math.random()*(larg_fenetre-am[i]-40);
            yp[i] = 0;
        }
        document.getElementById("dot"+i).style.top = yp[i] + "px";
        document.getElementById("dot"+i).style.left = xp[i] + am[i]*Math.sin(dx[i]) + "px";
    }
    setTimeout("neige()", delai);
}

neige();

`

I want to use javascript to make a snow effect on my website but I only want to use it 50% high on the website. Can anyone help me tidy up my code?

Can anyone help me solve this Java problem?

Can anyone solve this Java problem?

Write an algorithm + a program that will allow us to display the following output:

N=1

*

N=2

**

*

N=3


**

*

and so on…….

Now modify the above program so that it now displays the following output:

N=1

*

N=2

**

*

N=3


**

*

and so on…….

Stuck on first part itself

Solve a typing problem on a helper with TypeScript

I am having a problem on typing a helper. My goal is to replace null values in an object with an empty string while maintaining my key values relationships in typescript

// from 
{
    name: string | undefined
    url: string | null | undefined
    icon: string | null | undefined
}

// to
{
    name: string | undefined
    url: string | undefined
    icon: string | undefined
}

For this I use a mapObjIndexed from Ramda to replace each null by '' nothing complicated

const mapObjIndexed = (callBack, values) => {
    Object.fromEntries(
        Object.entries(values).map(entries => [
            entries[0],
            callBack(entries[1])
        ])
    )
}

Let’s show you my problem

import { mapObjIndexed } from "ramda"

// helper
const types = {
    isNull: (value: any): value is null => value === null
}

// test 1 => ts error
const nullToEmptyString = <T>(value: T | null): T | '' => types.isNull(value) ? '' : value

// test 2 => ts error
const nullToEmptyString2 = <T extends any>(value: T): T extends null ? '' : T => types.isNull(value) ? '' : value

// parser => ts error
const nullsToEmptyStrings = <T>(value: { [K in keyof T]: T[K] | null }): { [K in keyof T]: T[K] | '' } => mapObjIndexed(nullToEmptyString, value)

The only way to make it work is to force the return values with as

I can’t find any solution and my level in Typescript does not allow me to do it