' + this.options.close + '
').css({
top: 0,
left: 0,
width: 0,
height: 0,
position: 'fixed',
'z-index': 9991,
display: 'none'
});
jQuery('body').append(this.container);
this.window.resize(function() {
me.resize();
});
this.container.find('.lightbox-close').on( 'click', function() {
me.close();
});
jQuery(document).keyup(function(e) {
if (e.keyCode == 27) { me.close(); } // esc
});
},
open: function(options) {
this.options = jQuery.extend({
id: 'lightbox',
close: '',
width: 0,
height: 0,
maxWidth: 0,
maxHeight: 0,
minWidth: 0,
minHeight: 0,
widthPercent: 0.6,
heightPercent: 0.8,
content: null,
url: null,
callback: null
}, options);
this.create();
if (this.options.content) {
this.content(this.options.content);
} else if (this.options.url) {
this.load(this.options.url, this.options.callback);
if (window.w3tc_ga) {
var w3tc_action = this.options.url.match(/w3tc_action=([^&]+)/);
if (! w3tc_action || ! w3tc_action[1]) {
w3tc_action = this.options.url.match(/&(w3tc_[^&]+)&/);
}
if (w3tc_action && w3tc_action[1]) {
w3tc_ga(
'event',
'pageview',
{
eventLabel: 'overlays/' + w3tc_action[1]
}
);
}
}
}
W3tc_Overlay.show();
this.container.show();
},
close: function() {
if (this.options.onClose)
this.options.onClose();
this.container.remove();
W3tc_Overlay.hide();
},
resize: function() {
var width = (this.options.width ? this.options.width : this.window.width() * this.options.widthPercent);
var height = (this.options.height ? this.options.height : this.window.height() * this.options.heightPercent);
if (!this.options.maxWidth)
this.options.maxWidth = this.window.width();
if (!this.options.maxHeight)
this.options.maxHeight = this.window.height();
if (this.options.maxWidth && width > this.options.maxWidth) {
width = this.options.maxWidth;
} else if (width < this.options.minWidth) {
width = this.options.minWidth;
}
if (this.options.maxHeight && height > this.options.maxHeight) {
height = this.options.maxHeight;
} else if (height < this.options.minHeight) {
height = this.options.minHeight;
}
this.container.css({
width: width,
height: height
});
this.container.css({
top: (this.window.height() / 2 - this.container.outerHeight() / 2)>=0 ? this.window.height() / 2 - this.container.outerHeight() / 2 : 0,
left: (this.window.width() / 2 - this.container.outerWidth() / 2)>=0 ? this.window.width() / 2 - this.container.outerWidth() / 2 : 0
});
jQuery('.lightbox-content', this.container).css({
width: width,
height: height
});
},
load: function(url, callback) {
this.content('');
this.loading(true);
var me = this;
jQuery.get(url, {}, function(content) {
me.loading(false);
if (content.substr(0, 9) === 'Location ') {
w3tc_beforeupload_unbind();
window.location = content.substr(9);
return;
}
me.content(content);
if (callback) {
callback.call(this, me);
}
});
},
/**
* adds all controls of the form to the url
*/
load_form: function(url, form_selector, callback) {
data = {};
var v = jQuery(form_selector).find('input').each(function(i) {
var name = jQuery(this).attr('name');
var type = jQuery(this).attr('type');
if (type == 'radio' || type == 'checkbox' ) {
if (!jQuery(this).prop('checked'))
return;
}
if (name)
data[name] = jQuery(this).val();
});
this.content('');
this.loading(true);
var me = this;
jQuery.post(url, data, function(content) {
me.loading(false);
if (content.substr(0, 9) === 'Location ') {
w3tc_beforeupload_unbind();
window.location = content.substr(9);
return;
}
me.content(content);
if (callback) {
callback.call(this, me);
}
});
},
content: function(content) {
return this.container.find('.lightbox-content').html(content);
},
width: function(width) {
if (width === undefined) {
return this.container.width();
} else {
this.container.css('width', width);
return this.resize();
}
},
height: function(height) {
if (height === undefined) {
return this.container.height();
} else {
this.container.css('height', height);
return this.resize();
}
},
loading: function(loading) {
if (loading)
this.container.find('.lightbox-content').addClass('lightbox-loader');
else
this.container.find('.lightbox-content').removeClass('lightbox-loader');
},
show_spinner: function() {
this.container.find('.lightbox-spinner').show(); // Show the spinner
this.container.find('.lightbox-content').css('opacity', '0.5'); // Gray out the modal
this.container.find('input, button, a').prop('disabled', true); // Disable other interactions
},
hide_spinner: function() {
this.container.find('.lightbox-spinner').hide(); // Hide the spinner
this.container.find('.lightbox-content').css('opacity', '1'); // Restore the modal opacity
this.container.find('input, button, a').prop('disabled', false); // Enable interactions
}
};
var W3tc_Overlay = {
window: jQuery(window),
container: null,
create: function() {
var me = this;
this.container = jQuery('