Pass Pasted Clipboard Image From CKeditor to Dropzone - ckeditor

We currently have code that handles all our image uploads via Dropzone.js. This includes functionality to paste from the clipboard and upload via dropzone.js, which currently works. This is that event code:
document.onpaste = function(event)
{
alert('pasted');
var items = (event.clipboardData || event.originalEvent.clipboardData).items;
for (index in items) {
var item = items[index];
if (item.kind === 'file') {
// adds the file to your dropzone instance
myDropzone.addFile(item.getAsFile());
}
}
}
Following this, we have added a CKEditor (v4.10) html text editor to that page. The CKEditor has its own clipboard handling built in. If you activate the CKEditor (for example by clicking the text area), the CKEditor effectively takes control of the clipboard from that point. Which is correct, because we want the editor to be able to copy and paste text still.
However, CKEditor does not natively have image uploading built into it. It requires a plugin. But we would prefer not to use this plugin, and rather intercept the paste event, and if the data pasted is an image, pass that along to our dropzone.js handler instead.
While I am able to intercept that event, I am not sure what event data (if any) I can extract from the CKEditor paste event to pass along to the Dropzone handler. Here is the code so far:
var editor = CKEDITOR.instances.NoteText;
editor.on( 'paste', function( event )
{
alert('pasted ck');
console.dir(event);
//myDropzone.addFile(item.getAsFile());
} );
I have tried inspecting the event to see if anything is available for me to use, but don't seem to find anything.
Is what I'm trying to accomplish possible? Is it possible for me to somehow find and pass along the pasted event data from CKEditor to DropZone? Or am I going to have to implement the CKEditor image upload plugin?
Thanks.

Related

How can I allow for image insertion via URL but not uploading?

I'm using CKEditor and I want to allow people to place images by using a URL, but not upload. I can't figure out how to accomplish that. My toolbar is:
toolbar: {
items: [
'heading','|','bold','italic','link','bulletedList','numberedList','|','indent','outdent','alignment','|','HorizontalLine','ImageInsert','BlockQuote','InsertTable','MediaEmbed','Undo','Redo','|','FontColor','FontSize','Strikethrough','Subscript','Superscript'
]
},
Originally it had 'ImageUpload', so I removed that thinking it would work yet the image icon for ImageInsert, when clicked directly, opens the browser file dialog for an upload. You have to hit the down arrow to get the URL. What should I change it to such that clicking the icon opens the URL dialog directly?
Thanks!
PS, I inherited this, I didn't make it initially and as such I have no idea what version of CK it is nor how to determine that, sorry.
Try This :
CKEDITOR.editorConfig = function( config ) {
....
config.removePlugins = 'easyimage, cloudservices';
....
};
Then click on image tab on Editor and insert your Image Url In Url Field

CKEditor is changing my SRC or Href when saving

I am trying to save a link in DotNetNuke (DNN) using the CKEditor for the HTML module.
When I save, the editor will automatically adjust the link.
I am trying to save it as
data-src="#bronze"
The reason for the hashtag is for displaying a fancybox pop-up with hidden content. https://fancyapps.com/fancybox/3/docs/#inline
But the editor adds /portals/2/ in front of this URL.
I have looked at this article below.
CKEditor - Change image source
I assume the CKEditor is saving the SRC and Href links in protected mode for browsers. Is there a way that I can turn this off in the settings?
I did try to change to RAW mode, but it still does the same thing.
I face the same problem on data-fancybox-href, the only solution I can think of is using jQuery / javascript to change back to correct value:
var src = $(".more_info_btn")
$.each(src, function(){
var href = src.attr("data-src")
var hrefArr = href.split("#")
href = "#" + hrefArr[hrefArr.length-1]
$(this).attr("data-src", href)
})

Dropzone - Replace filename with link after upload is complete?

I've integrated dropzone and it's working fine with the files getting uploaded etc. What I'd like to do is hide the progress bar once the upload is successful and replace the filename with a link to the actual upload file automatically. This would happen automatically as each file finished uploading...
Looking at the documentation, I know I should use
this.on("success", function(file, response) {
if (response.success == 'true') {
// hide progress bar '.dz-progress'
// replace .data-dz-name with url from response
}
});
However, I haven't been able to figure out how to get access to that specific html element to replace/hide etc.
Edit: I was able to use css classes from the original dropzone.css to hide/transition the progress bar. Now just need to find a way to replace the filename with an 'a' tag.
For Dropzone 5.x and above
The correct way to update the thumbnail is by modifying the Preview Template in the success callback as follows:
this.on("success", function(file, response) {
// modify the preview template
file.previewTemplate.appendChild(document.createTextNode(response.filePath));
});
Reference tutorial for Dropzone along with server side handling
$('.dz-progress').hide();
or
$(".dz-progress").remove();
and to replace .data-dz-name
$('.data-dz-name').html(url from response);

dropzone.js: Only use file drop only with no output

I have an existing file upload (manual) in my web application. My application already shows existing uploaded files and a way to delete files.
I would like to incorporate the dropzone.js drag and drop into a small target area - but that is all. I don't want dropzone to print/render anything back to the screen - no messages, no images, nothing.
Could someone provide and example of how to configure dropzone for this limited functionality?
You can accomplish this by modifying the stylesheet. For example, setting
.dz-details
{
display:none;
}
will remove the box which shows what was uploaded. By modifying more styles, you should be able to remove the other elements that normally appear.
You can do that on init:
const dropzoneConfig = {
addedfile: file => { console.log(file); }
}
const myDropzone = new Dropzone(myDiv, dropzoneConfig)

CKEditor 4: Replacing code when in editor view

My software allows people to upload images to a "Files" section on my site. I want to allow users to insert those images into a CKEditor 4 instance but I want to control where those images are hosted.
Instead of inserting the following:
<img src="http://domain.com/image.jpg" />
I want it to insert:
<img src="[file:12345678]" />
I can then use PHP to control what URL will be displayed on the website.
The issue is, in the WYSIWYG view of CKEditor, it shows as the image could not be found. Is there anyway I can create a plugin that replaces the [file:12345678] with the image code when in WYSIWYG view but in source view it reverts back to [file:12345678]?
Kind of like how the BBCode plugin works. When you go to source view you see:
The [b]brown fox[/b] jumped over the log
But the editor view you see:
The brown fox jumped over the log
I tried to work out the code from the BBCode plugin but the BBCode parsers seems to be something built-in.
I found the following code but it only applies to the source view. I can't seem to find out if there is a similar function of the WYSIWYG view.
editor.dataProcessor.htmlFilter.addRules(
{
elements :
{
img : function( element )
{
// I can get the src of any image and then replace it.
element.attributes.src
}
}
});
Thanks for any advice you can give ;)
There are two type of filters in htmlDataProcessor (which is the default data processor) - htmlFilter which is used to filter HTML format, so the format used "inside" editor while editing; and dataFilter which is used to filter data format, so the format used "outside" editor - the one you see in source mode or when you call editor.getData(). Those names can be confusing, but it helps when you remember that "data" is outside (because editor.getData()).
So I guess that when loading data to editor (transforming data to HTML) you want to replace [file:\d+] URLs with addresses from some hash and when getting data back (transforming HTML to data) you want to make the opposite transformation.
Therefore you need to extend both filters - htmlFilter and dataFilter. This is how the dataFilter may look:
editor.dataProcessor.dataFilter.addRules( {
elements: {
img: function( el ) {
el.attributes.src = fileIdToUrlHash[ el.attributes.src ];
}
}
} );
Similar operation you have to do in the htmlFilter.

Resources