Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I get the quill instance and add an ImageHandler,but work incorrect #43

Closed
HeavyKumamon opened this issue Apr 24, 2017 · 3 comments
Closed

Comments

@HeavyKumamon
Copy link

HeavyKumamon commented Apr 24, 2017

I am using vue2.0,
I get the quill instance, and then add an imageHandler, it is expected accept two params(image,callback),but in fact only one with value true.
here is my code in method mounted()

this.$refs.newEditor.quill.getModule("toolbar").addHandler("image", imageHandler)
@surmon-china
Copy link
Owner

surmon-china commented Apr 24, 2017

addHandler is not a valid quill api.

@LovaszNorbertM
Copy link

https://quilljs.com/docs/modules/toolbar/ excuse me but can you read the last line of code on the page you/your team wrote.

@jaycethanks
Copy link

jaycethanks commented Jun 6, 2022

image

addHandler is valid quill api (now) ,

You can both overwrite the handler in beblow ways:

1. Overwrite Directly

toolbar.handlers.image = function () {
    // do something here
}

2. AddHandler

toolbar.addHandler('image', function(){
    // do something here
})

Note : this in handler function point to Toolbar object, if you want to use it, keep in mind don't write in arrow function way

And the function handler define here is src code :

[[FunctionLocation]]: quill.js?9339:6851

        image: function image() {
          var _this3 = this;

          var fileInput = this.container.querySelector('input.ql-image[type=file]');
          if (fileInput == null) {
            fileInput = document.createElement('input');
            fileInput.setAttribute('type', 'file');
            fileInput.setAttribute('accept', 'image/png, image/gif, image/jpeg, image/bmp, image/x-icon');
            fileInput.classList.add('ql-image');
            fileInput.addEventListener('change', function () {
              if (fileInput.files != null && fileInput.files[0] != null) {
                var reader = new FileReader();
                reader.onload = function (e) {
                  var range = _this3.quill.getSelection(true);
                  _this3.quill.updateContents(new _quillDelta2.default().retain(range.index).delete(range.length).insert({ image: e.target.result }), _emitter2.default.sources.USER);
                  _this3.quill.setSelection(range.index + 1, _emitter2.default.sources.SILENT);
                  fileInput.value = "";
                };
                reader.readAsDataURL(fileInput.files[0]);
              }
            });
            this.container.appendChild(fileInput);
          }
          fileInput.click();
        },

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants