|
@@ -1,7 +1,6 @@
|
|
import $ from './util/dom-core.js';
|
|
import $ from './util/dom-core.js';
|
|
import {getParentByClassname, getParentNodeByClass, isEmptyElement, trim} from './util/util.js';
|
|
import {getParentByClassname, getParentNodeByClass, isEmptyElement, trim} from './util/util.js';
|
|
import QuestionTools from './util/question';
|
|
import QuestionTools from './util/question';
|
|
-import QuestionPrevTools from './util/questionPrev';
|
|
|
|
import JQuery from 'jquery';
|
|
import JQuery from 'jquery';
|
|
let yzPage = function (manage, $page) {
|
|
let yzPage = function (manage, $page) {
|
|
this.manage = manage;
|
|
this.manage = manage;
|
|
@@ -23,10 +22,9 @@ yzPage.prototype = {
|
|
_init: function () {
|
|
_init: function () {
|
|
this._initStyles();
|
|
this._initStyles();
|
|
this._initColumn();
|
|
this._initColumn();
|
|
- // this._initPositionPlaceholder();
|
|
|
|
- // this._initPAndNPlaceholder();
|
|
|
|
|
|
+ this._initPositionPlaceholder();
|
|
|
|
+ this._initPAndNPlaceholder();
|
|
this.questionTools = new QuestionTools();
|
|
this.questionTools = new QuestionTools();
|
|
- this.questionPrevTools = new QuestionPrevTools();
|
|
|
|
},
|
|
},
|
|
/**
|
|
/**
|
|
* function 初始化样式
|
|
* function 初始化样式
|
|
@@ -119,10 +117,21 @@ yzPage.prototype = {
|
|
$postionDom.css('height', '16px');
|
|
$postionDom.css('height', '16px');
|
|
return $postionDom;
|
|
return $postionDom;
|
|
},
|
|
},
|
|
- // 生成正反面定位符
|
|
|
|
|
|
+ /**
|
|
|
|
+ * function 生成正反面定位符
|
|
|
|
+ */
|
|
_initPAndNPlaceholder: function () {
|
|
_initPAndNPlaceholder: function () {
|
|
|
|
+ let count = this.pageIndex + 2;
|
|
|
|
+ for (let i = 0; i < count; i++) {
|
|
|
|
+ let template = this._placeholderTemplate();
|
|
|
|
+ let top = i * 22 - 16;
|
|
|
|
+ template.css('width', '25px').css('height', '16px').css('left', '-25px').css('top', top + 'px');
|
|
|
|
+ this.$textElem.append(template);
|
|
|
|
+ }
|
|
},
|
|
},
|
|
- // 初始化占位符
|
|
|
|
|
|
+ /**
|
|
|
|
+ * function 初始化占位符
|
|
|
|
+ */
|
|
_initPositionPlaceholder: function () {
|
|
_initPositionPlaceholder: function () {
|
|
let $columns = this.$colums;
|
|
let $columns = this.$colums;
|
|
let clength = $columns.length;
|
|
let clength = $columns.length;
|
|
@@ -151,10 +160,88 @@ yzPage.prototype = {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- // 更新跨栏符
|
|
|
|
|
|
+ /**
|
|
|
|
+ * function 更新跨栏符
|
|
|
|
+ */
|
|
_updateCrossColumn: function ($column) {
|
|
_updateCrossColumn: function ($column) {
|
|
|
|
+ let index =parseInt($column.attr('data-column-i'));
|
|
|
|
+ if (index === 0) {
|
|
|
|
+ return '';
|
|
|
|
+ }
|
|
|
|
+ let column = $column[0];
|
|
|
|
+ let firstParagh = column.firstChild;
|
|
|
|
+ firstParagh = this._cycleFindParagraph(firstParagh);
|
|
|
|
+ if (firstParagh) {
|
|
|
|
+ let page = column.parentNode;
|
|
|
|
+ if (page) {
|
|
|
|
+ let $page = $(page);
|
|
|
|
+ let columnIndex = parseInt(column.getAttribute('data-column-i'));
|
|
|
|
+ let crossPlaceholder = '.js-cross-placeholder-' + columnIndex;
|
|
|
|
+ let classname = 'js-cross-placeholder-' + columnIndex;
|
|
|
|
+ let $placeholder = $page.find(crossPlaceholder);
|
|
|
|
+ let firstBorder = firstParagh.firstChild;
|
|
|
|
+ if (firstParagh.className && firstParagh.className.indexOf('js-split-paragraph') > -1) {
|
|
|
|
+ if (firstBorder && firstBorder.className && firstBorder.className.indexOf('js-lsiten-border') > -1) {
|
|
|
|
+ if (!$placeholder.length) {
|
|
|
|
+ // 添加跨栏符
|
|
|
|
+ // 判断是否有该栏跨栏符
|
|
|
|
+ let $template = this._placeholderTemplate();
|
|
|
|
+ let cwidth = this._pagesWidth[this.editor.pageSize] / parseInt(this.editor.columnNumber);
|
|
|
|
+ let left = columnIndex * cwidth + 20;
|
|
|
|
+ $template.css('left', left + 'px').css('top', '-15px').css('width', '12px').css('height', '12px');
|
|
|
|
+ $template.addClass(classname);
|
|
|
|
+ $page.append($template);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (firstBorder && firstBorder.className && firstBorder.className.indexOf('js-lsiten-border') > -1) {
|
|
|
|
+ if ($placeholder.length > 0) {
|
|
|
|
+ // 删除跨栏符
|
|
|
|
+ $placeholder.remove();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ let page = column.parentNode;
|
|
|
|
+ if (page) {
|
|
|
|
+ let $page = $(page);
|
|
|
|
+ let columnIndex = parseInt(column.getAttribute('data-column-i'));
|
|
|
|
+ let crossPlaceholder = '.js-cross-placeholder-' + columnIndex;
|
|
|
|
+ let classname = 'js-cross-placeholder-' + columnIndex;
|
|
|
|
+ let $placeholder = $page.find(crossPlaceholder);
|
|
|
|
+ if ($placeholder.length > 0) {
|
|
|
|
+ // 删除跨栏符
|
|
|
|
+ $placeholder.remove();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
},
|
|
},
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * function 循环查找段落
|
|
|
|
+ */
|
|
|
|
+ _cycleFindParagraph: function (paragraph) {
|
|
|
|
+ if (!paragraph) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+ let i = 0;
|
|
|
|
+ while (i < 100 && (!paragraph.className || paragraph.className.indexOf('js-paragraph-view') < 0)) {
|
|
|
|
+ let temp = paragraph.nextSibling;
|
|
|
|
+ paragraph.parentNode.removeChild(paragraph);
|
|
|
|
+ paragraph = temp;
|
|
|
|
+ i++;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ let firstContent = paragraph.firstChild;
|
|
|
|
+ if (firstContent && firstContent.className && firstContent.className.indexOf('js-answer-header') > -1) {
|
|
|
|
+ let temp = paragraph.nextSibling;
|
|
|
|
+ paragraph = temp;
|
|
|
|
+ return this._cycleFindParagraph(paragraph);
|
|
|
|
+ }
|
|
|
|
+ return paragraph || null;
|
|
|
|
+ },
|
|
/**
|
|
/**
|
|
* @param {DomElement} $column 栏dom
|
|
* @param {DomElement} $column 栏dom
|
|
*/
|
|
*/
|
|
@@ -162,9 +249,6 @@ yzPage.prototype = {
|
|
let $paragraphs = $column.find('.js-paragraph-view');
|
|
let $paragraphs = $column.find('.js-paragraph-view');
|
|
let cSize = $column.getSizeData();
|
|
let cSize = $column.getSizeData();
|
|
let i = $paragraphs.length - 1;
|
|
let i = $paragraphs.length - 1;
|
|
- if(!i || i < 0) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
let $moves = [];
|
|
let $moves = [];
|
|
while (i >=0 ) {
|
|
while (i >=0 ) {
|
|
let $paragraph = $($paragraphs[i]);
|
|
let $paragraph = $($paragraphs[i]);
|
|
@@ -192,7 +276,11 @@ yzPage.prototype = {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
nextColumn.page._checkColumnOut(nextColumn.column);
|
|
nextColumn.page._checkColumnOut(nextColumn.column);
|
|
|
|
+ // 跨栏符检测
|
|
|
|
+ this._updateCrossColumn(nextColumn.column);
|
|
}
|
|
}
|
|
|
|
+ // 跨栏符检测
|
|
|
|
+ this._updateCrossColumn($column);
|
|
}
|
|
}
|
|
},
|
|
},
|
|
/**
|
|
/**
|
|
@@ -235,7 +323,7 @@ yzPage.prototype = {
|
|
this._insertDomBeforeByFirst($Allparagraph, firstFirst);
|
|
this._insertDomBeforeByFirst($Allparagraph, firstFirst);
|
|
} else if (insertLast.className && insertLast.className.indexOf('js-lsiten-border') > -1) {
|
|
} else if (insertLast.className && insertLast.className.indexOf('js-lsiten-border') > -1) {
|
|
// 框处理
|
|
// 框处理
|
|
- if (firstFirst.className && firstFirst.className.indexOf('js-lsiten-border') > -1) {
|
|
|
|
|
|
+ if (firstFirst && firstFirst.className && firstFirst.className.indexOf('js-lsiten-border') > -1) {
|
|
// 如果下一段第一个dom是框
|
|
// 如果下一段第一个dom是框
|
|
let borderId = insertLast.getAttribute('data-id');
|
|
let borderId = insertLast.getAttribute('data-id');
|
|
let nextBorderId = firstFirst.getAttribute('data-id');
|
|
let nextBorderId = firstFirst.getAttribute('data-id');
|
|
@@ -360,12 +448,16 @@ yzPage.prototype = {
|
|
$columns.forEach($column => {
|
|
$columns.forEach($column => {
|
|
this._checkColumnBack($column);
|
|
this._checkColumnBack($column);
|
|
});
|
|
});
|
|
|
|
+ this.manage._checkRemovePage();
|
|
},
|
|
},
|
|
/**
|
|
/**
|
|
* function 检测该段落是否为答题卡头
|
|
* function 检测该段落是否为答题卡头
|
|
* @param {DomElement} 需要检测的段落
|
|
* @param {DomElement} 需要检测的段落
|
|
*/
|
|
*/
|
|
isHeadParagraph: function ($paragraph) {
|
|
isHeadParagraph: function ($paragraph) {
|
|
|
|
+ if (!$paragraph || !$paragraph[0]) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
let firstChild = $paragraph[0].firstChild;
|
|
let firstChild = $paragraph[0].firstChild;
|
|
return firstChild && firstChild.className && firstChild.className.indexOf('js-answer-header') > -1;
|
|
return firstChild && firstChild.className && firstChild.className.indexOf('js-answer-header') > -1;
|
|
},
|
|
},
|
|
@@ -377,10 +469,10 @@ yzPage.prototype = {
|
|
let $paragraphs = $column.find('.js-paragraph-view');
|
|
let $paragraphs = $column.find('.js-paragraph-view');
|
|
let cSize = $column.getSizeData();
|
|
let cSize = $column.getSizeData();
|
|
let i = $paragraphs.length - 1;
|
|
let i = $paragraphs.length - 1;
|
|
- if(!i || i < 0) {
|
|
|
|
|
|
+ let $moves = [];
|
|
|
|
+ if (!$paragraphs[i]) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- let $moves = [];
|
|
|
|
let $lastParagraph = $($paragraphs[i]);
|
|
let $lastParagraph = $($paragraphs[i]);
|
|
let lastSize = $lastParagraph.getSizeData();
|
|
let lastSize = $lastParagraph.getSizeData();
|
|
let diff = cSize.bottom - lastSize.bottom;
|
|
let diff = cSize.bottom - lastSize.bottom;
|
|
@@ -390,17 +482,129 @@ yzPage.prototype = {
|
|
if (nextColumn.column) {
|
|
if (nextColumn.column) {
|
|
let $nextParagraphs = nextColumn.column.find('.js-paragraph-view');
|
|
let $nextParagraphs = nextColumn.column.find('.js-paragraph-view');
|
|
while (i >=0 ) {
|
|
while (i >=0 ) {
|
|
- let $paragraph = $($nextParagraphs[i]);
|
|
|
|
- if (!this.isHeadParagraph($paragraph)) {
|
|
|
|
- let pSize = $paragraph.getSizeData();
|
|
|
|
- if (pSize.height < diff) {
|
|
|
|
- $moves.push($paragraph);
|
|
|
|
- } else {
|
|
|
|
- this._prevParagraph($moves, $paragraph, diff, $lastParagraph);
|
|
|
|
|
|
+ if ($nextParagraphs[i]) {
|
|
|
|
+ let $paragraph = $($nextParagraphs[i]);
|
|
|
|
+ if ($paragraph && !this.isHeadParagraph($paragraph)) {
|
|
|
|
+ let pSize = $paragraph.getSizeData();
|
|
|
|
+ if (pSize.height < diff) {
|
|
|
|
+ $moves.push($paragraph);
|
|
|
|
+ } else {
|
|
|
|
+ let size = {
|
|
|
|
+ diff: diff
|
|
|
|
+ }
|
|
|
|
+ this._prevParagraph($moves, $paragraph, size, $lastParagraph);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
i--;
|
|
i--;
|
|
}
|
|
}
|
|
|
|
+ let lastPid = $lastParagraph.attr('data-index');
|
|
|
|
+ let lastBorderItem = $lastParagraph[0].lastChild;
|
|
|
|
+ let lastIsBorder = lastBorderItem.className && lastBorderItem.className.indexOf('js-lsiten-border') > -1;
|
|
|
|
+ $moves.forEach($paragraphITem => {
|
|
|
|
+ let currentPid = $paragraphITem.attr('data-index');
|
|
|
|
+ if (lastPid === currentPid) {
|
|
|
|
+ $paragraphITem.childNodes().forEach(item => {
|
|
|
|
+ if (item.nodeType === 3) {
|
|
|
|
+ $paragraph[0].removeChild(item);
|
|
|
|
+ } else {
|
|
|
|
+ let $item = $(item);
|
|
|
|
+ let itemClass = $item.attr('class');
|
|
|
|
+ if (itemClass && itemClass.indexOf('js-lsiten-line') > -1) {
|
|
|
|
+ // 普通行
|
|
|
|
+ $lastParagraph.append($item);
|
|
|
|
+ } else if (itemClass && itemClass.indexOf('js-lsiten-border') > -1) {
|
|
|
|
+ // 框处理
|
|
|
|
+ if (lastIsBorder) {
|
|
|
|
+ let borderId = lastBorderItem.getAttribute('data-id');
|
|
|
|
+ let currentBorderId = $item.attr('data-id');
|
|
|
|
+
|
|
|
|
+ if (currentBorderId === borderId) {
|
|
|
|
+ $($item[0].firstChild).childNodes().forEach(borderItem => {
|
|
|
|
+ if (borderItem.className) {
|
|
|
|
+ if (borderItem.className.indexOf('js-lsiten-question') > -1) {
|
|
|
|
+ let qustionType = parseInt(borderItem.getAttribute('data-type'));
|
|
|
|
+ let lastQuestionItem = lastBorderItem.lastChild;
|
|
|
|
+ let lastQuestionId = lastQuestionItem.getAttribute('data-id');
|
|
|
|
+ let currentQuestionId = borderItem.getAttribute('data-id');
|
|
|
|
+ if (lastQuestionId && currentQuestionId && currentQuestionId === lastQuestionId) {
|
|
|
|
+ if (qustionType === 3) {
|
|
|
|
+ $(borderItem).childNodes().forEach(subjectItem => {
|
|
|
|
+ lastQuestionItem.appendChild(subjectItem);
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ } else if (qustionType === 4) {
|
|
|
|
+ $(borderItem).childNodes().forEach(writtingItem => {
|
|
|
|
+ if (writtingItem.className.indexOf('lsiten-title') > -1) {
|
|
|
|
+ let $prevWrittingTitleItem = $(lastQuestionItem).find('.lsiten-title');
|
|
|
|
+ let needMergeItem = true;
|
|
|
|
+ if (!$prevWrittingTitleItem.length) {
|
|
|
|
+ needMergeItem = false;
|
|
|
|
+ $prevWrittingTitleItem = $($prevWrittingTitleItem);
|
|
|
|
+ } else {
|
|
|
|
+ needMergeItem = false;
|
|
|
|
+ $prevWrittingTitleItem = $(writtingItem).clone(false);
|
|
|
|
+ }
|
|
|
|
+ $(writtingItem).childNodes().forEach(writtingTitleItem => {
|
|
|
|
+ $prevWrittingTitleItem[0].appendChild(writtingTitleItem);
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ if (needMergeItem && !isEmptyElement($prevWrittingTitleItem[0])) {
|
|
|
|
+ lastQuestionItem.appendChild($prevWrittingTitleItem[0]);
|
|
|
|
+ }
|
|
|
|
+ } else if (writtingItem.className.indexOf('lsiten-border-box') > -1) {
|
|
|
|
+ let $prevWrittingRowsItem = $(lastQuestionItem).find('.lsiten-border-box');
|
|
|
|
+ let needMergeItem = true;
|
|
|
|
+ if (!$prevWrittingRowsItem.length) {
|
|
|
|
+ needMergeItem = false;
|
|
|
|
+ $prevWrittingRowsItem = $($prevWrittingRowsItem);
|
|
|
|
+ } else {
|
|
|
|
+ needMergeItem = false;
|
|
|
|
+ $prevWrittingRowsItem = $(writtingItem).clone(false);
|
|
|
|
+ }
|
|
|
|
+ $(writtingItem).childNodes().forEach(writtingRowItem => {
|
|
|
|
+ $prevWrittingRowsItem[0].appendChild(writtingRowItem);
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ if (needMergeItem && !isEmptyElement($prevWrittingRowsItem[0])) {
|
|
|
|
+ lastQuestionItem.appendChild($prevWrittingRowsItem[0]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ $(borderItem).remove();
|
|
|
|
+ }
|
|
|
|
+ $(borderItem).remove();
|
|
|
|
+ } else {
|
|
|
|
+ lastBorderItem.firstChild.appendChild(borderItem);
|
|
|
|
+ }
|
|
|
|
+ } else if (borderItem.className.indexOf('js-lsiten-line') > -1) {
|
|
|
|
+ lastBorderItem.firstChild.appendChild(borderItem);
|
|
|
|
+ } else {
|
|
|
|
+ $(borderItem).remove();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ $item.remove();
|
|
|
|
+ } else {
|
|
|
|
+ $lastParagraph.append($item);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ $lastParagraph.append($item);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ $item.remove();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ $paragraphITem.remove();
|
|
|
|
+ } else {
|
|
|
|
+ $paragraphITem.insertAfter($lastParagraph);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ // 跨栏符检测
|
|
|
|
+ this._updateCrossColumn($column);
|
|
|
|
+ this._updateCrossColumn(nextColumn.column);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
},
|
|
@@ -409,10 +613,10 @@ yzPage.prototype = {
|
|
* function 检测段落是否需要上移
|
|
* function 检测段落是否需要上移
|
|
* @param {array} $moves 需要移动的段落数组
|
|
* @param {array} $moves 需要移动的段落数组
|
|
* @param {DomElement} $paragraph 需要检测的段落
|
|
* @param {DomElement} $paragraph 需要检测的段落
|
|
- * @param {number} diff 可以上移的空间
|
|
|
|
|
|
+ * @param {object} size 可以上移的空间
|
|
* @param {DomElement} $lastParagraph 该段最后一段
|
|
* @param {DomElement} $lastParagraph 该段最后一段
|
|
*/
|
|
*/
|
|
- _prevParagraph: function ($moves, $paragraph, diff, $lastParagraph) {
|
|
|
|
|
|
+ _prevParagraph: function ($moves, $paragraph, size, $lastParagraph) {
|
|
let lastClass = $lastParagraph.attr('class');
|
|
let lastClass = $lastParagraph.attr('class');
|
|
let currentClass = $paragraph.attr('class');
|
|
let currentClass = $paragraph.attr('class');
|
|
let lastPid = $lastParagraph.attr('data-index');
|
|
let lastPid = $lastParagraph.attr('data-index');
|
|
@@ -420,7 +624,7 @@ yzPage.prototype = {
|
|
if (lastClass && lastClass.indexOf('js-split-paragraph') > -1) {
|
|
if (lastClass && lastClass.indexOf('js-split-paragraph') > -1) {
|
|
if (currentClass && currentClass.indexOf('js-split-paragraph') > -1 && lastPid === currentPid) {
|
|
if (currentClass && currentClass.indexOf('js-split-paragraph') > -1 && lastPid === currentPid) {
|
|
// 如果两个段落需要合并
|
|
// 如果两个段落需要合并
|
|
- let $prevParagraph = $paragraph.clone(false);
|
|
|
|
|
|
+ let $prevParagraph = $lastParagraph;
|
|
$paragraph.childNodes().forEach(item => {
|
|
$paragraph.childNodes().forEach(item => {
|
|
if (item.nodeType === 3) {
|
|
if (item.nodeType === 3) {
|
|
$paragraph[0].removeChild(item);
|
|
$paragraph[0].removeChild(item);
|
|
@@ -430,68 +634,175 @@ yzPage.prototype = {
|
|
if (itemClass && itemClass.indexOf('js-lsiten-line') > -1) {
|
|
if (itemClass && itemClass.indexOf('js-lsiten-line') > -1) {
|
|
// 普通行
|
|
// 普通行
|
|
let height = $item.getSizeData().height;
|
|
let height = $item.getSizeData().height;
|
|
- if (height < diff) {
|
|
|
|
|
|
+ if (height < size.diff) {
|
|
|
|
+ $prevParagraph.append($item);
|
|
|
|
+ size.diff -= height;
|
|
|
|
+ }
|
|
|
|
+ } else if (itemClass && itemClass.indexOf('js-lsiten-border') > -1) {
|
|
|
|
+ // 框处理
|
|
|
|
+ this._prevBorder($prevParagraph, size, $item, $lastParagraph, true);
|
|
|
|
+ } else {
|
|
|
|
+ $item.remove();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ } else {
|
|
|
|
+ // 两段落不需要合并
|
|
|
|
+ let $prevParagraph = $paragraph.clone(false);
|
|
|
|
+ $paragraph.childNodes().forEach(item => {
|
|
|
|
+ if (item.nodeType === 3) {
|
|
|
|
+ $paragraph[0].removeChild(item);
|
|
|
|
+ } else {
|
|
|
|
+ let $item = $(item);
|
|
|
|
+ let itemClass = $item.attr('class');
|
|
|
|
+ if (itemClass && itemClass.indexOf('js-lsiten-line') > -1) {
|
|
|
|
+ let height = $item.getSizeData().height;
|
|
|
|
+ if (height < size.diff) {
|
|
$prevParagraph.append($item);
|
|
$prevParagraph.append($item);
|
|
- diff -= height;
|
|
|
|
|
|
+ size.diff -= height;
|
|
}
|
|
}
|
|
} else if (itemClass && itemClass.indexOf('js-lsiten-border') > -1) {
|
|
} else if (itemClass && itemClass.indexOf('js-lsiten-border') > -1) {
|
|
// 框处理
|
|
// 框处理
|
|
- this._prevBorder($prevParagraph, diff, $item, $lastParagraph);
|
|
|
|
|
|
+ this._prevBorder($prevParagraph, size, $item, $lastParagraph, false);
|
|
} else {
|
|
} else {
|
|
$item.remove();
|
|
$item.remove();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
+
|
|
if (!isEmptyElement($prevParagraph[0])) {
|
|
if (!isEmptyElement($prevParagraph[0])) {
|
|
$moves.push($prevParagraph);
|
|
$moves.push($prevParagraph);
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
-
|
|
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
|
|
+ // 两段落不需要合并
|
|
|
|
+ let $prevParagraph = $paragraph.clone(false);
|
|
|
|
+ $paragraph.childNodes().forEach(item => {
|
|
|
|
+ if (item.nodeType === 3) {
|
|
|
|
+ $paragraph[0].removeChild(item);
|
|
|
|
+ } else {
|
|
|
|
+ let $item = $(item);
|
|
|
|
+ let itemClass = $item.attr('class');
|
|
|
|
+ if (itemClass && itemClass.indexOf('js-lsiten-line') > -1) {
|
|
|
|
+ let height = $item.getSizeData().height;
|
|
|
|
+ if (height < size.diff) {
|
|
|
|
+ $prevParagraph.append($item);
|
|
|
|
+ size.diff -= height;
|
|
|
|
+ }
|
|
|
|
+ } else if (itemClass && itemClass.indexOf('js-lsiten-border') > -1) {
|
|
|
|
+ // 框处理
|
|
|
|
+ this._prevBorder($prevParagraph, size, $item, $lastParagraph, false);
|
|
|
|
+ } else {
|
|
|
|
+ $item.remove();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
|
|
|
|
+ if (!isEmptyElement($prevParagraph[0])) {
|
|
|
|
+ $moves.push($prevParagraph);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
/**
|
|
/**
|
|
* function 处理需要上移的框
|
|
* function 处理需要上移的框
|
|
* @param {DomElement} $prevParagraph 前移段落暂存
|
|
* @param {DomElement} $prevParagraph 前移段落暂存
|
|
- * @param {number} diff 可移空间
|
|
|
|
|
|
+ * @param {object} size 可移空间
|
|
* @param {DomElement} $border 需要处理的框
|
|
* @param {DomElement} $border 需要处理的框
|
|
* @param {DomElement} $lastParagraph 最后一段dom
|
|
* @param {DomElement} $lastParagraph 最后一段dom
|
|
|
|
+ * @param {boolean} 是否需要合并
|
|
*/
|
|
*/
|
|
- _prevBorder: function ($prevParagraph, diff, $border, $lastParagraph) {
|
|
|
|
|
|
+ _prevBorder: function ($prevParagraph, size, $border, $lastParagraph, isMerge) {
|
|
let lastCentent = $lastParagraph[0].lastChild;
|
|
let lastCentent = $lastParagraph[0].lastChild;
|
|
if (lastCentent.className && lastCentent.className.indexOf('js-lsiten-border') > -1) {
|
|
if (lastCentent.className && lastCentent.className.indexOf('js-lsiten-border') > -1) {
|
|
let prevBid = $border.attr('data-id');
|
|
let prevBid = $border.attr('data-id');
|
|
let bid = $(lastCentent).attr('data-id');
|
|
let bid = $(lastCentent).attr('data-id');
|
|
if (prevBid === bid) {
|
|
if (prevBid === bid) {
|
|
let $prevBorder = $border.clone(false);
|
|
let $prevBorder = $border.clone(false);
|
|
- this._prevQuestions($prevBorder, diff, $border, $(lastCentent));
|
|
|
|
|
|
+ let $prevBorderContent = $($border[0].firstChild).clone(false);
|
|
|
|
+ $prevBorder.append($prevBorderContent);
|
|
|
|
+ if (isMerge) {
|
|
|
|
+ $prevBorder = $($prevParagraph[0].lastChild);
|
|
|
|
+ $prevBorderContent = $prevBorder[0].firstChild;
|
|
|
|
+ }
|
|
|
|
+ this._prevQuestions($prevBorder, size, $border, $(lastCentent));
|
|
|
|
+ if (!isMerge && !isEmptyElement($prevBorderContent[0])) {
|
|
|
|
+ $prevParagraph.append($prevBorder);
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
let borderSize= $border.getSizeData();
|
|
let borderSize= $border.getSizeData();
|
|
- if (borderSize.height < diff) {
|
|
|
|
|
|
+ if (borderSize.height < size.diff) {
|
|
$prevParagraph.append($border);
|
|
$prevParagraph.append($border);
|
|
- diff -= borderSize.height;
|
|
|
|
|
|
+ size.diff -= borderSize.height;
|
|
|
|
+ } else {
|
|
|
|
+ // 框的padding+margin+border
|
|
|
|
+ let borderOutSize = 22;
|
|
|
|
+ let $prevBorder = $border.clone(false);
|
|
|
|
+ let $borderContent = $($border[0].firstChild);
|
|
|
|
+ let $prevBorderContent = $borderContent.clone(false);
|
|
|
|
+ $prevBorder.append($prevBorderContent);
|
|
|
|
+ size.diff -= borderOutSize;
|
|
|
|
+ $borderContent.childNodes().forEach(item => {
|
|
|
|
+ if (item.className) {
|
|
|
|
+ if (item.className.indexOf('js-lsiten-question') > -1) {
|
|
|
|
+ let qustionType = parseInt(item.getAttribute('data-type'));
|
|
|
|
+ if (qustionType === 3) {
|
|
|
|
+ this._prevSubjectQuestion($prevSubject, size, $(item), false);
|
|
|
|
+ if (!isEmptyElement($prevSubject)) {
|
|
|
|
+ $prevBorderContent.appendChild($prevSubject[0]);
|
|
|
|
+ }
|
|
|
|
+ } else if (qustionType === 4) {
|
|
|
|
+ let $prevWritting = $(item).clone(false);
|
|
|
|
+ this._prevWrittingQuestion($prevWritting, size, $(item), false);
|
|
|
|
+ if (!isEmptyElement($prevWritting)) {
|
|
|
|
+ $prevBorderContent.appendChild($prevWritting[0]);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ let height = $(item).getSizeData().height;
|
|
|
|
+ if (height < size.diff) {
|
|
|
|
+ $prevBorderContent.appendChild(item);
|
|
|
|
+ size.diff -= height;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else if (item.className.indexOf('js-lsiten-line') > -1) {
|
|
|
|
+ let height = $(item).getSizeData().height;
|
|
|
|
+ if (height < size.diff) {
|
|
|
|
+ $prevBorderContent.appendChild(item);
|
|
|
|
+ size.diff -= height;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ $(item).remove();
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ item && item.parentNode.removeChild(item);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ size.diff += borderOutSize;
|
|
|
|
+ if (!isEmptyElement($prevBorderContent[0])) {
|
|
|
|
+ $prevParagraph.append($prevBorder);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
let borderSize= $border.getSizeData();
|
|
let borderSize= $border.getSizeData();
|
|
- if (borderSize.height < diff) {
|
|
|
|
|
|
+ if (borderSize.height < size.diff) {
|
|
$prevParagraph.append($border);
|
|
$prevParagraph.append($border);
|
|
- diff -= borderSize.height;
|
|
|
|
|
|
+ size.diff -= borderSize.height;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ if (isEmptyElement($border[0].firstChild)) {
|
|
|
|
+ $border.remove();
|
|
|
|
+ }
|
|
},
|
|
},
|
|
/**
|
|
/**
|
|
* function 前移问题
|
|
* function 前移问题
|
|
* @param {DomElement} $prevBorder 前移框暂存
|
|
* @param {DomElement} $prevBorder 前移框暂存
|
|
- * @param {number} diff 前移段落暂存
|
|
|
|
|
|
+ * @param {object} size 前移段落暂存
|
|
* @param {DomElement} $border 前移段落暂存
|
|
* @param {DomElement} $border 前移段落暂存
|
|
* @param {DomElement} $lastBorder 前段落最后一个框
|
|
* @param {DomElement} $lastBorder 前段落最后一个框
|
|
*
|
|
*
|
|
*/
|
|
*/
|
|
- _prevQuestions: function ($prevBorder, diff, $border, $lastBorder) {
|
|
|
|
|
|
+ _prevQuestions: function ($prevBorder, size, $border, $lastBorder) {
|
|
let lastQuestion = $lastBorder[0].firstChild.lastChild;
|
|
let lastQuestion = $lastBorder[0].firstChild.lastChild;
|
|
let $borderContent = $($border[0].firstChild);
|
|
let $borderContent = $($border[0].firstChild);
|
|
$borderContent.childNodes().forEach(item => {
|
|
$borderContent.childNodes().forEach(item => {
|
|
@@ -500,33 +811,68 @@ yzPage.prototype = {
|
|
let qustionType = parseInt(item.getAttribute('data-type'));
|
|
let qustionType = parseInt(item.getAttribute('data-type'));
|
|
let questionId = item.getAttribute('data-id');
|
|
let questionId = item.getAttribute('data-id');
|
|
if (lastQuestion.className && lastQuestion.className.indexOf('js-lsiten-question') > -1) {
|
|
if (lastQuestion.className && lastQuestion.className.indexOf('js-lsiten-question') > -1) {
|
|
-
|
|
|
|
|
|
+ let lastQuestionId = lastQuestion.getAttribute('data-id');
|
|
|
|
+ if (questionId && lastQuestionId && lastQuestionId === questionId) {
|
|
|
|
+ // 需要合并2个小问
|
|
|
|
+ if (qustionType === 3) {
|
|
|
|
+ this._prevSubjectQuestion($(lastQuestion), size, $(item), true);
|
|
|
|
+ } else if (qustionType === 4) {
|
|
|
|
+ this._prevWrittingQuestion($(lastQuestion), size, $(item), true);
|
|
|
|
+ } else {
|
|
|
|
+ let height = $(item).getSizeData().height;
|
|
|
|
+ if (height < size.diff) {
|
|
|
|
+ $prevBorder[0].firstChild.appendChild(item);
|
|
|
|
+ size.diff -= height;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ if (qustionType === 3) {
|
|
|
|
+ let $prevSubject = $(item).clone(false);
|
|
|
|
+ this._prevSubjectQuestion($prevSubject, size, $(item), false);
|
|
|
|
+ if (!isEmptyElement($prevSubject[0])) {
|
|
|
|
+ $prevBorder[0].firstChild.appendChild($prevSubject[0]);
|
|
|
|
+ }
|
|
|
|
+ } else if (qustionType === 4) {
|
|
|
|
+ let $prevWritting = $(item).clone(false);
|
|
|
|
+ this._prevWrittingQuestion($prevWritting, size, $(item), false);
|
|
|
|
+ if (!isEmptyElement($prevWritting[0])) {
|
|
|
|
+ $prevBorder[0].firstChild.appendChild($prevWritting[0]);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ let height = $(item).getSizeData().height;
|
|
|
|
+ if (height < size.diff) {
|
|
|
|
+ $prevBorder[0].firstChild.appendChild(item);
|
|
|
|
+ size.diff -= height;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
} else {
|
|
} else {
|
|
if (qustionType === 3) {
|
|
if (qustionType === 3) {
|
|
let $prevSubject = $(item).clone(false);
|
|
let $prevSubject = $(item).clone(false);
|
|
- this._prevSubjectQuestion($prevSubject, diff, $(item));
|
|
|
|
- if (!isEmptyElement($prevSubject)) {
|
|
|
|
|
|
+ this._prevSubjectQuestion($prevSubject, size, $(item), false);
|
|
|
|
+ if (!isEmptyElement($prevSubject[0])) {
|
|
$prevBorder[0].firstChild.appendChild($prevSubject[0]);
|
|
$prevBorder[0].firstChild.appendChild($prevSubject[0]);
|
|
}
|
|
}
|
|
} else if (qustionType === 4) {
|
|
} else if (qustionType === 4) {
|
|
let $prevWritting = $(item).clone(false);
|
|
let $prevWritting = $(item).clone(false);
|
|
- this._prevWrittingQuestion($prevWritting, diff, $(item));
|
|
|
|
- if (!isEmptyElement($prevWritting)) {
|
|
|
|
|
|
+ this._prevWrittingQuestion($prevWritting, size, $(item), false);
|
|
|
|
+ if (!isEmptyElement($prevWritting[0])) {
|
|
$prevBorder[0].firstChild.appendChild($prevWritting[0]);
|
|
$prevBorder[0].firstChild.appendChild($prevWritting[0]);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- let height = $(item).getSizeData();
|
|
|
|
- if (height < diff) {
|
|
|
|
|
|
+ let height = $(item).getSizeData().height;
|
|
|
|
+ if (height < size.diff) {
|
|
$prevBorder[0].firstChild.appendChild(item);
|
|
$prevBorder[0].firstChild.appendChild(item);
|
|
- diff -= height;
|
|
|
|
|
|
+ size.diff -= height;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else if (item.className.indexOf('js-lsiten-line') > -1) {
|
|
} else if (item.className.indexOf('js-lsiten-line') > -1) {
|
|
- let height = $(item).getSizeData();
|
|
|
|
- if (height < diff) {
|
|
|
|
|
|
+ let height = $(item).getSizeData().height;
|
|
|
|
+ if (height < size.diff) {
|
|
$prevBorder[0].firstChild.appendChild(item);
|
|
$prevBorder[0].firstChild.appendChild(item);
|
|
- diff -= height;
|
|
|
|
|
|
+ size.diff -= height;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
$(item).remove();
|
|
$(item).remove();
|
|
@@ -539,34 +885,109 @@ yzPage.prototype = {
|
|
/**
|
|
/**
|
|
* function 前移主观题框
|
|
* function 前移主观题框
|
|
* @param {DomElement} $prevSubject 前移框暂存
|
|
* @param {DomElement} $prevSubject 前移框暂存
|
|
- * @param {number} diff 可移动空间
|
|
|
|
|
|
+ * @param {object} size 可移动空间
|
|
* @param {DomElement} $subject 需要前移客观题处理
|
|
* @param {DomElement} $subject 需要前移客观题处理
|
|
|
|
+ * @param {boolean} isMerge 是否需要合并
|
|
*/
|
|
*/
|
|
- _prevSubjectQuestion: function ($prevSubject, diff, $subject) {
|
|
|
|
|
|
+ _prevSubjectQuestion: function ($prevSubject, size, $subject, isMerge) {
|
|
$subject.childNodes().forEach(item => {
|
|
$subject.childNodes().forEach(item => {
|
|
- let height = $(item).getSizeData();
|
|
|
|
- if (height < diff) {
|
|
|
|
|
|
+ let height = $(item).getSizeData().height;
|
|
|
|
+ if (height < size.diff) {
|
|
$prevSubject[0].appendChild(item);
|
|
$prevSubject[0].appendChild(item);
|
|
- diff -= height;
|
|
|
|
|
|
+ size.diff -= height;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (isEmptyElement($subject[0])) {
|
|
|
|
+ $subject.remove();
|
|
}
|
|
}
|
|
})
|
|
})
|
|
},
|
|
},
|
|
/**
|
|
/**
|
|
* function 前移主观题框
|
|
* function 前移主观题框
|
|
- * @param {DomElement} $prevSubject 前移框暂存
|
|
|
|
- * @param {number} diff 可移动空间
|
|
|
|
- * @param {DomElement} $subject 需要前移客观题处理
|
|
|
|
|
|
+ * @param {DomElement} $prevWritting 前移框暂存
|
|
|
|
+ * @param {number} size 可移动空间
|
|
|
|
+ * @param {DomElement} $Writting 需要前移客观题处理
|
|
|
|
+ * @param {boolean} isMerge 是否需要合并
|
|
*/
|
|
*/
|
|
- _prevWrittingQuestion: function ($prevWritting, diff, $Writting) {
|
|
|
|
|
|
+ _prevWrittingQuestion: function ($prevWritting, size, $Writting, isMerge) {
|
|
$Writting.childNodes().forEach(item => {
|
|
$Writting.childNodes().forEach(item => {
|
|
if (item.className) {
|
|
if (item.className) {
|
|
if (item.className.indexOf('lsiten-title') > -1) {
|
|
if (item.className.indexOf('lsiten-title') > -1) {
|
|
-
|
|
|
|
|
|
+ let $prevWrittingTitle = null;
|
|
|
|
+ let needApppend = true;
|
|
|
|
+ if (isMerge) {
|
|
|
|
+ $prevWrittingTitle = $prevWritting.find('.lsiten-title');
|
|
|
|
+ if ($prevWrittingTitle.length) {
|
|
|
|
+ $prevWrittingTitle = $($prevWrittingTitle);
|
|
|
|
+ needApppend = false;
|
|
|
|
+ } else {
|
|
|
|
+ $prevWrittingTitle = null;
|
|
|
|
+ let needApppend = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ let $writtingTitle = $(item);
|
|
|
|
+ $prevWrittingTitle = $prevWrittingTitle || $writtingTitle.clone(false);
|
|
|
|
+ $writtingTitle.childNodes().forEach(titleItem => {
|
|
|
|
+ if (titleItem.className && titleItem.className.indexOf('js-lsiten-line') > -1) {
|
|
|
|
+ let height = $(titleItem).getSizeData().height;
|
|
|
|
+ if (height < size.diff) {
|
|
|
|
+ $prevWrittingTitle[0].appendChild(titleItem);
|
|
|
|
+ size.diff -= height;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ titleItem && item.removeChild(titleItem);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ if (needApppend && !isEmptyElement($prevWrittingTitle[0])) {
|
|
|
|
+ $prevWritting.append($prevWrittingTitle);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (isEmptyElement($writtingTitle[0])) {
|
|
|
|
+ $writtingTitle.remove();
|
|
|
|
+ }
|
|
} else if (item.className.indexOf('lsiten-border-box') > -1) {
|
|
} else if (item.className.indexOf('lsiten-border-box') > -1) {
|
|
-
|
|
|
|
|
|
+ let $prevWrittingRows = null;
|
|
|
|
+ let needApppend = true;
|
|
|
|
+ if (isMerge) {
|
|
|
|
+ $prevWrittingRows = $prevWritting.find('.lsiten-border-box');
|
|
|
|
+ if ($prevWrittingRows.length) {
|
|
|
|
+ $prevWrittingRows = $($prevWrittingRows);
|
|
|
|
+ needApppend = false;
|
|
|
|
+ } else {
|
|
|
|
+ $prevWrittingRows = null;
|
|
|
|
+ needApppend = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ let $writtingRows = $(item);
|
|
|
|
+ $prevWrittingRows = $prevWrittingRows || $writtingRows.clone(false);
|
|
|
|
+ // 行的margin值
|
|
|
|
+ let rowOutSize = 8;
|
|
|
|
+ $writtingRows.childNodes().forEach(rowItem => {
|
|
|
|
+ if (rowItem.className && rowItem.className.indexOf('js-lsiten-writting-row') > -1) {
|
|
|
|
+ let height = $(rowItem).getSizeData().height + rowOutSize;
|
|
|
|
+ if (height < size.diff) {
|
|
|
|
+ $prevWrittingRows[0].appendChild(rowItem);
|
|
|
|
+ size.diff -= height;
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ rowItem && item.removeChild(rowItem);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ if (needApppend && !isEmptyElement($prevWrittingRows[0])) {
|
|
|
|
+ $prevWritting.append($prevWrittingRows);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (isEmptyElement($writtingRows[0])) {
|
|
|
|
+ $writtingRows.remove();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
+
|
|
|
|
+ if (isEmptyElement($Writting[0])) {
|
|
|
|
+ $Writting.remove();
|
|
|
|
+ }
|
|
},
|
|
},
|
|
/**
|
|
/**
|
|
* function 检测内容是否超出
|
|
* function 检测内容是否超出
|
|
@@ -585,6 +1006,9 @@ yzPage.prototype = {
|
|
_getFirstPargraph: function (column) {
|
|
_getFirstPargraph: function (column) {
|
|
let $paragraphs = column.find('.js-paragraph-view');
|
|
let $paragraphs = column.find('.js-paragraph-view');
|
|
let firstParagraph = $paragraphs[0];
|
|
let firstParagraph = $paragraphs[0];
|
|
|
|
+ if (!firstParagraph) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
let firstChild = firstParagraph.firstChild;
|
|
let firstChild = firstParagraph.firstChild;
|
|
if (firstChild && firstChild.className && firstChild.className.indexOf('js-answer-header') > -1) {
|
|
if (firstChild && firstChild.className && firstChild.className.indexOf('js-answer-header') > -1) {
|
|
firstParagraph = $paragraphs[1];
|
|
firstParagraph = $paragraphs[1];
|