I'm facing a problem with using ZeroClipboard (https://github.com/zeroclipboard/zeroclipboard) while handling newline characters.
My idea is to copy some HTML content to internal clipboard and paste it into Win32 application (I mean some business app, but it behaves like simple notepad in this situation).
While pasting data into web browser (Chrome), or some other text editing application (like notepad++) everything works fine, but when text is pasted to notepad line breaks are not preserved - in exchange of CRLF there are some unknown character.
Here is sample code:
<?php
$ClipboardText = pack("a*CCa*", "xxx", $newLine0, $newLine, "yy");
print '<button id="d_clip_button" class="d_clip_info" data-clipboard-text="'.$ClipboardText.'">Copy text</button>';
?>
<script>
$(function() {
var clip = new ZeroClipboard($(".d_clip_info"));
});
</script>
I've finally made a tweak in ZeroClipboard to deal with it, here is the code of
var _setData = function(format, data) {
var dataObj;
if (typeof format === "object" && format && typeof data === "undefined") {
dataObj = format;
ZeroClipboard.clearData();
} else if (typeof format === "string" && format) {
dataObj = {};
dataObj[format] = data;
} else {
return;
}
for (var dataFormat in dataObj) {
if (typeof dataFormat === "string" && dataFormat && _hasOwn.call(dataObj, dataFormat) && typeof dataObj[dataFormat] === "string" && dataObj[dataFormat]) {
// Here is the tweak to replace all \n with \r\n characters in data sended to clipboard
_clipData[dataFormat] = dataObj[dataFormat].replace(/\n/g, "\r\n");
}
}
};