//require ScrollHelper.js
function DialogHelper() {
var _this = this;
var doc = window.document;
_this.maskDiv = null;
_this.contentDiv = null;
var options = {
opacity: 0.4
}; this.popup = function (contentdiv, optionArg) {
if (optionArg) {
for (var prop in optionArg) {
options[prop] = optionArg[prop];
}
} _this.contentDiv = contentdiv || _this.contentDiv; _this.maskDiv = $('<div>');
_this.maskDiv.addClass('MaskDiv');
_this.maskDiv.css({
'filter': "Alpha(opacity=" + ( options.opacity - "0" ) * 100 + ");",
'opacity': options.opacity,
'display': 'block'
}); $(doc.body).append(_this.maskDiv); if (_this.contentDiv) {
$(doc.body).append(_this.contentDiv);
_this.contentDiv.show();
_this.contentDiv.draggable({
containment: "document",
cursor: 'move',
handle: ".Dialog_Head"
});
$(_this.maskDiv).on("mousemove", function() {
$("body").preventScroll();
});
$(_this.maskDiv).on("mouseout", function() {
$("body").liveScroll();
});
if ($(".cke").length == 0 && $(".Dialog_Body").length > 0) {
$(".Dialog_Body").preventOuterScroll();
}
}
}; this.remove = function () {
if (_this.contentDiv) {
_this.contentDiv.remove();
}
if (_this.maskDiv) {
_this.maskDiv.remove();
}
$("body").liveScroll();
}; this.formatPercentNumber = function (value, whole) {
if (isNaN(value) && typeof value === "string") {
if (value.indexOf("%") !== -1) {
value = (value.replace("%", "") / 100) * whole;
} else if (value.indexOf("px") !== -1) {
value = value.replace("px", "");
}
}
return Math.ceil(value);
}; this.position = function (dialog, dialogBody, minusHeight) {
dialog = dialog || $(".ShowDialogDiv");
if (dialog[0]) {
var clientWidth = document.documentElement.clientWidth;
var clientHeight = document.documentElement.clientHeight;
var width = _this.formatPercentNumber(dialog.data("position").width, clientWidth) || dialog.width();
var height = _this.formatPercentNumber(dialog.data("position").height, clientHeight) || dialog.height();
width = width < 300 ? 300 : width;
height = height < 450 ? 450 : height;
$(dialog).css({
"width": width + "px",
"height": height + "px",
"top": Math.ceil((clientHeight - height) / 2) + "px",
"left": Math.ceil((clientWidth - width) / 2) + "px"
});
dialogBody = dialogBody || $(".Dialog_Body");
if (dialogBody[0]) {
minusHeight = minusHeight || ($(".Dialog_Head").outerHeight() + $(".Dialog_Foot").outerHeight());
var dialogBodyHeight = height - minusHeight;
dialogBody.height(dialogBodyHeight);
}
}
}
} var createDialogTemplate = function (optionArg, contentHtml, saveBtnClickHandler) {
var options = {
"Action": "",
"Title": "",
"Width": "50%",
"Height": "50%"
};
if (optionArg) {
for (var prop in optionArg) {
options[prop] = optionArg[prop];
}
}
var newDialog = $("<div class='ShowDialogDiv' id='Dialog_" + options.Title + "'>");
var DialogHead = $("<div class='Dialog_Head'>").appendTo(newDialog);
$("<span class='HeadLabel'>").html(options.Action + " " + options.Title).appendTo(DialogHead);
var DialogClose = $("<span class='DialogClose'>").appendTo(DialogHead);
var DialogBody = $("<div class='Dialog_Body'>").html(contentHtml).appendTo(newDialog);
var DialogFoot = $("<div class='Dialog_Foot'>").appendTo(newDialog);
var newDiv = $("<div class='Right'>").appendTo(DialogFoot);
var ActionCancelDiv = $("<div class='ActionButtonContainer' title='Cancel'>").appendTo(newDiv);
DialogClose.on("click", function() {
dialogHelper.remove();
});
ActionCancelDiv.on("click", function() {
dialogHelper.remove();
});
var newA = $("<div class='ActionButton' id='ActionButtonCancel'>").appendTo(ActionCancelDiv);
$("<div class='Icon Cancel'>").appendTo(newA);
$("<div class='Title IconTitle'>").html("Cancel").appendTo(newA);
var ActionSaveDiv = $("<div class='ActionButtonContainer' title='Save'>").appendTo(newDiv);
var newB = $("<div class='ActionButton ActionButtonAttention' id='ActionButtonSave'>").appendTo(ActionSaveDiv);
newB.on('click', function () {
if (typeof saveBtnClickHandler == "function") {
saveBtnClickHandler();
}
});
$("<div class='Icon Save'>").appendTo(newB);
$("<div class='Title IconTitle SaveButton'>").html("Save").appendTo(newB);
var minusHeight = DialogHead.outerHeight() + DialogFoot.outerHeight();
newDialog.data("position", {
width: options.Width,
height: options.Height
});
dialogHelper.position(newDialog, DialogBody, minusHeight);
return newDialog;
}; var changeDialogLayout = function(optionArg, dialogObj) {
var options = {
"Width": "70%",
"Height": "90%"
};
if (optionArg) {
for (var prop in optionArg) {
options[prop] = optionArg[prop];
}
}
var DialogBody = $(dialogObj).find(".Dialog_Body");
var DialogHead = $(dialogObj).find(".Dialog_Head");
var DialogFoot = $(dialogObj).find(".Dialog_Foot");
var other = Math.round(DialogBody.css("padding-top").replace(/[a-z]/ig, "")) + Math.round(DialogBody.css("padding-bottom").replace(/[a-z]/ig, ""));
var minusHeight = DialogHead.outerHeight() + DialogFoot.outerHeight() + other;
dialogObj.data("position", {
width: options.Width,
height: options.Height
});
dialogHelper.position(dialogObj, DialogBody, minusHeight);
};

最新文章

  1. 使用MySQL制作SNP146数据库
  2. 使用 Google Web Fonts
  3. apache htpasswd.exe创建密码
  4. 【Oracle】如何导库
  5. ASP.NET MVC学习系列(一)-WebAPI初探
  6. js控制进度条到达100%跳转界面一
  7. Headless MSBuild Support for SSDT (*.sqlproj) Projects [利用msbuild自动化部署 .sqlproj]- 摘自网络
  8. Append加载动态轮播
  9. [Usaco2007 Dec]穿越泥地[bfs][水]
  10. SQL---约束---add constraint方法添加约束
  11. Laravel框架使用的一些注意细节(一)
  12. vue环境搭建过程中,遇到的坑爹的问题
  13. 利用LogParser将IIS日志插入到数据库
  14. php仿经典省市县三级联动
  15. MySQL基于左右值编码的树形数据库表结构设计
  16. 驰骋工作流引擎JFlow与activiti的对比之2种取消模式
  17. 开源框架.netCore DncZeus学习(一)npm安装
  18. 爬虫----BeautifulSoup模块
  19. 详解Android中的四大组件之一:Activity详解
  20. Android学习之基础知识十三 — 四大组件之服务详解第一讲

热门文章

  1. redis cluster 实践总结
  2. CSS 浏览器兼容
  3. OGG 进程清除、重建
  4. bzoj4763
  5. 如何解决 Matlab 画图时中文显示乱码的问题?
  6. sparse matrix format
  7. 如何让div中的span垂直居中 ----height:100%设置div的高度
  8. Unity DOTS 走马观花
  9. 洛谷P3080 [USACO13MAR]牛跑The Cow Run
  10. codevs 2314 数学作业