Template:Jilin China/renderText.js

/**

* 
* @authors Lhx (you@example.org)
* @date    2019-05-31 19:31:05
* @version 1.1
*/

//全局div textCont var content=cloneObjectFn(content_alpha);

var textCont = document.createElement("div"); var TH = document.createElement("div"); $$("third_1_1").appendChild(TH); addClass(TH, "tnr"); $$("third_1_1").appendChild(textCont); TH.setAttribute("id", "TH");

textCont.setAttribute('id', "tC"); //全局单种元素统计 var countWord = 0; var countPic = 0; var countTable = 0; var countDiv = 0; var eachCountWord = []; //查询word在每个部分自己的编号 var folderNow = []; var replaceList = []; //词汇替换列表 var textMode = 1; if(setting.pageSetting.cWTS=="Card"){ textMode = 1; } else{ textMode = 0; }



function deall(str){ //var sstr=str; var regExp_s = /\(ita\)|\(itaed\)|\(sup\)|\(suped\)|\(sub\)|\(subed\)/g;

   var result = str.replace(regExp_s, "");

return result; } function qjobj(){ for (var i = 0; i < content.part.length; i++) { for (var j = 0; j < content.part[i].para.length; j++) {

 			if (content.part[i].para[j].type == "word") {

content.part[i].para[j].cont=deall(content.part[i].para[j].cont); } } } } qjobj(); //自定义区新增下角标和上角标和斜体文字(in Textlab)

//元老函数 //文字处理 生成不断更新的字符串 function productWord(that) { if (!that.hasOwnProperty("cont") || that.cont.length == 0) { return; } var wordCont = document.createElement("p");

var htmlStr = that.cont; if (that.hasOwnProperty("spClass") && that.spClass.length > 0) { for (var i = 0; i < that.spClass.length; i++) { htmlStr = findWordAndReplace(that.spClass[i][0], that.spClass[i][1], htmlStr); } } if (that.hasOwnProperty("link") && that.link.length > 0) { for (var i = 0; i < that.link.length; i++) { htmlStr = addUrl(that.link[i][0], that.link[i][1], htmlStr); } } wordCont.innerHTML = htmlStr; if (that.hasOwnProperty("class")) { addClass(wordCont, that.class); }

return wordCont;

}

function renderWord(that, i, j, cont) { var newWord = productWord(that); addClass(newWord, "word") cont.appendChild(newWord); countWord++; eachCountWord[i]++;

newWord.setAttribute('data-para-fatherid', i); //new 7/23 //part的编号 newWord.setAttribute('id', "a" + (countWord + i)); newWord.setAttribute('data-para-id', countWord); //全文章中word总 newWord.setAttribute('data-para-eachid', eachCountWord[i]); //查询word在每个部分单纯word中自己的编号 newWord.setAttribute('data-para-realid', j); //查询word在实际部分自己的编号 console.log(newWord); //控制台展示

}

