js库依赖jquery
//所有对话框ui-dialog居中显示插件, 固定宽高
;
! function($) {
$.fn.setDialogshow = function() {
var that = this;
var w_w = $(window).width();
var w_h = $(window).height();
function Throttle(tf) {
clearTimeout(Throttle.sto);
Throttle.sto = setTimeout(tf, 100);
}
$(window).on('resize', function() {
Throttle(function() {
w_w = $(window).width();
w_h = $(window).height();
$(that).each(function(index, val) {
if ($(this).css('display') != 'none') {
$(this).trigger('open');
}
});
})
});
return this.each(function(index, val) {
var d_w = parseInt($(this).css('width'));
var d_h = parseInt($(this).css('height'));
$(this).on('openDialog', function(event) {
var top = (w_h - d_h) * 2 / 5,
left = (w_w - d_w) / 2;
$(this).css({ 'top': (top > 0 ? top : 0) + 'px', 'left': (left > 0 ? left : 0) + 'px' });
$(this).show();
});
$(this).on('open', function(event) {
var top = (w_h - d_h) * 2 / 5,
left = (w_w - d_w) / 2;
$(this).css({ 'top': (top > 0 ? top : 0) + 'px', 'left': (left > 0 ? left : 0) + 'px' });
$(this).show();
});
$(this).on('close', function(event) {
$(this).hide();
window.mask.hide();
});
$(this).find('.cancel, .close').on('click', function() {
$(val).trigger('close');
});
});
}
}(jQuery);
//所有对话居中
$(function() {
$('.ui-dialog').setDialogshow();
$('.ui-dialog-move').moveDialog();
});