if(!I18n) {
var I18n = {
trans: function(s) { return s; }
};
}
var DialogUtil = function(){
var _innerDialogTpl = '
',
_innerDialogWrapperHeight = 140;
/**鑾峰彇鏁翠釜椤甸潰鐨勯珮搴?/
function getTotalHeight(){
if(jQuery.browser.msie){
return document.compatMode == "CSS1Compat"? document.documentElement.clientHeight :
document.body.clientHeight;
}else{
return self.innerHeight;
}
}
function showInnerDialog(options, html) {
var innerHtmlFirst = '',
innerHtmlLast = '';
if(options.close) {
innerHtmlFirst = '';
}
if(options.title || innerHtmlFirst) {
innerHtmlFirst = '';
}
innerHtmlFirst += '';
if(options.buttons) {
innerHtmlLast += '';
}
var blockUICssOptions = {
border: 'none',
backgroundColor: 'transparent',
top: options.top,
cursor: 'default',
'text-align': 'left'
},
blockUIOptions = {
focusInput: options.focusInput,
fadeIn: 1000,
//do not want key and mouse events to be disabled for content that is blocked
//fix bug:閲岄潰鏈塪atepicker鐨勮瘽瀵艰嚧澶氭鐐瑰嚮鍚屼竴涓猧nput鏃讹紝鏃犳硶鏄剧ずdatepicker
bindEvents: false,
showOverlay: options.showOverlay,
baseZ: options.zIndex
};
if(options.width) {
blockUICssOptions.width = options.width + 'px';
blockUICssOptions.left = ((jQuery(window).width() - options.width) / 2) + 'px';
}else{
blockUICssOptions.width = '40%';
blockUICssOptions.left = '30%';
}
if(options.height) {
blockUICssOptions.height = (options.height + _innerDialogWrapperHeight) + 'px';
}
if(typeof html == 'string') {
jQuery.blockUI(jQuery.extend({
message: _innerDialogTpl.replace('{content}', innerHtmlFirst + html + innerHtmlLast),
css: blockUICssOptions
}, blockUIOptions));
}else{
//鎻掑叆鐨勬槸涓€涓璞
jQuery.blockUI(jQuery.extend({
message: jQuery(html),
css: blockUICssOptions,
fadeIn: 1000
}, blockUIOptions));
//鍖呬釜澶栧3锛屼究浜庢坊鍔犳寜閽拰淇敼鏍峰紡
var container = jQuery(_innerDialogTpl.replace('{content}', innerHtmlFirst + innerHtmlLast));
jQuery('.blockPage').append(container);
container.find('.popup-center').append(jQuery(html));
}
if(options.buttons) {
for(var i = 0; i < options.buttons.length; i++) {
var b = options.buttons[i];
var btn = jQuery('');
btn.click(b.callback);
btn.appendTo(jQuery('#popupButtons'));
}
}
//鍒濆鍖栧悗鐨勫洖璋冩柟娉
if(typeof options.initCallback == 'function') {
options.initCallback();
}
//鍏抽棴鍚庣殑鍥炶皟鏂规硶
if(options.close && typeof options.closeCallback == 'function') {
jQuery(".close a:first-child").removeAttr("onclick").click(function(){
jQuery.unblockUI();
options.closeCallback();
});
}
//淇濊瘉鍦ㄤ竴涓〉闈腑鑳芥樉绀轰笅
var dialogHeight = jQuery('.blockPage .popup-dialog').height(),
offset = jQuery('.blockPage .popup-dialog').offset(),
winHeight = getTotalHeight();
if((offset.top + dialogHeight) > winHeight) {
if(dialogHeight >= winHeight) {
jQuery('.blockPage').css({ top: '5px'} );
jQuery('.blockPage .popup-dialog .popup-center').css({ height: (winHeight - _innerDialogWrapperHeight - 10) + 'px' });
}else{
jQuery('.blockPage').css({ top: ((winHeight - dialogHeight) / 2) + 'px' } );
}
}else if(!options.top) {
//濡傛灉娌℃湁鎸囧畾top鍊肩殑璇濓紝鑷姩鍨傜洿灞呬腑
jQuery('.blockPage').css({ top: ((winHeight - dialogHeight) / 2) + 'px' } );
}
}
return {
showDialogProcessMsg: function(){
var btns = P && P.document.getElementById('btns');
if(btns) {
btns.style.display = 'none';
Message.success(jQuery('body'), '\t 澶勭悊涓?..', -1, {left : 0, top : 0});
}
},
hideDialogProcessMsg:function(btnName){
var btns = P && P.document.getElementById('btns');
if(btns) {
btns.style.display = '';
Message.hide();
}
},
innerDialog: function(options) {
options = options || {};
options.close = (typeof options.close == 'undefined')? true : options.close;
options.title = options.title || '';
if(options.title) {
options.title = I18n.trans(options.title);
}
if(options.url) {
jQuery.blockUI({
message: '
杞藉叆涓?..',
showOverlay: false,
css: {
border: 'none',
padding: '15px',
background: 'transparent',
opacity: .5,
top: '50%',
color: 'black',
'z-index': '999'
}
});
options.url = appEncodeURL(options.url);
options.url += '&_' + new Date().getTime();
jQuery.get(options.url, {}, function(data){
showInnerDialog(options, data);
});
}else{
showInnerDialog(options, options.html);
}
},
adjustDialogHeight: function(dialogHeight){
var winHeight = $(window).height();
if((typeof dialogHeight=='undefined') || winHeight<(dialogHeight + _innerDialogWrapperHeight)){
dialogHeight = winHeight-_innerDialogWrapperHeight;
jQuery('.blockPage').css({ top: '5px'} );
}else{
jQuery('.blockPage').css({ top: ((winHeight - dialogHeight - _innerDialogWrapperHeight) / 2) + 'px' } );
}
jQuery('.blockPage .popup-dialog .popup-center').css({ height: (dialogHeight-10) + 'px' });
},
constructWapperHtml: function(html, options) {
options = options || {};
var innerHtmlFirst = '',
innerHtmlLast = '';
if(options.closeFunc) {
innerHtmlFirst = '';
}
if(options.title || innerHtmlFirst) {
innerHtmlFirst = '';
}
innerHtmlFirst += '';
if(options.buttons) {
innerHtmlLast += '';
}
return _innerDialogTpl.replace('{content}', innerHtmlFirst + html + innerHtmlLast);
}
};
}();
var AppDialog = {
open : function(options) {
var position = {};
if(options.top) {
position['top'] = options.top;
}else{
//榛樿鏄剧ず鍦ㄩ《閮
position['top'] = 0;
}
if(options.left) {
position['left'] = options.left;
}
var d = (typeof D != 'undefined' && D) ? D.lhgdialog : lhgdialog;
var pin = true;
if(((typeof options.pin) + '') != 'undefined') {
pin = options.pin;
}
var onloadEvent = null;
if(options.buttons) {
onloadEvent = function() {
var crebtn = (this.contentWindow && this.contentWindow.crebtn);
for(var i = 0; i < options.buttons.length; i++) {
var b = options.buttons[i];
crebtn( b.id, I18n.trans(b.text), b.callback, b['class']);
}
};
}
if(options.html) {
options.link = 'hcode';
options.url = options.html;
}
var resourceContextPath,
htmlContextPath;
if(resourceContextPath) {
htmlContextPath = resourceContextPath;
}else if(window.resourceContextPath) {
htmlContextPath = window.resourceContextPath;
}else if(parent.resourceContextPath){
htmlContextPath = parent.resourceContextPath;
}else{
htmlContextPath = contextPath;
}
if(htmlContextPath.charAt(htmlContextPath.length - 1) != '/') {
htmlContextPath += '/';
}
var template = htmlContextPath + 'thirdparty/lhgdialog/lhgdialog-extra-v5.htm?20140326';
if(options.template) {
template = options.template;
}
d.opendlg(
I18n.trans(options.title),
options.url, //濡傛灉link鏄痟code锛岃繖閲屼负鍐呭椤电殑html浠g爜
options.width||400,
Math.min(options.height||300, jQuery(window).height()),
options.cover || true, //鏄惁甯﹂伄缃╁眰
options.link || true, //鏄惁鏄閮ㄩ摼鎺ワ紝濡傛灉涓篽code鐨勮瘽鍒欒鏄庡唴瀹归〉涓篽tml浠g爜
options.name || 'appDialog', //绐楀彛鍚嶇О
pin, //鏄惁鍥哄畾鍦ㄦ煇涓綅缃紝闅忔粴鍔ㄦ潯婊氬姩
position, //鑷畾涔夌殑浣嶇疆
template, // 閫夋嫨涓嶅悓妯$増
onloadEvent,
options.closeText||I18n.trans('鍙栨秷'),
options.maxSize, //閰嶇疆鏄惁鍙互鏈€澶у寲绐楀彛
options.cancelBtn, //鏄惁鏄剧ず鍏抽棴鎸夐挳
options.theme, //寮瑰嚭妗嗕富棰?娌℃湁鎸囧畾鍒欎娇鐢ㄩ粯璁ょ毊鑲?
options.onClose,
options.win,
options.xButton
);
},
getDialogWindow : function(dialogName){
if(D && D.parent && D.parent.document.getElementById(dialogName)) {
return D.parent.document.getElementById(dialogName).contentWindow.document.getElementById('frmain').contentWindow;
}else if (D && D.document.getElementById(dialogName)) {
return D.document.getElementById(dialogName).contentWindow.document.getElementById('frmain').contentWindow;
}else if(!dialogName && D.document.getElementById('frmain')) {
return D.document.getElementById('frmain').contentWindow;
}
return null;
},
closeDialog : function() {
if(window.parent && window.parent.closedlg) {
window.parent.closedlg();
return true;
}else{
return false;
}
},
close : function(dialogId) {
if(top.document.getElementById(dialogId) && top.document.getElementById(dialogId).contentWindow.closedlg) {
top.document.getElementById(dialogId).contentWindow.closedlg();
return true;
}else{
return false;
}
}
};