function renderPic(that, cont) {

if (!that.hasOwnProperty("cont") || that.cont.length == 0) { //图组检测 没有内容不进行渲染 return; } var picCont = document.createElement("div"); //图组的总div if (that.hasOwnProperty("maxClass")) { addClass(picCont, that.maxClass); } addClass(picCont, "picCont"); for (var i = 0; i < that.cont.length; i++) { //迭代进行每一组的渲染

if (!(that.cont[i].hasOwnProperty("num")) || that.cont[i].num <= 0) { //检测图组数量,未标明的情况下为图adress数 that.cont[i].num = that.cont[i].adress.length; }

if (that.cont[i].hasOwnProperty("pre") && that.cont[i].pre.length > 0) { var perNum = [0, 0, 0]; //后面计算百分比的 perNum[0] = i; perNum[2] = Math.min.apply(null, that.cont[i].pre); if (that.cont[i].pre.length - 1 < that.cont[i].num) { addClass(picCont, "w100"); for (p = 0; p < that.cont[i].pre.length; p++) { perNum[1] += that.cont[i].pre[p]; } perNum[1] += (that.cont[i].num - that.cont[i].pre.length) * perNum[2]; } if (that.cont[i].pre.length - 1 == that.cont[i].num) { addClass(picCont, "w" + that.cont[i].pre[that.cont[i].pre.length - 1]); for (var x = 0; x < that.cont[i].pre.length - 1; x++) { perNum[1] += that.cont[i].pre[x]; } }

}


if (that.cont[i].num != 1) { //为了节省计算速度,将最常见的一张图渲染单拿出来 //当图的数量不为1的时候按照以下步骤操作 for (var j = 0; j < that.cont[i].num; j++) { //尝试一张图一张图的渲染 var innerPic = document.createElement("div"); //创造一个小div装图片 每次换图更新那种 addClass(innerPic, "pic"); if (that.cont[i].hasOwnProperty("adress") && that.cont[i].adress.length > 0) { //如果addre属性存在的话

for (var k = 0; k < that.cont[i].adress.length; k++) { //根据adress(因为他的数准)进行迭代带匹配 按j顺序

if (that.cont[i].adress[k][0] == (j + 1)) { //顺便带一手 省得下边的循环 innerPic.style.backgroundImage = "url(" + that.cont[i].adress[k][1] + ")"; } else { for (var l = 0; l < that.cont[i].adress.length; l++) { if (that.cont[i].adress[l][0] == (j + 1)) { innerPic.style.backgroundImage = "url(" + that.cont[i].adress[l][1] + ")"; break; }


} } //在还未输出的时候对链接进行填充 if (that.cont[i].hasOwnProperty("link") && that.cont[i].link.length > 0) { var linkInPic = ""; if (that.cont[i].link[j][0] == (j + 1)) { //一样,不按顺序写可就麻烦了 linkInPic = "<a href=\"" + that.cont[i].link[j][1] + "\"><\/a>"; } else { for (var o = 0; o < that.cont[i].link.length; o++) { if (that.cont[i].link[o][0] == (j + 1)) { linkInPic = "<a href=\"" + that.cont[i].link[o][1] + "\"><\/a>"; break; } } }


innerPic.innerHTML = linkInPic; }

//在链接填充后在获取一下class和比例 if (that.cont[i].hasOwnProperty("pre") && that.cont[i].pre.length > 0) { if (that.cont[i].pre.length - 1 < that.cont[i].num) { if (j < that.cont[i].pre.length) { var percent = that.cont[i].pre[j] * 100 / perNum[1]; addClass(innerPic, "w" + percent); innerPic.style.width = percent + "%"; } else { var percent = perNum[2] * 100 / perNum[1]; addClass(innerPic, "w" + percent); innerPic.style.width = percent + "%"; }

//没写的按照最小的按照比例进行平分

} else { //按比例分配 总的按照第三个来 var percent = that.cont[i].pre[j] * 100 / perNum[1]; addClass(innerPic, "w" + percent); innerPic.style.width = percent + "%"; }

} picCont.appendChild(innerPic); //修饰好的innerpic }

} if (that.cont[i].hasOwnProperty("figure")) { for (var y = 0; y < that.cont[i].figure.length; y++) { if (y == j) { var newfigure = productWord(that.cont[i].figure[y][1]); addClass(newfigure, "picword"); picCont.appendChild(newfigure); } } }


} //分配比例区 未声明情况下 50% 50% 100%



}

if (that.cont[i].num == 1) { var innerPic = document.createElement("div"); addClass(innerPic, "pic"); innerPic.style.backgroundImage = "url("+ that.cont[i].adress + ")"; innerPic.innerHTML = "<a href=\"" + that.cont[i].link + "\"><\/a>"; addClass(innerPic, "w" + that.cont[i].pre); innerPic.style.width = that.cont[i].pre + "%"; picCont.appendChild(innerPic);

if (that.cont[i].hasOwnProperty("figure")) { var newfigure = productWord(that.cont[i].figure); addClass(newfigure, "picword"); picCont.appendChild(newfigure); }

}


} //所有组渲染结束 cont.appendChild(picCont); console.log(picCont); //console.log(that.cont);

}

