Office JS Dialog – How to get back/keep context with Excel

I’m messing around w/ Office Dialog for Add-Ins in JS. I’ve got it so far where I can open a dialog, capture input to console, run a function from a button and close the dialog box, but I can’t seem to get my function to interact with Excel. It’s lost context I beleive, I tried using this and I get no errors, but it doesn’t work –> var context = new Excel.RequestContext().

Here is my open function and my main function and the end function.

main.js

export async function helloworld(event) {
    try {
        await Excel.run(async (context) => {
            //Start Func
            console.log("BEFORE OPEN UI");
            openDialog("/yo/dist/dialog.html", 30, 20);
            console.log("AFTER OPEN UI");
            await context.sync()
                .then(function () {
                    console.log("AFTER SYNC UI");
                    var ws = context.workbook.worksheets.getActiveWorksheet();
                    var range = ws.getRange("A1:D5");
                    range.select();
                })
            //End Func
            await context.sync();
        });
    } catch (error) {
        console.error(error);
    }
    console.log("EVENT COMPLETEED HELLOW");
    //event.completed();
}

open.js

function openDialog(RelURLStr, H, W) {
    Office.context.ui.displayDialogAsync(window.location.origin + RelURLStr,
        { height: H, width: W }, dialogCallback);
}

run func //this gets ran, but nothing output to worksheet and no errors.

function dobuttonrun() {
    console.log("ENDING");
    var context = new Excel.RequestContext()
    var ws = context.workbook.worksheets.getActiveWorksheet();
    var fakedatarng = ws.getRange("A1");
    fakedatarng.values = "TEST";
}

document.addEventListener blocking highlight in textarea

I did a div that is moveable but unfortunetaly the function that let user move the div also block the highlight of the text in the text area behind.

I would like to keep the possibility to move the div and to highlight the text in textarea like I want.

Ps: I already tried to put the addEventListener on varMoveButtonNotesWindow but it’s really ncomfortable to use it like that (we need to keep the cursor in the little box, and I dont want the box to be bigger it wouldn’t look good).

Here’s the code:

var mousePosition;
var offset = [0,0];
var isDown = false;
var varMoveButtonNotesWindow = document.getElementById('moveButtonNotesWindow');
var varNotesWindow = document.getElementById('notesWindow');

varMoveButtonNotesWindow.addEventListener('mousedown', function(e) {
    isDown = true;
    offset = [
        varNotesWindow.offsetLeft - e.clientX,
        varNotesWindow.offsetTop - e.clientY
    ];
}, true);

document.addEventListener('mouseup', function() {
    isDown = false;
}, true);

//The bug occurs here
document.addEventListener('mousemove', function(event) { 
    event.preventDefault();
    if (isDown) {
        mousePosition = {
    
            x : event.clientX,
            y : event.clientY
    
        };
        varNotesWindow.style.left = (mousePosition.x + offset[0]) + 'px';
        varNotesWindow.style.top  = (mousePosition.y + offset[1]) + 'px';
    }
}, true); 
//so far


function closeNotesWindow() {
  varNotesWindow.classList.remove('show');
}

function openNotesWindow() {
  windowsModalContainer.classList.remove('show');
  varNotesWindow.classList.add('show');
};
.firstTextarea {
  height: 300px;
  width: 300px;
}

#notesWindow {
  display: block;
  position: absolute;
  width: 300px;
  height: 275px;
  top: 0px;
  left: 0px;
  border: 2px solid #313131;
  z-index: 2;
  resize: both;
  overflow: auto;
}

#headerNotesWindow {
  height: 35px;
  background-color: black;
}


#moveButtonNotesWindow {
  position: absolute;
  background-color: blue;
  color: white;
  width: 20px;
  height: 20px;
  right: 5px;
  z-index: 1;
  top: 7.5px;
}

#closeButtonNotesWindow {
  position: absolute;
  background-color: red;
  color: white;
  width: 20px;
  height: 20px;
  right: 30px;
  z-index: 1;
  top: 7.5px;
}

#divTextareaNotesWindow {
  text-align: center;
  height: calc(100% - 6px - 35px);
}

#textareaNotesWindow {
  resize: none;
  width: calc(100% - 6px);
  height: 100%;
  outline: none;
}
<textarea class="firstTextarea">Pokemon is the best game of my childhood.</textarea>

<div class="divWindow" id="notesWindow">
    <div id="headerNotesWindow">
      <div id="moveButtonNotesWindow"></div>
      <div id="closeButtonNotesWindow" onclick="closeNotesWindow()"></div>
    </div>
  
    <div id="divTextareaNotesWindow">
      <textarea id="textareaNotesWindow"></textarea>
    </div>
  </div>

When I click the anchor tag, page re-direct to to another page. Then I need to load specific content using Java Script

In index.html page of my web site there are three buttons.

Three Buttons in the web site

