ui icon indicating copy to clipboard operation
ui copied to clipboard

Download button aria-disabled attribute

Open l205306 opened this issue 1 year ago • 1 comments

The PDF was rendered from a Base64 string, but the download button is disabled by default. I want to keep the download button enabled since I have implemented a custom download function.

Below is the approach I've tried so far, but it's not working.

Fancybox.show([
    {
        "src": "data:application/pdf;base64,JVB...",
        "type": "pdf",
        "caption": "Caption - ...",
        "width": "80%",
        "height": "80%"
    },
    {
	"src": "data:image/png;base64,iVB...",
	"type": "image",
	"caption": "Caption - ..."
    }
], {
	on: {
		'Carousel.ready': fancybox => {
			$('button[data-carousel-download]', fancybox.getContainer()).removeAttr('aria-disabled');
		},
		'Carousel.contentReady': instance => {
			$('button[data-carousel-download]', instance.getContainer()).removeAttr('aria-disabled');
		}
	},
	backdropClick: false,
	dragToClose: false,
	Carousel: {
		gestures: false,
		infinite: false,
		Toolbar: {
			display: {
				right: ['download', 'close'],
			},
			items: {
				download: {
					click: instance => {
						const { src, type, caption } = instance.getPage().slides[0];
						const mimeType = type == 'pdf' ? 'application/pdf' : 'image/png';
						const ext = type == 'image' ? '.png' : '.pdf';
						download(src, `${String(caption).replaceAll(new RegExp(/[\s\-]/g), '_')}${ext}`, mimeType);
					}
				}
			}
		}
	}
});

l205306 avatar Jul 21 '25 07:07 l205306

Hi,

Simply do not fight with the existing code and add your own button in the toolbar:

Fancybox.bind("[data-fancybox]", {
  Carousel: {
    gestures: false,
    infinite: false,
    Toolbar: {
      display: {
        right: ['customDownload', 'close'],
      },
      items: {
        customDownload: {
          tpl : '<button class="f-button">D</button>',
          click: (instance) => {
            const { src, type, caption } = Fancybox.getSlide();
            
            const mimeType = type == 'pdf' ? 'application/pdf' : 'image/png';
            const ext = type == 'image' ? '.png' : '.pdf';
            
            alert(`${String(caption).replaceAll(new RegExp(/[\s\-]/g), '_')}${ext}`);
          }
        }
      }
    }
  }
});

https://jsbin.com/zasusogobu/edit?html,output

fancyapps avatar Jul 21 '25 08:07 fancyapps