/*
* Interspire Modal 1.0
* (c) 2008 Interspire Pty. Ltd.
*
* Based on SimpleModal 1.1.1 - jQuery Plugin
* http://www.ericmmartin.com/projects/simplemodal/
* http://plugins.jquery.com/project/SimpleModal
* http://code.google.com/p/simplemodal/
*
* Copyright (c) 2007 Eric Martin - http://ericmmartin.com
*
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* Revision: $Id$
*
*/
(function ($) {
$.iModal = function(options) {
return $.iModal.modal.init(options);
};
$.modal = function() {
};
$.modal.close = function () {
return $.iModal.modal.close(true);
};
$.iModal.close = function () {
return $.iModal.modal.close(true);
};
$.fn.iModal = function (options) {
options = $.extend({}, {
type: 'inline',
inline: $(this).html()
}, options);
return $.iModal.modal.init(options);
};
$.iModal.defaults = {
overlay: 50,
overlayCss: {},
containerCss: {},
close: true,
closeTitle: 'Close',
onOpen: null,
onShow: null,
onClose: null,
onBeforeClose: null,
type: 'string',
width: '630',
buttons: '',
title: ''
};
$.iModal.modal = {
options: null,
init: function(options) {
// Can\'t have more than one modal window open at a time
if($('#ModalContentContainer').length > 0) {
return this;
}
this.options = $.extend({}, $.iModal.defaults, options);
if(this.options.type == 'inline') {
this.options.data = $(this.options.inline).html();
$(this.options.inline).html('');
}
this.generateModal();
return this;
},
displayModal: function(data)
{
this.hideLoader();
modalContent = '';
if(!$.browser.msie || $.browser.version >= 7) {
modalContent = '
')
.attr('id', 'ModalContainer')
.addClass('modalContainer')
.css(cssProperties)
.hide()
.appendTo('body')
.html('
'+modalContent+'
')
;
if($('#ModalContainer').find('.ModalButtonRow, #ModalButtonRow').length > 0) {
$('#ModalContainer').addClass('ModalContentWithButtons');
}
if(this.options.close) {
modal = this;
$('
')
.addClass('modalClose')
.attr('title', this.options.closeTitle)
.appendTo('#ModalContainer')
.click(function(e) {
e.preventDefault();
modal.close();
})
;
$(document).bind('keypress', function(e) {
if(e.keyCode == 27) {
$('#ModalContainer .modalClose').click();
}
});
}
if($.isFunction(this.options.onOpen)) {
this.options.onOpen.apply(this);
}
else {
$('#ModalContainer').show();
if($.isFunction(this.options.onShow)) {
this.options.onShow.apply(this);
}
}
},
showLoader: function()
{
$('
')
.attr('id', 'ModalLoadingIndicator')
.appendTo('body');
;
},
showOverlayLoader: function(){
$('
')
.attr('id', 'ModalOverlay')
.addClass('modalOverlay')
.css({
opacity: 50 / 100,
height: '100%',
width: '100%',
position: 'fixed',
left: 0,
top: 0,
zIndex: 3000
})
.appendTo('body')
;
$('
')
.attr('id', 'ModalLoadingIndicator')
.appendTo('body');
;
},
hideOverlayLoader: function(){
$('#ModalLoadingIndicator').remove();
$('.modalOverlay').remove();
},
hideLoader: function()
{
$('#ModalLoadingIndicator').remove();
},
generateModal: function()
{
$('
')
.attr('id', 'ModalOverlay')
.addClass('modalOverlay')
.css({
opacity: this.options.overlay / 100,
height: '100%',
width: '100%',
position: 'fixed',
left: 0,
top: 0,
zIndex: 3000
})
.appendTo('body')
;
if($.browser.msie && $.browser.version < 7) {
wHeight = $(document.body).height()+'px';
wWidth = $(document.body).width()+'px';
$('#ModalOverlay').css({
position: 'absolute',
height: wHeight,
width: wWidth
});
$('
')
.attr('src', 'javascript:false;')
.attr('id', 'ModalTempiFrame')
.css({opacity: 0, position: 'absolute', width: wWidth, height: wHeight, zIndex: 1000, top: 0, left: 0})
.appendTo('body')
;
}
this.showLoader();
if(this.options.type == 'ajax') {
modal = this;
data = {};
if(this.options.urlData != undefined) {
data = this.options.urlData;
}
$.ajax({
url: this.options.url,
success: function(data) {
modal.displayModal(data);
},
data: data
});
}
else {
this.displayModal(this.options.data);
}
},
close: function(external)
{
if($.isFunction(this.options.onBeforeClose)) {
this.options.onBeforeClose.apply(this, []);
}
if(this.options.type == 'inline') {
$(this.options.inline).html(this.options.data);
}
if($.isFunction(this.options.onClose) && !external) {
this.options.onClose.apply(this);
}
else {
$('#ModalContainer').remove();
}
$('#ModalLoadingIndicator').remove();
$('#ModalOverlay').remove();
$('#ModalTempiFrame').remove();
}
};
})(jQuery);
function ModalBox(title, content){
var str = '
'+title+'
'+content+ '
';
$.iModal({ data: str });
}
function ModalBoxInline(title, content, width, withCloseButton){
if(typeof(width) == 'undefined'){
var width = 800;
}
if(typeof(withCloseButton) == 'undefined'){
var withCloseButton = false;
}
if(withCloseButton){
var str = '
'+title+'
'+$(content).html()+ '
';
}else{
var str = '
'+title+'
'+$(content).html()+ '
';
}
$.iModal({ 'data': str, 'width':width });
}