简体   繁体   中英

CKEditor image upload: “accept” attribute

Html element "input" has very useful attribute "accept" ( Example ).

When I am uploading image with CKEditor, I can not use this attribute ( Example ), but I want to. How is it possible?

I'm a bit late to the game and this question is very ambiguous, but as I understand it you are trying to upload and image (I am assuming) using CKEditor's built in Image plugin an add the "accept" attribute to the file input. Though this may not be the most elegant way to achieve the result it does successfully default to "Image Files".

In image.js you can add an onClick event to the file element on the upload tab. In the onClick you have access to the input element via this.getInputElement(). there you can set accept to whichever type you would like to default to. Here is the code for the element from the standard plugin after the addition of the onClick:

               {
                    type: 'file',
                    id: 'upload',
                    label: editor.lang.image.btnUpload,
                    style: 'height:40px',
                    size: 38,
                    onClick: function () {
                        var input = this.getInputElement();
                        input.$.accept = 'image/*';
                    }
                }

I believe this will get you what you are looking for that is if all of my assumptions about your question are correct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM