wdDragHeight.js 11 KB

1
  1. function initWdDragHeight(offsetheight, topNum) { line(offsetheight); if(true)return var reduceHeight = window.innerHeight - document.body.offsetHeight var TAGATTRIBUTE = "ssDragh"; // = "wdDragHeight"。Lin var iframes = document.querySelectorAll("[" + TAGATTRIBUTE + "]"); var lines = document.querySelectorAll("#line"); var maxHeight = (window.innerHeight || window.screen.availHeight) - offsetheight; for (var i = 0; i < iframes.length; i++) { iframes[i].setHeight = function (v) { this.style.height = v + "px"; this.height = v; } } if(iframes.length>0&&lines.length==0){ var line_div = document.createElement('div'); // 新增元素 line_div.className ="content-hSeperator"; line_div.id = "line"; line_div.innerHTML = "<img src='wd/js/app/line.png' alt='' />"; iframes[1].parentNode.insertBefore(line_div, iframes[1]); // 在这个元素前面增加上去 } //抽取top数值与topNum相同iframes。 if (topNum != null) { var temp = []; for (var i = 0; i < iframes.length; i++) { var array = /top\s*?:\s*?(\d+)/ig.exec(iframes[i].getAttribute(TAGATTRIBUTE)) if (array != null && array[1] == topNum) {//无top参数并且topNum为1时 temp.push(iframes[i]); } } iframes = temp } else {//topNum为null默认为第一层 var temp = []; for (var i = 0; i < iframes.length; i++) { if (!/top\s*?:\s*?(\d+)/ig.test(iframes[i].getAttribute(TAGATTRIBUTE))) {//无top参数并且topNum为1时 temp.push(iframes[i]); } else if (/top\s*?:\s*?1/ig.test(iframes[i].getAttribute(TAGATTRIBUTE))) { temp.push(iframes[i]); } } iframes = temp; } if (iframes.length == 0) return; //如果iframes的长度大于0执行自适应 var usableHeight = 0; if (topNum == null || topNum < 2) {//第一层的处理,iframes可以适应的高度计算 usableHeight = reduceHeight; for (var i = 0; i < iframes.length; i++) { usableHeight += iframes[i].offsetHeight; } //如果有bjgd数据,优先使用bjgd if (offsetheight != null) { usableHeight = maxHeight; } } else { var p = findParent(iframes[0], topNum - 1);//查找上一级的自适应元素,用于获取高 var pWdFitHeight = p.getAttribute(TAGATTRIBUTE); var array = /fixHeight\s*?:\s*?(\d+)/ig.exec(pWdFitHeight); if (array != null) { usableHeight = p.offsetHeight - parseInt(array[1]); } else { usableHeight = p.offsetHeight; } } // console.log("usableHeight: " + usableHeight); //禁止滚动条 document.body.style.overflow = "hidden"; var heightArr = [];//存放计算后得到的height百分 var minHighArr = [];//存放iframe的minHigh var maxHighArr = [];//存放iframe的maxHigh var currentHeight = 0;//当前百分比 var hasHeightCount = 0; for (var i = 0; i < iframes.length; i++) { var wdFitHeight = iframes[i].getAttribute(TAGATTRIBUTE); var array = /(\d+)%/.exec(wdFitHeight); if (!!array) { heightArr[i] = parseInt(array[1]); currentHeight += parseInt(array[1]); hasHeightCount++; } array = /min\s*?:\s*?(\d+)/.exec(wdFitHeight) if (!!array) { minHighArr[i] = parseInt(array[1]); } array = /max\s*?:\s*?(\d+)/.exec(wdFitHeight) if (!!array) { maxHighArr[i] = parseInt(array[1]); } } //重新计算heightArr; //计算百分比 if (currentHeight < 100) { var a = (100 - currentHeight) / (iframes.length - hasHeightCount); for (var i = 0; i < iframes.length; i++) { if (!!!heightArr[i]) { heightArr[i] = a; currentHeight += a; } } } var temp = usableHeight; // tip("usableHeight:"+usableHeight,true) //min max 限制百分比高度 for (var i = 0; i < iframes.length; i++) { //百分比高度 var height = usableHeight * heightArr[i] / 100; //限定高度最大值 if (height > temp) { height = temp; temp = 0; } else { //最小值 if (!!minHighArr[i] && minHighArr[i] > height) { height = minHighArr[i]; //最大值 } else if (!!maxHighArr[i] && maxHighArr[i] < height) { height = maxHighArr[i]; } temp -= height; } // if(iframes[i].name && iframes[i].name.indexOf('Edit') != -1) { // height -= 107; // } // console.log("height:" + height); iframes[i].style.height = height + "px"; // iframes[i].setHeight(height); // var ifr=iframes[i].querySelector("iframe"); // if(ifr){ // ifr.height=height; // ifr.style.height=height; // } } //计算内层wdFitHeight元素 if (topNum == null) { arguments.callee(offsetheight, 2) } else { arguments.callee(offsetheight, topNum + 1); } line(offsetheight); function findParent(ele, topNum) { var cur = ele; do { cur = cur.parentElement; if (cur == null) return null; if (new RegExp('top\s*?:\s*?' + topNum, 'ig').test(cur.getAttribute(TAGATTRIBUTE))) { return cur; } } while (true); return null; } } //初始化拖动线 function line(offsetheight) { var iframes = document.querySelectorAll("[ssDragh]"); // ("[" + "wdDragheight" + "]")。Lin if (iframes.length != 2) return for (var i = 0; i < iframes.length; i++) { iframes[i].setHeight = function (v) { this.style.height = v + "px"; this.height = v; } } var lines = document.querySelectorAll("#line"); if(iframes.length>0&&lines.length==0){ var line_div = document.createElement('div'); // 新增元素 line_div.className ="content-hSeperator"; line_div.id = "line"; //拖动遮罩层 var mask="<div class=\"dragmask\" style=\"display:none;position: absolute;width: 70px;height: 70px;top: -35px;right: 0px;\"></div>" // line_div.innerHTML =mask+ "<span></span>"; line_div.innerHTML ="<span></span>"; iframes[1].parentNode.insertBefore(line_div, iframes[1]); // 在这个元素前面增加上去 } el = document.getElementById("line"); el.style.zIndex = "99"; var wh = window.innerHeight; var lineOneHeight = el.offsetHeight; iframes[0].style.display = "block"; iframes[1].style.display = "block"; var maxHeight = document.body.offsetHeight - offsetheight; var topDiv = iframes[0]; var bottomDiv = iframes[1]; // console.log(window.getComputedStyle(el).height); //减少怎加线导致总高度问题 bottomDiv.style.height=parseInt(bottomDiv.style.height)-parseInt(window.getComputedStyle(el).height); // topDiv.innerHTML = window.screen.availHeight+' '+ document.body.offsetHeight; // bottomDiv.style.height = maxHeight - topDiv.offsetHeight - 40 + 'px'; // console.log(bottomDiv.offsetHeight); // topDiv.style.maxHeight=parseInt( bottomDiv.style.height)+parseInt( topDiv.style.height); // bottomDiv.style.maxHeight=parseInt( bottomDiv.style.height)+parseInt( topDiv.style.height); //PC端的变量 var start_Y; var top_Height; var middle_Height; var starty = 0; var topStartHeight = 0; var bottomStartHeight = 0; var dragmask=el.querySelector(".dragmask"); var ismousedown = false; el.onmousedown = function (e) { ismousedown = true; e.preventDefault(); starty = e.screenY; // topStartHeight = parseInt(topDiv.offsetHeight) || 50; // bottomStartHeight = parseInt(bottomDiv.offsetHeight) || 50; topStartHeight = parseInt(topDiv.style.height) || 0; bottomStartHeight = parseInt(bottomDiv.style.height) || 0; if(dragmask){ dragmask.style.display=""; } } document.onmouseup = function (e) { ismousedown = false; wd.display.initWdFitHeight(window); if(dragmask){ dragmask.style.display="none"; } } document.onmousemove = function (e) { e = e || window.event; if(ismousedown&&e.which ==0){ ismousedown = false; // wd.display.initWdFitHeight(window); } if (ismousedown) { e.preventDefault(); var pageY = e.screenY; // var topDivHeight = topStartHeight + (pageY - starty); // var bottomDivHeight = maxHeight - topDivHeight - 2; var topDivHeight = topStartHeight + (pageY - starty); var bottomDivHeight = bottomStartHeight - (pageY - starty); // console.log(topDivHeight+" "+bottomDivHeight) if (topDivHeight < 0 || bottomDivHeight < 0) { ismousedown = false; // wd.display.initWdFitHeight(window); return; } topDiv.style.height = topDivHeight + "px"; bottomDiv.style.height = bottomDivHeight + "px"; //console.log(e.which); } } // el.addEventListener('mousedown', pcLineOneStart, false); // /**** // PC端的处理 // ****/ // function pcLineOneStart(e) { // e.preventDefault(); // starty = e.screenY; // document.addEventListener('mousemove', pcLineOneMove, false); // el.addEventListener('mouseup', pcLineOneEnd, false); // topStartHeight = parseInt(topDiv.offsetHeight) || 50; // bottomStartHeight = parseInt(bottomDiv.offsetHeight) || 50; // } // function pcLineOneMove(e) { // e.preventDefault(); // var pageY = e.screenY; // // // if(pageY>= (maxHeight - 20) || pageY < 10 )return // // if (pageY >= (maxHeight - 20)) { // // topDiv.style.height = maxHeight - 20 + 'px'; // // return // // } else if (pageY < 10) { // // return // // } // var topDivHeight = topStartHeight + (pageY - starty); // // var bottomDivHeight=bottomStartHeight-(pageY-starty); // var bottomDivHeight = maxHeight - topDivHeight - 2; // if(topDivHeight<=0||bottomDivHeight<=0){ // return; // } // topDiv.style.height = topDivHeight + "px" // bottomDiv.style.height = bottomDivHeight + "px" // } // function pcLineOneEnd() { // document.removeEventListener('mousemove', pcLineOneMove, false); // wd.display.initWdFitHeight(); // } }