');
html.push('
#-MESSAGE-#
');
html.push(' ');
html.push('
');
return html.join('\r\n');
})()
};
//各种状态集合
that.status = {
//基础(未整理)
base: {},
//皮肤(未整理)
skin: {},
//默认
defaults: { min: null, max: null, close: null, yes: 'ui-btn-blue', no: 'ui-btn-gray', cancel: 'ui-btn-gray' },
//鼠标靠近
hover: { min: 'ui-xbox-min-focus', max: 'ui-xbox-max-focus', close: 'ui-xbox-close-focus', yes: 'ui-btn-blue-hover', no: 'ui-btn-gray-hover', cancel: 'ui-btn-gray-hover' },
//鼠标按下
down: { min: null, max: null, close: null, yes: null, no: null, cancel: null },
//禁用
disabled: { min: null, max: null, close: null, yes: 'ui-btn-disable', no: 'ui-btn-disable', cancel: 'ui-btn-disable' }
};
//各种自定义属性
that.dataAttr = {
//XBox唯一标识
dataIdentity: 'data-identity',
//XBox是否绑定事件
dataEventIsBind: 'data-event-isBind'
};
};
var BoxConfigInstance = new BoxConfig();
var BoxLang = function () {
var that = this;
//加载中提示语
that.loading = '正在加载,请稍后...';
that.titleLoading = '正在连接...';
//操作失败提示语
that.error = '抱歉,操作失败!';
that.titleError = '连接失败';
};
var BoxLangInstance = new BoxLang();
that.RenderBox = function (options) {
var that = this;
var BoxModel = function (model) {
var that = this;
//静态弹出框模板
that.xbox = model.xbox || null;
//静态背景遮罩
that.mask = model.mask || null;
//宽度
that.width = model.width || 200;
//高度
that.height = model.height || 50;
//初始化属性
that.initAttribute = isTrue(model.initAttribute) ? true : false;
//目标路径
that.url = model.url || null;
//加载类型(ajax|iframe)
that.loadType = model.loadType || 'ajax';
//是否加载完成
that.isCompleteLoad = false;
//加载一次
that.loadOnce = isFalse(model.loadOnce) ? false : true;
//请求附带数据集合对象
that.data = model.data || null;
//内容
that.content = model.data || '[空白面板]';
//标题
that.title = model.title || '[无标题]';
//是否可拖动
that.isDrag = isFalse(model.isDrag) ? false : true;
//每次关闭xbox时,是否作为隐藏处理(true.隐藏 false.直接删除)
that.isHidden = isFalse(model.isHidden) ? false : true;
//是否为模态窗口
that.isModal = isFalse(model.isModal) ? false : true;
//是否需要背景遮罩
that.isMask = isFalse(model.isMask) ? false : true;
//是否允许改变大小
that.isResize = isTrue(model.isResize) ? true : false;
//最小宽度和高度
that.min = { width: 240, height: 60 };
//最大宽度和高度
that.max = { width: 'auto', height: 'auto' };
//将弹出框添加到
that.appendTo = model.appendTo || null;
//按钮集合
that.buttons = {
//最小化窗体
min: { type: 'system', isShow: false, isDisabled: false, text: null, callBack: null },
//最大化窗体
max: { type: 'system', isShow: false, isDisabled: false, text: null, callBack: null },
//关闭窗体
close: { type: 'system', isShow: true, isDisabled: false, text: null, callBack: null },
//肯定
yes: { type: 'custom', isShow: true, isDisabled: false, text: '确定', callBack: null },
//否定
no: { type: 'custom', isShow: true, isDisabled: false, text: '取消', callBack: null },
//还原或不改变现状
cancel: { type: 'custom', isShow: false, isDisabled: false, text: '返回', callBack: null }
};
//元素对象(表示当前实例控件的对象)
that.element = { mask: null, xbox: null, content: null, title: null, buttons: null, toolsBar: null };
//操作元素类名
that.handleClassName = { drag: 'J-xbox-drag', content: 'J-xbox-cont', title: 'J-xbox-title', buttons: 'J-xbox-btns', toolsBar: 'J-xbox-toolsBar', close: 'J-xbox-btn-close', max: 'J-xbox-btn-max', min: 'J-xbox-btn-min', restore: 'J-xbox-btn-restore', yes: 'J-xbox-btn-yes', no: 'J-xbox-btn-no', cancel: 'J-xbox-btn-cancel' };
//浏览器信息
that.browser = model.browser || browser();
//是否重写XBox中的内容(包括标题、内容和按钮,主要应用在使用静态自定义弹出框时)
that.isOverRide = isFalse(model.isOverRide) ? false : true;
//当前弹出框状态类型(默认:'default' 最小化:'min' 最大化:'max')
that.statusType = model.statusType || 'default';
//是否响应自定义事件
that.isInteraction = isFalse(model.isInteraction) ? false : true;
//弹出框显示状态
that.boxStatus = 'hide';
var buttons = model.buttons;
if (buttons) {
var buttonItem;
for (var key in buttons) {
buttonItem = buttons[key];
for (var itemKey in buttonItem) {
that.buttons[key][itemKey] = buttonItem[itemKey];
}
}
}
};
var BoxModelInstance = new BoxModel(options || {});
var createMask = function () {
if (!BoxConfigInstance.isCreateMask) {
var mask = $(BoxModelInstance.mask || BoxConfigInstance.template.mask);
$(document.body).append(mask);
//已创建背景遮罩
BoxConfigInstance.isCreateMask = true;
//未显示遮罩
BoxConfigInstance.isShowMask = false;
//保存背景遮罩对象
BoxConfigInstance.mask = mask;
BoxModelInstance.element.mask = mask;
}
else {
BoxModelInstance.element.mask = BoxConfigInstance.mask;
}
};
var createXBox = function () {
var xbox = $(BoxModelInstance.xbox || BoxConfigInstance.template.xbox),
appendTo = $(BoxModelInstance.appendTo || document.body);
var handleClassName = BoxModelInstance.handleClassName;
xbox.appendTo(appendTo);
//弹出框个数+1
BoxConfigInstance.xBox++;
//保存当前弹出框对象
BoxConfigInstance.currentXBox = xbox;
//弹出框对象
BoxModelInstance.element.xbox = xbox;
//弹出框内容区域对象
BoxModelInstance.element.content = xbox.find('.' + handleClassName.content);
//标题区域对象
BoxModelInstance.element.title = xbox.find('.' + handleClassName.title);
//按钮区域对象
BoxModelInstance.element.buttons = xbox.find('.' + handleClassName.buttons);
//工具栏区域对象
BoxModelInstance.element.toolsBar = xbox.find('.' + handleClassName.toolsBar);
var identity = Module.Guid('XBOX-IDENTITY-');
xbox.attr(BoxConfigInstance.dataAttr.dataIdentity, identity);
//保存所有弹出框
BoxConfigInstance.allXBox[identity] = xbox;
};
var bindEvent = function () {
var xbox = BoxConfigInstance.currentXBox,
dataEventIsBind = BoxConfigInstance.dataAttr.dataEventIsBind,
handleClassName = BoxModelInstance.handleClassName;
var isBind = xbox.attr(dataEventIsBind);
if (isBind != true) {
//点击事件
xbox.click(function (e) {
var target = $(eventTarget(e));
var key = target.attr('data-key');
var isDisabled = BoxConfigInstance.status.disabled[key];
var buttons = BoxModelInstance.buttons,
customEvent = BoxModelInstance.customEvent;
if (!target.hasClass(isDisabled)) {
if (target.hasClass(handleClassName.close)) {
//关闭
var closeButton = buttons[key];
if (!closeButton.isDisabled) {
close(closeButton.callBack);
}
}
else if (target.hasClass(handleClassName.yes)) {
//确定按钮
var yesButton = buttons[key];
if (!yesButton.isDisabled) {
var yesEvent = null;
if (customEvent) {
yesEvent = customEvent['onYes'];
}
var yesCallBack = function () {
var callBackResult = true, eventResult = true, result = true;
if (yesButton.callBack) {
callBackResult = yesButton.callBack.call(BoxModelInstance.element.xbox);
if (isFalse(callBackResult)) {
result = false;
}
}
if (yesEvent) {
eventResult = yesEvent.call(BoxModelInstance.element.xbox);
if (isFalse(eventResult)) {
result = false;
}
}
return result;
};
close(yesCallBack);
}
}
else if (target.hasClass(handleClassName.no)) {
//否定按钮
var noButton = buttons[key];
if (!noButton.isDisabled) {
var noEvent = null;
if (customEvent) {
noEvent = customEvent['onNo'];
}
var noCallBack = function () {
var callBackResult = true, eventResult = true, result = true;
if (noButton.callBack) {
callBackResult = noButton.callBack.call(BoxModelInstance.element.xbox);
if (isFalse(callBackResult)) {
result = false;
}
}
if (noEvent) {
eventResult = noEvent.call(BoxModelInstance.element.xbox);
if (isFalse(eventResult)) {
result = false;
}
}
return result;
};
close(noCallBack);
}
}
else if (target.hasClass(handleClassName.cancel)) {
//取消按钮
var cancelButton = buttons[key];
if (!cancelButton.isDisabled) {
var cancelEvent = null;
if (customEvent) {
cancelEvent = customEvent['onCancel'];
}
var cancelCallBack = function () {
var callBackResult = true, eventResult = true, result = true;
if (cancelButton.callBack) {
callBackResult = cancelButton.callBack.call(BoxModelInstance.element.xbox);
if (isFalse(callBackResult)) {
result = false;
}
}
if (cancelEvent) {
eventResult = cancelEvent.call(BoxModelInstance.element.xbox);
if (isFalse(eventResult)) {
result = false;
}
}
return result;
};
close(cancelCallBack);
}
}
}
var customEvent = BoxModelInstance.customEvent;
if (customEvent) {
var clickEvent = customEvent.onClick;
if (clickEvent) {
clickEvent.call(target, e);
}
}
});
//mouseover事件
xbox.mouseover(function (e) {
var target = $(eventTarget(e));
});
//mousedown事件
xbox.mousedown(function (e) {
var target = $(eventTarget(e));
});
xbox.attr(dataEventIsBind, true);
}
};
var drag = function (opts) {
var dragOptions = {
//拖动触发元素
drag: null,
//拖动移动元素,如果为null,默认为drag对象
move: null,
//拖动范围限制区域
region: document.body
}, browserInfo = BoxModelInstance.browser;
//遍历自定义参数
if (opts) {
for (var key in opts) { dragOptions[key.toLocaleLowerCase()] = opts[key]; }
//如果移动对象为空
if (!dragOptions.move) { dragOptions.move = dragOptions.drag; }
}
var dragEvent = function (event) {
event = event || window.event;
//获取移动元素的相对坐标
var movePosition = getPosition(dragOptions.move);
//响应拖动事件
var customEvent = BoxModelInstance.customEvent;
if (customEvent) {
var dragEvent = customEvent.onDrag;
if (dragEvent && BoxModelInstance.isInteraction) {
var eventResult = dragEvent.call(BoxModelInstance.element.xbox, event, movePosition.top, movePosition.left);
if (eventResult == false || eventResult == 'false' || eventResult == 'False') {
return false;
}
}
}
//判断移动元素是否为浮动元素
dragOptions.drag.style.cursor = 'move';
//获取拖动限制区域相对坐标
var regionPosition = getPosition(dragOptions.region);
var regionTop = regionPosition.top, regionLeft = regionPosition.left;
var moveStyle = dragOptions.move.style;
if (browserInfo.ie !== '6.0') {
moveStyle.position = 'absolute';
moveStyle.top = movePosition.top + 'px';
moveStyle.left = movePosition.left + 'px';
moveStyle.margin = '0px';
}
//获取移动元素的宽和高
var moveWidth = dragOptions.move.offsetWidth, moveHeight = dragOptions.move.offsetHeight;
//移动元素在限制区域的最小坐标
var minTop = 0, minLeft = 0;
//移动元素在限制区域的最大坐标
var scrolls = getScroll();
var clients = clientSize();
var maxTop = clients.height + scrolls.top - moveHeight,
maxLeft = clients.width + scrolls.left - moveWidth;
//初始化鼠标坐标
var dragClientX = event.clientX, dragClientY = event.clientY;
//定义元素移动距离
var top, left;
//鼠标移动事件
document.onmousemove = function (e) {
e = e || window.event;
//获取鼠标当前坐标位置
var moveClientX = e.clientX, moveClientY = e.clientY;
top = movePosition.top + moveClientY - dragClientY, left = movePosition.left + moveClientX - dragClientX;
if (top <= minTop) { top = minTop; }
if (top >= maxTop) { top = maxTop; }
if (left <= minLeft) { left = minLeft; }
if (left >= maxLeft) { left = maxLeft; }
moveStyle.top = top + 'px';
moveStyle.left = left + 'px';
//响应控件移动事件
if (customEvent) {
var moveEvent = customEvent.onDragMove;
if (moveEvent) {
moveEvent.call(BoxModelInstance.element.xbox, e, top, left);
}
}
};
document.onmouseup = function (e) {
document.onmousemove = null;
document.onmouseup = null;
dragOptions.drag.style.cursor = 'default';
BoxModelInstance.ie6XBoxTop = parseInt(moveStyle.top) - getScroll().top;
if (browserInfo.ie !== '6.0') {
moveStyle.top = BoxModelInstance.ie6XBoxTop + 'px';
moveStyle.position = 'fixed';
}
movePosition = getPosition(dragOptions.move);
if (customEvent) {
var dragEndEvent = customEvent.onDragEnd;
//响应控件拖拽结束事件
if (dragEndEvent) {
dragEndEvent.call(BoxModelInstance.element.xbox, e, movePosition.top, movePosition.left);
}
}
};
};
//绑定事件
if (dragOptions.drag) { dragOptions.drag.onmousedown = dragEvent; }
};
var show = function (callBack) {
var xbox = BoxModelInstance.element.xbox,
mask = BoxModelInstance.element.mask;
if (!xbox) {
var buttons = options.buttons;
if (buttons) {
var buttonItem;
for (var key in buttons) {
buttonItem = buttons[key];
for (var itemKey in buttonItem) {
BoxModelInstance.buttons[key][itemKey] = buttonItem[itemKey];
}
}
}
install();
xbox = BoxModelInstance.element.xbox;
}
//弹出框zindex+2
BoxConfigInstance.xBoxZIndex += 2;
xbox.css('z-index', BoxConfigInstance.xBoxZIndex).show();
//弹出框显示个数+1
BoxConfigInstance.showXBox++;
if (BoxModelInstance.isMask) {
BoxConfigInstance.maskZIndex += 2;
mask.css('z-index', BoxConfigInstance.maskZIndex).show();
BoxConfigInstance.isShowMask = true;
}
BoxModelInstance.boxStatus = 'show';
renderBoxPosition();
if (callBack && isFunction(callBack)) {
callBack();
}
//响应显示事件
var customEvent = BoxModelInstance.customEvent;
if (customEvent) {
var showEvent = customEvent.onShow;
if (showEvent && BoxModelInstance.isInteraction) {
var eventResult = showEvent.call(BoxModelInstance.element.xbox);
if (eventResult == false || eventResult == 'false' || eventResult == 'False') {
return that;
}
}
}
return that;
};
var close = function (callBack) {
if (BoxModelInstance.boxStatus === 'show') {
if (callBack && isFunction(callBack)) {
//执行自定义操作
var eventResult = callBack.call(BoxModelInstance.element.xbox);
if (eventResult == false || eventResult == 'false' || eventResult == 'False') {
return that;
}
}
//响应关闭事件
var customEvent = BoxModelInstance.customEvent;
if (customEvent) {
var closeEvent = customEvent.onClose;
if (closeEvent && BoxModelInstance.isInteraction) {
var eventResult = closeEvent.call(BoxModelInstance.element.xbox);
if (eventResult == false || eventResult == 'false' || eventResult == 'False') {
return that;
}
}
}
//ZIndex递减
BoxConfigInstance.xBoxZIndex -= 2, BoxConfigInstance.maskZIndex -= 2;
if (BoxModelInstance.isHidden) {
//隐藏弹出框
BoxModelInstance.element.xbox.hide();
//设置xbox状态
BoxModelInstance.boxStatus = 'hide';
//弹出框显示个数减一
BoxConfigInstance.showXBox--;
//如果是链接加载页面,关闭时终止页面的加载
if (BoxModelInstance.url && !BoxModelInstance.isCompleteLoad) {
that.stopLoad();
}
}
else {
//删除弹出框,并设置状态
BoxModelInstance.element.xbox.remove();
BoxModelInstance.element.xbox = null;
BoxModelInstance.boxStatus = 'remove';
//弹出框个数减一、显示个数减一
BoxConfigInstance.showXBox--;
BoxConfigInstance.xBox--;
//
if (BoxModelInstance.next) {
BoxModelInstance.next.idx = 0;
}
}
if (BoxConfigInstance.showXBox > 0) {
BoxModelInstance.element.mask.css('z-index', BoxConfigInstance.maskZIndex);
//如果存在非模态窗口
}
else {
//隐藏背景遮罩
BoxModelInstance.element.mask.hide();
BoxConfigInstance.isShowMask = false;
}
}
return that;
};
var renderButton = function (buttons, overRide) {
if (isBoolean(buttons)) {
overRide = buttons;
buttons = null;
}
if (overRide || overRide == undefined || overRide == null) {
if (buttons) {
var boxButtons = null, btns = null;
for (var key in buttons) {
boxButtons = BoxModelInstance.buttons[key];
btns = buttons[key];
for (var btnKey in btns) {
boxButtons[btnKey] = btns[btnKey];
}
}
}
buttons = BoxModelInstance.buttons;
var sysButton = BoxConfigInstance.template.sysButton,
cusButton = BoxConfigInstance.template.cusButton,
disabled = BoxConfigInstance.status.disabled,
defaults = BoxConfigInstance.status.defaults,
handleClassName = BoxModelInstance.handleClassName,
item, handleLink, btnButton;
var toolsBar = BoxModelInstance.element.toolsBar.html(''),
xboxButton = BoxModelInstance.element.buttons.html('');
var showCount = 0;
for (var key in buttons) {
item = buttons[key];
if (item.isShow) {
if (item.type == 'system') {
handleLink = $(sysButton.replaceAll('#KEY#', key)
.replace('#DISABLED#', (item.isDisabled ? (disabled[key] ? disabled[key] : '') : '')));
handleLink.addClass(handleClassName[key]);
toolsBar.append(handleLink);
}
else if (item.type == 'custom') {
btnButton = $(cusButton.replaceAll('#KEY#', key)
.replace('#TEXT#', item.text || '')
.replace('#DEFAULT#', defaults[key] || '')
.replace('#DISABLED#', (item.isDisabled ? (disabled[key] || '') : '')));
btnButton.addClass(handleClassName[key]);
xboxButton.append(btnButton);
}
showCount++;
}
}
if (!showCount) {
xboxButton.parents('tfoot').hide();
}
}
};
var renderButtonKey = function () {
var toolsBar = BoxModelInstance.element.toolsBar,
xboxButton = BoxModelInstance.element.buttons,
handleClassName = BoxModelInstance.handleClassName;
toolsBar.find('.' + handleClassName.close).addClass('J-btn-sys').attr('data-key', 'close');
toolsBar.find('.' + handleClassName.min).addClass('J-btn-sys').attr('data-key', 'min');
toolsBar.find('.' + handleClassName.max).addClass('J-btn-sys').attr('data-key', 'max');
toolsBar.find('.' + handleClassName.restore).addClass('J-btn-sys').attr('data-key', 'restore');
xboxButton.find('.' + handleClassName.yes).addClass('J-btn-cus').attr('data-key', 'yes');
xboxButton.find('.' + handleClassName.no).addClass('J-btn-cus').attr('data-key', 'no');
xboxButton.find('.' + handleClassName.cancel).addClass('J-btn-cus').attr('data-key', 'cancel');
};
var renderBoxPosition = function () {
var mask = BoxModelInstance.element.mask,
xbox = BoxModelInstance.element.xbox;
//获取浏览器内容区域的宽和高
var scroller = scrollSize();
mask.css('width', (scroller.width) + 'px').css('height', (scroller.height) + 'px');
var contentTarget = BoxModelInstance.element.content;
contentTarget.css('width', 'auto').css('height', 'auto');
if (BoxModelInstance.url === null || BoxModelInstance.isCompleteLoad || BoxModelInstance.initAttribute) {
//设置最小宽度和高度
var contentWidth = contentTarget[0].offsetWidth, contentHeight = contentTarget[0].offsetHeight;
var min = BoxModelInstance.min, max = BoxModelInstance.max;
var minWidth = min.width, minHeight = min.height,
maxWidth = max.width, maxHeight = max.height;
var width = BoxModelInstance.width,
height = BoxModelInstance.height;
if (minWidth != 'auto') {
if (contentWidth <= minWidth) {
if (minWidth < width) {
contentTarget.css('width', width + 'px').css('overflow', 'auto');
}
else {
contentTarget.css('width', minWidth + 'px').css('overflow', 'auto');
}
}
else if (width > contentWidth) {
contentTarget.css('width', width + 'px').css('overflow', 'auto');
}
}
if (minHeight != 'auto') {
if (contentHeight <= minHeight) {
if (minHeight < height) {
contentTarget.css('height', height + 'px').css('overflow', 'auto');
}
else {
contentTarget.css('height', minHeight + 'px').css('overflow', 'auto');
}
}
else if (height > contentHeight) {
contentTarget.css('height', height + 'px').css('overflow', 'auto');
}
}
if (maxWidth != 'auto') {
if (contentWidth >= maxWidth) {
contentTarget.css('width', maxWidth + 'px').css('overflow', 'auto');
}
else if (width > maxWidth) {
contentTarget.css('width', maxWidth + 'px').css('overflow', 'auto');
}
}
if (maxHeight != 'auto') {
if (contentHeight <= maxHeight) { contentTarget.css('height', maxHeight + 'px').css('overflow', 'auto'); }
}
}
var width = xbox[0].offsetWidth, height = xbox[0].offsetHeight;
if (BoxModelInstance.browser.ie !== '6.0') {
xbox.css('left', '50%');
xbox.css('top', '50%');
xbox.css('margin', '-' + (height / 2) + 'px ' + '-' + (width / 2) + 'px');
}
else {
//获取浏览器可见区域的宽和高
var clients = clientSize();
//获取滚动条距离
var scrollBar = getScroll();
xbox.css('left', ((clients.width / 2) - (width / 2) + scrollBar.left) + 'px');
xbox.css('top', ((clients.height / 2) - (height / 2) + scrollBar.top) + 'px');
}
};
var renderTitle = function (title, overRide) {
if (isBoolean(title)) {
overRide = title;
title = null;
}
if (overRide || overRide == undefined || overRide == null) {
title = title || BoxModelInstance.title;
var xbox = BoxModelInstance.element.xbox;
if (xbox) {
if (title) {
BoxModelInstance.element.title.html(title);
}
else {
BoxModelInstance.element.title.parents('thead').hide();
}
}
}
else {
BoxModelInstance.title = BoxModelInstance.element.title.html();
}
};
var renderContent = function (content, overRide) {
if (isBoolean(content)) {
overRide = content;
content = BoxModelInstance.content;
}
if (overRide || overRide == undefined || overRide == null) {
content = content || BoxModelInstance.content;
var xbox = BoxModelInstance.element.xbox;
if (xbox) {
if (isString(content)) {
BoxModelInstance.element.content.html(content);
}
else {
BoxModelInstance.element.content.append(content);
}
renderBoxPosition();
}
}
else {
BoxModelInstance.content = BoxModelInstance.element.content.html();
}
};
var saveHistory = function (options) {
var boxLoadHistory = {
//URL
url: options.url,
//标题
title: options.title,
//数据
data: options.data,
//请求方式
loadType: options.loadType,
//宽
width: options.width,
//高
height: options.height,
//按钮
buttons: options.buttons,
//其他属性(非BoxModelInstance中的属性)
other: options.other
};
if (!BoxModelInstance.loadHistory) {
BoxModelInstance.loadHistory = {
//历史记录信息集合
history: [boxLoadHistory],
//当前记录位置下标,从0开始
index: 0
};
}
else {
//判断是否已经存在
var history = BoxModelInstance.loadHistory.history;
var i = 0, length = history.length, historyItem, status = true;
for (; i < length; i++) {
historyItem = history[i];
if (historyItem['url'] == boxLoadHistory['url']) {
status = false;
break;
}
}
if (status) {
BoxModelInstance.loadHistory.history.push(boxLoadHistory);
}
}
};
var clearHistory = function (url) {
if (url) {
var history = BoxModelInstance.loadHistory.history,
index = BoxModelInstance.loadHistory.index;
var i = 0, length = history.length, historyItem, tempHistory = [];
for (; i < length; i++) {
historyItem = history[i];
if (historyItem['url'] != url) {
//重新组合记录
tempHistory.push(historyItem);
}
else {
//重新设置记录当前位置下标
if (index > i) {
BoxModelInstance.loadHistory.index -= 1;
}
}
}
//重新设置历史记录
BoxModelInstance.loadHistory.history = tempHistory;
}
else {
BoxModelInstance.loadHistory = {
//历史记录信息集合
history: [],
//当前记录位置下标,从0开始
index: 0
};
}
};
var loadPage = function (options) {
options = options || {};
if (options.data) {
//重置请求提交数据
BoxModelInstance.data = options.data;
}
if (options.url) {
//重置请求路径
BoxModelInstance.url = options.url;
}
if (options.loadType) {
//重置加载类型
BoxModelInstance.loadType = options.loadType;
}
if (options.title) {
//重置标题
BoxModelInstance.title = options.title;
}
BoxModelInstance.next = null;
//失败
var error = options.error,
//完成
complete = options.complete,
//成功
success = options.success,
//是否缓存数据
isCache = options.isCache;
if (isCache != false) {
//保存历史记录
saveHistory({
url: BoxModelInstance.url,
data: BoxModelInstance.data,
title: BoxModelInstance.title,
loadType: BoxModelInstance.loadType,
width: BoxModelInstance.width,
height: BoxModelInstance.height,
buttons: BoxModelInstance.buttons,
other: {
error: error,
complete: complete,
success: success
}
});
}
//自定义事件
var customEvent = BoxModelInstance.customEvent;
if (BoxModelInstance.boxStatus == 'hide') {
show();
}
if (BoxModelInstance.loadOnce) {
if (BoxModelInstance.isCompleteLoad) {
return that;
}
}
//设置加载状态
BoxModelInstance.isCompleteLoad = false;
//设置加载模板
var loading = BoxConfigInstance.template.msgTip.replace('#-TYPE-#', 'loading').replace('#-MESSAGE-#', BoxLangInstance.loading).replace('#-REMARK-#', '');
renderContent(loading, true);
renderTitle(BoxLangInstance.titleLoading);
//保持最大化
if (BoxModelInstance.statusType === 'max') {
var thisInteraction = BoxModelInstance.isInteraction;
BoxModelInstance.isInteraction = false;
that.reMax();
BoxModelInstance.isInteraction = thisInteraction;
}
var loadType = BoxModelInstance.loadType.toLocaleLowerCase();
if (loadType == 'iframe') {
//嵌入iframe方式
var iframes = document.createElement('iframe');
$(iframes).attr('frameBorder', 'none')
.css('display', 'none')
.css('border', 'none')
.css('width', '100%')
.css('height', '98%');
BoxModelInstance.content = $(iframes);
BoxModelInstance.element.content.append($(iframes));
iframes.onload = function () {
renderTitle(BoxModelInstance.title);
$(iframes).show();
BoxModelInstance.element.content.find('.ui-msg').remove();
//设置加载完成
BoxModelInstance.isCompleteLoad = true;
renderBoxPosition();
//保持最大化
if (BoxModelInstance.statusType === 'max') {
var thisInteraction = BoxModelInstance.isInteraction;
BoxModelInstance.isInteraction = false;
that.reMax();
BoxModelInstance.isInteraction = thisInteraction;
}
if (success) {
success.call(that);
}
if (customEvent) {
var loadEvent = customEvent.onLoad;
//响应加载完成事件
if (loadEvent && BoxModelInstance.isInteraction) {
loadEvent.call(BoxModelInstance.element.xbox);
}
}
};
var data = BoxModelInstance.data,
url = BoxModelInstance.url;
if (data) {
var dataString = '';
for (var key in data) {
if (dataString == '') {
dataString = '?' + key + '=' + data[key];
}
else {
dataString += '&' + key + '=' + data[key];
}
}
url = url + dataString;
}
iframes.src = url;
}
else if (loadType == 'ajax') {
var method = BoxModelInstance.url.substring(BoxModelInstance.url.length - 5, BoxModelInstance.url.length) == '.html' ? 'GET' : 'POST';
//加载内容
BoxModelInstance.ajaxRequired = $.ajax({
//请求路径
url: BoxModelInstance.url,
//请求方式(POST/GET)
method: method,
//同步(false)/异步(true)
async: true,
//提交数据
data: BoxModelInstance.data,
//请求出错
error: function (responseText, response) {
renderTitle(BoxLangInstance.titleError);
var errors = BoxConfigInstance.template.msgTip.replace('#-TYPE-#', 'error').replace('#-MESSAGE-#', BoxLangInstance.error).replace('#-REMARK-#', '');
BoxModelInstance.element.content.html(error);
renderBoxPosition();
//保持最大化
if (BoxModelInstance.statusType == 'max') {
var thisInteraction = BoxModelInstance.isInteraction;
BoxModelInstance.isInteraction = false;
that.reMax();
BoxModelInstance.isInteraction = thisInteraction;
}
if (error) {
error.call(BoxModelInstance.element.xbox, responseText, response);
}
},
//请求完成
complete: function (responseText, response) {
if (complete) {
complete.call(BoxModelInstance.element.xbox);
}
},
//请求成功
success: function (responseText, response) {
renderTitle(BoxModelInstance.title);
BoxModelInstance.content = responseText
BoxModelInstance.element.content.html(responseText);
//保持最大化
if (BoxModelInstance.statusType === 'max') {
var thisInteraction = BoxModelInstance.isInteraction;
BoxModelInstance.isInteraction = false;
that.reMax();
BoxModelInstance.isInteraction = thisInteraction;
}
//设置加载完成
BoxModelInstance.loadComplete = true;
renderBoxPosition();
if (Module.asyncRunHandle) {
Module.asyncRunHandle();
}
if (success) {
success.call(BoxModelInstance.element.xbox, responseText, response);
}
if (customEvent) {
var loadEvent = customEvent.onLoad;
//响应加载完成事件
if (loadEvent && BoxModelInstance.isInteraction) {
loadEvent.call(BoxModelInstance.element.xbox, responseText, response);
}
}
}
});
}
return that;
};
var renderLoad = function (options) {
var loadType = options.loadType,
url = options.url,
data = options.data,
callBack = options.callBack;
};
var createNextPanel = function (option, callBack) {
var optionID = option.id;
BoxModelInstance.next = BoxModelInstance.next || {
list: {},
keys: [],
idx: 0
};
var tempPanel = '