function renderTable(that, cont) { if (!that.hasOwnProperty("cont") || that.cont.length == 0) { //表组检测 没有内容不进行渲染 return; } var tableCont = document.createElement("div"); //表组的总div addClass(tableCont, "tableCont"); for (var i = 0; i < that.cont.length; i++) { //表组循环 几个组 if (!(that.cont[i].hasOwnProperty("num")) || that.cont[i].num <= 0) { //检测表组数量,未标明的情况下为图table_c数 that.cont[i].num = that.cont[i].table_c.length; } if (that.cont[i].hasOwnProperty("pre") && that.cont[i].pre.length > 0) { var perNum = [0, 0, 0]; //后面计算百分比的 perNum[0] = i; perNum[2] = Math.min.apply(null, that.cont[i].pre); if (that.cont[i].pre.length - 1 < that.cont[i].num) { addClass(tableCont, "w100"); for (p = 0; p < that.cont[i].pre.length; p++) { perNum[1] += that.cont[i].pre[p]; } perNum[1] += (that.cont[i].num - that.cont[i].pre.length) * perNum[2]; } if (that.cont[i].pre.length - 1 == that.cont[i].num) {

addClass(tableCont, that.cont[i].pre[that.cont[i].pre.length - 1]); for (var x = 0; x < that.cont[i].pre.length - 1; x++) { perNum[1] += that.cont[i].pre[x]; } }

} if (that.cont[i].num != 1) { //为了节省计算速度,将最常见的一张渲染单拿出来 //当表的数量大于1的时候按照以下步骤操作

for (var j = 0; j < that.cont[i].num; j++) { //尝试一张一张的渲染 var outerTable = document.createElement("table"); addClass(outerTable, "table"); var innerTable = document.createElement("tbody"); //创造一个小div装图片 每次换图更新那种

addClass(innerTable, that.cont[i].table_s[j][1].class); if (that.cont[i].hasOwnProperty("table_c") && that.cont[i].table_c.length > 0) { //如果table_c属性存在的话

//根据table_c(因为他的数准)进行迭代带匹配 按j顺序 if (that.cont[i].table_c[j][0] == (j + 1)) { //顺便带一手 省得下边的循环 if (that.cont[i].table_s[j][0] && that.cont[i].table_s[j][0] == (j + 1)) { innerTable.innerHTML = productTable(that.cont[i].table_c[j][1], that.cont[i].table_s[j][1]); } //懒得兼容哦


} else { for (var l = 0; l < that.cont[i].table_c.length; l++) { if (that.cont[i].table_c[l][0] == (j + 1)) { if (that.cont[i].table_s[l][0] && that.cont[i].table_s[l][0] == (j + 1)) { innerTable.innerHTML = productTable(that.cont[i].table_c[l][1], that.cont[i].table_s[l][1]); //懒得兼容哦 break; } }


} }


}

//在链接填充后在获取一下class和比例 if (that.cont[i].hasOwnProperty("pre") && that.cont[i].pre.length > 0) { if (that.cont[i].pre.length - 1 < that.cont[i].num) { if (j < that.cont[i].pre.length) { var percent = that.cont[i].pre[j] * 100 / perNum[1]; addClass(innerTable, "w" + percent); } else { var percent = perNum[2] * 100 / perNum[1]; addClass(innerTable, "w" + percent); }

//没写的按照最小的按照比例进行平分

} else { //按比例分配 总的按照第三个来 var percent = that.cont[i].pre[j] * 100 / perNum[1]; addClass(innerTable, "w" + percent); }

} outerTable.appendChild(innerTable); tableCont.appendChild(outerTable); if (that.cont[i].hasOwnProperty("figure")) {


for (var y = 0; y < that.cont[i].figure.length; y++) { if (y == j) { var newfigure = productWord(that.cont[i].figure[y][1]); addClass(newfigure, "tableword"); tableCont.appendChild(newfigure); } } }


}


} if (that.cont[i].num == 1) { var outerTable = document.createElement("table"); addClass(outerTable, "table"); var innerTable = document.createElement("tbody"); addClass(innerTable, "w100"); innerTable.innerHTML = productTable(that.cont[i].table_c, that.cont[i].table_s); addClass(innerTable, "w" + that.cont[i].pre); outerTable.appendChild(innerTable); tableCont.appendChild(outerTable);

if (that.cont[i].hasOwnProperty("figure")) { var newfigure = productWord(that.cont[i].figure); addClass(newfigure, "tableword"); tableCont.appendChild(newfigure); }

}


cont.appendChild(tableCont);





}

//console.log(that.cont);

}

function renderDiv(that, cont) { var div = document.createElement("div"); div.setAttribute("id", that.id); if (that.hasOwnProperty("class")){ for(var i=0;i<that.class.length;i++){ addClass(div,that.class[i]); } } cont.appendChild(div); console.log(that.num);

}

//功能函数

//在某段文字中为特定的几个文字加上特定的标签 function findWordAndReplace(reg, tag, sStr) { var regExp_s = new RegExp(reg, "ug"); //console.log(regExp_s.test(sStr)); //console.log(regExp_s); var result = sStr.replace(regExp_s, "<" + tag + ">" + reg + "</" + tag + ">"); return result; } //在某段文字中为特定的几个文字加上链接 function addUrl(reg, sUrl, sStr) { var regExp_s = new RegExp(reg, "ug"); //console.log(regExp_s.test(sStr)); //console.log(regExp_s); var result = sStr.replace(regExp_s, "<a href=\"" + sUrl + "\">" + reg + "<\/a>"); return result; }

function productTable(arr, ars) { var tableStr = ""; if (ars) {

//加特殊标记 for (var k = 0; k < ars.spClass.length; k++) { for (var l = 0; l < ars.spClass[k][0].length; l++) { if (ars.spClass[k][0][l][0] == "all" || ars.spClass[k][0][l][1] == "all") { if (ars.spClass[k][0][l][0] == "all" && ars.spClass[k][0][l][1] != "all") { for (var m = 0; m < arr.length; m++) { arr[m][ars.spClass[k][0][l][1] - 1] = "<" + ars.spClass[k][1] + ">" + arr[m][ars.spClass[k][0][l][1] - 1] + "<\/" + ars.spClass[k][1] + ">"; } } if (ars.spClass[k][0][l][1] == "all" && ars.spClass[k][0][l][0] != "all") { for (var m = 0; m < arr[0].length; m++) { arr[ars.spClass[k][0][l][0] - 1][m] = "<" + ars.spClass[k][1] + ">" + arr[ars.spClass[k][0][l][0] - 1][m] + "<\/" + ars.spClass[k][1] + ">"; } }

} if (ars.spClass[k][0][l][0] != "all" && ars.spClass[k][0][l][1] != "all") { arr[ars.spClass[k][0][l][0] - 1][ars.spClass[k][0][l][1] - 1] = "<" + ars.spClass[k][1] + ">" + arr[ars.spClass[k][0][l][0] - 1][ars.spClass[k][0][l][1] - 1] + "<\/" + ars.spClass[k][1] + ">"; } } }

