JODIT WYSIWYG editor 3.24.1 - how to call a function and get source filename after a base64 encoded image has been inserted - jodit

I've got images inserting into the editor as base64 encoded images (uploader option insertImageAsBase64URI is set to true). However, I'd like to call a function after the image has been inserted and also read the source filename for the inserted image.
I'm new to the JODIT editor, it seems great so far, but I need to tweak it a bit and am not sure how to register an event callback for this, or if there is another/better way. Any help is appreciated!

I think the best solution is to fork JODIT in github and edit the code. For some reason, however, I have been unable to build the code on my mac laptop for at least a couple of reasons (missing file in node module, fixed, and a build error "TypeError: require(...) is not a function" that may indicate circular dependencies in node modules?). Anyway, I found a complete and limited "HACK" for my needs and that is to actually capture the filename when the file is added by attaching an "onchange" handler function to the JODIT instance's file input element. This works roughly as follows (I'm using jQuery):
var selectedFile = null;
function setSelectedFile(){
$('.jodit').find('input[type="file"]').removeProp('multiple');
$('.jodit').find('input[type="file"]').on('change', function(){
var files = $(this).prop('files');
selectedFile = files[0].name;
});
});
$('.jodit').find('button[aria-label="Insert file"]').on('click',
function(){
setSelectedFile();
}
);
I run something like this after the page has loaded. This works only for the "change" event (where you select a file directly) and I could not figure out how to read the filename after a file is "dropped". Dropping a file does not seem to trigger the "change" event in the file input element. If anyone knows how to get the filename of a dropped file for the JODIT editor I'd appreciate sharing. I will update this if I get around to fixing that.

Related

Loading JSON file not reflecting changes

I have a JSON file I use to store dialogue for a game. However, the changes I make to this JSON file are sometimes not reflected in my game even after hard reloads (I've been doing ctrl+shift+r or shift+F5 for this). I have made sure the changes to the JSON file are saved.
I have this.load.json('dialogue', 'assets/dialogue.json'); in preload(), and this.dialogue = this.cache.json.get('dialogue'); in create().
When I try copy+pasting the contents to a new different file (e.g. dialogue-2.json), and update my this.load.json() to reflect the new file name, the changes do get loaded.
The problem is that phaser doesn't automatic start the loading files, except in the preload function.
If you want to load files in other functions you need to call the start method of the LoadPlugin. Here the link to the official documentation.
The code should look something like this:
function create(){
// some code here ...
this.load.json(/* key and file...*/);
// start the loading of the enqueued files
this.load.start();
// some code here...
}
..., than the files should get loaded.
Update (copied form comments):
to check (and as a tempoary quickfix) if your problem, is a caching issue from the Webserver or browser or ..., you can load the file with a "dynamic" Url.
Just a load the file with a questionmark and random number added to the url, so that each call to the json uses aunique Url.
For Example like this:
this.load.json('dialogue', 'assets/dialogue.json?' + Math.random());
If this solves the problem, there is a caching problem. It could be in the browser, or simply caused by serviceworker or on the webserver.

Copy JSON only copies half of the JSON

I'm using Webstorm's debugger to inspect local variables for my Node application. However, when I right click on the variable I'm interested in and click Copy JSON, the pasted output only contains half of the JSON.
Has anyone experienced this issue and what did you do to resolve this? Yes, I could console.log the data or write it to a file, but I figured that using a debugger would be more efficient.
Thanks in advance,
Q
Yes, I have seen this too. Not sure what causes it. Here is a workaround:
Try switching to the console tab and saving variable out as a JSON string as follows:
JSON.stringify(myvar);
Then copy the results and, if necessary, parse it elsewhere with:
JSON.parse('..data goes here..')
Don't forget to use single quotes because the JSON contains double quotes everywhere.

Node fs.watch to read changes only

fs.watch('log-file', function(event, filename) {}); only returns the file name that was changed.
Is it possible to only get what was actually changed? I don't want to read the entire file, and rather want to know what was modified from my file (in my case, there is always addition to a log file. nothing ever gets erased).
It seems that you are looking to solve a similar problem to How to do `tail -f logfile.txt`-like processing in node.js?
As per the first response I would look into the the node-tail module.

get result from extendscript runs by node js

I have a nodejs code, that exec an extendscript code, and i need to get a result from the extendscript if the code result is true or false(like return or something else).
The only way that I found is to create a flag-file when the extendscript finished, and then to check it in the node.
Is there a better way doing this?
Thank you all!
I'm assuming that you can edit extendscript since you have mentioned 'you can create flag-file'.
In your extendscript instead of creating flag-file write the boolean value in standard output.
In your parent script (which is actually calling the extendsscript) use something like
var cp = exec('extendsscript');
cp.stdout.on('data', function(data) {
// do whatever you want to do with the data. Might have to change encoding
});
Line of advice, if you are planning to get small amount of data (status message) exec is fine but for large amount of data use spawn instead as exec buffers data in memory.
If you install extendscript-stream you can add $.write(JSON.stringify(data)); to your ExtendScript file to pipe data back to Node.js.

MVC3 return File action causes intermittent Excel program error

I have a problem that closely relates to this problem Microsoft Excel Error: "There was a problem sending the command to the program." whereby opening Excel gives There was an error sending a command to the program error.
However, rather than the file existing and being opened or shortcutted-to, I am using MVC3 with an action that generates a bunch of data, generates an excel file (using NPOI), writes it to a MemoryStream and then chucks that to the browser using the built-in return File(etc) ActionResult, with something akin (but shortened here to aid readability) to this:
return File(myMemoryStream, "application/vnd.ms-excel", "filename.xls");
The first time you click the link which fires this action and returns this File - it comes up with the error. if you press ok and try it again it works, and will continue to work... forever
Now I know this is potentially something to do with disabling DDE/plug-ins or something in Excel - but since I'm generating an excel workbook and dumping it to a memory stream rather than opening something that exists permanently on the file system, I'm not sure what options I have to remove the issue.
Any suggestions on how to get around it? Perhaps I have the wrong mime-type?
The Content-Type application/vnd.ms-excel is sending the command to the Browser to open the file in the Browser. Which can be the cause of issue. Try setting the content type to application/x-msexcel.
In your example the browser will try to open an Excel spreadsheet in the browser (if the user has Excel installed).
return File(myMemoryStream, "application/vnd.ms-excel", "filename.xls")
Please make the following change
return File(myMemoryStream, "application/x-ms-excel", "filename.xls")

Resources