You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
first of all thanks for your great work. I really apprechiate resizing images in an editor like you made it possible!
I am using quill-blot-formatter2 with images, links and even links around images - all with custom blots and custom modals on the frontend.
nevertheless, selecting an image or a linked image, does not toggle the toolbar buttons active. Even if I try to toggle these by hand. whereas selecting a plain link does toggle the link button active.
its just a sneaky suspicion, but it seems the toggled/added class get's removed right away by qbf2. if I turn off quill-blot-formatter2 like commenting out the config, the buttons will get active as you'd wish.
importQuillfrom'quill';constBlockEmbed=Quill.import('blots/block/embed');/** * CustomImageBlot of an Image in Quill Editor * * `this.linkProps` acts as a gatekeeper to prevent unintentional properties * if you want to add new properties to your blot, add them to the array and to static value() * and pass them to your instance methods */exportdefaultclassCustomImageBlotextendsBlockEmbed{staticblotName='customImage';statictagName='div';constructor(scroll,domNode,value){super(scroll.scroll,domNode);this.link=domNode.querySelector('a');this.image=domNode.querySelector('img');this.linkProps=['href','target','aria-label'];this.imageFloatingClassTemplate='ql-image-float-';this.imageFloatingActiveClass='';}staticcreate(value){constnode=super.create();constimage=document.createElement('img');image.setAttribute('src',value.src);if(value.alt)image.setAttribute('alt',value.alt);if(value.copyright)image.setAttribute('data-copyright',value.copyright);if(value.width)image.setAttribute('width',value.width);if(value.height)image.setAttribute('height',value.height);if(value.link){constlink=document.createElement('a');link.setAttribute('href',value.link.href);link.setAttribute('target',value.link.target);link.setAttribute('aria-label',value.link.ariaLabel);link.appendChild(image);node.appendChild(link);returnnode;}node.appendChild(image);returnnode;}staticvalue(node){constimage=node.querySelector('img');constlink=node.querySelector('a');try{constv={src: image.getAttribute('src'),alt: image.getAttribute('alt'),copyright: image.getAttribute('data-copyright'),width: image.getAttribute('width'),height: image.getAttribute('height'),};if(link)v['link']={href: link.getAttribute('href'),target: link.getAttribute('target'),ariaLabel: link.getAttribute('aria-label'),};returnv;}catch(e){returntrue;}}/** * wraps the image with an anchor tag * @param {{ href: string, target: '_self' | '_blank' }} linkAttributes */createImageAnchorWrapper(linkAttributes){if(this.link)thrownewError('Cannot wrap an existing Anchor!');if(!linkAttributes.href||!linkAttributes.target||!linkAttributes)thrownewError('Missing link properties!');constlink=document.createElement('a');Object.keys(linkAttributes).forEach(attribute=>{// make sure to attach only defined attributesif(this.linkProps.findIndex(item=>item===attribute)!==-1){link.setAttribute(attribute,linkAttributes[attribute]);}});link.appendChild(this.image);this.domNode.appendChild(link);returnthis;}/** * edit existing anchor-wrapper of the image * @param {{ href: string, target: '_self' | '_blank', aria-label: string }} linkAttributes */editImageAnchorWrapper(linkAttributes){if(!this.link)thrownewError('Missing Anchor-Wrapper');Object.keys(linkAttributes).forEach(attribute=>{// make sure to attach only defined attributesif(this.linkProps.findIndex(item=>item===attribute)!==-1){this.link.removeAttribute(attribute);this.link.setAttribute(attribute,linkAttributes[attribute]);}});returnthis;}/** * removes existing anchor-wrapper from the image */removeImageAnchorWrapper(){if(!this.link)thrownewError('Missing Anchor-Wrapper');this.domNode.removeChild(this.link);this.domNode.appendChild(this.image);returnthis;}/** * floats an image * @param {"right" | "left" | "full" | null} value */floatImage(value){if(value){constclassName=`${this.imageFloatingClassTemplate}${value}`;if(this.imageFloatingActiveClass){this.image.classList.remove(this.imageFloatingActiveClass);this.image.classList.add(className);}else{this.image.classList.add(className);}this.imageFloatingActiveClass=className;}elsethis.image.classList.remove(this.imageFloatingActiveClass);returnthis;}}
How can I take influence on that behavior?
Update:
I managed to handle toolbar-button active-state by myself with two click listeners
The key here is to set a timeout to let events populate properly within quill and then toggle the class
This does the job, but still doesn't really feel naturally.
Another sideffect is now, when resizing the image, active-class still gets vanished, so the buttons turn 'off'
The text was updated successfully, but these errors were encountered:
Hi,
first of all thanks for your great work. I really apprechiate resizing images in an editor like you made it possible!
I am using quill-blot-formatter2 with images, links and even links around images - all with custom blots and custom modals on the frontend.
nevertheless, selecting an image or a linked image, does not toggle the toolbar buttons active. Even if I try to toggle these by hand. whereas selecting a plain link does toggle the link button active.
this is what my page looks like using qbf2:

this is without:
its just a sneaky suspicion, but it seems the toggled/added class get's removed right away by qbf2. if I turn off quill-blot-formatter2 like commenting out the config, the buttons will get active as you'd wish.
This is my config:
These are my custom blots:
How can I take influence on that behavior?
Update:
I managed to handle toolbar-button active-state by myself with two click listeners
The key here is to set a timeout to let events populate properly within quill and then toggle the class
This does the job, but still doesn't really feel naturally.
Another sideffect is now, when resizing the image, active-class still gets vanished, so the buttons turn 'off'
The text was updated successfully, but these errors were encountered: