Hello, all. I'm not sure whether this behavior of node's is only in a node-webkit context, or not.--I have the following code:function saveFileAs() {var inputSaveAsFile = document.querySelector(inputSaveAsFileId);inputSaveAsFile.addEventListener('change', function(evt) {var textBox = document.querySelector('#theText');var data = textBox.innerHTML;var path = this.value;fs.writeFile(path, data, {encoding: 'ascii'}, function(err) {if (err) throw err;console.log('writeFile succeeded.');});}, false);inputSaveAsFile.click();}I can type something into my contenteditable div that has the id "theText," and use my file menu to come to the saveFileAs function. It opens the file dialog as expected, and I come to the fs.writeFile call. (I have an input with type file and the attribute nwsaveas.) Right before the call:path"C:\node-webkit\experiment\Inigo_Sunday.txt"data"Hallo.<div>My name is Inigo Montoya.</div><div>You killed my father.</div><div>Prepare to die.</div>"After the call I type out the file, and it isn't all the data:
Rick@RicksLaptop /cygdrive/c/node-webkit/experiment $ cat Inigo_Sunday.txt Hallo.<div>My name is Inigo Montoya.</div><div>You Rick@RicksLaptop /cygdrive/c/node-webkit/experiment $I am mystified. Does anyone know what's going on?
Regards, Rick
You received this message because you are subscribed to the Google Groups "node-webkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-webkit...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "node-webkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-webkit...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
EventListeners are registered on the same EventTarget with the same parameters, the duplicate instances are discarded. They do not cause the EventListener to be called twice, and since the duplicates are discarded, they do not need to be removed manually with the removeEventListener method.If it were, we would see the output from the console logs on lines 57 & 58
--
You received this message because you are subscribed to the Google Groups "node-webkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-webkit...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi, Anatoly.At first I thought "That's it!" Then I realized the event handler isn't being called. If it were, we would see the output from the console logs on lines 57 & 58. Only the callback from the call to fs.writeFile is being called.Also, I found this in Mozilla's Developer Network:If multiple identicalEventListeners are registered on the sameEventTargetwith the same parameters, the duplicate instances are discarded. They do not cause theEventListenerto be called twice, and since the duplicates are discarded, they do not need to be removed manually with the removeEventListener method.It was an oversight on my part to set the event handler over and over, and I'll take it out, but I don't think it's the cause of the trouble.
On Monday, April 14, 2014 9:26:25 PM UTC-5, Anatoly Pashin wrote:You just create new event listener on every click. This way you got it incrementing each time. You've to attach it once or create new <input> each click instead of var inputSaveAsFile = document.querySelector(inputSaveAsFileId);
Hi,
I can't wrap my head around that encoding. Could you post a sample of your index.html to test?
Also try setting an encoding on the index.html document it self to utf-8 and see if that helps. That way nw will use that encoding on the entire content instead of auto picking one.
<html>
<head> Hello, Laszlo.I have solved the multiple-handlers problem. The remaining problem is the encoding, and getting the whole string written to disk.I added this to my <head> section, per your suggestion.<meta charset="utf-8"/>It didn't appear to affect the outcome.
Something I don't understand that might be involved is that when I ask the file command to evaluate my html file, it reports an error.Rick@RicksLaptop /cygdrive/c/Abe/node-webkit/experiment$ file index.htmlindex.html: ERROR: line 163: regex error 17, (illegal byte sequence)I'm using Brackets to edit my files. Could it write its files in some strange format?
I could just use utf16le and call it good. But I hate to got forward when I don't understand. It might bite me later, in unexpected ways.
1.Is the Raptor editor itself open source? Is the code available for inspection?The dialogs are nice. I am past the getting the file name from the dialogs now, and want to write my data to disk. I suspect the way that your editor handles encoding will illuminate things for me.
2.The only encoding that works is utf16le. If I use utf8, or ascii, the whole file doesn't get written.That doesn't make sense to me. It seems to me that once I have my data in a Javascript string, Javascript knows how it's encoded. If fs.writeFile writes the data to disk using a particular encoding, it should appear on the disk in that encoding.Thanks for any ideas.Rick
On Monday, April 14, 2014 10:49:02 PM UTC-5, Rick H. wrote:Hi, Laszlo.I responded to your questions below.Regards, Rick
On Monday, April 14, 2014 10:30:03 PM UTC-5, LZAntal wrote:Hi,To avoid all those event issues you could use this https://github.com/lzantal/LZADialogThat looks really good!I can't wrap my head around that encoding. Could you post a sample of your index.html to test?I assume you mean attach it as a file right here. Well, I'm not proud of the file, but humility is a virtue, right?Also try setting an encoding on the index.html document it self to utf-8 and see if that helps. That way nw will use that encoding on the entire content instead of auto picking one.Do you mean this?<html> <head><meta http-equiv="Content-Type" content="text/html; Charset=UTF-8" />
$ file index.htmlindex.html: ERROR: line 163: regex error 17, (illegal byte sequence)
--
You received this message because you are subscribed to the Google Groups "node-webkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-webkit...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
OK, check it. Looks like you'd better show all your sources so we all can test this very very strange case.
function utfTrick(text){text=(0xFEFF==text.charCodeAt(0)?text.substring(1):text);text='\ufeff'+text;text=(0xFEFF==text.charCodeAt(0)?text.substring(1):text);return text;}