for (var x = 0; x < ars.link.length; x++) { arr[ars.link[x][0][0] - 1][ars.link[x][0][1] - 1] = "<a href=\"" + ars.link[x][1] + "\">" + arr[ars.link[x][0][0] - 1][ars.link[x][0][1] - 1] + "<\/a>"; }

//加链接


} for (var i = 0; i < arr.length; i++) { tableStr += "<tr>" for (var j = 0; j < arr[0].length; j++) { tableStr += "<td>" + arr[i][j] + "<\/td>"; } tableStr += "<\/tr>"; } return tableStr;


}

function renderTitle(that, i, cont) { var titleCont = document.createElement("p"); titleCont.innerHTML = that.title; addClass(titleCont, "titleCont"); addClass(titleCont, "word"); addClass(titleCont, "np1"); titleCont.setAttribute('data-para-fatherid', i); cont.appendChild(titleCont);


}


function renderTH() {

  $$("t_1_0_1").innerHTML="";
  $$("TH").innerHTML="";
  $$("wdmy").innerHTML=content.prospect.title;

var th1 = document.createElement("div"); th1.setAttribute("id", "th1"); //var th2=document.createElement("div"); //th2.setAttribute("id","th2"); th1.innerHTML = content.prospect.title; ///th2.innerHTML=content.prospect.cont; $$("t_1_0_1").appendChild(th1); ///TH.appendChild(th2);


var th2 = document.createElement("div"); th2.setAttribute("id", "th2"); th2.innerHTML = content.prospect.title; $$("TH").appendChild(th2); }


function renderTP() { countWord = 0; eachCountWord = []; for (var i = 0; i < content.part.length; i++) {

eachCountWord[i] = 0;

var partCont = document.createElement("div"); partCont.setAttribute('id', "part" + (i + 1)); partCont.setAttribute('data-partid', i); addClass(partCont, "textParts"); textCont.appendChild(partCont);


renderTitle(content.part[i], i, partCont);

for (var j = 0; j < content.part[i].para.length; j++) {

if (content.part[i].para[j].type == "word") { renderWord(content.part[i].para[j], i, j, partCont); } if (content.part[i].para[j].type == "pic") { renderPic(content.part[i].para[j], partCont); } if (content.part[i].para[j].type == "table") { renderTable(content.part[i].para[j], partCont); } if (content.part[i].para[j].type == "div") { renderDiv(content.part[i].para[j], partCont); } } } var hiddenCont = document.createElement("div"); hiddenCont.setAttribute("id", "hiddenCont"); textCont.appendChild(hiddenCont); }

//此处之后可以引入插件

//插件1:图注显示 function showPicFigure() { for (var i = 0; i < $C$("picword").length; i++) { var picInner = document.createElement("div"); picInner.appendChild($C$("picword")[i]); //挪走 //picInner.innerHTML=$C$("picword")[i].innerHTML; addClass(picInner, "picinner"); $C$("pic")[i].appendChild(picInner); //$C$("picword")[i].style.display="none"; (function (i) { $C$("pic")[i].onmouseenter = function () { $C$("picinner")[i].style.transition = 1 + "s"; $C$("picinner")[i].style.transform = "translate(" + 0 + "px," + 100 + "%)"; setTimeout(function () { $C$("picinner")[i].style.transform = "translate(" + 0 + "px," + 0 + "%)"; }, 2000) } })(i);




}

}


