/** * @file * Bootstrap Modals. */ (function ($, Drupal, Bootstrap) { "use strict"; /** * Extend the Bootstrap Modal plugin constructor class. */ Bootstrap.extendPlugin('modal', function (settings) { return { DEFAULTS: { animation: !!settings.modal_animation, backdrop: settings.modal_backdrop === 'static' ? 'static' : !!settings.modal_backdrop, keyboard: !!settings.modal_keyboard, show: !!settings.modal_show, size: settings.modal_size } }; }); /** * Replace the Bootstrap Modal jQuery plugin definition. * * Replacing this is needed so that the "option" method can return values. */ Bootstrap.replacePlugin('modal', function () { var Modal = this; // Extract the arguments. var args = Array.prototype.slice.call(arguments, 1); // Modal jQuery Plugin Definition. return function (option, _relatedTarget) { var ret = void(0); this.each(function () { var $this = $(this); var data = $this.data('bs.modal'); var options = $.extend({}, Modal.DEFAULTS, $this.data(), typeof option == 'object' && option); if (!data) $this.data('bs.modal', (data = new Modal(this, options))); if (typeof option == 'string') ret = data[option].apply(data, args); else if (options.show) data.show(_relatedTarget); }); // If just one element and there was a result returned for the option passed, // then return the result. Otherwise, just return the jQuery object. return this.length === 1 && ret !== void(0) ? ret : this; } }); /** * Extend Drupal theming functions. */ $.extend(Drupal.theme, /** @lend Drupal.theme */ { /** * Theme function for a Bootstrap Modal. * * @param {object}[variables] * An object with the following keys: * - title: The name of the tab. * * @return {string} * The HTML for the modal. */ bootstrapModal: function (variables) { var settings = drupalSettings.bootstrap || {}; var defaults = { body: '', closeButton: true, description: { content: null, position: 'before' }, footer: '', id: 'drupal-modal', size: settings.modal_size ? settings.modal_size : '', title: Drupal.t('Loading...') }; variables = $.extend(true, {}, defaults, variables); var output = ''; // Build the modal wrapper. var classes = ['modal']; if (settings.modal_animation) { classes.push('fade'); } output += ''; // Return the constructed modal. return output; }, /** * Theme function for a Bootstrap Modal body markup. * * @param {string} id * A unique ID for the modal body div. * @param {string} body * The HTML markup to place in the body. * @param {string|object} description * A description to show. Can either be a string or an object with the * following key/value pairs: * - content: The description value. * - position: (optional) A display setting that can have these values: * - before: The description is displayed before the body. This is the * default value. * - after: The description is display after the body. * - invisible: The description is displayed after the element, hidden * visually but available to screen readers. * * @return {string} * The HTML for the modal close button. */ bootstrapModalBody: function (id, body, description) { var output = ''; output += ''; return output; }, /** * Theme function for a Bootstrap Modal close button. * * @return {string} * The HTML for the modal close button. */ bootstrapModalClose: function () { return ''; }, /** * Theme function for a Bootstrap Modal footer. * * @param {string} [footer] * The HTML markup to place in the footer. * @param {boolean} [force] * Flag to force the rendering of the footer. * * @return {string} * The HTML for the modal footer. */ bootstrapModalFooter: function (footer, force) { return footer || force ? '' : ''; }, /** * Theme function for a Bootstrap Modal header. * * @param {string} [title] * The title for the header. * @param {boolean} [closeButton] * Flag indicating whether or not to show the close button in the header. * * @return {string} * The HTML for the modal header. */ bootstrapModalHeader: function (title, closeButton) { var output = ''; if (title) { closeButton = closeButton !== void(0) ? closeButton : true; output += ''; } return output; } }) })(window.jQuery, window.Drupal, window.Drupal.bootstrap);