After clicking these buttons, page re-direct to another page named productandservices.html. In their I show fishes for each selected category(when someone select Freshwater fish in index.html, it shows freshwater fishes in productandservices.html).

<a href="servicesAndProduct.html"><button class="menu-buttons">FRESHWATER FISH</button></a>
            <a href="servicesAndProduct.html"><button class="menu-buttons">MARINE FISH</button></a>
            <a href="servicesAndProduct.html"><button class="menu-buttons">AQUA PLANTS</button></a>

Above you can see the three buttons in index.html. But after clicking these buttons, they only re-directing page. But do not show the selected category. To achieve that, What I can do in Java Script?

What I want is when someone click on Marine fish index.html, I want to show them Marine fish category in servicesandproduct.html

Mongoose 3 to 6 and modelSchemas

I’m working on migrating an old project from mongoose 3 to 6 and can’t seem to find anything in the change docs about modelSchemas and how they’ve been superseded.. In some unit tests, I have this v3 code;

function clearModels(models) {
  models.forEach(model => {
    delete mongoose.models[model];
    delete mongoose.modelSchemas[model];
  });
}

This of course fails because mongoose.modelSchemas no longer exists — so the question is, how do I re-write this in a v6 compatible way?

Normalize Set of Data To Specified Sum Keeping as Integers Javascript [closed]

I have a set of data: var data = [312, 91, 53, 28, 22, 13, 13, 11, 5, 3]; with a sum of 551.

I want to “normalize” this data so that the sum equals a specified input smaller or larger than the original sum.

I know that I can do this simply by dividing each number in the set by 551 and then multiplying it by my target value but this results in floats when I want my answer to consist only of integers.

var data = [312, 91, 53, 28, 22, 13, 13, 11, 5, 3];
var dataNew = [];
var target = 541;
var sum = data.reduce((a, b) => a + b)


for (var point in data) {
    dataNew.push(data[point]/sum*target);
}

console.log(dataNew)

I know that this will mean that the relative weights of each data point will change slightly but that is something I can accept.

I also need to keep all original entries so no data point can be discarded during the process just set to the minimum value of 1.

Input Text Editable in Angular js

I have a problem of trying to make the input text field editable.

Currently, I am unable to make the input text box editable on click of add or edit button.

I have set the values statically in the state objects.

How can I edit the code below to make the input text box editable?

The sample code is as below
HTML

<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>

<body ng-app="myApp" ng-controller="myCtrl">

<input type="text" input-disabled="editableInput"/>
<button type="submit" ng-click="editableInput = ! editableInput;" value="submit">Add</button>
<table>
<tr ng-repeat="x in records">
<td><h4>{{x}}</h4></td>
<td><button type="submit" ng-click="editableInput = ! editableInput;" value="submit">Edit</button></td>
</tr>
</table>

</body>
</html>

Script

var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
  $scope.records = [
    "Alfreds Futterkiste",
    "Berglunds snabbköp",
    "Centro comercial Moctezuma",
    "Ernst Handel",
  ]
});
app.directive("inputDisabled", function(){
    return function(scope, element, attrs){
        scope.$watch(attrs.inputDisabled, function(val){
            if(val) {
                element.removeAttr("disbaled");
            } else {
                element.attr("disabled", "disabled");
            }
        });
    }
});

Any Help would be much appreciated.

How to set caret line number and position in contenteditable div

I am attempting to reset the caret to its original position in a contenteditable div after injecting HTML tags into the div’s innerHTML.

I’ve seen similar threads on here but have run into issues using code I found and struggle to debug because I don’t really understand selection or range objects. Would really appreciate some help.

Here is my current attempt:

const highlighting = () => {
  let sel = window.getSelection();
  let pos = sel.getRangeAt(0).startOffset
  code.innerHTML = code.innerText.replaceAll(/(d+)/g, `<number>$1</number>`);
  let range = document.createRange();
  range.setStart(code.childNodes[currentLineNumber - 1], pos);
  range.collapse(false);
  sel.removeAllRanges();
  sel.addRange(range);
}

I think I found something that almost worked but didn’t work for multi-line editing or something.

Would really, really appreciate some help getting this right so I can focus on the actual syntax highlighting.

My goal is to be able to do something like moveCaret(lineNumber, position)

How to remove event listener from Vue Component

I have a vue2 component which contains an added eventListener i created on ‘mounted’. I was wondering how do i properly remove this listener when the component is destroyed?

<template>
    <div>
      ...
    </div>
  </template>
  
  <script>
  export default {
    mounted() {
        window.addEventListener('click', (evt) => {
          this.handleClickEvent(evt)
        })
    },
    destroyed() {
      //   window.removeEventListener('click', ????);
    },
    methods: {
      handleClickEvent(evt) {
        // do stuff with (evt) 
      },
    },
  }
  </script>
  