function getWidthAndHeight(url) { var wAH = {}; var img_url = url; var img = new Image(); img.src = img_url; wAH.width = img.naturalWidth; wAH.height = img.naturalHeight; //console.log(wAH); return wAH; }


function heightChange() {

function heightCC() { for (var i = 0; i < $C$("pic").length; i++) {

(function (i) { var url = $C$("pic")[i].style.backgroundImage.match(/url\(\"(.*?)\"\)/)[1]; //console.log(url); var wH = getWidthAndHeight(url); //console.log(parseInt($C$("pic")[0].style.width)*0.01*window.innerWidth*wH.width/wH.height+"px");


//$C$("pic")[i].style.height=parseInt($C$("pic")[0].style.width)*0.01*window.innerWidth*0.85*wH.height/wH.width+"px"; $C$("pic")[i].style.height = ($C$("pic")[i].offsetWidth * wH.height / wH.width) + "px";

})(i);


}

} window.addEventListener('resize', heightCC); $$("third_1_1").addEventListener('scroll',heightCC);

setInterval(function () { heightCC() }, 80000); };

function showTableFigure() { for (var i = 0; i < $C$("tableword").length; i++) { var tableInner = document.createElement("div"); tableInner.appendChild($C$("tableword")[i]); //挪走 //picInner.innerHTML=$C$("picword")[i].innerHTML; addClass(tableInner, "tableinner"); $C$("table")[i].appendChild(tableInner); //$C$("picword")[i].style.display="none";


}

}


//初始化开关按钮 function showTextFoldBtn() { for (var i = 0; i < $C$("textParts").length; i++) { var tPE = document.createElement("div"); addClass(tPE, "textfoldbtns"); tPE.innerHTML = "" $C$("textParts")[i].appendChild(tPE);


if(document.body.clientWidth<600){

$$("part" + (i + 1)).style.maxHeight = 50 + "px"; }

if(document.body.clientWidth>=600){

$$("part" + (i + 1)).style.maxHeight = 80 + "px"; }




}


for (var i = 0; i < $C$("textParts").length; i++) { (function (i) {

$C$("textfoldbtns")[i].onclick = function () { if (hasClass($C$("textfa")[i], "fa-expand")) { openFolder(i); } else { closeFolder(i); } } })(i)

}

for (var i = 0; i < $C$("textParts").length; i++) { $C$("textParts")[i].style.width = 90 + "%"; $C$("textParts")[i].style.marginTop = 10 + "px"; $C$("textParts")[i].style.borderRadius = 10 + "px"; }

} //初始化折叠状态 function folderNowF() { for (var i = 0; i < $C$("textParts").length; i++) { folderNow.push(0); } }

//折叠开 function openFolder(i) { folderNow[i] = 1; addClass($C$("textfa")[i], "fa-compress"); removeClass($C$("textfa")[i], "fa-expand"); $$("part" + (i + 1)).style.transition = "max-height " + .5 + "s linear"; $$("part" + (i + 1)).style.maxHeight = 26000 + "px";

} //折叠关 function closeFolder(i) { addClass($C$("textfa")[i], "fa-expand"); removeClass($C$("textfa")[i], "fa-compress"); folderNow[i] = 0; $$("part" + (i + 1)).style.transition = "max-height " + 0.3 + "s linear"; if(document.body.clientWidth<600){

$$("part" + (i + 1)).style.maxHeight = 50 + "px"; }else{ $$("part" + (i + 1)).style.maxHeight = 80 + "px"; }


} //折叠复原

function foldRecovery() { for (var i = 0; i < folderNow.length; i++) { if (folderNow[i] == 0) {

if(document.body.clientWidth<600){

$$("part" + (i + 1)).style.maxHeight = 50 + "px"; }else{ $$("part" + (i + 1)).style.maxHeight = 80 + "px"; }

} if (folderNow[i] == 1) { addClass($C$("textfa")[i], "fa-compress"); removeClass($C$("textfa")[i], "fa-expand"); $$("part" + (i + 1)).style.transition = "max-height " + 0 + "s linear"; $$("part" + (i + 1)).style.height = "auto"; $$("part" + (i + 1)).style.maxHeight = 26000 + "px";

} }

}

