Namespace.register("U.MD.O.E.BC");
/*excel 的 基础功能*/
U.MD.O.E.BC.scroll = {};
U.MD.O.E.BC.scroll.isScroll = false; //鼠标在不可以滚动的范围
/*
*判断是否可以滚动
*/
U.MD.O.E.BC.scroll.canScroll = function () {
var _rowBoard = $(".U_MD_O_E_rowBoard")[0], //左边div
_cellBox = $(".U_MD_O_E_cellBox")[0]; //div区域
var _mouseenter = function () {
U.MD.O.E.BC.scroll.isScroll = true; //鼠标进入可以滚动的范围
}
var _mouseleave = function () {
U.MD.O.E.BC.scroll.isScroll = false; //鼠标离开可以滚动的范围
}
$(_rowBoard).bind({//绑定鼠标移动事件
mouseenter: _mouseenter,
mouseleave: _mouseleave
})
$(_cellBox).bind({//绑定鼠标移动事件
mouseenter: _mouseenter,
mouseleave: _mouseleave
})
}
U.MD.O.E.BC.headInputFocus = true; //文本框正在是否聚焦 (默认聚焦)
U.MD.O.E.BC.editorFocus = false; //单元格编辑框是否聚焦
/*
* 上下滚轮总事件
*/
U.MD.O.E.BC.scrollY = function () {
U.MD.O.E.BC.scroll.canScroll(); //判断是否可以滚动
U.MD.O.E.BC.scrollY.mousewheel(); //鼠标绑定滚动事件
U.MD.O.E.BC.scrollY.tbDragChecked(); //滚轮选中上下拖拽事件
U.MD.O.E.BC.scrollY.rlDragChecked(); //滚轮选中左右拖拽事件
}
/*
* 滚轮选中左右拖拽事件
*/
U.MD.O.E.BC.scrollY.rlDragChecked = function () {
var _xBar = $(".U_MD_O_E_Xbar")[0], //滚动条
_xBarRoll = $(".U_MD_O_E_XbarRoll")[0], //滚动条里面的滚动按钮
_headInput = $(".U_MD_O_E_headInput")[0], //c6区域
_colBoardBox = $(".U_MD_O_E_colBoardBox")[0], //顶部div
_cellBox = $(".U_MD_O_E_cellBox")[0]; //div区域
$(_xBarRoll).bind("mousedown", function (e) {
U.UF.EV.stopBubble(e); //阻止冒泡
console.log(_xBarRoll.offsetLeft);
var _barRollX = _xBarRoll.offsetLeft,
_oX = e.pageX, //选中时的X
_newX;
console.log(_oX);
var _drapMove = function (e) {//拖拽时移动用的函数
U.UF.EV.stopBubble(e); //阻止冒泡
U.UF.EV.stopDefault(e); //取消默认拖拽
_newX = e.pageX;
var _left = Math.max(0, _newX - _oX + _barRollX); //滚动按钮的left值不能小于0
_left = Math.min(_xBar.offsetWidth + 1, _left); //滚动按钮的left值不能大于滚动条的宽
_xBarRoll.style.left = _left + "px";
_NewRollleft = parseFloat(_xBarRoll.style.left); //拉拽后的left
_xBar.style.width = _headInput.offsetWidth - 65 + "px"; //滚动条的长度随着页面百分比的变化而变化
_double = ($(".U_MD_O_E_colBoardBox")[0].offsetWidth + 60 - document.body.clientWidth) / parseFloat(_xBar.style.width); //滚动占滚动条的百分比
$(".U_MD_O_E_colBoardBox")[0].style.left = -_NewRollleft * _double + "px"; //顶部div的left值
_cellBox.style.left = -_NewRollleft * _double + "px"; //div区域left值
_Newleft = parseInt($(".U_MD_O_E_colBoardBox")[0].style.left);
};
var _dragUp = function () { //拖拽时松开用的函数
$(document).unbind('mousemove', _drapMove);
$(document).unbind('mouseup', _dragUp);
};
$(document).bind('mousemove', _drapMove);
$(document).bind('mouseup', _dragUp);
})
}
/*
* 滚轮选中上下拖拽事件
*/
U.MD.O.E.BC.scrollY.tbDragChecked = function () {
var _Ybar = $(".U_MD_O_E_Ybar")[0], //滚动条
_yBarRoll = $(".U_MD_O_E_YbarRoll")[0], //滚动条里面的滚动按钮
_taskBar = $(".U_MD_O_E_taskBar")[0].offsetHeight, //互联办公模块
_rowBoard = $(".U_MD_O_E_rowBoard")[0], //左边div
_cellBox = $(".U_MD_O_E_cellBox")[0], //div区域
_head_features = $(".U_MD_O_E_Editor_head_features")[0].offsetHeight;
_NewRolltop = 0;
$(_yBarRoll).bind("mousedown", function (e) {
U.UF.EV.stopBubble(e); //阻止冒泡
var _barRollY = _yBarRoll.offsetTop,
_oY = e.pageY, //选中时的y
_newY;
var _drapMove = function (e) {//拖拽时移动用的函数
U.UF.EV.stopBubble(e); //阻止冒泡wx`
U.UF.EV.stopDefault(e); //取消默认拖拽
_newY = e.pageY;
var _top = Math.max(0, _newY - _oY + _barRollY), //滚动按钮的top值不能小于0
_top = Math.min(_Ybar.offsetHeight + 1, _top); //滚动按钮的top值不能大于滚动条的高
_yBarRoll.style.top = _top + "px";
_NewRolltop = parseFloat(_yBarRoll.style.top); //拉拽后的top
_visual = document.body.clientHeight - 36 - _head_features - _taskBar; //可视页面高度
_Ybar.style.height = _visual - 40 + "px"; //滚动条的长度随着页面百分比的变化而变化
_double = (_rowBoard.offsetHeight + 25 - _visual) / parseFloat(_Ybar.style.height); //页面滚动和滚动条滚动的百分比
_rowBoard.style.top = -_NewRolltop * _double + "px"; //最终左边div的高
_cellBox.style.top = -_NewRolltop * _double + "px"; //最终div的高
_Newtop = parseInt(_rowBoard.style.top);
};
var _dragUp = function () { //拖拽时松开用的函数
$(document).unbind('mousemove', _drapMove);
$(document).unbind('mouseup', _dragUp);
};
$(document).bind('mousemove', _drapMove);
$(document).bind('mouseup', _dragUp);
})
}
/*
* 绑定鼠标滚轮事件
*/
U.MD.O.E.BC.scrollY.mousewheel = function () {
var _Ybar = $(".U_MD_O_E_Ybar")[0], //滚动条
_yBarRoll = $(".U_MD_O_E_YbarRoll")[0], //滚动条里面的滚动按钮
_taskBar = $(".U_MD_O_E_taskBar")[0].offsetHeight, //互联办公模块
_rowBoard = $(".U_MD_O_E_rowBoard")[0], //左边div
_cellBox = $(".U_MD_O_E_cellBox")[0], //div区域
_head_features = $(".U_MD_O_E_Editor_head_features")[0].offsetHeight;
$(document).bind('mousewheel', function (e) {
if (!U.MD.O.E.BC.scroll.isScroll) return;
if (e.deltaY > 0) { //向下滚动
_visual = document.body.clientHeight - 36 - _head_features - _taskBar; //可视页面高度
_Ybar.style.height = _visual - 40 + "px"; //滚动条的长度随着页面百分比的变化而变化
_double = (_rowBoard.offsetHeight + 25 - _visual) / parseFloat(_Ybar.style.height); //页面滚动和滚动条滚动的百分比
if (_NewRolltop - 1 > _Ybar.offsetHeight) return;
_yBarRoll.style.top = (_NewRolltop + 2) + "px";
_NewRolltop = parseFloat(_yBarRoll.style.top); //删除尾部的px
_rowBoard.style.top = -_NewRolltop * _double + "px"; //最终左边div的高
_cellBox.style.top = -_NewRolltop * _double + "px"; //最终div的高
_Newtop = parseInt(_rowBoard.style.top);
} else {//向上滚动
if (_Newtop == 0) return;
_visual = document.body.clientHeight - 36 - _head_features - _taskBar; //可视页面高度
_Ybar.style.height = _visual - 40 + "px"; //滚动条的长度随着页面百分比的变化而变化
_double = (_rowBoard.offsetHeight + 25 - _visual) / parseFloat(_Ybar.style.height); //页面滚动和滚动条滚动的百分比
_yBarRoll.style.top = Math.max((_NewRolltop - 2), 0) + "px"; //取最大值
_NewRolltop = parseFloat(_yBarRoll.style.top); //删除尾部的px
_rowBoard.style.top = -Math.max(_NewRolltop * _double, 0) + "px"; //最终左边div的高
_cellBox.style.top = -Math.max(_NewRolltop * _double, 0) + "px"; //最终div的高
_Newtop = Math.min(parseInt(_rowBoard.style.top), 0);
}
});
}
/**
*
* 给cell添加鼠标拖拽的选中效果
* @param {object} cell 添加鼠标拖拽效果的
*/
U.MD.O.E.BC.dragCheckd = function (cell) {
var _cellEl = cell;
var _Ybar = $(".U_MD_O_E_Ybar")[0], //滚动条
_yBarRoll = $(".U_MD_O_E_YbarRoll")[0], //滚动条里面的滚动按钮
_taskBar = $(".U_MD_O_E_taskBar")[0].offsetHeight, //互联办公模块
_rowBoard = $(".U_MD_O_E_rowBoard")[0], //左边div
_cellBox = $(".U_MD_O_E_cellBox")[0], //div区域
_head_features = $(".U_MD_O_E_Editor_head_features")[0].offsetHeight;
var _xBar = $(".U_MD_O_E_Xbar")[0], //滚动条
_xBarRoll = $(".U_MD_O_E_XbarRoll")[0], //滚动条里面的滚动按钮
_headInput = $(".U_MD_O_E_headInput")[0], //c6区域
_colBoardBox = $(".U_MD_O_E_colBoardBox")[0]; //顶部div
$(_cellEl).bind('mousedown', function (e) {
var _Excel = top.$("#UD_Excel" + U.MD.O.E.fileinfo.UserDirectoryID)[0];
U.UF.EV.stopBubble(e); //阻止冒泡
//if (e.button === 2) return; //不准右键拖拽
var _excel = U.MD.O.E,
_focusBox = $("#U_MD_O_E_focusBox")[0],
_editorBox = $("#U_MD_O_E_editorBox")[0],
_startEl = this, //获取点击元素
_startX = _startEl.col, //记录x坐标轴 A-Z
_startY = _startEl.row, //获取y坐标轴 1-200的数字\
_endX = _startX, //结束点x
_endY = _startY, //结束点y
_endPreX = _startX,
_endPreY = _startY,
_parent = this.parentNode,
_elList,
_drag = false,
i,
j,
minX = Math.min(_startX, _endX),
maxX = Math.max(_startX, _endX),
minY = Math.min(_startY, _endY),
maxY = Math.max(_startY, _endY),
_endEl;
if (e.button === 2 && (_focusBox.style.background)) return;
$("#U_UF_EL_rightmenu")[0] && $("#U_UF_EL_rightmenu")[0].remove(); //删除右键元素
$(".U_MD_O_E_cellCheckd").removeClass("U_MD_O_E_cellCheckd"); //删除所有被选中状态的单元格
if (this.s_merge) { //如果点击的是合并单元格元素
maxX = this.e_mergecol;
maxY = this.e_mergerow;
_excel.BC.modifyFocusSize(minX, minY, maxX, maxY);
} else {
_excel.BC.modifyFocusSize(minX, minY, maxX, maxY);
//$(this).addClass('U_MD_O_E_cellCheckd');
}
var _drapMove = function (e) {//拖拽时移动用的函数
var _moveY = e.pageY + _Excel.getElementsByClassName("U_MD_O_E_S")[0].parentNode.clientHeight,
_moveX = e.pageX;
if (_moveX < 0) {//超出区域-左
clearInterval(_PageMove);
_PageMove = setInterval(function () {
if (_Newleft == 0) return; //到A列的时候不再执行
_visual = document.body.clientWidth; //可视页面宽度
_xBar.style.width = _visual - 100 + "px"; //滚动条的长度随着页面百分比的变化而变化
_double = (_colBoardBox.offsetWidth - _visual) / parseFloat(_xBar.style.width); //滚动条的长度和页面总宽度的比例
_xBarRoll.style.left = Math.max((_NewRollleft - (107 / _double)), 0) + "px"; //滚动条里面的滚动按钮的左边距
_NewRollleft = parseFloat(_xBarRoll.style.left); //当前滚动按钮的左边距
_colBoardBox.style.left = -Math.max((_NewRollleft * _double), 0) + "px"; //取最大值
_cellBox.style.left = -Math.max((_NewRollleft * _double), 0) + "px";
_Newleft = Math.min(parseInt(_colBoardBox.style.left), 0); //取最小值
U.MD.O.E.BC.cellCheckd(param, "left", e);
}, 100)
} else if (_moveX > _Excel.clientWidth) {//超出区域-右
clearInterval(_PageMove);
_PageMove = setInterval(function () {
_visual = document.body.clientWidth; //可视页面宽度
_xBar.style.width = _visual - 100 + "px"; //滚动条的长度随着页面百分比的变化而变化
_double = (_colBoardBox.offsetWidth - _visual) / parseFloat(_xBar.style.width); //滚动条的长度和页面总宽度的比例
if (_NewRollleft + 1 > _xBar.offsetWidth) return; //到最后一列的时候不再执行
_xBarRoll.style.left = (_NewRollleft + (107 / _double)) + "px"; //滚动条里面的滚动按钮的左边距
_NewRollleft = parseFloat(_xBarRoll.style.left); //当前滚动按钮的左边距
_colBoardBox.style.left = -_NewRollleft * _double + "px";
_cellBox.style.left = -_NewRollleft * _double + "px";
_Newleft = parseInt(_colBoardBox.style.left);
U.MD.O.E.BC.cellCheckd(param, "right", e);
}, 100)
} else if (_moveY < 0) {//超出区域-上
clearInterval(_PageMove);
_PageMove = setInterval(function () {
if (_Newtop == 0) return; //到达最上面一行return
_visual = document.body.clientHeight - 36 - _head_features - _taskBar; //可视页面高度
_Ybar.style.height = _visual - 40 + "px"; //滚动条的长度随着页面百分比的变化而变化
_double = (_rowBoard.offsetHeight + 25 - _visual) / parseFloat(_Ybar.style.height); //页面滚动和滚动条滚动的百分比
_yBarRoll.style.top = Math.max((_NewRolltop - 2), 0) + "px"; //滚动按钮的的高取最大值
_NewRolltop = parseFloat(_yBarRoll.style.top); //当前滚动按钮的上边距
_rowBoard.style.top = -Math.max(_NewRolltop * _double, 0) + "px";
_cellBox.style.top = -Math.max(_NewRolltop * _double, 0) + "px";
_Newtop = Math.min(parseInt(_rowBoard.style.top), 0);
U.MD.O.E.BC.cellCheckd(param, "up", e);
}, 100)
} else if (_moveY > _Excel.clientHeight) {//超出区域-下
clearInterval(_PageMove);
_PageMove = setInterval(function () {
_visual = document.body.clientHeight - 36 - _head_features - _taskBar; //可视页面高度
_Ybar.style.height = _visual - 40 + "px"; //滚动条的长度随着页面百分比的变化而变化
_double = (_rowBoard.offsetHeight + 25 - _visual) / parseFloat(_Ybar.style.height); //页面滚动和滚动条滚动的百分比
if (_NewRolltop - 1 > _Ybar.offsetHeight) return; //到达最后一行则return
_yBarRoll.style.top = (_NewRolltop + 2) + "px";
_NewRolltop = parseFloat(_yBarRoll.style.top); //当前滚动按钮的上边距
_rowBoard.style.top = -_NewRolltop * _double + "px";
_cellBox.style.top = -_NewRolltop * _double + "px";
_Newtop = parseInt(_rowBoard.style.top);
U.MD.O.E.BC.cellCheckd(param, "down", e);
}, 100);
} else {
clearInterval(_PageMove);
}
U.MD.O.E.BC.cellCheckd(param, "", e);
};
var _dragUp = function () { //拖拽时松开用的函数
_startEl.style.zIndex = "0";
_excel.BC.cellAddClass(minX, parseInt(minY), maxX, parseInt(maxY));
clearInterval(_PageMove);
$(document).unbind('mousemove', _drapMove);
$(document).unbind('mouseup', _dragUp);
$(document).unbind('mousewheel', _scrollMove);
};
var _scrollMove = function (e) {
var _elNum = 0,
_elList = e.path,
_endEl = _elList.filter(_filter)[0];
U.UF.EV.stopBubble(e); //阻止冒泡
U.UF.EV.stopDefault(e); //取消默认拖拽
if (!_endEl || !(_endEl.row) || !(_endEl.col)) return; //如果没有自定义属性(其他非单元格元素) 则不判断
_endX = _endEl.col; //结束点的x坐标
_endY = _endEl.row; //结束点的y坐标
if (_endX !== _endPreX || _endY !== _endPreY) { //意思是当鼠标mousemove指向的元素不同时
_focusBox.style.zIndex = "";
minX = Math.min(_startX, _endX);
maxX = Math.max(_startX, _endX);
minY = Math.min(_startY, _endY);
maxY = Math.max(_startY, _endY);
var _cellEl,
s_mergeCell, //合并单元格元素
_cellArr = [];
for (i = minX; i <= maxX; i++) {
for (j = minY; j <= maxY; j++) {
_cellEl = $(_parent).find("#POS_" + i + "_" + j)[0];
_cellEl.s_merge ? s_mergeCell = $(_parent).find("#" + _cellEl.s_merge)[0] : "";
if (s_mergeCell && _cellArr.indexOf(s_mergeCell) === -1) { //如果选中的是合并单元格的元素
_endCell = $(_parent).find("#" + _cellEl.e_merge)[0];
_cellArr.push(s_mergeCell);
minX = Math.min(minX, s_mergeCell.col, _endCell.col);
maxX = Math.max(maxX, s_mergeCell.col, _endCell.col);
minY = Math.min(minY, s_mergeCell.row, _endCell.row);
maxY = Math.max(maxY, s_mergeCell.row, _endCell.row);
i = minX;
j = minY;
}
}
}
_excel.BC.modifyFocusSize(minX, parseInt(minY), maxX, parseInt(maxY));
_endPreX = _endX;
_endPreY = _endY;
}
};
var param = {
startEl: _startEl,
startX: _startX,
startY: _startY,
filter: _filter,
parent: _parent,
endX: _endX,
endY: _endY,
endPreX: _endPreX,
endPreY: _endPreY,
minX: minX,
maxX: maxX,
minY: minY,
maxY: maxY,
i: i,
j: j
}
$(document).bind('mousemove', _drapMove); //执行mousemove事件
$(document).bind('mouseup', _dragUp); //执行mouseup事件
$(document).bind('mousewheel', _scrollMove); //执行mousewheel事件
});
var _filter = function (d) {
return d.nodeName === "DIV" && d.col;
};
};
/*
*单元格选中超出单元格选区外的操作
*@param {object} obj 操作对象
*@param {number} direction 超出单元格选区的方向
*/
U.MD.O.E.BC.cellCheckd = function (obj, direction, e) {
var _excel = U.MD.O.E,
_focusBox = $("#U_MD_O_E_focusBox")[0],
_editorBox = $("#U_MD_O_E_editorBox")[0];
var _elNum = 0,
_elList = e.path,
_endEl = _elList.filter(obj.filter)[0],
_direction = direction || "";
U.UF.EV.stopBubble(e); //阻止冒泡
U.UF.EV.stopDefault(e); //取消默认拖拽
if (_direction == "left") {
obj.endX -= 1; //结束点的x坐标
} else if (_direction == "right") {
obj.endX = Math.min(obj.endX + 1, 26); //结束点的x坐标
} else if (_direction == "up") {
obj.endY -= 1; //结束点的y坐标
} else if (_direction == "down") {
obj.endY = Math.min(obj.endY + 1, 200); //结束点的y坐标
} else {
if (!_endEl || !(_endEl.row) || !(_endEl.col)) return; //如果没有自定义属性(其他非单元格元素) 则不判断
obj.endX = _endEl.col; //结束点的x坐标
obj.endY = _endEl.row; //结束点的y坐标
}
//console.log(_endY);
if (obj.endX !== obj.endPreX || obj.endY !== obj.endPreY) { //意思是当鼠标mousemove指向的元素不同时
_focusBox.style.zIndex = "";
obj.minX = Math.min(obj.startX, obj.endX);
obj.maxX = Math.max(obj.startX, obj.endX);
obj.minY = Math.min(obj.startY, obj.endY);
obj.maxY = Math.max(obj.startY, obj.endY);
var _cellEl,
s_mergeCell, //合并单元格元素
_cellArr = [];
for (var i = obj.minX; i <= obj.maxX; i++) {
for (var j = obj.minY; j <= obj.maxY; j++) {
_cellEl = $(obj.parent).find("#POS_" + i + "_" + j)[0];
_cellEl.s_merge ? s_mergeCell = $(obj.parent).find("#" + _cellEl.s_merge)[0] : "";
if (s_mergeCell && _cellArr.indexOf(s_mergeCell) === -1) { //如果选中的是合并单元格的元素
_endCell = $(obj.parent).find("#" + _cellEl.e_merge)[0];
_cellArr.push(s_mergeCell);
obj.minX = Math.min(obj.minX, s_mergeCell.col, _endCell.col);
obj.maxX = Math.max(obj.maxX, s_mergeCell.col, _endCell.col);
obj.minY = Math.min(obj.minY, s_mergeCell.row, _endCell.row);
obj.maxY = Math.max(obj.maxY, s_mergeCell.row, _endCell.row);
i = obj.minX;
j = obj.minY;
}
}
}
_excel.BC.modifyFocusSize(obj.minX, parseInt(obj.minY), obj.maxX, parseInt(obj.maxY)); //改变聚焦区域大小
_excel.BC.cellAddClass(obj.minX, parseInt(obj.minY), obj.maxX, parseInt(obj.maxY)); //给聚焦区内的单元格添加样式
obj.endPreX = obj.endX;
obj.endPreY = obj.endY;
}
}
/**
*上下拉伸事件
* @param {number} rowrule 行尺
*/
U.MD.O.E.BC.rowExpanding = function (rowrule) { //高度扩张
var _div = rowrule;
$(_div).bind({
'mousedown': function (e) {
//$("#U_UF_EL_rightmenu")[0] && $("#U_UF_EL_rightmenu")[0].remove(); //删除右键元素
this.style.backgroundColor = "";
this.style.width = document.body.clientWidth + "px"; //将行尺宽度暂满全屏
U.UF.EV.stopBubble(e); //阻止冒泡
var _oMouseY = e.pageY, //获取鼠标按下时的Y坐标
_rowrule = this,
_oY = parseInt(this.style.top), //获取当前Top坐标
_rowDiv = this.parentNode, //获取行尺对应的div元素
_initHeight = _rowDiv.offsetHeight, //行被拉伸前的初始高度
_mouseY, //鼠标移动时的Y坐标
_dis, //移动后的高度
_oHeight = _rowDiv.offsetHeight, //_rowDiv的高度 会根据内容有个最小值 因此 这个_rowDiv最后的高度 才是最终值
_rowName = +(this.parentNode.rowname),
_moveDis; //移动的距离
var expandingMove = function (e) { //拖拽时移动用的函数
U.UF.EV.stopDefault(e); //取消默认拖拽
_mouseY = e.pageY; //鼠标移动时的Y坐标
_dis = _mouseY - _oMouseY + _oY; //
_dis = Math.max(20, _dis); //拉伸后的高度不能小于20px
_moveDis = _dis - _oHeight; //移动的距离
_rowDiv.style.height = _dis + "px";
_rowrule.style.top = _dis + "px";
};
var expandingUp = function () { //拖拽时松开用的函数
$(document).unbind('mousemove', expandingMove);
$(document).unbind('mouseup', expandingUp);
_rowrule.style.backgroundColor = "";
_rowrule.style.width = "100%";
var info = {
initHeight: _initHeight,
rowName: _rowName,
moveDis: _moveDis
}
U.MD.O.E.BC.rowExpandingEnd([info]);
U.MD.O.E.BC.reSelectCell();
};
$(document).bind('mousemove', expandingMove);
$(document).bind('mouseup', expandingUp)
},
'mousemove': function (e) {
U.UF.EV.stopBubble(e); //阻止冒泡
U.UF.EV.stopDefault(e); //取消默认拖拽
}
});
};
/*
* 行的拉伸
* param infoArr 为数组json 格式[{info},{info},{info}]
info 内容:
{
initHeight 行被拉伸前的高度
rowName 拉伸行的 位置
moveDis 拉伸行的 距离
}
* req 为true时 表示 不发送send请求
*/
U.MD.O.E.BC.rowExpandingEnd = function (infoArr, req) {
var _cellList = U.UF.C.toArray($(".U_MD_O_E_cell")), //所有的单元格
_cellParent = $(".U_MD_O_E_cellBox")[0], //单元格的父元素
_rowBoardList = $(".U_MD_O_E_row"),
_data = [],
len = _rowBoardList.length;
infoArr.forEach(function (info) {
var _rowName = info.rowName,
_moveDis = info.moveDis,
i,
_rowCellList = _cellList.filter(function (el) { //第 rowName 列 的 所有单元格
return +(el.row) === _rowName;
}),
_oHeight = info.initHeight, //行被拉伸前的高度
_top,
_mergeId,
_elMergeId,
_mergeCell,
_iRowCell, //第i行的所有单元格
_elId,
_frag = $$("frag");
_rowCellList.forEach(function (el) {
_elMergeId = el.s_merge; //被合并单元格(最大)的位置
if (_elMergeId && (_mergeId !== _elMergeId)) { //合并单元格的 拉伸判断
_mergeId = _elMergeId; //被合并单元格的位置 记录 防止重复给被合并的单元格拉伸
_elId = el.id;
_mergeCell = $("#" + _mergeId)[0];
_mergeCell.style.height = _mergeCell.offsetHeight + _moveDis + "px";
if (_elId === _mergeId) return; //如果被合并单元格的位置和单元格的位置相等 则返回 不需要再添加一次宽
}
_frag.appendChild(el);
el.style.height = _oHeight + _moveDis + "px";
});
for (i = _rowName + 1; i <= len; i++) {
_iRowCell = _cellList.filter(function (el) { //第 i 行 的 所有单元格
return +(el.row) === i;
});
_top = _rowBoardList[i - 1].offsetTop
_iRowCell.forEach(function (el) {
_frag.appendChild(el);
el.style.top = _top + "px";
});
}
_cellParent.appendChild(_frag);
_data.push({
rowName: _rowName, //拉伸行的位置
height: _oHeight + _moveDis, //被拉伸后的高度
moveDis: _moveDis //被拉伸的 距离
});
});
U.MD.O.E.dataChange(U.MD.O.E.excelInfo("rowExpanding", _data), req);
};
/**
*左右拉伸事件
*@param {number} colrule 列尺
*/
U.MD.O.E.BC.colExpanding = function (colrule) { //宽度扩张
var _div = colrule;
$(_div).bind({
'mousedown': function (e) {
this.style.backgroundColor = "#8cb3e0";
this.style.height = document.body.clientHeight + "px";
U.UF.EV.stopBubble(e); //阻止冒泡
var _oMouseX = e.pageX, //获取鼠标按下时的X坐标
_colrule = this,
_oX = parseInt(this.style.left), //获取当前left坐标
_colDiv = this.parentNode, //获取列尺对应的div元素
_initWidth = _colDiv.offsetWidth, //列的初始宽度
_colBoard = $(".U_MD_O_E_colBoard")[0], //列板 A-Z 的父元素
_colBoardWidth = _colBoard.offsetWidth, //为添加总宽用
_mouseX, //鼠标移动时的X坐标
//_colName = +($(this.parentNode).attr("colname")), //鼠标移动时的X坐标
_colName = +(this.parentNode.colname),
_dis, //移动的距离
_oWidth = _colDiv.offsetWidth, //_colDiv的宽度最小值 mousemove时 要拿来做比较
_moveDis;
var expandingMove = function (e) { //拖拽时移动用的函数
U.UF.EV.stopDefault(e); //取消默认拖拽
_mouseX = e.pageX; //鼠标移动时的Y坐标
_dis = _mouseX - _oMouseX + _oX; //
_dis = Math.max(50, _dis); //拉伸后的高度不能小于20px
_moveDis = _dis - _oWidth; //移动的距离
_colBoard.style.width = _colBoardWidth + _moveDis + "px";
_colDiv.style.width = _dis + "px";
_colrule.style.left = _dis + "px";
};
var expandingUp = function () { //拖拽时松开用的函数
$(document).unbind('mousemove', expandingMove);
$(document).unbind('mouseup', expandingUp);
_colrule.style.backgroundColor = "";
_colrule.style.height = "100%";
var info = {
initWidth: _initWidth,
colName: _colName,
moveDis: _moveDis
}
U.MD.O.E.BC.colExpandingEnd([info]);
U.MD.O.E.BC.reSelectCell();
};
$(document).bind('mousemove', expandingMove);
$(document).bind('mouseup', expandingUp)
},
'mousemove': function (e) {
U.UF.EV.stopBubble(e); //阻止冒泡
U.UF.EV.stopDefault(e); //取消默认拖拽
}
});
};
/**
* @param i nfoArr 为数组json 格式[{info},{info},{info}]
info 内容:
{ initWidth 列拉伸前的宽度
colName 拉伸列的 位置
moveDis 拉伸列的 距离
}
* req 为true时 表示 不发送send请求
*/
U.MD.O.E.BC.colExpandingEnd = function (infoArr, req) {
var _cellList = U.UF.C.toArray($(".U_MD_O_E_cell")), //所有的单元格
_cellParent = $(".U_MD_O_E_cellBox")[0], //单元格的父元素
_colBoardList = $(".U_MD_O_E_column"),
_data = [],
len = _colBoardList.length;
infoArr.forEach(function (info) {
var _colName = info.colName,
_moveDis = info.moveDis,
i,
_colCellList = _cellList.filter(function (el) { //第 colName 列 的 所有单元格
return +(el.col) === _colName;
}),
_oWidth = info.initWidth,
_left,
_mergeId,
_elMergeId,
_elId,
_mergeCell,
_iColCell, //第 i 列的 所有单元格
_frag = $$("frag");
_colCellList.forEach(function (el) {
_elMergeId = el.s_merge; //被合并单元格(最大)的位置
if (_elMergeId && (_mergeId !== _elMergeId)) { //合并单元格的 拉伸判断
_mergeId = _elMergeId; //被合并单元格的位置 记录 防止重复给被合并的单元格拉伸
_elId = el.id;
_mergeCell = $("#" + _mergeId)[0];
_mergeCell.style.width = _mergeCell.offsetWidth + _moveDis + "px";
if (_elId === _mergeId) return; //如果被合并单元格的位置和单元格的位置相等 则返回 不需要再添加一次宽
}
_frag.appendChild(el);
el.style.width = _oWidth + _moveDis + "px";
});
for (i = _colName + 1; i <= len; i++) {
_iColCell = _cellList.filter(function (el) { //第 colName 列 的 所有单元格
return +(el.col) === i;
});
_left = _colBoardList[i - 1].offsetLeft;
_iColCell.forEach(function (el) {
_frag.appendChild(el);
el.style.left = _left + "px";
})
}
_cellParent.appendChild(_frag);
_data.push({
colName: _colName, //拉伸列的位置
width: _oWidth + _moveDis, //被拉伸后的宽度
moveDis: _moveDis //被拉伸的 距离
});
});
console.log(_data);
U.MD.O.E.dataChange(U.MD.O.E.excelInfo("colExpanding", _data), req);
}
/*
* 单元格添加样式
*@param {number} minX 最小X值
*@param {number} minY 最小Y值
*@param {number} maxX 最大X值
*@param {number} maxY 最大Y值
*/
U.MD.O.E.BC.cellAddClass = function (minX, minY, maxX, maxY) {
var _focusBox = $("#U_MD_O_E_focusBox")[0],
_id,
_cell,
i,
j;
for (i = minX; i <= maxX; i++) {
for (j = minY; j <= maxY; j++) {
_id = "POS_" + i + "_" + j
_cell = $("#" + _id)[0];
$(_cell).addClass("U_MD_O_E_cellCheckd");
}
}
}
/**
*
* @param tr 获取所有tr用的(遍历所有tr)
* @param {number} x1 开始点x坐标
* @param {number} y1 开始点y坐标
* @param {number} x2 结束点x坐标
* @param {number} y2 结束点y坐标
*/
U.MD.O.E.BC.modifyFocusSize = function (x1, y1, x2, y2) { //获取首尾坐标轴 修改聚焦元素大小
var _x1 = Math.min(x1, x2), //A-Z 65-91
_x2 = Math.max(x1, x2), //A-Z 65-91
_y1 = Math.min(y1, y2), //1-200
_y2 = Math.max(y1, y2),
allWidth = 0,
allHeight = 0,
i,
j,
_colNum = _x1,
_colEl = $(".U_MD_O_E_column")[_colNum - 1],
_rowNum = _y1,
_rowEl = $(".U_MD_O_E_row")[_rowNum - 1],
_lFCornerEl = $("#POS_" + _x1 + "_" + _y1)[0],
_focusBox = $("#U_MD_O_E_focusBox")[0], //单元格里的选中元素
_colCheckdEl = $(".U_MD_O_E_colCheckdEl")[0], //列板里的选中元素
_rowCheckdEl = $(".U_MD_O_E_rowCheckdEl")[0]; //行板里的选中元素
_focusBox.style.display = "block";
_focusBox.style.zIndex = "";
while (_colNum !== _x2 + 1) { //获取选中元素的 宽 = 聚焦div的宽
allWidth += _colEl.offsetWidth; //每一列的宽度之和
_colEl = _colEl.nextElementSibling;
_colNum++;
}
while (_rowNum !== _y2 + 1) {
allHeight += _rowEl.offsetHeight; //每一行的高度之和
_rowEl = _rowEl.nextElementSibling;
_rowNum++;
}
_colCheckdEl.style.width = allWidth + "px";
_colCheckdEl.style.left = _lFCornerEl.style.left;
_colCheckdEl.style.background = "#e1e2e6";
_rowCheckdEl.style.height = allHeight + "px";
_rowCheckdEl.style.top = _lFCornerEl.style.top;
_rowCheckdEl.style.background = "#e1e2e6";
_focusBox.style.width = allWidth + "px";
_focusBox.style.height = allHeight + "px";
_focusBox.style.left = _lFCornerEl.style.left;
_focusBox.style.top = _lFCornerEl.style.top;
_focusBox.style.background = "#c1e3ff";
}
/*
*列的选中与拖拽
*@param {number}colBoard 选中的列头
*/
U.MD.O.E.BC.cBoardChecked = function (colBoard) {
$(colBoard).bind('mousedown', function (e) {
U.UF.EV.stopBubble(e); //阻止冒泡
$("#U_UF_EL_rightmenu")[0] && $("#U_UF_EL_rightmenu")[0].remove(); //删除右键元素
var _excel = U.MD.O.E,
_x1 = this.colname,
_x2 = this.colname,
_y1 = 1,
_y2 = $(".U_MD_O_E_row").length,
_focusBox = $("#U_MD_O_E_focusBox")[0], //获取聚焦元素
_editorBox = $("#U_MD_O_E_editorBox")[0], //获取编辑元素
_startEl = this, //获取点击元素
_startX = _startEl.colname, //记录x坐标轴 A-Z
_startY = 1,
_endX = _startX,
_endY = $(".U_MD_O_E_row").length,
_endPreX = _startX, //记录上一个的位置
_parent = $(".U_MD_O_E_cellBox"),
i,
j,
minX = Math.min(_startX, _endX),
maxX = Math.max(_startX, _endX),
minY = Math.min(_startY, _endY),
maxY = Math.max(_startY, _endY),
_endEl;
if (e.button === 2 && (_focusBox.style.background)) return; //无视
$(".U_MD_O_E_cellCheckd").removeClass("U_MD_O_E_cellCheckd"); //删除所有被选中状态的单元格
var _firstCell = $("#POS_" + _x1 + "_1")[0];
U.MD.O.E.BC.focusSwitch(_firstCell);
U.MD.O.E.BC.modifyFocusSize(_x1, _y1, _x2, _y2);
var move = function (e) {
U.MD.O.E.BC.cellAddClass();
_endEl = e.path.filter(_filter)[0];
U.UF.EV.stopBubble(e); //阻止冒泡
U.UF.EV.stopDefault(e); //取消默认拖拽
if (!_endEl) return;
if (_endEl.row) { //单元格
_endX = _endEl.col; //结束点的x坐标
}
if (_endEl.colname) { //列板元素
_endX = _endEl.colname; //结束点的x坐标
}
if (_endX !== _endPreX) { //意思是当鼠标mousemove指向的元素不同时
minX = Math.min(_startX, _endX);
maxX = Math.max(_startX, _endX);
minY = Math.min(_startY, _endY);
maxY = Math.max(_startY, _endY);
_excel.BC.modifyFocusSize(minX, parseInt(minY), maxX, parseInt(maxY));
_endPreX = _endX;
}
};
var stop = function (e) {
_excel.BC.cellAddClass(minX, parseInt(minY), maxX, parseInt(maxY)); //
$(document).unbind({
'mousemove': move,
'mouseup': stop
});
}
$(document).bind({
'mousemove': move,
'mouseup': stop
});
var _filter = function (d) {
return d.nodeName === "DIV" && (d.col || d.colname);
};
})
}
/*
*行的选中与拖拽
*@param {number} rowBoard 选中的行头
*/
U.MD.O.E.BC.rBoardChecked = function (rowBoard) {
$(rowBoard).bind('mousedown', function (e) {
U.UF.EV.stopBubble(e); //阻止冒泡
$("#U_UF_EL_rightmenu")[0] && $("#U_UF_EL_rightmenu")[0].remove(); //删除右键元素
var _excel = U.MD.O.E,
_x1 = 1,
_x2 = $(".U_MD_O_E_column").length,
_y1 = this.rowname,
_y2 = this.rowname,
_focusBox = $("#U_MD_O_E_focusBox")[0], //获取聚焦元素
_editorBox = $("#U_MD_O_E_editorBox")[0], //获取编辑元素
_startEl = this, //获取点击元素
_startX = 1, //记录x坐标轴 A-Z
_endX = $(".U_MD_O_E_column").length,
_startY = _startEl.rowname,
_endY = _startY,
_endPreY = _startY, //记录上一个的位置
_parent = $(".U_MD_O_E_cellBox"),
i,
j,
minX = Math.min(_startX, _endX),
maxX = Math.max(_startX, _endX),
minY = Math.min(_startY, _endY),
maxY = Math.max(_startY, _endY),
_endEl;
if (e.button === 2 && (_focusBox.style.background)) return; //无视
$(".U_MD_O_E_cellCheckd").removeClass("U_MD_O_E_cellCheckd"); //删除所有被选中状态的单元格
var _firstCell = $("#POS_" + "1_" + _y1)[0];
U.MD.O.E.BC.focusSwitch(_firstCell);
_excel.BC.modifyFocusSize(minX, parseInt(minY), maxX, parseInt(maxY));
var move = function (e) {
console.log("_startY:" + _startY + "_endPreY:" + _endPreY);
U.MD.O.E.BC.cellAddClass();
_endEl = e.path.filter(_filter)[0];
U.UF.EV.stopBubble(e); //阻止冒泡
U.UF.EV.stopDefault(e); //取消默认拖拽
if (!_endEl) return;
if (_endEl.row) { //单元格
_endY = _endEl.row; //结束点的x坐标
}
if (_endEl.rowname) { //列板元素
_endY = _endEl.rowname; //结束点的x坐标
}
if (_endY !== _endPreY) { //意思是当鼠标mousemove指向的元素不同时
minX = Math.min(_startX, _endX);
maxX = Math.max(_startX, _endX);
minY = Math.min(_startY, _endY);
maxY = Math.max(_startY, _endY);
_excel.BC.modifyFocusSize(minX, parseInt(minY), maxX, parseInt(maxY));
_endPreY = _endY;
}
}
var stop = function (e) {
_excel.BC.cellAddClass(minX, parseInt(minY), maxX, parseInt(maxY));
$(document).unbind({
'mousemove': move,
'mouseup': stop
});
}
$(document).bind({
'mousemove': move,
'mouseup': stop
});
var _filter = function (d) {
return d.nodeName === "DIV" && (d.row || d.rowname);
};
});
}
/**
* 单元格聚焦
*@param {number} el = 传进来的单元格元素
*/
U.MD.O.E.BC.Focus = function (el) {
$(el).bind('mousedown', function (e) {
var _focusBox = $("#U_MD_O_E_focusBox")[0], //聚焦元素
_editorBox = $("#U_MD_O_E_editorBox")[0], //编辑元素
_headInput = $(".U_MD_O_E_headInput")[0]; //文本框元素
U.MD.O.E.BC.focusSwitch(this); //文本框内容同步
if (el.getAttribute("name") == "seted") {
var _style = el.getAttribute("style");
_editorBox.setAttribute("style", _style);
_editorBox.style.zIndex = "";
} else {
$('#U_MD_O_E_editorBox')[0].removeAttribute("style");
}
})
}
/*
* 编辑器失去焦点函数
*/
U.MD.O.E.BC.blur = function () {
var _editorBox = $("#U_MD_O_E_editorBox")[0], //聚焦元素里的编辑器
_focusBox = $("#U_MD_O_E_focusBox")[0],
_headInput = $(".U_MD_O_E_headInput")[0]; //c6文本框元素
$(_editorBox).bind('blur', function (e) {
U.MD.O.E.BC.editorBlur(e);
});
$(_editorBox).bind('mousedown', function (e) {
if ($(this).attr("contenteditable")) {
U.MD.O.E.BC.editorFocus = true;
}
})
$(_headInput).bind('blur', function () {
U.MD.O.E.BC.headInputBlur();
})
}
/*
* 编辑器失焦
*/
U.MD.O.E.BC.editorBlur = function (e) {
var _editorBox = $("#U_MD_O_E_editorBox")[0]; //聚焦元素里的编辑器
U.MD.O.E.BC.editorFocus = false; //文本框已失焦
if (U.MD.O.E.setStyle) {
U.MD.O.E.placeCaretAtEnd(_editorBox.lastElementChild);
U.MD.O.E.setStyle = false;
return;
}
if (!U.MD.O.E.BC.editorFocus && !U.MD.O.E.BC.headInputFocus) {
var _cell = _editorBox.editorCell; //获取最底层的div
_cell.innerHTML = _editorBox.innerHTML; //将聚焦元素的内容赋值给最底层
$(_editorBox).attr("contenteditable", false);
var _allButton = $(".U_MD_O_E_Editor_head_features_ul_d");
for (var i = 0; i < _allButton.length; i++) {
_allButton[i].removeAttribute("disabled");
}
_editorBox.innerHTML = ""; //聚焦元素的内容清空
var _data = {
row: _cell.row,
col: _cell.col,
content: _cell.innerHTML,
innerText: _cell.innerText //之所以要发innerText 是因为要用来判断data数据里单元格的内容如果被改为空 则删除掉该单元格的数据
}; //讲内容打包给后台
U.MD.O.E.dataChange(U.MD.O.E.excelInfo("blur", [_data])); //聚焦时 保存数据
console.log(_cell.id + ":" + "成功!");
}
}
/*
* 文本框失焦事件
*/
U.MD.O.E.BC.headInputBlur = function () {
var _editorBox = $("#U_MD_O_E_editorBox")[0]; //聚焦元素里的
U.MD.O.E.BC.headInputFocus = false;
if (!U.MD.O.E.BC.editorFocus && !U.MD.O.E.BC.headInputFocus) {
var _cell = _editorBox.editorCell;
if (!_cell) return;
_cell.innerHTML = _editorBox.innerHTML; //将值赋值给最下层div
_editorBox.innerHTML = ""; //将聚焦层的值清空
$(_editorBox).attr("contenteditable", false);
var _allButton = $(".U_MD_O_E_Editor_head_features_ul_d");
for (var i = 0; i < _allButton.length; i++) {
_allButton[i].removeAttribute("disabled");
}
//协同操作
var _data = {
row: _cell.row,
col: _cell.col,
content: _cell.innerHTML,
innerText: _cell.innerText //之所以要发innerText 是因为要用来判断data数据里单元格的内容如果被改为空 则删除掉该单元格的数据
}; //讲内容打包给后台
U.MD.O.E.dataChange(U.MD.O.E.excelInfo("blur", [_data])); //聚焦时 保存数据
}
}
/*
* 单元格聚焦后的双击绑定
*/
U.MD.O.E.BC.focusDbClick = function () {
$("#U_MD_O_E_editorBox").bind('dblclick', function (e) {
var _cell = this.focusEl;
this.innerHTML = _cell.innerHTML;
_cell.innerHTML = "";
$(this).attr("contenteditable", true);
if (!this.innerHTML) {
var _div = $$("div", { innerHTML: "\u200D" }, this)
_div.focus();
this.focus();
}
U.MD.O.E.placeCaretAtEnd(this.lastElementChild);
U.MD.O.E.BC.editorFocus = true; //编辑器正在聚焦
this.editorCell = _cell;
var _borderDivList = $(".U_MD_O_E_borderDefalut");
_borderDivList.removeClass("U_MD_O_E_borderDefalut");
_borderDivList.addClass("U_MD_O_E_borderEditable");
});
}
/*
*双击编辑时的初始化
*/
U.MD.O.E.BC.editorKeyEvent = function () {
U.MD.O.E.BC.editorKeyUp(); //keyup事件
U.MD.O.E.BC.editorKeyDown(); //keydown事件
// var _keydown = function (e) {
// var _code = e.keyCode;
// if (_code === 13) {
// // return false;
// //console.log(112)
// }
// }
// var _delinput = function () { //此处为第一行不能删除
// var _range = U.UF.E.getRangeAt(),
// _firstDiv = U.UF.E.getLineElement(_range.startContainer),
// _div;
// if (_firstDiv.id === "U_MD_O_E_editorBox") {
// this.querySelectorAll("br").forEach(function (br) {
// br.remove();
// })
// _div = $$("div", { innerHTML: "\u200D" }, this);
// U.MD.O.E.placeCaretAtEnd(_div);
// }
// };
// var _editorBox = $("#U_MD_O_E_editorBox")[0]; //聚焦元素里的 可编辑div
// var _json = {};
// $(_editorBox).bind('input', _delinput);
};
/*
* 编辑器keyup事件编写
*/
U.MD.O.E.BC.editorKeyUp = function () {
var _cellBox = $(".U_MD_O_E_cellBox")[0], //所有单元格的父节点
_focusBox = $("#U_MD_O_E_focusBox")[0], //聚焦元素
_editorBox = $("#U_MD_O_E_editorBox")[0], //聚焦元素里的 可编辑div
_headInput = $(".U_MD_O_E_headInput")[0]; //c6文本框元素
$(document).bind("keypress", function (e) { //执行函数
if (e.charCode === 13) return; //如果是enter键 则直接return
if ($(_editorBox).attr("contenteditable") === "true") return; //如果编辑器是编辑状态的话 则直接return
$(_editorBox).attr("contenteditable", true);
var _div = $$("div", { innerHTML: "\u200D" }, _editorBox)
U.MD.O.E.placeCaretAtEnd(_div); //产生光标
U.MD.O.E.BC.editorFocus = true; //编辑器正在聚焦
_editorBox.focusEl.innerHTML = ""; //单元格内容清空
_headInput.innerHTML = _editorBox.innerText; //将聚焦元素的 innerHTML 传给文本框
_editorBox.editorCell = _editorBox.focusEl;
var _allButton = $(".U_MD_O_E_Editor_head_features_ul_d");
for (var i = 0; i < _allButton.length; i++) {
_allButton[i].setAttribute("disabled", true);
}
if (_focusBox.style.background) {
var _cell = _editorBox.editorCell;
$(".U_MD_O_E_cellCheckd").removeClass("U_MD_O_E_cellCheckd"); //删除所有被选中状态的单元格
U.MD.O.E.BC.modifyFocusSize(_cell.col, _cell.row, _cell.col, _cell.row);
$(_cell).addClass("U_MD_O_E_cellCheckd");
$(_cell).removeClass("U_MD_O_E_focus");
_focusBox.style.background = "";
}
})
$(_editorBox).bind("input", function (e) { //执行函数
_headInput.innerHTML = _editorBox.innerText; //将聚焦元素的 innerHTML 传给文本框
})
$(_headInput).bind("input", function (e) { //执行函数
U.UF.EV.stopBubble(e); //阻止冒泡
$(_editorBox).attr("contenteditable", true);
_editorBox.innerHTML = this.innerHTML; //将聚焦元素的 innerHTML 传给文本框
_editorBox.focusEl.innerHTML = ""; //单元格内容清空
_editorBox.editorCell = _editorBox.focusEl;
})
$(_headInput).bind("mousedown", function (e) { //执行函数
U.MD.O.E.BC.headInputFocus = true;
})
$(_headInput).bind("keypress", function (e) { //执行函数
U.UF.EV.stopBubble(e); //阻止冒泡
})
}
/*
* 编辑器keyDown事件编写
*/
U.MD.O.E.BC.editorKeyDown = function (e) {
U.UF.EV.addElementEvent("keydown", document, function (e) { //执行函数
var _keyCode = e.keyCode,
_excel = U.MD.O.E.BC;
if (_keyCode === 40 || _keyCode === 13) {
}
if (_keyCode == 8 || _keyCode == 46 || _keyCode == 110) {
if ($('.U_MD_O_E_excelBox')[0].imgStretch.stretch.style.display == "block") {//判断是否为图片删除
var imgObj = $('.U_MD_O_E_excelBox')[0].imgStretch.stretch.upimg.path[0];
imgObj.parentNode.removeChild(imgObj); //删除图片
$('.U_MD_O_E_excelBox')[0].imgStretch.stretch.style.display = "none"; //影藏拉伸框
}
}
switch (_keyCode) {
case 40:
case 13:
_excel.down();
break;
case 37:
_excel.left();
break;
case 38:
_excel.up();
break;
case 39:
_excel.right();
break;
}
}); //禁止浏览器回退
// $(document).bind("keydown", )
};
/*
* 键盘事件向下事件
*/
U.MD.O.E.BC.down = function () {
var _excel = U.MD.O.E.BC,
_editorBox = $("#U_MD_O_E_editorBox")[0], //编辑元素
_headInput = $(".U_MD_O_E_headInput")[0], //文本框元素
cell = _editorBox.focusEl,
minX = cell.col,
maxX = cell.col,
minY = cell.row + 1,
maxY = cell.row + 1; //编辑元素
if (cell.e_merge) { //如果当前是合并单元格元素
minY = cell.e_mergerow + 1;
maxY = cell.e_mergerow + 1;
}
$(cell).attr("contenteditable", false);
cell = $("#POS_" + minX + "_" + minY)[0];
if (!cell) return;
if (cell.e_merge) { //如果下一行的元素是合并单元格元素
minX = cell.s_mergecol;
maxX = cell.e_mergecol;
minY = cell.s_mergerow;
maxY = cell.e_mergerow;
}
_excel.modifyFocusSize(minX, minY, maxX, maxY);
_excel.cellAddClass(minX, minY, maxX, maxY);
if (cell.e_merge) {
_excel.focusSwitch($("#" + cell.s_merge)[0])
} else {
_excel.focusSwitch(cell);
}
_editorBox.blur();
_headInput.blur();
}
/*
* 键盘事件向上事件
*/
U.MD.O.E.BC.up = function () {
var _excel = U.MD.O.E.BC,
_editorBox = $("#U_MD_O_E_editorBox")[0], //编辑元素
_headInput = $(".U_MD_O_E_headInput")[0], //文本框元素
cell = _editorBox.focusEl,
minX = cell.col,
maxX = cell.col,
minY = cell.row - 1,
maxY = cell.row - 1; //编辑元素
if (cell.e_merge) { //如果当前是合并单元格元素
minY = cell.s_mergerow - 1;
maxY = cell.s_mergerow - 1;
}
$(cell).attr("contenteditable", false);
cell = $("#POS_" + minX + "_" + minY)[0];
if (!cell) return;
if (cell.e_merge) { //如果下一行的元素是合并单元格元素
minX = cell.s_mergecol;
maxX = cell.e_mergecol;
minY = cell.s_mergerow;
maxY = cell.e_mergerow;
}
_excel.modifyFocusSize(minX, minY, maxX, maxY);
_excel.cellAddClass(minX, minY, maxX, maxY);
if (cell.e_merge) {
_excel.focusSwitch($("#" + cell.s_merge)[0])
} else {
_excel.focusSwitch(cell);
}
_editorBox.blur();
_headInput.blur();
}
/*
* 键盘事件向左事件
*/
U.MD.O.E.BC.left = function () {
var _excel = U.MD.O.E.BC,
_editorBox = $("#U_MD_O_E_editorBox")[0], //编辑元素
_headInput = $(".U_MD_O_E_headInput")[0], //文本框元素
cell = _editorBox.focusEl,
minX = cell.col - 1,
maxX = cell.col - 1,
minY = cell.row,
maxY = cell.row; //编辑元素
if (cell.e_merge) { //如果当前是合并单元格元素
minX = cell.s_mergecol - 1;
maxX = cell.s_mergecol - 1;
}
$(cell).attr("contenteditable", false);
cell = $("#POS_" + minX + "_" + minY)[0];
if (!cell) return;
if (cell.e_merge) { //如果下一行的元素是合并单元格元素
minX = cell.s_mergecol;
maxX = cell.e_mergecol;
minY = cell.s_mergerow;
maxY = cell.e_mergerow;
}
_excel.modifyFocusSize(minX, minY, maxX, maxY);
_excel.cellAddClass(minX, minY, maxX, maxY);
if (cell.e_merge) {
_excel.focusSwitch($("#" + cell.s_merge)[0])
} else {
_excel.focusSwitch(cell);
}
_editorBox.blur();
_headInput.blur();
}
/*
* 键盘事件向右事件
*/
U.MD.O.E.BC.right = function () {
var _excel = U.MD.O.E.BC,
_editorBox = $("#U_MD_O_E_editorBox")[0], //编辑元素
_headInput = $(".U_MD_O_E_headInput")[0], //文本框元素
cell = _editorBox.focusEl,
minX = cell.col + 1,
maxX = cell.col + 1,
minY = cell.row,
maxY = cell.row; //编辑元素
if (cell.e_merge) { //如果当前是合并单元格元素
minX = cell.e_mergecol + 1;
maxX = cell.e_mergecol + 1;
}
$(cell).attr("contenteditable", false);
cell = $("#POS_" + minX + "_" + minY)[0];
console.log($("#" + cell.s_merge)[0]);
if (!cell) return;
if (cell.e_merge) { //如果下一行的元素是合并单元格元素
minX = cell.s_mergecol;
maxX = cell.e_mergecol;
minY = cell.s_mergerow;
maxY = cell.e_mergerow;
}
_excel.modifyFocusSize(minX, minY, maxX, maxY);
_excel.cellAddClass(minX, minY, maxX, maxY);
if (cell.e_merge) {
_excel.focusSwitch($("#" + cell.s_merge)[0])
} else {
_excel.focusSwitch(cell);
}
_editorBox.blur();
_headInput.blur();
}
/* 聚焦元素切换时 文本框内容同步
* @param {number} cell 单元格元素
*/
U.MD.O.E.BC.focusSwitch = function (cell) {
var _editorBox = $("#U_MD_O_E_editorBox")[0], //编辑元素
_focusBox = $("#U_MD_O_E_focusBox")[0], //聚焦元素
_headInput = $(".U_MD_O_E_headInput")[0]; //文本框元素
_editorBox.focusEl = cell;
_headInput.innerHTML = cell.innerHTML; //将聚焦元素的 innerHTML 传给文本框
$(".U_MD_O_E_focus").removeClass("U_MD_O_E_focus");
$(cell).addClass('U_MD_O_E_focus'); //第一个聚焦的颜色一定是白色
_focusBox.style.zIndex = "1";
_focusBox.style.background = "";
$(cell).attr("contenteditable", true);
}
/*
* 重新选择单元格
* @param {element} data 如果data不存在 则重新调整聚焦元素的大小
*/
U.MD.O.E.BC.reSelectCell = function (data) {
var _excel = U.MD.O.E;
if (!data) { //如果data不存在 则重新调整聚焦元素的大小
var _startcell = _excel.cellCheckd()[0], //获取首个选中元素
_endcell = _excel.cellCheckd()[1], //获取最后一个选中的元素
_minx = _startcell.col,
_miny = _startcell.row,
_maxx = _endcell.col,
_maxy = _endcell.row;
_excel.BC.modifyFocusSize(_minx, _miny, _maxx, _maxy); //重新调整聚焦元素的大小
return;
} else {
var _data = data,
_checkeddata = _data.checkeddata, //右键前的两单元格的坐标数据
_type = data.type;
if (_data.type === "removeLine") {
var _linenum = $(".U_MD_O_E_row").length, //总行数
_rmlineNum = _data.rmlinenum; //删除行的数量
if (_checkeddata.maxy > _linenum) { //如果删除前单元格的行 大于 删后的总数量的话:
_checkeddata.miny = _checkeddata.miny - _rmlineNum;
_checkeddata.maxy = _checkeddata.maxy - _rmlineNum;
}
} else if (_data.type === "removeCol") {
var _colnum = $(".U_MD_O_E_column").length, //总列数
_rmcolnum = _data.rmcolnum; //删除列的数量
if (_checkeddata.maxx > _colnum) { //如果删除前单元格的列 大于 删后的总数量的话:
_checkeddata.minx = _checkeddata.minx - _rmcolnum;
_checkeddata.maxx = _checkeddata.maxx - _rmcolnum;
}
}
}
var _minx = _checkeddata.minx,
_miny = _checkeddata.miny,
_maxx = _checkeddata.maxx,
_maxy = _checkeddata.maxy;
_excel.BC.modifyFocusSize(_minx, _miny, _maxx, _maxy);
_excel.BC.cellAddClass(_minx, _miny, _maxx, _maxy);
}
/*
* return object
* @param {element} startcell 左上角的单元格
* @param {element} endcell 右下角的单元格
*/
U.MD.O.E.BC.selectCellData = function (startcell, endcell) {
var minx = startcell.col,
miny = startcell.row,
maxx = endcell.col,
maxy = endcell.row;
return {
minx: minx,
miny: miny,
maxx: maxx,
maxy: maxy
}
}
/*
* 添加自定义attr属性的同时 且添加了原型链下的属性
* @param {element} value 属性
*/
U.select.prototype.eAttr = function (value, item) {
$(this).attr(value, item);
var _value = value.toLowerCase();
this[0][_value] = item;
}
/*
* 删除attr属性时 原型链下的属性也跟着删掉
* @param {element} value 属性
*/
U.select.prototype.eRmAttr = function (value) {
$(this).rmAttr(value);
delete (this[0][value]);
}
/*
* 图片总控制
* @param {element} img 图片元素
*/
U.MD.O.E.BC.pictureControl = function (img) {
U.MD.O.E.BC.pictureControl.imgDrag(img); //图片拖拽
}
/*
* 图片拖拽
* @param {element} img 图片元素
*/
U.MD.O.E.BC.pictureControl.imgDrag = function (img) {
$(img).bind("mousedown", function (e) {
U.UF.EV.stopBubble(e); //阻止冒泡
U.UF.EV.stopDefault(e); //取消默认拖拽
var _oY = e.pageY, //选中时的y
_oX = e.pageX, //选中时的x
_marginLeft = img.offsetLeft, //图片的左边距
_marginTop = img.offsetTop, //图片的上边距
_newY,
_newX,
_copydata = {};
var _drapMove = function (e) {//拖拽时移动用的函数
U.UF.EV.stopBubble(e); //阻止冒泡wx`
_newY = e.pageY; //位移后的Y
_newX = e.pageX; //位移后的X
_differenceY = _newY - _oY; //位移后的值和选中的值得差值
_differenceX = _newX - _oX;
img.style.left = _marginLeft + _differenceX + "px";
img.style.top = _marginTop + _differenceY + "px";
};
var _dragUp = function () { //拖拽时松开用的函数
$(document).unbind('mousemove', _drapMove);
$(document).unbind('mouseup', _dragUp);
var _data = {
src: img.src,
left: parseFloat(img.style.left),
top: parseFloat(img.style.top),
width: img.offsetWidth,
height: img.offsetHeight,
type: "img"
};
U.MD.O.E.dataChange(U.MD.O.E.excelInfo("imgChange", _data));
};
$(document).bind('mousemove', _drapMove);
$(document).bind('mouseup', _dragUp);
})
}
/**
* 添加超链接
* @param {element} _cellList为选中的单元集合
* @param {element} req 判断是否发送数据给后台
* */
U.UF.E.excelAddHref = function (_cellList, req) {
var _editorBox = $("#U_MD_O_E_editorBox")[0],
_cellList = U.UF.C.toArray($(".U_MD_O_E_cellCheckd"));
//判断是否多个单元格选择
if (req !== true) {
if (_cellList.length > 1) {
//如果是则提示无法添加A标签
U.UF.UI.alertClick('选择范围过多,因此无法编辑');
} else {
//否则执行添加A标签操作
_a = $('a', _cellList[0])[0]; //获取选区中的第一个a标签
if (_a) {//如果有a标签则执行弹出删除链接的提示框
_href = _a ? _a.href : '', //如果存在则已第一个a标签做为href
_text = _editorBox.focusEl.innerText; //获取选区的文字
_trimtext = _text.trim(); //删除空格字符
var _box = $$('div'); //创建Confirm最大层div
var _hrefinput = $$('div', { innerHTML: '链接', style: { 'margin-top': '15px'} }, _box); //创建链接区域
U.UF.UI.canconfirm(_box, U.UF.C.closure(U.UF.E.addHref.excelConfirm, [_cellList, _hrefinput, _textinput, _trimtext])); //创建Confirm
} else {
_href = _a ? _a.href : '', //如果存在则已第一个a标签做为href
_text = _editorBox.focusEl.innerText; //获取选区的文字
_trimtext = _text.trim(); //删除空格字符
var _box = $$('div', { "style": { 'display': 'flex', 'flex-direction': 'column', 'margin-left': '41px'} }); //创建Confirm最大层div
var _textinput = $$('div', { innerHTML: '文本', style: { 'margin-top': '25px'} }, _box); //创建文本区域
var _hrefinput = $$('div', { innerHTML: '链接', style: { 'margin-top': '20px'} }, _box); //创建链接区域
U.UF.UI.confirm(_box, U.UF.C.closure(U.UF.E.addHref.excelConfirm, [_cellList, _hrefinput, _textinput, _trimtext])); //创建Confirm
}
$(".confirm_input").bind('keyup', function (e) {
U.UF.EV.stopBubble(e); //阻止冒泡
})
$(".confirm_input").bind('keydown', function (e) {
U.UF.EV.stopBubble(e); //阻止冒泡
})
$(".confirm_input").bind('keypress', function (e) {
U.UF.EV.stopBubble(e); //阻止冒泡
})
}
}
//判断是否发送给后台
if (req == true) {
var _data = {
row: _cellList[0].row,
col: _cellList[0].col,
content: _cellList[0].innerHTML
}
U.MD.O.E.dataChange(U.MD.O.E.excelInfo("clearAContent", _data));
}
};
/*
*单元格文字复制
*/
U.MD.O.E.BC.cloneCell = function () {
var _clonecorner = $(".U_MD_O_E_borderCorner")[0]; //获取选中的单元格
$(_clonecorner).bind('mousedown', function (e) {
var _excel = U.MD.O.E,
_focusBox = $("#U_MD_O_E_focusBox")[0], //获取选中单元格的最上层
_editorBox = $("#U_MD_O_E_editorBox")[0], //获取选中单元格的内容层
_startEl = $(".U_MD_O_E_focus")[0], //获取点击元素
_startElHtml = _startEl.innerHTML,
_startX = _startEl.col, //记录x坐标轴 A-Z
_startY = _startEl.row, //获取y坐标轴 1-200的数字\
_endX = _startX, //结束点x
_endY = _startY, //结束点y
_endPreX = _startX,
_endPreY = _startY,
_parent = $(".U_MD_O_E_focus")[0].parentNode,
_elList,
_drag = false,
i,
j,
minX = Math.min(_startX, _endX),
maxX = Math.max(_startX, _endX),
minY = Math.min(_startY, _endY),
maxY = Math.max(_startY, _endY),
_endEl;
var _drapMove = function (e) {
//单元格选中
var _elNum = 0,
_elList = e.path,
_endEl = _elList.filter(_filter)[0];
U.UF.EV.stopBubble(e); //阻止冒泡
U.UF.EV.stopDefault(e); //取消默认拖拽
if (!_endEl || !(_endEl.row) || !(_endEl.col)) return; //如果没有自定义属性(其他非单元格元素) 则不判断
_endX = _endEl.col; //结束点的x坐标
_endY = _endEl.row; //结束点的y坐标
if (_endX !== _endPreX || _endY !== _endPreY) { //意思是当鼠标mousemove指向的元素不同时
_focusBox.style.zIndex = "";
minX = Math.min(_startX, _endX);
maxX = Math.max(_startX, _endX);
minY = Math.min(_startY, _endY);
maxY = Math.max(_startY, _endY);
var _cellEl,
s_mergeCell, //合并单元格元素
_cellArr = [];
for (i = minX; i <= maxX; i++) {
for (j = minY; j <= maxY; j++) {
_cellEl = $(_parent).find("#POS_" + i + "_" + j)[0];
_cellEl.s_merge ? s_mergeCell = $(_parent).find("#" + _cellEl.s_merge)[0] : "";
if (s_mergeCell && _cellArr.indexOf(s_mergeCell) === -1) { //如果选中的是合并单元格的元素
_endCell = $(_parent).find("#" + _cellEl.e_merge)[0];
_cellArr.push(s_mergeCell);
minX = Math.min(minX, s_mergeCell.col, _endCell.col);
maxX = Math.max(maxX, s_mergeCell.col, _endCell.col);
minY = Math.min(minY, s_mergeCell.row, _endCell.row);
maxY = Math.max(maxY, s_mergeCell.row, _endCell.row);
i = minX;
j = minY;
}
}
}
_excel.BC.modifyFocusSize(minX, parseInt(minY), maxX, parseInt(maxY));
_endPreX = _endX;
_endPreY = _endY;
}
}
var _drapUp = function (e) {
//结束事件
_startEl.style.zIndex = "0";
_excel.BC.cellAddClass(minX, parseInt(minY), maxX, parseInt(maxY));
var _allcheckdcell = $(".U_MD_O_E_cellCheckd"),
_copydata = [];
for (var k = 0; k < _allcheckdcell.length; k++) {
_allcheckdcell[k].innerHTML = _startElHtml;
var _data = {
row: _allcheckdcell[k].row,
col: _allcheckdcell[k].col,
content: _allcheckdcell[k].innerHTML,
innerText: _allcheckdcell[k].innerText //之所以要发innerText 是因为要用来判断data数据里单元格的内容如果被改为空 则删除掉该单元格的数据
}; //讲内容打包给后台
_copydata.push(_data);
}
U.MD.O.E.dataChange(U.MD.O.E.excelInfo("blur", _copydata));
$(document).unbind('mousemove', _drapMove); //结束mousemove事件
$(document).unbind('mouseup', _drapUp); //结束mouseup事件
}
$(document).bind('mousemove', _drapMove);
$(document).bind('mouseup', _drapUp);
});
var _filter = function (d) {
return d.nodeName === "DIV" && d.col;
};
}