I can’t seem to find whats wrong with my code

I am using xampp for the project,and this my php code for the registration side of things, if anyone can help i would appreciate it.

ERROR MESSAGE: Parse error: syntax error, unexpected ‘}’ in E:xampplitehtdocsProjetoPaphtml&phpincludessigned.inc.php on line 44

  <?php
if (isset($_POST["submit"])) {

  $username = $_POST["Username"];
  $email = $_POST["email"];
  $password = $_POST["Password"];
  $passwordrepeat = $_POST["passwordrepeat"];
  $dataNASCI = $_POST["dataNASCI"];
  $accept = $_POST["accept"];
require_ONCE 'DBH.inc.php';
require_ONCE 'functions.inc.php';

if (emptyinputsignup($username, $email, $password, $passwordrepeat,  $dataNASCI, $accept) !== false) {
    body("location: ../create_account.php?error=emptyinput");
    exit();
   }
if (invalidUsername($username) !== false) {
       body("location: ../create_account.php?error=emptyinput");
       exit();
   }
   if (invalidEmail($email) !== false) {
       body("location: ../create_account.php?error=emptyinput");
       exit();
      }
      if (invalidPassword($password) !== false) {
          body("location: ../create_account.php?error=emptyinput");
          exit();
         }
         if (passwordMatch($password, $passwordrepeat) !== false) {
             body("location: ../create_account.php?error=Passwordsnãocoincidem");
             exit();
            }
            if (invalidDataNASCI($dataNASCI) !== false) {
                body("location: ../create_account.php?error=emptyinput");
                exit();
               }
                if (emailExists($conn, $email, $username) !== false) {
                    body("location: ../create_account.php?error=Emailalreadyinuse");
                  exit();
                  }
  createuser($conn, $username, $email, $password, $dataNASCI);
}
else {
  body("location: ../create_account.php");
  exit();
}

?>

Cannot read properties of undefined (reading ‘bannable’)

    message.mentions.members.forEach(men => {
      let member = message.mentions.members.get(men)

      if (!member.bannable) return message.reply(not_bannable)
    
      const reason = args.slice(1).join(" ");
      member.ban({reason: reason || "no reason"}).then((member) => {
        message.channel.send(member + " banned by " + message.author.id)
      }).catch(err => console.log(err))
  })

I’m trying to build a ban command that allows you to ban multiple users at once. Unfortunately, an error occurs when I execute it.

I work with discord v13

Why does this error occur?

Cannot read properties of undefined (reading 'bannable')

query load page go instantly to div

i have problem with scroll. Its working fine, but i want to make it instantly without any animation, just then page refreshing be the same place as before without scrolling to the place.

my js code.

<script type = "text/javascript">
    $(function() {
        $(window).scrollTop( $("#col-6").offset().top)

    });
</script>

My project structure for example.

First including css and html

    <?php 

    include(html/css.php);
    some code....
     <div class=col-6> 
     some code....
    </div>
    include(footer.php);
    ?>

so in footer php after

<script src="assets/bootstrap/js/bootstrap.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://kit.fontawesome.com/5fbb5e690d.js" crossorigin="anonymous"></script>
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.js"></script>

i use my js code.

And after page load its scrolling to col-6 div. But, i want instantly without any animation or scrolling be in what place.

What i try

<script>
    $(window).on('beforeunload', function() {
        $('body').hide();
        $(window).( $("#col-6").offset().top)
    });
</script> 

any1 have solution for it ?

How to copy all images from a src folder to a dist folder recursively using copy files npm module?

Using the copy files command, how can I copy images (.png, .jpg) from a “src” folder to the “dist” folder, while preserving the same filepaths internally. Should also work recursively.

https://www.npmjs.com/package/copyfiles

I have this

copyfiles(["src/**/*.png", "dist"], {u:2}, (err) => {
    if (err) {
        console.log("Error occurred while copying", err);
    }
    console.log("folder(s) copied to destination");
});

But it doesn’t seem to work. It creates the src folder inside dist folder.

Thanks

How can you make the bounding box of text in an HTML5 canvas account for transformations such as panning and scaling?

I’ve been playing with a Javascript program which is composed of an HTML5 Canvas that can be panned and zoomed. Text can also be added and a bounding box is initially generated for it. I’ve got the program to account for the panning transformations, but I’m unable to get the bounding box to account for the scaling/zooming in and out. The initial bounding box is also not perfect, although it works when you try to click and drag the text, it is off by quite a bit.

Please help me figure out how to fix these issues.

Here is the program: https://jsfiddle.net/HappyAcorn77/hekagmb2/2/

/* I use this code to account for panning transformations for the bounding box on line   
   362 

   The Zooming/Scaling function can be found on line 372 which is what I am unable to 
   adjust the bounding box for.

*/
  • Click and hold to drag the text
  • Left click to default to inital display transformation values