function switchRecovery() { //开关恢复 for (var i = 0; i < $C$("th13_1").length; i++) { if (!t3BtnData[i][1]) { continue; } if (t3BtnData[i][0] == 1) { t3BtnData[i][1](); } } }

//下方开关


//页码显示 var t3BtnData = [];

function renderPageNum() {

for (var i = 0; i < $C$("word").length; i++) {


if (hasClass($C$("word")[i], "titleCont")) { continue; } //$C$("word")[i].style.borderBottom="1px solid #fff"; //$C$("word")[i].style.borderImage="linear-gradient( 270deg, transparent 50%, #fff 100%) 30 30"; var pndiv = document.createElement("div"); addClass(pndiv, "pndiv"); $C$("word")[i].appendChild(pndiv); var div = document.createElement("div"); pndiv.appendChild(div) div.innerHTML = (parseInt($C$("word")[i].getAttribute('data-para-fatherid')) + 1) + "-" + (parseInt($C$("word")[i].getAttribute('data-para-eachid')));

var pdiv = document.createElement("div");

addClass(pdiv, "pdiv"); $C$("word")[i].appendChild(pdiv);

}

}

//页码消失与关闭 function PageNumOn() {

for (var i = 0; i < $C$("word").length; i++) { if (hasClass($C$("word")[i], "titleCont")) { continue; } $C$("word")[i].style.transition = .5 + "s"; $C$("word")[i].style.transform = "translate(10px,0px)"; } //setTimeout(function(){ },0) for (var i = 0; i < $C$("pdiv").length; i++) { $C$("pdiv")[i].style.transition = .3 + "s"; $C$("pdiv")[i].style.width = 60 + "%"; $C$("pndiv")[i].style.transition = .3 + "s"; $C$("pndiv")[i].style.transform = "translate(0px,0px)"; $C$("pndiv")[i].style.opacity = "1"; } }


function PageNumOff() { for (var i = 0; i < $C$("word").length; i++) { $C$("word")[i].style.transition = .5 + "s"; $C$("word")[i].style.transform = "translate(0px,0px)"; } for (var i = 0; i < $C$("pdiv").length; i++) { $C$("pdiv")[i].style.transition = .3 + "s"; $C$("pdiv")[i].style.width = 0 + "%"; $C$("pndiv")[i].style.transition = .3 + "s"; $C$("pndiv")[i].style.transform = "translate(-10px,0px)"; $C$("pndiv")[i].style.opacity = "0"; }

}


function modeCC() { textMode == 1 ? textMode = 0 : textMode = 1; textCont.innerHTML = "";


replaceWork(); }

$C$("th13_1s")[0].onclick = function () { modeCC(); }



//按钮函数装配 function t3BtnPut() { for (var i = 0; i < $C$("th13_1").length; i++) { t3BtnData.push([0]); } t3BtnData[0].push(PageNumOn); t3BtnData[0].push(PageNumOff); }




//查看大图插件

function seeLImg() {

var urlsList = []; var imgnow = 0; var imgview = document.createElement("div"); $$("third_1_1").appendChild(imgview); addClass(imgview, "imgcontent");

imgview.innerHTML = "<img id=\"olol\" src=\"img/1.png\" class=\"img\">
<button class=\"btnn scaleL\"></button><button class=\"btnn scaleS\"></button><button class=\"btnn rotateL\"></button><button class=\"btnn rotateR\"></button>
"


for (var i = 0; i < $C$("pic").length; i++) { (function (i) {

urlsList[i] = $C$("pic")[i].style.backgroundImage.match(/url\(\"(.*?)\"\)/)[1]; $C$("pic")[i].onclick = function () { imgnow = i; $C$("imgcontent")[0].style.display = "block"; }

})(i); }


function renderimgview() {

var imageview = new ImageView($$("olol"), { movingCheck: false, // 可选, 当移动的时候,是否检查边界,达到的效果就是当到边界的时候, // 可不可以继续拖拽等效果 实验下就明白了 默认true scaleNum: 1 // 可选,缩放比例 当进行缩放时 scale 时的比例 默认2 }); var rotateNum = 0; var ctlMap = { scaleL: function () { imageview.scale(0.1); }, scaleS: function () { imageview.scale(-0.1); }, rotateL: function () { imageview.rotate(rotateNum -= 90); }, rotateR: function () { imageview.rotate(rotateNum += 90); } }; document.getElementsByClassName('btns')[0].onclick = function (e) { var target = e.target; if (target.tagName === 'BUTTON') { ctlMap[target.className.replace(/^btnn\s+/, )](); } } }

renderimgview(); //console.log(urlsList);


for (var i = 0; i < $C$("pic").length; i++) { (function (i) { $C$("pic")[i].onclick = function () { imgnow = i; $$("olol").setAttribute("src", urlsList[imgnow]); renderimgview(); $C$("imgcontent")[0].style.display = "block"; } })(i); }



$$("nextimg").onclick = function () {

$$("olol").setAttribute("src", urlsList[(imgnow + 1) > urlsList.length - 1 ? 0 : imgnow + 1]); imgnow = (imgnow + 1) > urlsList.length - 1 ? 0 : imgnow + 1; renderimgview(); } $$("lastimg").onclick = function () {

$$("olol").setAttribute("src", urlsList[(imgnow - 1) < 0 ? urlsList.length - 1 : imgnow - 1]); imgnow = (imgnow - 1) < 0 ? urlsList.length - 1 : imgnow - 1; renderimgview(); }

$$("chaimg").onclick = function () { $C$("imgcontent")[0].style.display = "none"; }


}





function renderAll() { renderTH(); renderTP(); showPicFigure(); showTableFigure(); heightChange(); t3BtnPut(); renderT3Btn(); renderPageNum(); textSelect(); renderPDF(); seeLImg();

if (textMode == 1) { showTextFoldBtn(); foldRecovery(); }

switchRecovery(); }


replaceWork();

folderNowF();

//按钮函数实际实行 function renderT3Btn() { for (var i = 0; i < $C$("th13_1").length; i++) { (function (i) { $C$("th13_1")[i].onclick = function () { if (!t3BtnData[i][1]) { return; }

if (t3BtnData[i][0] == 0) { t3BtnData[i][1](); t3BtnData[i][0] = 1; addClass(this, "th13_1_act"); } else { t3BtnData[i][2](); t3BtnData[i][0] = 0; removeClass(this, "th13_1_act"); }


} })(i); }


}


//(function(i){$C$("pic")[i].style.height=heightChange(i)})(i);

// 获得信息 //var id = oBtn.getAttribute('data-id'); // 改变数据信息 //delBtn.setAttribute('data-id', id); var paraNow; var selectL; var selectR;

var md1 = 0; var md2 = 0; var md3 = 0; var md4 = 0;

function textSelect() {

function textMU() {

var reg = /\n/;

if (getTheSelected() == "" || reg.test(window.getSelection().toString())) { $$("third_1_10").style.display = "none"; } else { md2 = getMousePos().x; md4 = getMousePos().y;

$$("third_1_10").style.display = "block";


copytextcont=window.getSelection().toString();

copyparacont=content.part[$C$("word")[paraNow].getAttribute('data-para-fatherid')].para[$C$("word")[paraNow].getAttribute('data-para-realid')].cont;       console.log(reg.test(window.getSelection().toString()));    checkSW();         //console.log( window.getSelection().anchorOffset); //开始位置 var dir = ""; var cha = parseInt(window.getComputedStyle($C$("word")[paraNow]).lineHeight.slice(0, -2)) - parseInt(window.getComputedStyle($C$("word")[paraNow]).fontSize.slice(0, -2));


if (Math.abs(md3 - md4) > 1.5 * cha) { if (md3 - md4 < 0 && md4 - md3 > cha) {

dir = "right"

} if (md3 - md4 > 0 && md3 - md4 > cha) { //xia to shang

dir = "left";

}

} else { dir = md1 - md2 <= 0 ? "right" : "left"; }

console.log(dir); var hehe = selectPosition(dir); console.log(hehe); selectL = hehe[0]; selectR = hehe[1];         // console.log( window.getSelection().focusOffset); //结束位置 }

$$("third_1_10").style.left = getMousePos().x + "px"; $$("third_1_10").style.top = (getMousePos().y) + "px"; //document.removeEventListener("mousedown",textSelecterOut,false); document.removeEventListener("mouseup", textMU, false); }

for (var i = 0; i < $C$("word").length; i++) {

(function (i) { $C$("word")[i].onmousedown = function () { paraNow = i; md1 = getMousePos().x; md3 = getMousePos().y; console.log(i); window.getSelection().removeAllRanges(); document.addEventListener("mouseup", textMU, false);

} })(i);

}

}

var markList3 = { a11: [ ["222222", [ [2, 5] ]] ], a2: [ ["7ecef4", [ [178, 180], [7, 10] ]], ["8ec8f4", [ [1, 4] ]] ]

}


function renderParaColor(num) { var render = renderColorList(markList3["a" + num]); console.log(render); console.log(markList3); var hcHTML = content.part[$C$("word")[num].getAttribute('data-para-fatherid')].para[$C$("word")[num].getAttribute('data-para-realid')].cont;

for (var i = render.length - 1; i >= 0; i--) {

hcHTML = replaceColorText(hcHTML, render[i][0], render[i][1], "font"); console.log(hcHTML); }

$C$("word")[num].innerHTML = hcHTML; }


function replaceColorText(txt, color, arr, tag) {

var tempStr1 = txt.substring(0, arr[0]); var selectedText = txt.substring(arr[0], arr[1]); var tempStr2 = txt.substring(arr[1]);

return tempStr1 + "" + selectedText + "</" + tag + ">" + tempStr2; }

//输出渲染队列 function renderColorList(arr) { var timearr = [];

if (arr.length == 1) { for (var i = 0; i < arr[0][1].length; i++) { timearr.push([arr[0][0], arr[0][1][i]]); } return timearr; } else {


for (var i = 0; i < arr.length; i++) { for (var j = 0; j < arr[i][1].length; j++) { timearr.push([arr[i][0], arr[i][1][j]]); } }


for (var i = 0; i < timearr.length - 1; i++) { for (var j = 0; j < timearr.length - 1; j++) { if (timearr[j][1][0] > timearr[j + 1][1][0]) { var tran = timearr[j + 1]; timearr[j + 1] = timearr[j]; timearr[j] = tran; } } }

return timearr;

} }



function renderSmallNav() { var sNavHtml = ""; var sb3="" $$("Btitle3").innerHTML="";

for (var i = 0; i < $C$("titleCont").length; i++) {



sNavHtml += "
" + $C$("titleCont")[i].innerHTML + "
40%
";


sb3+="
"+(i+1)+"."+$C$("titleCont")[i].innerHTML+"
";



}

$$("smallmenu").innerHTML = sNavHtml; $$("Btitle3").innerHTML=sb3; } renderSmallNav();



//搜索模块 全局搜索和局部搜索



function lpGo(dom) { var the_id = dom.getAttribute("data-search"); animateScroll($$(the_id), 50); }




/* //替换部分


//[["fdfdf","dsdsd","Global","global"],["fdfdf","dsdsd","Part 1 p3",18]]; $$("t3t_rp_b3").onclick = function () { if ($$("t3t_rp_b1").value == "" || $$("t3t_rp_b4").value == "") { console.log("信息填写不全"); return; } var tmrl = []; tmrl.push($$("t3t_rp_b1").value); tmrl.push($$("t3t_rp_b4").value); tmrl.push(getSelectedText("t3t_rp_b2")); tmrl.push($$("t3t_rp_b2").value); replaceList.push(tmrl); var ch = replaceWork(); if (ch[ch.length - 1] == 0) { replaceList.pop(); alert("未找到可以替换的项目"); return; } renderReplaceData(replaceList);

}

  • /


function renderReplaceData(arr) { var arrHtml = ""; var pageNum = Math.ceil(arr.length / 3); var lastPNum = arr.length % 3; lastPNum = (lastPNum == 0 ? 3 : lastPNum); if (arr.length > 21) { alert("不能在换了"); return; } if (pageNum <= 1) { $$("houjiade4").style.display = "none"; if (arr.length == 0) { $$("houjiade3").innerHTML = "替换列表为空!"; return; } for (var i = 0; i < arr.length; i++) {

arrHtml += "
" + (i + 1) + "
" + arr[i][2] + "
" + arr[i][0] + " → " + arr[i][1] + "
Go
"

} $$("houjiade3").innerHTML = arrHtml; } else {

$$("houjiade4").style.display = "block";

$C$("t3trpbox2_1_2")[0].style.width = 32 * pageNum + "px"; var btnHtml = "";

for (var i = 0; i < pageNum; i++) { if (i == (pageNum - 1)) {

btnHtml += "
" + (i + 1) + "
";

} if (i != (pageNum - 1)) {

btnHtml += "
" + (i + 1) + "
";

} }

$C$("t3trpbox2_1_2")[0].innerHTML = btnHtml;


for (var i = 0; i < lastPNum; i++) {

arrHtml += "
" + ((pageNum - 1) * 3 + i + 1) + "
" + arr[(pageNum - 1) * 3 + i][2] + "
" + arr[(pageNum - 1) * 3 + i][0] + " → " + arr[(pageNum - 1) * 3 + i][1] + "
Go
"

} $$("houjiade3").innerHTML = arrHtml; btnInitrp();

}




function btnInitrp() {

for (var i = 0; i < pageNum; i++) { (function (i) { $C$("t3trpbox2_12")[i].onclick = function () { arrHtml = ""; for (var l = 0; l < pageNum; l++) { removeClass($C$("t3trpbox2_12")[l], "t3trpbox2_12_act"); } addClass(this, "t3trpbox2_12_act"); for (var j = 0; j < (i == (pageNum - 1) ? lastPNum : 3); j++) { //console.log(arr); //console.log(j);

arrHtml += "
" + (i * 3 + 1 + j) + "
" + arr[i * 3 + j][2] + "
" + arr[i * 3 + j][0] + " → " + arr[i * 3 + j][1] + "
Go
";

} $$("houjiade3").innerHTML = arrHtml; t3trpBtn();

} })(i); }



}

t3trpBtn();


} //[["fdfdf","dsdsd","Global","global"],["fdfdf","dsdsd","Part 1 p3",18]]; function replaceWork() { //很重要!!!


textCont.innerHTML = ""; renderAll();

var replaceNum = []; for (var i = 0; i < replaceList.length; i++) { replaceNum.push(0); if (replaceList[i][3] == "global") { for (var j = 0; j < $C$("word").length; j++) {

if (hasClass($C$("word")[j], "titleCont")) { continue; }


if (ifFindWord(replaceList[i][0], $C$("word")[j].innerHTML)) { replaceNum[i]++; $C$("word")[j].innerHTML = findWordAndRWO(replaceList[i][0], replaceList[i][1], $C$("word")[j].innerHTML);

}


} } else { if (ifFindWord(replaceList[i][0], $C$("word")[replaceList[i][3]].innerHTML)) { replaceNum[i]++; $C$("word")[replaceList[i][3]].innerHTML = findWordAndRWO(replaceList[i][0], replaceList[i][1], $C$("word")[replaceList[i][3]].innerHTML); } } }

return replaceNum; }

function t3trpBtn() { for (var i = 0; i < $C$("t3trpgo").length; i++) { (function (i) { $C$("t3trpgo")[i].onclick = function () { replaceList.splice(i, 1); replaceWork(); renderReplaceData(replaceList); } })(i); } }


function findWordAndRWO(reg, other, sStr) { var regExp_s = new RegExp(reg, "ig"); var result = sStr.replace(regExp_s, other); return result; }

function ifFindWord(reg, sStr) { var regExp_s = new RegExp(reg, "ig"); var result = regExp_s.test(sStr); return result; }

//小导航


window.addEventListener('resize', CC19); var kg19=0; function CC19(){ if (document.body.clientWidth<=998) { $$("third_1_9").style.right="-330px"; kg19=0; $$("zhong19").innerHTML="<";

} if (document.body.clientWidth>998) { $$("third_1_9").style.right="0%"; } console.log(document.body.clientWidth+","+document.body.clientHeight);

if (textMode==1) {

if(document.body.clientWidth<600){ //console.log(99); for (var i = 0; i < $C$("textParts").length; i++) { $$("part" + (i + 1)).style.maxHeight = 50 + "px";} } else{ for (var i = 0; i < $C$("textParts").length; i++) { $$("part" + (i + 1)).style.maxHeight = 80 + "px";} }

  foldRecovery();


}


}

CC19();