var maxModal; jQuery(document).ready(function(jq) { $ = jq; maxModal = function maxModal() { } maxModal.prototype = { currentModal: null, modals: [], controls: [], parent: '#maxbuttons', // modal will be written to this element. multiple: false, windowHeight: false, windowWidth: false, setWidth: false, setHeight: false, target: false, } maxModal.prototype.init = function() { this.windowHeight = $(window).height(); this.windowWidth = $(window).width(); $(document).off('click', '.maxmodal'); // should be on next update $(document).on('click', '.maxmodal', $.proxy(this.buildModal, this)); $(window).on('resize', $.proxy(this.checkResize, this)); } maxModal.prototype.focus = function() { this.currentModal.show(); } maxModal.prototype.get = function() { return this.currentModal; } maxModal.prototype.show = function() { $('.maxmodal_overlay').remove(); $('body').removeClass('max-modal-active'); this.writeOverlay(); this.currentModal.show(); if (this.setWidth) { this.currentModal.width(this.setWidth); } if (this.setHeight) { this.currentModal.height(this.setHeight); } $m = this.currentModal; var headerHeight = $m.find('.modal_header').outerHeight(); var contentHeight = $m.find('.modal_content').outerHeight(); var contentWidth = $m.find('.modal_content').width(); var controlsHeight = $m.find('.modal_controls').outerHeight(); var modalHeight = headerHeight + contentHeight + controlsHeight; //this.currentModal.height(); var modalWidth = contentWidth; //this.currentModal.width(); var top = (this.windowHeight - modalHeight) / 2; var left = (this.windowWidth - modalWidth) / 2; if (top < 30) { top = 30; // top + admin bar } if (left < 0) { left: 0; } if (modalHeight > this.windowHeight) // if height is higher than screen supports { newHeight = this.windowHeight - top - 5; this.currentModal.height(newHeight); var newContentH = newHeight - headerHeight - controlsHeight; $m.find('.modal_content').height(newContentH); } this.currentModal.css('left', left + 'px'); this.currentModal.css('top', top + 'px'); this.currentModal.css('height', modalHeight); $('.maxmodal_overlay').show(); $('body').addClass('max-modal-active'); $(document).off('keydown', $.proxy(this.keyPressHandler, this)); $(document).on('keydown', $.proxy(this.keyPressHandler, this)); this.currentModal.focus(); } maxModal.prototype.keyPressHandler = function (e) { if (e.keyCode === 27) this.close(); } maxModal.prototype.checkResize = function () { this.windowHeight = $(window).height(); this.windowWidth = $(window).width(); if (this.currentModal === null) return; this.currentModal.removeAttr('style'); this.currentModal.find('.modal_content').removeAttr('style'); this.currentModal.removeAttr('style'); // redo sizes, repaint. this.show(); } maxModal.prototype.close = function() { this.currentModal.trigger('modal_close', [this]); this.currentModal.remove(); this.currentModal = null; $('.maxmodal_overlay').remove(); $('body').removeClass('max-modal-active'); $(document).off('keydown', $.proxy(this.keyPressHandler, this)); } maxModal.prototype.fadeOut = function (timeOut) { if (typeof timeOut == undefined) timeOut = 600; var self = this; this.currentModal.fadeOut(timeOut, function() { self.close(); } ); } maxModal.prototype.setTitle = function(title) { this.currentModal.find('.modal_title').text(title); } maxModal.prototype.resetControls = function() { this.controls = []; } maxModal.prototype.setControls = function(controls) { var content = this.currentModal.find('.modal_content'); var controldiv = $('