|
@@ -4,12 +4,15 @@
|
|
* Description:
|
|
* Description:
|
|
*/
|
|
*/
|
|
import $ from 'jquery';
|
|
import $ from 'jquery';
|
|
-import boxContent from './box/boxContent';
|
|
|
|
|
|
|
|
var yzToolbar = function(){
|
|
var yzToolbar = function(){
|
|
this.menu = [{
|
|
this.menu = [{
|
|
- name: 'table',
|
|
|
|
- title: '表格',
|
|
|
|
|
|
+ name: 'blank',
|
|
|
|
+ title: '加空',
|
|
|
|
+ icon: 'fa-square-o'
|
|
|
|
+ },{
|
|
|
|
+ name: 'composition',
|
|
|
|
+ title: '作文格',
|
|
icon: 'fa-table'
|
|
icon: 'fa-table'
|
|
},{
|
|
},{
|
|
name: 'underline',
|
|
name: 'underline',
|
|
@@ -22,18 +25,23 @@ var yzToolbar = function(){
|
|
},{
|
|
},{
|
|
name: 'component',
|
|
name: 'component',
|
|
title: '组件框',
|
|
title: '组件框',
|
|
- icon: 'fa-square'
|
|
|
|
|
|
+ icon: 'fa-object-ungroup'
|
|
},{
|
|
},{
|
|
name: 'subject',
|
|
name: 'subject',
|
|
title: '无',
|
|
title: '无',
|
|
icon: 'fa-list-alt'
|
|
icon: 'fa-list-alt'
|
|
}];
|
|
}];
|
|
|
|
|
|
|
|
+ // 导航栏的dom;
|
|
|
|
+ this.vdom = null;
|
|
|
|
+
|
|
// 问题编号
|
|
// 问题编号
|
|
this.subjectNum = null;
|
|
this.subjectNum = null;
|
|
// 获取当前需要插入的Dom
|
|
// 获取当前需要插入的Dom
|
|
this.currentContent = null;
|
|
this.currentContent = null;
|
|
|
|
|
|
|
|
+ this.$dashboard = $('<div class="dashboard" style="max-height: 300px"></div>');
|
|
|
|
+
|
|
};
|
|
};
|
|
|
|
|
|
yzToolbar.prototype.toolbarContent = function () {
|
|
yzToolbar.prototype.toolbarContent = function () {
|
|
@@ -48,26 +56,55 @@ yzToolbar.prototype.toolbarContent = function () {
|
|
liDom.setAttribute('title',item.title);
|
|
liDom.setAttribute('title',item.title);
|
|
liDom.appendChild(spanDom);
|
|
liDom.appendChild(spanDom);
|
|
liDom.appendChild(liText);
|
|
liDom.appendChild(liText);
|
|
- ulDom.appendChild(liDom);
|
|
|
|
if( item.name == 'component' ){
|
|
if( item.name == 'component' ){
|
|
liDom.addEventListener('click', () => {
|
|
liDom.addEventListener('click', () => {
|
|
this.addComponent(liDom);
|
|
this.addComponent(liDom);
|
|
},!0);
|
|
},!0);
|
|
}
|
|
}
|
|
-
|
|
|
|
if( item.name == 'underline' ){
|
|
if( item.name == 'underline' ){
|
|
liDom.addEventListener('click', () => {
|
|
liDom.addEventListener('click', () => {
|
|
this.addUnderline();
|
|
this.addUnderline();
|
|
},!0);
|
|
},!0);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ if( item.name == 'blank' ){
|
|
|
|
+ liDom.addEventListener('click', () => {
|
|
|
|
+ this.addBlank();
|
|
|
|
+ },!0);
|
|
|
|
+ }
|
|
|
|
+ if( item.name == 'composition' ){
|
|
|
|
+ liDom.addEventListener('click',() => {
|
|
|
|
+ this.addComposition();
|
|
|
|
+ },!0);
|
|
|
|
+ }
|
|
|
|
+ if( item.name == 'picture' ){
|
|
|
|
+ let input = document.createElement('input');
|
|
|
|
+ input.setAttribute('type','file');input.setAttribute('accept','image/png,image/jpeg,image/gif,image/jpg');
|
|
|
|
+ input.style.display = 'none';input.setAttribute('id','uploadPhoto');
|
|
|
|
+ liDom.appendChild(input);
|
|
|
|
+ liDom.addEventListener('click',() => {
|
|
|
|
+ this.addPhoto();
|
|
|
|
+ },!0);
|
|
|
|
+ }
|
|
|
|
+ ulDom.appendChild(liDom);
|
|
});
|
|
});
|
|
toolDom.className = 'toolbar';
|
|
toolDom.className = 'toolbar';
|
|
toolDom.appendChild(ulDom);
|
|
toolDom.appendChild(ulDom);
|
|
toolDom.setAttribute('id','toolbar');
|
|
toolDom.setAttribute('id','toolbar');
|
|
|
|
+ this.removeCompositionNumDom();
|
|
|
|
+ this.vdom = toolDom;
|
|
return toolDom;
|
|
return toolDom;
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+yzToolbar.prototype.compositionNumDom = function(){
|
|
|
|
+ let table = $('<div class="table-dashboard"><label>作文字数<input class="blank-number" type="number" min="0" step="5" width="80px"></label><button class="submit-btn">添加</button></div>');
|
|
|
|
+ this.$dashboard.append(table);
|
|
|
|
+ $(this.vdom).append(this.$dashboard);
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+yzToolbar.prototype.removeCompositionNumDom = function () {
|
|
|
|
+ this.$dashboard.html('');
|
|
|
|
+};
|
|
|
|
+
|
|
yzToolbar.prototype.setSubjectTitle = function(pNum,content) {
|
|
yzToolbar.prototype.setSubjectTitle = function(pNum,content) {
|
|
this.subjectNum = pNum;
|
|
this.subjectNum = pNum;
|
|
this.currentContent = content;
|
|
this.currentContent = content;
|
|
@@ -89,7 +126,45 @@ yzToolbar.prototype.addComponent = function() {
|
|
};
|
|
};
|
|
|
|
|
|
yzToolbar.prototype.addUnderline = function() {
|
|
yzToolbar.prototype.addUnderline = function() {
|
|
|
|
+ if(this.subjectNum == 'none' || !this.subjectNum){
|
|
|
|
+ alert('请选择主观题');return;
|
|
|
|
+ }
|
|
this.currentContent.addUnderline();
|
|
this.currentContent.addUnderline();
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+yzToolbar.prototype.addBlank = function () {
|
|
|
|
+ if(this.subjectNum == 'none' || !this.subjectNum){
|
|
|
|
+ alert('请选择主观题');return;
|
|
|
|
+ }
|
|
|
|
+ this.currentContent.addBlank();
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+// 添加作文格
|
|
|
|
+yzToolbar.prototype.addComposition = function () {
|
|
|
|
+ if(this.subjectNum == 'none' || !this.subjectNum){
|
|
|
|
+ alert('请选择主观题');return;
|
|
|
|
+ }
|
|
|
|
+ if(this.$dashboard.children().length === 0)this.compositionNumDom();
|
|
|
|
+ this.$dashboard.slideToggle().finish();
|
|
|
|
+ let _this = this;
|
|
|
|
+ $('.submit-btn').on('click', function(e){
|
|
|
|
+ e.stopPropagation();
|
|
|
|
+ _this.currentContent.addComposition($('.blank-number').val());
|
|
|
|
+ $(this).off('click')
|
|
|
|
+ });
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+// 上传图片
|
|
|
|
+yzToolbar.prototype.addPhoto = function () {
|
|
|
|
+ if(this.subjectNum == 'none' || !this.subjectNum){
|
|
|
|
+ alert('请选择主观题');return;
|
|
|
|
+ }
|
|
|
|
+ let _this = this;
|
|
|
|
+ $('#uploadPhoto').on('change',function(e){
|
|
|
|
+ let inputDom = this;
|
|
|
|
+ _this.currentContent.addPhoto(inputDom);
|
|
|
|
+ $(this).off('change');
|
|
|
|
+ }).get(0).click();
|
|
|
|
+};
|
|
|
|
+
|
|
export default yzToolbar;
|
|
export default yzToolbar;
|