This repository has been archived on 2025-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
drupalcampbristol/web/modules/contrib/webform/js/webform.element.image_file.modal.js

36 lines
994 B
JavaScript
Raw Normal View History

2018-11-23 12:29:20 +00:00
/**
* @file
* JavaScript behaviors for webform_image_file modal.
*/
(function ($, Drupal) {
'use strict';
/**
* Display webform image file in a modal.
*
* @type {Drupal~behavior}
*/
Drupal.behaviors.webformImageFileModal = {
attach: function (context) {
$('.js-webform-image-file-modal', context).once('js-webform-image-file-modal').on('click', function () {
// http://stackoverflow.com/questions/11442712/get-width-height-of-remote-image-from-url
var img = new Image();
img.src = $(this).attr('href');
img.onload = function () {
$('<div><img src="' + this.src + '" style="display: block; margin: 0 auto" /></div>').dialog({
dialogClass: 'webform-image-file-modal-dialog',
width: this.width + 60,
height: this.height + 100,
resizable: false,
modal: true
}).dialog('open');
};
return false;
});
}
};
})(jQuery, Drupal);