UNPKG

causeway-standard-theme

Version:

114 lines (92 loc) 3.31 kB
(function (window, $) { 'use strict'; // Lightbox modal -- change overlay color to white by adding a class name to the body. var lightbox = $('.modal.lightbox'); var getPromptModal = function (message) { return $("<div class='modal fade' id='alert_lightbox' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>" + "<div class='modal-dialog'>" + "<div class='modal-content'>" + "<div class='modal-header'>" + "<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>&times;</button>" + "<h4 id='myModalLabel' class='modal-title'>Dialogue Title</h4>" + "</div>" + "<div class='modal-body'>" + message + "</div>" + "<div class='modal-footer'>" + "<a href='javascript:void(0);' data-dismiss='modal'>No</a>" + "<button type='button' data-dismiss-lightbox='lightbox' class='btn btn-default'>" + "Yes" + "</button>" + "</div>" + "</div>" + "</div>" + "</div>"); }; lightbox.each(function () { var $this = $(this); if ($this.data('close-background') === false) { $this.modal({ 'show': false, 'backdrop': 'static' }); } var cancelBtn = $('[data-close-prompt]', $this), promptMessage = (cancelBtn.length > 0) ? cancelBtn.data('close-prompt') : '', promptModal = getPromptModal(promptMessage), promptYesBtn = $('[data-dismiss-lightbox]', promptModal); if (cancelBtn.length > 0) { cancelBtn.on('click', function () { promptModal.modal('show'); }); promptModal.on('show.bs.modal', function () { promptYesBtn = $('[data-dismiss-lightbox]'); }); promptYesBtn.on('click', function () { $('.modal').modal('hide'); }); } }); $(document).on('show.bs.modal', lightbox, function () { $('body').addClass('lightbox-modal'); }); var getModalBodyHeight = function (el) { return $('.modal-body', el)[0].scrollHeight; }; var modalBodyHeight = 0; var lightboxCustomScroll = function () { var thisEl = $('.modal.lightbox:visible'); if (thisEl.length > 0) { var modalDialogHeight = $('.modal-dialog', thisEl)[0].clientHeight - 165; modalBodyHeight = !!modalBodyHeight ? modalBodyHeight : $('.modal-body', thisEl)[0].clientHeight; if (modalBodyHeight > modalDialogHeight) { $('.modal-content', thisEl).css('height', '100%'); } else { $('.modal-content', thisEl).css('height', 'auto'); } } }; Causeway.lightboxCustomScroll = lightboxCustomScroll; $(document).on('shown.bs.modal', lightbox, function (e) { modalBodyHeight = getModalBodyHeight(e.target); lightboxCustomScroll(); $('.has-tooltip').each(function (index, element) { var $this = $(element), $parent = $this.parent(); $this.tooltip({ container: $parent, placement: 'bottom', delay: { show: 300, hide: 300 } }); }); // Causeway.initPostDynamic(); }); $(document).on('hidden.bs.modal', lightbox, function () { // $('.lightbox .modal-body').scrollbar('destroy'); $('body').removeClass('lightbox-modal'); }); // $(window).resize(lightboxCustomScroll); }(window, jQuery));