From e588128f9016ee99881c25e6b380ec21dec6db85 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Fri, 6 Sep 2019 18:20:03 +0800 Subject: [PATCH 1/9] sms --- app/services/users/apply_professional_auth_service.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/services/users/apply_professional_auth_service.rb b/app/services/users/apply_professional_auth_service.rb index 07afe18ae..a920caf55 100644 --- a/app/services/users/apply_professional_auth_service.rb +++ b/app/services/users/apply_professional_auth_service.rb @@ -38,7 +38,11 @@ class Users::ApplyProfessionalAuthService < ApplicationService move_image_file! unless params[:upload_image].to_s == 'false' - sms_notify_admin + sms_cache = Rails.cache.read("apply_pro_certification") + if sms_cache.nil? + sms_notify_admin + Rails.cache.write("apply_pro_certification", 1) + end end end From 4005ebf768af6a99e3ea7af522a9238504f5e77f Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 9 Sep 2019 19:08:16 +0800 Subject: [PATCH 2/9] =?UTF-8?q?=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/users/apply_professional_auth_service.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/services/users/apply_professional_auth_service.rb b/app/services/users/apply_professional_auth_service.rb index a920caf55..3ba9fbafd 100644 --- a/app/services/users/apply_professional_auth_service.rb +++ b/app/services/users/apply_professional_auth_service.rb @@ -38,11 +38,11 @@ class Users::ApplyProfessionalAuthService < ApplicationService move_image_file! unless params[:upload_image].to_s == 'false' - sms_cache = Rails.cache.read("apply_pro_certification") - if sms_cache.nil? - sms_notify_admin + # sms_cache = Rails.cache.read("apply_pro_certification") + # if sms_cache.nil? + # sms_notify_admin Rails.cache.write("apply_pro_certification", 1) - end + # end end end From 3b4f6c1a271d3b5ee4d7bdb5223e75dfdf115524 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Mon, 9 Sep 2019 19:48:27 +0800 Subject: [PATCH 3/9] =?UTF-8?q?=E5=AE=9E=E8=B7=B5=E8=AF=BE=E7=A8=8B?= =?UTF-8?q?=E7=9A=84=E5=B7=B2=E5=AD=A6=E5=85=B3=E5=8D=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/subjects_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/subjects_controller.rb b/app/controllers/subjects_controller.rb index 7c76748b1..952301053 100644 --- a/app/controllers/subjects_controller.rb +++ b/app/controllers/subjects_controller.rb @@ -442,7 +442,6 @@ class SubjectsController < ApplicationController # 用户进展和获取的标签 def user_subject_progress challenge_ids pass_games = Game.select(:id, :cost_time, :challenge_id).where(status: 2, user_id: current_user.id, challenge_id: challenge_ids) if current_user.logged? - @all_score = Challenge.where(id: challenge_ids).sum(:score) # 如果没有通关的,没必要再继续统计了 if pass_games.blank? @@ -451,6 +450,7 @@ class SubjectsController < ApplicationController @time = 0 @user_tags = [] else + @all_score = Challenge.where(id: challenge_ids).size pass_challenge_ids = pass_games.map(&:challenge_id).uniq # 按道理是不用去重的,但是历史数据与重复 subject_challenge_count = @subject.shixuns.sum(:challenges_count) # 用户通关获得的标签 @@ -460,7 +460,7 @@ class SubjectsController < ApplicationController subject_challenge_count == 0 ? 0 : ((pass_challenge_ids.size.to_f / subject_challenge_count).round(2) * 100).to_i # 用户通关分数 - @my_score = Challenge.where(id: pass_challenge_ids).pluck(:score).sum + @my_score = Challenge.where(id: pass_challenge_ids).size @time = pass_games.map(&:cost_time).sum end From baba6aa9e95d959ab445e559889d6ab8074bcc14 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 10 Sep 2019 14:31:59 +0800 Subject: [PATCH 4/9] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E5=9C=A8=E7=BA=BF?= =?UTF-8?q?=E5=AD=A6=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/course_stage.rb | 9 +++++++++ app/models/course_stage_shixun.rb | 5 +++++ db/migrate/20190910061807_create_course_stages.rb | 13 +++++++++++++ .../20190910062710_create_course_stage_shixuns.rb | 12 ++++++++++++ spec/models/course_stage_shixun_spec.rb | 5 +++++ spec/models/course_stage_spec.rb | 5 +++++ 6 files changed, 49 insertions(+) create mode 100644 app/models/course_stage.rb create mode 100644 app/models/course_stage_shixun.rb create mode 100644 db/migrate/20190910061807_create_course_stages.rb create mode 100644 db/migrate/20190910062710_create_course_stage_shixuns.rb create mode 100644 spec/models/course_stage_shixun_spec.rb create mode 100644 spec/models/course_stage_spec.rb diff --git a/app/models/course_stage.rb b/app/models/course_stage.rb new file mode 100644 index 000000000..27eb9de30 --- /dev/null +++ b/app/models/course_stage.rb @@ -0,0 +1,9 @@ +class CourseStage < ApplicationRecord + belongs_to :course, counter_cache: true + + has_many :course_stage_shixuns, -> { order("course_stage_shixuns.position ASC") }, dependent: :destroy + has_many :shixuns, :through => :course_stage_shixuns + + validates :name, length: { maximum: 60 } + validates :description, length: { maximum: 300 } +end diff --git a/app/models/course_stage_shixun.rb b/app/models/course_stage_shixun.rb new file mode 100644 index 000000000..be5a1bb7d --- /dev/null +++ b/app/models/course_stage_shixun.rb @@ -0,0 +1,5 @@ +class CourseStageShixun < ApplicationRecord + belongs_to :course, counter_cache: :stages_count, counter_cache: :shixuns_count + belongs_to :course_stage + belongs_to :shixun, counter_cache: :shixuns_count +end diff --git a/db/migrate/20190910061807_create_course_stages.rb b/db/migrate/20190910061807_create_course_stages.rb new file mode 100644 index 000000000..c664b7f92 --- /dev/null +++ b/db/migrate/20190910061807_create_course_stages.rb @@ -0,0 +1,13 @@ +class CreateCourseStages < ActiveRecord::Migration[5.2] + def change + create_table :course_stages do |t| + t.references :course, index: true + t.string :name + t.text :description + t.integer :position + t.integer :shixuns_count + + t.timestamps + end + end +end diff --git a/db/migrate/20190910062710_create_course_stage_shixuns.rb b/db/migrate/20190910062710_create_course_stage_shixuns.rb new file mode 100644 index 000000000..04512c7da --- /dev/null +++ b/db/migrate/20190910062710_create_course_stage_shixuns.rb @@ -0,0 +1,12 @@ +class CreateCourseStageShixuns < ActiveRecord::Migration[5.2] + def change + create_table :course_stage_shixuns do |t| + t.references :course, index: true + t.references :course_stage, index: true + t.references :shixun, index: true + t.integer :position + + t.timestamps + end + end +end diff --git a/spec/models/course_stage_shixun_spec.rb b/spec/models/course_stage_shixun_spec.rb new file mode 100644 index 000000000..716af2b97 --- /dev/null +++ b/spec/models/course_stage_shixun_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CourseStageShixun, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/course_stage_spec.rb b/spec/models/course_stage_spec.rb new file mode 100644 index 000000000..06c711908 --- /dev/null +++ b/spec/models/course_stage_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CourseStage, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 4f503270aab596076b7b663a1cc294009d58dd93 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 10 Sep 2019 15:30:49 +0800 Subject: [PATCH 5/9] =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E5=AD=A6=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/courses_controller.rb | 2 ++ app/models/course.rb | 11 +++++++++++ app/models/course_stage.rb | 2 +- app/models/course_stage_shixun.rb | 6 +++--- db/migrate/20190910063345_migrate_course_stages.rb | 14 ++++++++++++++ 5 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 db/migrate/20190910063345_migrate_course_stages.rb diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 2039dbc6f..c12b80da8 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -166,6 +166,8 @@ class CoursesController < ApplicationController end Inform.create(container: @course, description: @subject.learning_notes, name: "学习须知") + + @course.create_stages @course.subject end course_module_types = params[:course_module_types] diff --git a/app/models/course.rb b/app/models/course.rb index 54d897b07..2722c3b24 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -333,6 +333,17 @@ class Course < ApplicationRecord teacher_power_courses end + def create_stages subject + if subject + subject.stages.each do |stage| + new_stage = CourseStage.create!(course_id: id, name: stage.name, description: stage.description, position: stage.position) + stage.stage_shixuns.each do |stage_shixun| + CourseStageShixun.create!(course_id: id, course_stage_id: new_stage.id, shixun_id: stage_shixun.shixun_id, position: stage_shixun.position) + end + end + end + end + private #创建课程后,给该用户发送消息 diff --git a/app/models/course_stage.rb b/app/models/course_stage.rb index 27eb9de30..f105e25f6 100644 --- a/app/models/course_stage.rb +++ b/app/models/course_stage.rb @@ -1,5 +1,5 @@ class CourseStage < ApplicationRecord - belongs_to :course, counter_cache: true + belongs_to :course has_many :course_stage_shixuns, -> { order("course_stage_shixuns.position ASC") }, dependent: :destroy has_many :shixuns, :through => :course_stage_shixuns diff --git a/app/models/course_stage_shixun.rb b/app/models/course_stage_shixun.rb index be5a1bb7d..6ab2707a4 100644 --- a/app/models/course_stage_shixun.rb +++ b/app/models/course_stage_shixun.rb @@ -1,5 +1,5 @@ class CourseStageShixun < ApplicationRecord - belongs_to :course, counter_cache: :stages_count, counter_cache: :shixuns_count - belongs_to :course_stage - belongs_to :shixun, counter_cache: :shixuns_count + belongs_to :course + belongs_to :course_stage, counter_cache: :shixuns_count + belongs_to :shixun end diff --git a/db/migrate/20190910063345_migrate_course_stages.rb b/db/migrate/20190910063345_migrate_course_stages.rb new file mode 100644 index 000000000..0aae05103 --- /dev/null +++ b/db/migrate/20190910063345_migrate_course_stages.rb @@ -0,0 +1,14 @@ +class MigrateCourseStages < ActiveRecord::Migration[5.2] + def change + Course.where(excellent: 1).each do |course| + if course.subject + course.subject.stages.each do |stage| + new_stage = CourseStage.create!(course_id: course.id, name: stage.name, description: stage.description, position: stage.position) + stage.stage_shixuns.each do |stage_shixun| + CourseStageShixun.create!(course_id: course.id, course_stage_id: new_stage.id, shixun_id: stage_shixun.shixun_id, position: stage_shixun.position) + end + end + end + end + end +end From 3986029955e9dd99c6a0f325a2d51abb8be5da45 Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Tue, 10 Sep 2019 16:56:43 +0800 Subject: [PATCH 6/9] delay 500 --- public/react/public/js/editormd/editormd.min.js | 2 +- public/react/public/js/js_min_all.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/public/react/public/js/editormd/editormd.min.js b/public/react/public/js/editormd/editormd.min.js index ac3deac1a..289f1f171 100755 --- a/public/react/public/js/editormd/editormd.min.js +++ b/public/react/public/js/editormd/editormd.min.js @@ -101,7 +101,7 @@ height : "100%", path : "./lib/", // Dependents module file directory pluginPath : "", // If this empty, default use settings.path + "../plugins/" - delay : 300, // Delay parse markdown to html, Uint : ms + delay : 500, // Delay parse markdown to html, Uint : ms autoLoadModules : true, // Automatic load dependent module files watch : true, placeholder : "Enjoy Markdown! coding now...", diff --git a/public/react/public/js/js_min_all.js b/public/react/public/js/js_min_all.js index 57606faa6..37dd843b7 100755 --- a/public/react/public/js/js_min_all.js +++ b/public/react/public/js/js_min_all.js @@ -83,7 +83,7 @@ function AssertException(message){this.message=message}function assert(exp,messa * {@link https://github.com/pandao/editor.md} * @updateTime 2015-06-09 */ -function initEditormdPasteUpload(e,t,i){e.cm.getInputField().addEventListener("paste",function(i){_whenPasterDoUpload(i,t,function(t){t.id&&e.cm.replaceSelection("![](/api/attachments/"+t.id+")")})})}!function(e){"use strict";"function"==typeof require&&"object"==typeof exports&&"object"==typeof module?module.exports=e:"function"==typeof define?define.amd||define(["../../../../editormd/examples/js/jquery.min"],e):window.editormd=e()}(function(){"use strict";var e="undefined"!=typeof jQuery?jQuery:Zepto;if(void 0!==e){var t,i,o,r=function(e,t){return new r.fn.init(e,t)};r.title=r.$name="Editor.md",r.version="1.5.0",r.homePage="https://pandao.github.io/editor.md/",r.classPrefix="editormd-",r.toolbarModes={full:["undo","redo","|","bold","del","italic","quote","ucwords","uppercase","lowercase","|","h1","h2","h3","h4","h5","h6","|","list-ul","list-ol","hr","|","link","reference-link","image","code","preformatted-text","code-block","table","datetime","emoji","html-entities","pagebreak","|","goto-line","watch","preview","fullscreen","clear","search","|","help","info"],simple:["undo","redo","|","bold","del","italic","quote","uppercase","lowercase","|","h1","h2","h3","h4","h5","h6","|","list-ul","list-ol","hr","|","watch","preview","fullscreen","|","help","info"],mini:["undo","redo","|","watch","preview","|","help","info"]},r.defaults={mode:"gfm",name:"",value:"",theme:"",editorTheme:"default",previewTheme:"",markdown:"",appendMarkdown:"",width:"100%",height:"100%",path:"./lib/",pluginPath:"",delay:300,autoLoadModules:!0,watch:!0,placeholder:"Enjoy Markdown! coding now...",gotoLine:!0,codeFold:!1,autoHeight:!1,autoFocus:!0,autoCloseTags:!0,searchReplace:!0,syncScrolling:!0,readOnly:!1,tabSize:4,indentUnit:4,lineNumbers:!0,lineWrapping:!0,autoCloseBrackets:!0,showTrailingSpace:!0,matchBrackets:!0,indentWithTabs:!0,styleSelectedText:!0,matchWordHighlight:!0,styleActiveLine:!0,dialogLockScreen:!0,dialogShowMask:!0,dialogDraggable:!0,dialogMaskBgColor:"#fff",dialogMaskOpacity:.1,fontSize:"13px",saveHTMLToTextarea:!1,disabledKeyMaps:[],onload:function(){},onresize:function(){},onchange:function(){},onwatch:null,onunwatch:null,onpreviewing:function(){},onpreviewed:function(){},onfullscreen:function(){},onfullscreenExit:function(){},onscroll:function(){},onpreviewscroll:function(){},imageUpload:!1,imageFormats:["jpg","jpeg","gif","png","bmp","webp"],imageUploadURL:"",crossDomainUpload:!1,uploadCallbackURL:"",toc:!0,tocm:!1,tocTitle:"",tocDropdown:!1,tocContainer:"",tocStartLevel:1,htmlDecode:"style,iframe|on*",pageBreak:!0,atLink:!0,emailLink:!0,taskList:!1,emoji:!1,tex:!1,flowChart:!1,sequenceDiagram:!1,previewCodeHighlight:!0,toolbar:!0,toolbarAutoFixed:!0,toolbarIcons:"full",toolbarTitles:{},toolbarHandlers:{ucwords:function(){return r.toolbarHandlers.ucwords},lowercase:function(){return r.toolbarHandlers.lowercase}},toolbarCustomIcons:{lowercase:'a',ucwords:'Aa'},toolbarIconsClass:{undo:"fa-undo",redo:"fa-repeat",bold:"fa-bold",del:"fa-strikethrough",italic:"fa-italic",quote:"fa-quote-left",uppercase:"fa-font",h1:r.classPrefix+"bold",h2:r.classPrefix+"bold",h3:r.classPrefix+"bold",h4:r.classPrefix+"bold",h5:r.classPrefix+"bold",h6:r.classPrefix+"bold","list-ul":"fa-list-ul","list-ol":"fa-list-ol",hr:"fa-minus",link:"fa-link","reference-link":"fa-anchor",image:"fa-picture-o",code:"fa-code","preformatted-text":"fa-file-code-o","code-block":"fa-file-code-o",table:"fa-table",datetime:"fa-clock-o",emoji:"fa-smile-o","html-entities":"fa-copyright",pagebreak:"fa-newspaper-o","goto-line":"fa-terminal",watch:"fa-eye-slash",unwatch:"fa-eye",preview:"fa-desktop",search:"fa-search",fullscreen:"fa-arrows-alt",clear:"fa-eraser",help:"fa-question-circle",info:"fa-info-circle"},toolbarIconTexts:{},lang:{name:"zh-cn",description:"开源在线Markdown编辑器
Open source online Markdown editor.",tocTitle:"目录",toolbar:{undo:"撤销(Ctrl+Z)",redo:"重做(Ctrl+Y)",bold:"粗体",del:"删除线",italic:"斜体",quote:"引用",ucwords:"将每个单词首字母转成大写",uppercase:"将所选转换成大写",lowercase:"将所选转换成小写",h1:"标题1",h2:"标题2",h3:"标题3",h4:"标题4",h5:"标题5",h6:"标题6","list-ul":"无序列表","list-ol":"有序列表",hr:"横线",link:"链接","reference-link":"引用链接",image:"添加图片",code:"行内代码","preformatted-text":"预格式文本 / 代码块(缩进风格)","code-block":"代码块(多语言风格)",table:"添加表格",datetime:"日期时间",emoji:"Emoji表情","html-entities":"HTML实体字符",pagebreak:"插入分页符","goto-line":"跳转到行",watch:"关闭实时预览",unwatch:"开启实时预览",preview:"全窗口预览HTML(按 Shift + ESC还原)",fullscreen:"全屏(按ESC还原)",clear:"清空",search:"搜索",help:"使用帮助",info:"关于"+r.title},buttons:{enter:"确定",cancel:"取消",close:"关闭"},dialog:{link:{title:"添加链接",url:"链接地址",urlTitle:"链接标题",urlEmpty:"错误:请填写链接地址。"},referenceLink:{title:"添加引用链接",name:"引用名称",url:"链接地址",urlId:"链接ID",urlTitle:"链接标题",nameEmpty:"错误:引用链接的名称不能为空。",idEmpty:"错误:请填写引用链接的ID。",urlEmpty:"错误:请填写引用链接的URL地址。"},image:{title:"添加图片",url:"图片地址",link:"图片链接",alt:"图片描述",uploadButton:"本地上传",imageURLEmpty:"错误:图片地址不能为空。",uploadFileEmpty:"错误:上传的图片不能为空。",formatNotAllowed:"错误:只允许上传图片文件,允许上传的图片文件格式有:"},preformattedText:{title:"添加预格式文本或代码块",emptyAlert:"错误:请填写预格式文本或代码的内容。"},codeBlock:{title:"添加代码块",selectLabel:"代码语言:",selectDefaultText:"请选择代码语言",otherLanguage:"其他语言",unselectedLanguageAlert:"错误:请选择代码所属的语言类型。",codeEmptyAlert:"错误:请填写代码内容。"},htmlEntities:{title:"HTML 实体字符"},help:{title:"使用帮助"}}}},r.classNames={tex:r.classPrefix+"tex"},r.dialogZindex=99999,r.$katex=null,r.$marked=null,r.$CodeMirror=null,r.$prettyPrint=null,r.prototype=r.fn={state:{watching:!1,loaded:!1,preview:!1,fullscreen:!1},init:function(t,i){i=i||{},"object"==typeof t&&(i=t);var a=this.classPrefix=r.classPrefix,n=o=e.extend(!0,r.defaults,i);this.settings=n,t="object"==typeof t?n.id:t;var s=this.editor=e("#"+t);this.id=t,this.lang=n.lang;var l=this.classNames={textarea:{html:a+"html-textarea",markdown:a+"markdown-textarea"}};n.pluginPath=""===n.pluginPath?n.path+"../plugins/":n.pluginPath,this.state.watching=!!n.watch,s.hasClass("editormd")||s.addClass("editormd"),s.css({width:"number"==typeof n.width?n.width+"px":n.width,height:"number"==typeof n.height?n.height+"px":n.height}),n.autoHeight&&s.css("height","auto");var c=this.markdownTextarea=s.children("textarea");c.length<1&&(s.append(""),c=this.markdownTextarea=s.children("textarea")),c.addClass(l.textarea.markdown).attr("placeholder",n.placeholder),void 0!==c.attr("name")&&""!==c.attr("name")||c.attr("name",""!==n.name?n.name:t+"-markdown-doc");var h=[n.readOnly?"":'',n.saveHTMLToTextarea?'':"",'
','
','
'].join("\n");return s.append(h).addClass(a+"vertical"),""!==n.theme&&s.addClass(a+"theme-"+n.theme),this.mask=s.children("."+a+"mask"),this.containerMask=s.children("."+a+"container-mask"),""!==n.markdown&&c.val(n.markdown),""!==n.appendMarkdown&&c.val(c.val()+n.appendMarkdown),this.htmlTextarea=s.children("."+l.textarea.html),this.preview=s.children("."+a+"preview"),this.previewContainer=this.preview.children("."+a+"preview-container"),""!==n.previewTheme&&this.preview.addClass(a+"preview-theme-"+n.previewTheme),"function"==typeof define&&define.amd&&("undefined"!=typeof katex&&(r.$katex=katex),n.searchReplace&&!n.readOnly&&(r.loadCSS(n.path+"codemirror/addon/dialog/dialog"),r.loadCSS(n.path+"codemirror/addon/search/matchesonscrollbar"))),"function"==typeof define&&define.amd||!n.autoLoadModules?("undefined"!=typeof CodeMirror&&(r.$CodeMirror=CodeMirror),"undefined"!=typeof marked&&(r.$marked=marked),this.setCodeMirror().setToolbar().loadedDisplay()):this.loadQueues(),this},loadQueues:function(){var e=this,t=o,i=t.path,a=function(){r.isIE8?e.loadedDisplay():t.flowChart||t.sequenceDiagram?r.loadScript(i+"raphael.min",function(){r.loadScript(i+"underscore.min",function(){!t.flowChart&&t.sequenceDiagram?r.loadScript(i+"sequence-diagram.min",function(){e.loadedDisplay()}):t.flowChart&&!t.sequenceDiagram?r.loadScript(i+"flowchart.min",function(){r.loadScript(i+"jquery.flowchart.min",function(){e.loadedDisplay()})}):t.flowChart&&t.sequenceDiagram&&r.loadScript(i+"flowchart.min",function(){r.loadScript(i+"jquery.flowchart.min",function(){r.loadScript(i+"sequence-diagram.min",function(){e.loadedDisplay()})})})})}):e.loadedDisplay()};return t.searchReplace&&!t.readOnly&&(r.loadCSS(i+"codemirror/addon/dialog/dialog"),r.loadCSS(i+"codemirror/addon/search/matchesonscrollbar")),t.codeFold&&r.loadCSS(i+"codemirror/addon/fold/foldgutter"),r.$CodeMirror=CodeMirror,r.loadScript(i+"codemirror/modes.min",function(){r.loadScript(i+"codemirror/addons.min",function(){if(e.setCodeMirror(),"gfm"!==t.mode&&"markdown"!==t.mode)return e.loadedDisplay(),!1;e.setToolbar(),r.loadScript(i+"marked.min",function(){r.$marked=marked,t.previewCodeHighlight?r.loadScript(i+"prettify.min",function(){a()}):a()})})}),this},setTheme:function(e){var t=this.editor,i=o.theme,r=this.classPrefix+"theme-";return t.removeClass(r+i).addClass(r+e),o.theme=e,this},setEditorTheme:function(e){var t=o;return t.editorTheme=e,"default"!==e&&r.loadCSS(t.path+"codemirror/theme/"+t.editorTheme),this.cm.setOption("theme",e),this},setCodeMirrorTheme:function(e){return this.setEditorTheme(e),this},setPreviewTheme:function(e){var t=this.preview,i=o.previewTheme,r=this.classPrefix+"preview-theme-";return t.removeClass(r+i).addClass(r+e),o.previewTheme=e,this},setCodeMirror:function(){var e=o,t=this.editor;"default"!==e.editorTheme&&r.loadCSS(e.path+"codemirror/theme/"+e.editorTheme);var i={mode:e.mode,theme:e.editorTheme,tabSize:e.tabSize,dragDrop:!1,autofocus:e.autoFocus,autoCloseTags:e.autoCloseTags,readOnly:!!e.readOnly&&"nocursor",indentUnit:e.indentUnit,lineNumbers:e.lineNumbers,lineWrapping:e.lineWrapping,extraKeys:{"Ctrl-Q":function(e){e.foldCode(e.getCursor())}},foldGutter:e.codeFold,gutters:["CodeMirror-linenumbers","CodeMirror-foldgutter"],matchBrackets:e.matchBrackets,indentWithTabs:e.indentWithTabs,styleActiveLine:e.styleActiveLine,styleSelectedText:e.styleSelectedText,autoCloseBrackets:e.autoCloseBrackets,showTrailingSpace:e.showTrailingSpace,highlightSelectionMatches:!!e.matchWordHighlight&&{showToken:"onselected"!==e.matchWordHighlight&&/\w/}};return this.codeEditor=this.cm=r.$CodeMirror.fromTextArea(this.markdownTextarea[0],i),this.codeMirror=this.cmElement=t.children(".CodeMirror"),""!==e.value&&this.cm.setValue(e.value),this.codeMirror.css({fontSize:e.fontSize,width:e.watch?"50%":"100%"}),e.autoHeight&&(this.codeMirror.css("height","auto"),this.cm.setOption("viewportMargin",1/0)),e.lineNumbers||this.codeMirror.find(".CodeMirror-gutters").css("border-right","none"),this},getCodeMirrorOption:function(e){return this.cm.getOption(e)},setCodeMirrorOption:function(e,t){return this.cm.setOption(e,t),this},addKeyMap:function(e,t){return this.cm.addKeyMap(e,t),this},removeKeyMap:function(e){return this.cm.removeKeyMap(e),this},gotoLine:function(t){var i=o;if(!i.gotoLine)return this;var r=this.cm,a=(this.editor,r.lineCount()),n=this.preview;if("string"==typeof t&&("last"===t&&(t=a),"first"===t&&(t=1)),"number"!=typeof t)return alert("Error: The line number must be an integer."),this;if((t=parseInt(t)-1)>a)return alert("Error: The line number range 1-"+a),this;r.setCursor({line:t,ch:0});var s=r.getScrollInfo().clientHeight,l=r.charCoords({line:t,ch:0},"local");if(r.scrollTo(null,(l.top+l.bottom-s)/2),i.watch){var c=this.codeMirror.find(".CodeMirror-scroll")[0],h=e(c).height(),d=c.scrollTop,u=d/c.scrollHeight;0===d?n.scrollTop(0):d+h>=c.scrollHeight-16?n.scrollTop(n[0].scrollHeight):n.scrollTop(n[0].scrollHeight*u)}return r.focus(),this},extend:function(){return void 0!==arguments[1]&&("function"==typeof arguments[1]&&(arguments[1]=e.proxy(arguments[1],this)),this[arguments[0]]=arguments[1]),"object"==typeof arguments[0]&&void 0===arguments[0].length&&e.extend(!0,this,arguments[0]),this},set:function(t,i){return void 0!==i&&"function"==typeof i&&(i=e.proxy(i,this)),this[t]=i,this},config:function(t,i){var r=o;return"object"==typeof t&&(r=e.extend(!0,r,t)),"string"==typeof t&&(r[t]=i),o=r,this.recreate(),this},on:function(t,i){var r=o;return void 0!==r["on"+t]&&(r["on"+t]=e.proxy(i,this)),this},off:function(e){var t=o;return void 0!==t["on"+e]&&(t["on"+e]=function(){}),this},showToolbar:function(t){var i=o;return i.readOnly?this:(i.toolbar&&(this.toolbar.length<1||""===this.toolbar.find("."+this.classPrefix+"menu").html())&&this.setToolbar(),i.toolbar=!0,this.toolbar.show(),this.resize(),e.proxy(t||function(){},this)(),this)},hideToolbar:function(t){return o.toolbar=!1,this.toolbar.hide(),this.resize(),e.proxy(t||function(){},this)(),this},setToolbarAutoFixed:function(t){var i=this.state,r=this.editor,a=this.toolbar,n=o;void 0!==t&&(n.toolbarAutoFixed=t);return!i.fullscreen&&!i.preview&&n.toolbar&&n.toolbarAutoFixed&&e(window).bind("scroll",function(){var t=e(window),i=t.scrollTop();if(!n.toolbarAutoFixed)return!1;i-r.offset().top>10&&i
';t.append(n),a=this.toolbar=t.children("."+i+"toolbar")}if(!e.toolbar)return a.hide(),this;a.show();for(var s="function"==typeof e.toolbarIcons?e.toolbarIcons(this):"string"==typeof e.toolbarIcons?r.toolbarModes[e.toolbarIcons]:e.toolbarIcons,l=a.find("."+this.classPrefix+"menu"),c="",h=!1,d=0,u=s.length;d|';else{var p=/h(\d)/.test(f),m=f;"watch"!==f||e.watch||(m="unwatch");var g=e.lang.toolbar[m],w=e.toolbarIconTexts[m],v=e.toolbarIconsClass[m];g=void 0===g?"":g,w=void 0===w?"":w,v=void 0===v?"":v;var k=h?'
  • ':"
  • ";void 0!==e.toolbarCustomIcons[f]&&"function"!=typeof e.toolbarCustomIcons[f]?k+=e.toolbarCustomIcons[f]:(k+='',k+=''+(p?f.toUpperCase():""===v?w:"")+"",k+=""),k+="
  • ",c=h?k+c:c+k}}return l.html(c),l.find('[title="Lowercase"]').attr("title",e.lang.toolbar.lowercase),l.find('[title="ucwords"]').attr("title",e.lang.toolbar.ucwords),this.setToolbarHandler(),this.setToolbarAutoFixed(),this},dialogLockScreen:function(){return e.proxy(r.dialogLockScreen,this)(),this},dialogShowMask:function(t){return e.proxy(r.dialogShowMask,this)(t),this},getToolbarHandles:function(e){var t=this.toolbarHandlers=r.toolbarHandlers;return e&&void 0!==toolbarIconHandlers[e]?t[e]:t},setToolbarHandler:function(){var t=this,i=o;if(!i.toolbar||i.readOnly)return this;var a=this.toolbar,n=this.cm,s=this.classPrefix,l=this.toolbarIcons=a.find("."+s+"menu > li > a"),c=this.getToolbarHandles();return l.bind(r.mouseOrTouch("click","touchend"),function(o){var r=e(this).children(".fa"),a=r.attr("name"),s=n.getCursor(),l=n.getSelection();if(""!==a)return t.activeIcon=r,void 0!==c[a]?e.proxy(c[a],t)(n):void 0!==i.toolbarHandlers[a]&&e.proxy(i.toolbarHandlers[a],t)(n,r,s,l),"link"!==a&&"reference-link"!==a&&"image"!==a&&"code-block"!==a&&"preformatted-text"!==a&&"watch"!==a&&"preview"!==a&&"search"!==a&&"fullscreen"!==a&&"info"!==a&&n.focus(),!1}),this},createDialog:function(t){return e.proxy(r.createDialog,this)(t)},createInfoDialog:function(){var e=this,t=this.editor,i=this.classPrefix,o=['
    ','
    ','

    '+r.title+"v"+r.version+"

    ","

    "+this.lang.description+"

    ",'

    '+r.homePage+'

    ','

    Copyright © 2015 Pandao, The MIT License.

    ',"
    ",'',"
    "].join("\n");t.append(o);var a=this.infoDialog=t.children("."+i+"dialog-info");return a.find("."+i+"dialog-close").bind(r.mouseOrTouch("click","touchend"),function(){e.hideInfoDialog()}),a.css("border",r.isIE8?"1px solid #ddd":"").css("z-index",r.dialogZindex).show(),this.infoDialogPosition(),this},infoDialogPosition:function(){var t=this.infoDialog,i=function(){t.css({top:(e(window).height()-t.height())/2+"px",left:(e(window).width()-t.width())/2+"px"})};return i(),e(window).resize(i),this},showInfoDialog:function(){e("html,body").css("overflow-x","hidden");var t=this.editor,i=o,a=this.infoDialog=t.children("."+this.classPrefix+"dialog-info");return a.length<1&&this.createInfoDialog(),this.lockScreen(!0),this.mask.css({opacity:i.dialogMaskOpacity,backgroundColor:i.dialogMaskBgColor}).show(),a.css("z-index",r.dialogZindex).show(),this.infoDialogPosition(),this},hideInfoDialog:function(){return e("html,body").css("overflow-x",""),this.infoDialog.hide(),this.mask.hide(),this.lockScreen(!1),this},lockScreen:function(e){return r.lockScreen(e),this.resize(),this},recreate:function(){var e=this.editor,t=o;return this.codeMirror.remove(),this.setCodeMirror(),t.readOnly||(e.find(".editormd-dialog").length>0&&e.find(".editormd-dialog").remove(),t.toolbar&&(this.getToolbarHandles(),this.setToolbar())),this.loadedDisplay(!0),this},previewCodeHighlight:function(){var e=o,t=this.previewContainer;return e.previewCodeHighlight&&(t.find("pre").addClass("prettyprint linenums"),"undefined"!=typeof prettyPrint&&prettyPrint()),this},katexRender:function(){return null===t?this:(this.previewContainer.find("."+r.classNames.tex).each(function(){var t=e(this);r.$katex.render(t.text(),t[0]),t.find(".katex").css("font-size","1.0em")}),this)},flowChartAndSequenceDiagramRender:function(){var t=o,a=this.previewContainer;if(r.isIE8)return this;if(t.flowChart){if(null===i)return this;a.find(".flowchart").flowChart()}t.sequenceDiagram&&a.find(".sequence-diagram").sequenceDiagram({theme:"simple"});var n=this.preview,s=this.codeMirror.find(".CodeMirror-scroll"),l=s.height(),c=s.scrollTop(),h=c/s[0].scrollHeight,d=0;n.find(".markdown-toc-list").each(function(){d+=e(this).height()});var u=n.find(".editormd-toc-menu").height();return u=u||0,0===c?n.scrollTop(0):c+l>=s[0].scrollHeight-16?n.scrollTop(n[0].scrollHeight):n.scrollTop((n[0].scrollHeight+d+u)*h),this},registerKeyMaps:function(t){var i=this,a=this.cm,n=o,s=r.toolbarHandlers,l=n.disabledKeyMaps;if(t=t||null){for(var c in t)if(e.inArray(c,l)<0){t[c],a.addKeyMap(t)}}else{for(var h in r.keyMaps){var d=r.keyMaps[h],u="string"==typeof d?e.proxy(s[d],i):e.proxy(d,i);if(e.inArray(h,["F9","F10","F11"])<0&&e.inArray(h,l)<0){var f={};f[h]=u,a.addKeyMap(f)}}e(window).keydown(function(t){if(e.inArray({120:"F9",121:"F10",122:"F11"}[t.keyCode],l)<0)switch(t.keyCode){case 120:return e.proxy(s.watch,i)(),!1;case 121:return e.proxy(s.preview,i)(),!1;case 122:return e.proxy(s.fullscreen,i)(),!1}})}return this},bindScrollEvent:function(){var t=this,i=this.preview,a=o,n=this.codeMirror,s=r.mouseOrTouch;if(!a.syncScrolling)return this;var l=function(){n.find(".CodeMirror-scroll").bind(s("scroll","touchmove"),function(o){var r=e(this).height(),n=e(this).scrollTop(),s=n/e(this)[0].scrollHeight,l=0;i.find(".markdown-toc-list").each(function(){l+=e(this).height()});var c=i.find(".editormd-toc-menu").height();c=c||0,0===n?i.scrollTop(0):n+r>=e(this)[0].scrollHeight-16?i.scrollTop(i[0].scrollHeight):i.scrollTop((i[0].scrollHeight+l+c)*s),e.proxy(a.onscroll,t)(o)})},c=function(){n.find(".CodeMirror-scroll").unbind(s("scroll","touchmove"))},h=function(){i.bind(s("scroll","touchmove"),function(i){var o=e(this).height(),r=e(this).scrollTop(),s=r/e(this)[0].scrollHeight,l=n.find(".CodeMirror-scroll");0===r?l.scrollTop(0):r+o>=e(this)[0].scrollHeight?l.scrollTop(l[0].scrollHeight):l.scrollTop(l[0].scrollHeight*s),e.proxy(a.onpreviewscroll,t)(i)})},d=function(){i.unbind(s("scroll","touchmove"))};return n.bind({mouseover:l,mouseout:c,touchstart:l,touchend:c}),"single"===a.syncScrolling?this:(i.bind({mouseover:h,mouseout:d,touchstart:h,touchend:d}),this)},bindChangeEvent:function(){var e=this,i=this.cm,r=o;return r.syncScrolling?(i.on("change",function(i,o){r.watch&&e.previewContainer.css("padding",r.autoHeight?"20px 20px 50px 40px":"20px"),t=setTimeout(function(){clearTimeout(t),e.save(),t=null},r.delay)}),this):this},loadedDisplay:function(t){t=t||!1;var i=this,r=this.editor,a=this.preview,n=o;return this.containerMask.hide(),this.save(),n.watch&&a.show(),r.data("oldWidth",r.width()).data("oldHeight",r.height()),this.resize(),this.registerKeyMaps(),e(window).resize(function(){i.resize()}),this.bindScrollEvent().bindChangeEvent(),t||(n.imageUploadURL&&initEditormdPasteUpload(this,n.imageUploadURL),e.proxy(n.onload,this)()),this.state.loaded=!0,this},width:function(e){return this.editor.css("width","number"==typeof e?e+"px":e),this.resize(),this},height:function(e){return this.editor.css("height","number"==typeof e?e+"px":e),this.resize(),this},resize:function(t,i){t=t||null,i=i||null;var r=this.state,a=this.editor,n=this.preview,s=this.toolbar,l=o,c=this.codeMirror;if(t&&a.css("width","number"==typeof t?t+"px":t),!l.autoHeight||r.fullscreen||r.preview?(i&&a.css("height","number"==typeof i?i+"px":i),r.fullscreen&&a.height(e(window).height()),l.toolbar&&!l.readOnly?c.css("margin-top",s.height()+1).height(a.height()-s.height()):c.css("margin-top",0).height(a.height())):(a.css("height","auto"),c.css("height","auto")),l.watch)if(c.width(a.width()/2),n.width(r.preview?a.width():a.width()/2),this.previewContainer.css("padding",l.autoHeight?"20px 20px 50px 40px":"20px"),l.toolbar&&!l.readOnly?n.css("top",s.height()+1):n.css("top",0),!l.autoHeight||r.fullscreen||r.preview){var h=l.toolbar&&!l.readOnly?a.height()-s.height():a.height();n.height(h)}else n.height("");else c.width(a.width()),n.hide();return r.loaded&&e.proxy(l.onresize,this)(),this},save:function(){if(null===t)return this;var a=this,n=this.state,s=o,l=this.cm,c=l.getValue(),h=this.previewContainer;if("gfm"!==s.mode&&"markdown"!==s.mode)return this.markdownTextarea.val(c),this;var d=r.$marked,u=this.markdownToC=[],f=this.markedRendererOptions={toc:s.toc,tocm:s.tocm,tocStartLevel:s.tocStartLevel,pageBreak:s.pageBreak,taskList:s.taskList,emoji:s.emoji,tex:s.tex,atLink:s.atLink,emailLink:s.emailLink,flowChart:s.flowChart,sequenceDiagram:s.sequenceDiagram,previewCodeHighlight:s.previewCodeHighlight},p=this.markedOptions={renderer:r.markedRenderer(u,f),gfm:!0,tables:!0,breaks:!0,pedantic:!1,sanitize:!s.htmlDecode,smartLists:!0,smartypants:!0};d.setOptions(p);var m=r.$marked(c,p);if(m=r.filterHTMLTags(m,s.htmlDecode),this.markdownTextarea.text(c),l.save(),s.saveHTMLToTextarea&&this.htmlTextarea.text(m),s.watch||!s.watch&&n.preview){if(h.html(m),this.previewCodeHighlight(),s.toc){var g=""===s.tocContainer?h:e(s.tocContainer),w=g.find("."+this.classPrefix+"toc-menu");g.attr("previewContainer",""===s.tocContainer?"true":"false"),""!==s.tocContainer&&w.length>0&&w.remove(),r.markdownToCRenderer(u,g,s.tocDropdown,s.tocStartLevel),(s.tocDropdown||g.find("."+this.classPrefix+"toc-menu").length>0)&&r.tocDropdownMenu(g,""!==s.tocTitle?s.tocTitle:this.lang.tocTitle),""!==s.tocContainer&&h.find(".markdown-toc").css("border","none")}s.tex&&(!r.kaTeXLoaded&&s.autoLoadModules?r.loadKaTeX(function(){r.$katex=katex,r.kaTeXLoaded=!0,a.katexRender()}):(r.$katex=katex,this.katexRender())),(s.flowChart||s.sequenceDiagram)&&(i=setTimeout(function(){clearTimeout(i),a.flowChartAndSequenceDiagramRender(),i=null},10)),n.loaded&&e.proxy(s.onchange,this)()}return this},focus:function(){return this.cm.focus(),this},setCursor:function(e){return this.cm.setCursor(e),this},getCursor:function(){return this.cm.getCursor()},setSelection:function(e,t){return this.cm.setSelection(e,t),this},getSelection:function(){return this.cm.getSelection()},setSelections:function(e){return this.cm.setSelections(e),this},getSelections:function(){return this.cm.getSelections()},replaceSelection:function(e){return this.cm.replaceSelection(e),this},insertValue:function(e){return this.replaceSelection(e),this},appendMarkdown:function(e){var t=this.cm;return t.setValue(t.getValue()+e),this},setMarkdown:function(e){return this.cm.setValue(e||o.markdown),this},getMarkdown:function(){return this.cm.getValue()},getValue:function(){return this.cm.getValue()},setValue:function(e){return this.cm.setValue(e),this},clear:function(){return this.cm.setValue(""),this},getHTML:function(){return o.saveHTMLToTextarea?this.htmlTextarea.val():(alert("Error: settings.saveHTMLToTextarea == false"),!1)},getTextareaSavedHTML:function(){return this.getHTML()},getPreviewedHTML:function(){return o.watch?this.previewContainer.html():(alert("Error: settings.watch == false"),!1)},watch:function(i){var r=o;if(e.inArray(r.mode,["gfm","markdown"])<0)return this;if(this.state.watching=r.watch=!0,this.preview.show(),this.toolbar){var a=r.toolbarIconsClass.watch,n=r.toolbarIconsClass.unwatch,s=this.toolbar.find(".fa[name=watch]");s.parent().attr("title",r.lang.toolbar.watch),s.removeClass(n).addClass(a)}return this.codeMirror.css("border-right","1px solid #ddd").width(this.editor.width()/2),t=0,this.save().resize(),r.onwatch||(r.onwatch=i||function(){}),e.proxy(r.onwatch,this)(),this},unwatch:function(t){var i=o;if(this.state.watching=i.watch=!1,this.preview.hide(),this.toolbar){var r=i.toolbarIconsClass.watch,a=i.toolbarIconsClass.unwatch,n=this.toolbar.find(".fa[name=watch]");n.parent().attr("title",i.lang.toolbar.unwatch),n.removeClass(r).addClass(a)}return this.codeMirror.css("border-right","none").width(this.editor.width()),this.resize(),i.onunwatch||(i.onunwatch=t||function(){}),e.proxy(i.onunwatch,this)(),this},show:function(t){t=t||function(){};var i=this;return this.editor.show(0,function(){e.proxy(t,i)()}),this},hide:function(t){t=t||function(){};var i=this;return this.editor.hide(0,function(){e.proxy(t,i)()}),this},previewing:function(){var t=this,i=this.editor,a=this.preview,n=this.toolbar,s=o,l=this.codeMirror,c=this.previewContainer;if(e.inArray(s.mode,["gfm","markdown"])<0)return this;s.toolbar&&n&&(n.toggle(),n.find(".fa[name=preview]").toggleClass("active")),l.toggle();var h=function(e){e.shiftKey&&27===e.keyCode&&t.previewed()};"none"===l.css("display")?(this.state.preview=!0,this.state.fullscreen&&a.css("background","#fff"),i.find("."+this.classPrefix+"preview-close-btn").show().bind(r.mouseOrTouch("click","touchend"),function(){t.previewed()}),s.watch?c.css("padding",""):this.save(),c.addClass(this.classPrefix+"preview-active"),a.show().css({position:"",top:0,width:i.width(),height:s.autoHeight&&!this.state.fullscreen?"auto":i.height()}),this.state.loaded&&e.proxy(s.onpreviewing,this)(),e(window).bind("keyup",h)):(e(window).unbind("keyup",h),this.previewed())},previewed:function(){var t=this.editor,i=this.preview,a=this.toolbar,n=o,s=this.previewContainer,l=t.find("."+this.classPrefix+"preview-close-btn");return this.state.preview=!1,this.codeMirror.show(),n.toolbar&&a.show(),i[n.watch?"show":"hide"](),l.hide().unbind(r.mouseOrTouch("click","touchend")),s.removeClass(this.classPrefix+"preview-active"),n.watch&&s.css("padding","20px"),i.css({background:null,position:"absolute",width:t.width()/2,height:n.autoHeight&&!this.state.fullscreen?"auto":t.height()-a.height(),top:n.toolbar?a.height():0}),this.state.loaded&&e.proxy(n.onpreviewed,this)(),this},fullscreen:function(){var t=this,i=this.state,r=this.editor,a=(this.preview,this.toolbar),n=o,s=this.classPrefix+"fullscreen";a&&a.find(".fa[name=fullscreen]").parent().toggleClass("active");var l=function(e){e.shiftKey||27!==e.keyCode||i.fullscreen&&t.fullscreenExit()};return r.hasClass(s)?(e(window).unbind("keyup",l),this.fullscreenExit()):(i.fullscreen=!0,e("html,body").css("overflow","hidden"),r.css({width:e(window).width(),height:e(window).height()}).addClass(s),this.resize(),e.proxy(n.onfullscreen,this)(),e(window).bind("keyup",l)),this},fullscreenExit:function(){var t=this.editor,i=o,r=this.toolbar,a=this.classPrefix+"fullscreen";return this.state.fullscreen=!1,r&&r.find(".fa[name=fullscreen]").parent().removeClass("active"),e("html,body").css("overflow",""),t.css({width:t.data("oldWidth"),height:t.data("oldHeight")}).removeClass(a),this.resize(),e.proxy(i.onfullscreenExit,this)(),this},executePlugin:function(t,i){var a=this,n=this.cm;return i=o.pluginPath+i,"function"==typeof define?void 0===this[t]?(alert("Error: "+t+" plugin is not found, you are not load this plugin."),this):(this[t](n),this):(e.inArray(i,r.loadFiles.plugin)<0?r.loadPlugin(i,function(){r.loadPlugins[t]=a[t],a[t](n)}):e.proxy(r.loadPlugins[t],this)(n),this)},search:function(e){var t=o;return t.searchReplace?(t.readOnly||this.cm.execCommand(e||"find"),this):(alert("Error: settings.searchReplace == false"),this)},searchReplace:function(){return this.search("replace"),this},searchReplaceAll:function(){return this.search("replaceAll"),this}},r.fn.init.prototype=r.fn,r.dialogLockScreen=function(){(o||{dialogLockScreen:!0}).dialogLockScreen&&(e("html,body").css("overflow","hidden"),this.resize())},r.dialogShowMask=function(t){var i=this.editor,r=o||{dialogShowMask:!0};t.css({top:(e(window).height()-t.height())/2+"px",left:(e(window).width()-t.width())/2+"px"}),r.dialogShowMask&&i.children("."+this.classPrefix+"mask").css("z-index",parseInt(t.css("z-index"))-1).show()},r.toolbarHandlers={undo:function(){this.cm.undo()},redo:function(){this.cm.redo()},bold:function(){var e=this.cm,t=e.getCursor(),i=e.getSelection();e.replaceSelection("**"+i+"**"),""===i&&e.setCursor(t.line,t.ch+2)},del:function(){var e=this.cm,t=e.getCursor(),i=e.getSelection();e.replaceSelection("~~"+i+"~~"),""===i&&e.setCursor(t.line,t.ch+2)},italic:function(){var e=this.cm,t=e.getCursor(),i=e.getSelection();e.replaceSelection("*"+i+"*"),""===i&&e.setCursor(t.line,t.ch+1)},quote:function(){var e=this.cm,t=e.getCursor(),i=e.getSelection();0!==t.ch?(e.setCursor(t.line,0),e.replaceSelection("> "+i),e.setCursor(t.line,t.ch+2)):e.replaceSelection("> "+i)},ucfirst:function(){var e=this.cm,t=e.getSelection(),i=e.listSelections();e.replaceSelection(r.firstUpperCase(t)),e.setSelections(i)},ucwords:function(){var e=this.cm,t=e.getSelection(),i=e.listSelections();e.replaceSelection(r.wordsFirstUpperCase(t)),e.setSelections(i)},uppercase:function(){var e=this.cm,t=e.getSelection(),i=e.listSelections();e.replaceSelection(t.toUpperCase()),e.setSelections(i)},lowercase:function(){var e=this.cm,t=(e.getCursor(),e.getSelection()),i=e.listSelections();e.replaceSelection(t.toLowerCase()),e.setSelections(i)},h1:function(){var e=this.cm,t=e.getCursor(),i=e.getSelection();0!==t.ch?(e.setCursor(t.line,0),e.replaceSelection("# "+i),e.setCursor(t.line,t.ch+2)):e.replaceSelection("# "+i)},h2:function(){var e=this.cm,t=e.getCursor(),i=e.getSelection();0!==t.ch?(e.setCursor(t.line,0),e.replaceSelection("## "+i),e.setCursor(t.line,t.ch+3)):e.replaceSelection("## "+i)},h3:function(){var e=this.cm,t=e.getCursor(),i=e.getSelection();0!==t.ch?(e.setCursor(t.line,0),e.replaceSelection("### "+i),e.setCursor(t.line,t.ch+4)):e.replaceSelection("### "+i)},h4:function(){var e=this.cm,t=e.getCursor(),i=e.getSelection();0!==t.ch?(e.setCursor(t.line,0),e.replaceSelection("#### "+i),e.setCursor(t.line,t.ch+5)):e.replaceSelection("#### "+i)},h5:function(){var e=this.cm,t=e.getCursor(),i=e.getSelection();0!==t.ch?(e.setCursor(t.line,0),e.replaceSelection("##### "+i),e.setCursor(t.line,t.ch+6)):e.replaceSelection("##### "+i)},h6:function(){var e=this.cm,t=e.getCursor(),i=e.getSelection();0!==t.ch?(e.setCursor(t.line,0),e.replaceSelection("###### "+i),e.setCursor(t.line,t.ch+7)):e.replaceSelection("###### "+i)},"list-ul":function(){var e=this.cm,t=(e.getCursor(),e.getSelection());if(""===t)e.replaceSelection("- "+t);else{for(var i=t.split("\n"),o=0,r=i.length;o'}else{var l=e.match(m),c=e.match(f);if(l)for(var h=0,d=l.length;h'}else{if(!c){var g="+1"===o?"plus1":o;return g="moon"===(g="black_large_square"===g?"black_square":g)?"waxing_gibbous_moon":g,':'+o+':'}for(var w=0,v=c.length;w'}}}});return e},s.atLink=function(t){return c.test(t)?(o.atLink&&(t=(t=t.replace(d,function(e,t,i,o){return e.replace(/@/g,"_#_@_#_")})).replace(c,function(e,t){return''+e+""}).replace(/_#_@_#_/g,"@")),o.emailLink&&(t=t.replace(u,function(t,i,o,r,a){return!i&&e.inArray(a,"jpg|jpeg|png|gif|webp|ico|icon|pdf".split("|"))<0?''+t+"":t})),t):t},s.link=function(e,t,i){if(this.options.sanitize){try{var o=decodeURIComponent(unescape(e)).replace(/[^\w:]/g,"").toLowerCase()}catch(e){return""}if(0===o.indexOf("javascript:"))return""}var r=''+i.replace(/@/g,"@")+""):(t&&(r+=' title="'+t+'"'),r+=">"+i+"")},s.heading=function(e,i,o){var r=e,n=/\s*\]*)\>(.*)\<\/a\>\s*/;if(n.test(e)){for(var s=[],l=0,c=(e=e.split(/\]+)\>([^\>]*)\<\/a\>/)).length;l';return u+='',u+='',u+=n?this.atLink(this.emoji(r)):this.atLink(this.emoji(e)),u+=""},s.pageBreak=function(e){return g.test(e)&&o.pageBreak&&(e='
    '),e},s.em=function(e, capInput){return e&&-1!=e.indexOf("$$") || (capInput && capInput.indexOf('$$') != -1) ?"_"+e+"_":""+e+""},s.paragraph=function(e){var t=/\$\$(.*)\$\$/g.test(e),i=/^\$\$(.*)\$\$$/.test(e),a=i?' class="'+r.classNames.tex+'"':"",n=o.tocm?/^(\[TOC\]|\[TOCM\])$/.test(e):/^\[TOC\]$/.test(e),s=/^\[TOCM\]$/.test(e),l='
    '+(e=!i&&t?e.replace(/(\$\$([^\$]*)\$\$)+/g,function(e,t){return''+t.replace(/\$/g,"")+""}):i?e.replace(/\$/g,""):e)+"
    ";return n?s?'
    '+l+"

    ":l:g.test(e)?this.pageBreak(e):""+this.atLink(this.emoji(e))+"

    \n"},s.code=function(e,t,i){return"seq"===t||"sequence"===t?'
    '+e+"
    ":"flow"===t?'
    '+e+"
    ":"math"===t||"latex"===t||"katex"===t?'

    '+e+"

    ":n.Renderer.prototype.code.apply(this,arguments)},s.tablecell=function(e,t){var i=t.header?"th":"td";return(t.align?"<"+i+' style="text-align:'+t.align+'">':"<"+i+">")+this.atLink(this.emoji(e))+"\n"},s.listitem=function(e){return o.taskList&&/^\s*\[[x\s]\]\s*/.test(e)?(e=e.replace(/^\s*\[\s\]\s*/,' ').replace(/^\s*\[x\]\s*/,' '),'
  • '+this.atLink(this.emoji(e))+"
  • "):"
  • "+this.atLink(this.emoji(e))+"
  • "},s},r.markdownToCRenderer=function(e,t,i,o){var r="",a=0,n=this.classPrefix;o=o||1;for(var s=0,l=e.length;sa?"":h"):"",r+='
  • '+c+"
      ",a=h)}var d=t.find(".markdown-toc");if(d.length<1&&"false"===t.attr("previewContainer")){var u='
      ';u=i?'
      '+u+"
      ":u,t.html(u),d=t.find(".markdown-toc")}return i&&d.wrap('

      '),d.html('
        ').children(".markdown-toc-list").html(r.replace(/\r?\n?\\<\/ul\>/g,"")),d},r.tocDropdownMenu=function(t,i){i=i||"Table of Contents";var o=400,r=t.find("."+this.classPrefix+"toc-menu");return r.each(function(){var t=e(this),r=t.children(".markdown-toc"),a='',n=''+a+i+"",s=r.children("ul"),l=s.find("li");r.append(n),l.first().before("
      • "+i+" "+a+"

      • "),t.mouseover(function(){s.show(),l.each(function(){var t=e(this),i=t.children("ul");if(""===i.html()&&i.remove(),i.length>0&&""!==i.html()){var r=t.children("a").first();r.children(".fa").length<1&&r.append(e(a).css({float:"right",paddingTop:"4px"}))}t.mouseover(function(){i.css("z-index",o).show(),o+=1}).mouseleave(function(){i.hide()})})}).mouseleave(function(){s.hide()})}),r},r.filterHTMLTags=function(t,i){if("string"!=typeof t&&(t=new String(t)),"string"!=typeof i)return t;for(var o=i.split("|"),r=o[0].split(","),a=o[1],n=0,s=r.length;n]*)>([^>]*)","igm"),"")}if(void 0!==a){var c=/\<(\w+)\s*([^\>]*)\>([^\>]*)\<\/(\w+)\>/gi;t="*"===a?t.replace(c,function(e,t,i,o,r){return"<"+t+">"+o+""}):"on*"===a?t.replace(c,function(t,i,o,r,a){var n=e("<"+i+">"+r+""),s=e(t)[0].attributes,l={};e.each(s,function(e,t){'"'!==t.nodeName&&(l[t.nodeName]=t.nodeValue)}),e.each(l,function(e){0===e.indexOf("on")&&delete l[e]}),n.attr(l);var c=void 0!==n[1]?e(n[1]).text():"";return n[0].outerHTML+c}):t.replace(c,function(t,i,o,r){var n=a.split(","),s=e(t);return s.html(r),e.each(n,function(e){s.attr(n[e],null)}),s[0].outerHTML})}return t},r.markdownToHTML=function(t,i){r.$marked=marked;var o=e("#"+t),a=o.settings=e.extend(!0,{gfm:!0,toc:!0,tocm:!1,tocStartLevel:1,tocTitle:"目录",tocDropdown:!1,tocContainer:"",markdown:"",markdownSourceCode:!1,htmlDecode:!1,autoLoadKaTeX:!0,pageBreak:!0,atLink:!0,emailLink:!0,tex:!1,taskList:!1,emoji:!1,flowChart:!1,sequenceDiagram:!1,previewCodeHighlight:!0},i||{}),n=o.find("textarea");n.length<1&&(o.append(""),n=o.find("textarea"));var s=""===a.markdown?n.val():a.markdown,l=[],c={toc:a.toc,tocm:a.tocm,tocStartLevel:a.tocStartLevel,taskList:a.taskList,emoji:a.emoji,tex:a.tex,pageBreak:a.pageBreak,atLink:a.atLink,emailLink:a.emailLink,flowChart:a.flowChart,sequenceDiagram:a.sequenceDiagram,previewCodeHighlight:a.previewCodeHighlight},h={renderer:r.markedRenderer(l,c),gfm:a.gfm,tables:!0,breaks:!0,pedantic:!1,sanitize:!a.htmlDecode,smartLists:!0,smartypants:!0};s=new String(s);var d=marked(s,h);d=r.filterHTMLTags(d,a.htmlDecode),a.markdownSourceCode?n.text(s):n.remove(),o.addClass("markdown-body "+this.classPrefix+"html-preview").append(d);var u=""!==a.tocContainer?e(a.tocContainer):o;if(""!==a.tocContainer&&u.attr("previewContainer",!1),a.toc&&(o.tocContainer=this.markdownToCRenderer(l,u,a.tocDropdown,a.tocStartLevel),(a.tocDropdown||o.find("."+this.classPrefix+"toc-menu").length>0)&&this.tocDropdownMenu(o,a.tocTitle),""!==a.tocContainer&&o.find(".editormd-toc-menu, .editormd-markdown-toc").remove()),a.previewCodeHighlight&&(o.find("pre").addClass("prettyprint linenums"),prettyPrint()),r.isIE8||(a.flowChart&&o.find(".flowchart").flowChart(),a.sequenceDiagram&&o.find(".sequence-diagram").sequenceDiagram({theme:"simple"})),a.tex){var f=function(){o.find("."+r.classNames.tex).each(function(){var t=e(this);katex.render(t.text(),t[0]),t.find(".katex").css("font-size","1.0em")})};!a.autoLoadKaTeX||r.$katex||r.kaTeXLoaded?f():this.loadKaTeX(function(){r.$katex=katex,r.kaTeXLoaded=!0,f()})}return o.getMarkdown=function(){return n.val()},o},r.themes=["default","dark"],r.previewThemes=["default","dark"],r.editorThemes=["default","3024-day","3024-night","ambiance","ambiance-mobile","base16-dark","base16-light","blackboard","cobalt","eclipse","elegant","erlang-dark","lesser-dark","mbo","mdn-like","midnight","monokai","neat","neo","night","paraiso-dark","paraiso-light","pastel-on-dark","rubyblue","solarized","the-matrix","tomorrow-night-eighties","twilight","vibrant-ink","xq-dark","xq-light"],r.loadPlugins={},r.loadFiles={js:[],css:[],plugin:[]},r.loadPlugin=function(e,t,i){t=t||function(){},this.loadScript(e,function(){r.loadFiles.plugin.push(e),t()},i)},r.loadCSS=function(e,t,i){i=i||"head",t=t||function(){};var o=document.createElement("link");o.type="text/css",o.rel="stylesheet",o.onload=o.onreadystatechange=function(){r.loadFiles.css.push(e),t()},o.href=e+".css","head"===i?document.getElementsByTagName("head")[0].appendChild(o):document.body.appendChild(o)},r.isIE="Microsoft Internet Explorer"==navigator.appName,r.isIE8=r.isIE&&"8."==navigator.appVersion.match(/8./i),r.loadScript=function(e,t,i){i=i||"head",t=t||function(){};var o=null;(o=document.createElement("script")).id=e.replace(/[\./]+/g,"-"),o.type="text/javascript",o.src=e+".js",r.isIE8?o.onreadystatechange=function(){o.readyState&&("loaded"!==o.readyState&&"complete"!==o.readyState||(o.onreadystatechange=null,r.loadFiles.js.push(e),t()))}:o.onload=function(){r.loadFiles.js.push(e),t()},"head"===i?document.getElementsByTagName("head")[0].appendChild(o):document.body.appendChild(o)},r.katexURL={css:"/katex/katex.min",js:"/katex/katex.min"},r.kaTeXLoaded=!1,r.loadKaTeX=function(e){r.loadCSS(r.katexURL.css,function(){r.loadScript(r.katexURL.js,e||function(){})})},r.lockScreen=function(t){e("html,body").css("overflow",t?"hidden":"")},r.createDialog=function(t){t=e.extend(!0,{name:"",width:420,height:240,title:"",drag:!0,closed:!0,content:"",mask:!0,maskStyle:{backgroundColor:"#fff",opacity:.1},lockScreen:!0,footer:!0,buttons:!1},t);var i=this,o=this.editor,a=r.classPrefix,n=(new Date).getTime(),s=""===t.name?a+"dialog-"+n:t.name,l=r.mouseOrTouch,c='
        ';""!==t.title&&(c+='
        ",c+=''+t.title+"",c+="
        "),t.closed&&(c+=''),c+='
        '+t.content,(t.footer||"string"==typeof t.footer)&&(c+='"),c+="
        ",c+='
        ',c+='
        ',c+="
        ",o.append(c);var h=o.find("."+s);h.lockScreen=function(o){return t.lockScreen&&(e("html,body").css("overflow",o?"hidden":""),i.resize()),h},h.showMask=function(){return t.mask&&o.find("."+a+"mask").css(t.maskStyle).css("z-index",r.dialogZindex-1).show(),h},h.hideMask=function(){return t.mask&&o.find("."+a+"mask").hide(),h},h.loading=function(e){return h.find("."+a+"dialog-mask")[e?"show":"hide"](),h},h.lockScreen(!0).showMask(),h.show().css({zIndex:r.dialogZindex,border:r.isIE8?"1px solid #ddd":"",width:"number"==typeof t.width?t.width+"px":t.width,height:"number"==typeof t.height?t.height+"px":t.height});var d=function(){h.css({top:(e(window).height()-h.height())/2+"px",left:(e(window).width()-h.width())/2+"px"})};if(d(),e(window).resize(d),h.children("."+a+"dialog-close").bind(l("click","touchend"),function(){h.hide().lockScreen(!1).hideMask()}),"object"==typeof t.buttons){var u=h.footer=h.find("."+a+"dialog-footer");for(var f in t.buttons){var p=t.buttons[f],m=a+f+"-btn";u.append('"),p[1]=e.proxy(p[1],h),u.children("."+m).bind(l("click","touchend"),p[1])}}if(""!==t.title&&t.drag){var g,w,v=h.children("."+a+"dialog-header");t.mask||v.bind(l("click","touchend"),function(){r.dialogZindex+=2,h.css("z-index",r.dialogZindex)}),v.mousedown(function(e){e=e||window.event,g=e.clientX-parseInt(h[0].style.left),w=e.clientY-parseInt(h[0].style.top),document.onmousemove=x});var k=function(e){e.removeClass(a+"user-unselect").off("selectstart")},b=function(e){e.addClass(a+"user-unselect").on("selectstart",function(e){return!1})},x=function(t){t=t||window.event;var i,o,r=parseInt(h[0].style.left),a=parseInt(h[0].style.top);r>=0?r+h.width()<=e(window).width()?i=t.clientX-g:(i=e(window).width()-h.width(),document.onmousemove=null):(i=0,document.onmousemove=null),a>=0?o=t.clientY-w:(o=0,document.onmousemove=null),document.onselectstart=function(){return!1},b(e("body")),b(h),h[0].style.left=i+"px",h[0].style.top=o+"px"};document.onmouseup=function(){k(e("body")),k(h),document.onselectstart=null,document.onmousemove=null},v.touchDraggable=function(){var t=null;this.bind("touchstart",function(i){var o=i.originalEvent,r=e(this).parent().position();t={x:o.changedTouches[0].pageX-r.left,y:o.changedTouches[0].pageY-r.top}}).bind("touchmove",function(i){i.preventDefault();var o=i.originalEvent;e(this).parent().css({top:o.changedTouches[0].pageY-t.y,left:o.changedTouches[0].pageX-t.x})})},v.touchDraggable()}return r.dialogZindex+=2,e("body").removeAttr("style"),h},r.mouseOrTouch=function(e,t){t=t||"touchend";var i=e=e||"click";try{document.createEvent("TouchEvent"),i=t}catch(e){}return i},r.dateFormat=function(e){e=e||"";var t=function(e){return e<10?"0"+e:e},i=new Date,o=i.getFullYear(),r=o.toString().slice(2,4),a=t(i.getMonth()+1),n=t(i.getDate()),s=i.getDay(),l=t(i.getHours()),c=t(i.getMinutes()),h=t(i.getSeconds()),d=t(i.getMilliseconds()),u="",f=r+"-"+a+"-"+n,p=o+"-"+a+"-"+n,m=l+":"+c+":"+h;switch(e){case"UNIX Time":u=i.getTime();break;case"UTC":u=i.toUTCString();break;case"yy":u=r;break;case"year":case"yyyy":u=o;break;case"month":case"mm":u=a;break;case"cn-week-day":case"cn-wd":u="星期"+["日","一","二","三","四","五","六"][s];break;case"week-day":case"wd":u=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][s];break;case"day":case"dd":u=n;break;case"hour":case"hh":u=l;break;case"min":case"ii":u=c;break;case"second":case"ss":u=h;break;case"ms":u=d;break;case"yy-mm-dd":u=f;break;case"yyyy-mm-dd":u=p;break;case"yyyy-mm-dd h:i:s ms":case"full + ms":u=p+" "+m+" "+d;break;case"full":case"yyyy-mm-dd h:i:s":default:u=p+" "+m}return u},r}}),window._whenPasterDoUpload=function(e,t,i){var o,r,a,n=e.clipboardData,s=0;if(n){if(!(o=n.items))return;for(r=o[0],a=n.types||[];sa',ucwords:'Aa'},toolbarIconsClass:{undo:"fa-undo",redo:"fa-repeat",bold:"fa-bold",del:"fa-strikethrough",italic:"fa-italic",quote:"fa-quote-left",uppercase:"fa-font",h1:r.classPrefix+"bold",h2:r.classPrefix+"bold",h3:r.classPrefix+"bold",h4:r.classPrefix+"bold",h5:r.classPrefix+"bold",h6:r.classPrefix+"bold","list-ul":"fa-list-ul","list-ol":"fa-list-ol",hr:"fa-minus",link:"fa-link","reference-link":"fa-anchor",image:"fa-picture-o",code:"fa-code","preformatted-text":"fa-file-code-o","code-block":"fa-file-code-o",table:"fa-table",datetime:"fa-clock-o",emoji:"fa-smile-o","html-entities":"fa-copyright",pagebreak:"fa-newspaper-o","goto-line":"fa-terminal",watch:"fa-eye-slash",unwatch:"fa-eye",preview:"fa-desktop",search:"fa-search",fullscreen:"fa-arrows-alt",clear:"fa-eraser",help:"fa-question-circle",info:"fa-info-circle"},toolbarIconTexts:{},lang:{name:"zh-cn",description:"开源在线Markdown编辑器
        Open source online Markdown editor.",tocTitle:"目录",toolbar:{undo:"撤销(Ctrl+Z)",redo:"重做(Ctrl+Y)",bold:"粗体",del:"删除线",italic:"斜体",quote:"引用",ucwords:"将每个单词首字母转成大写",uppercase:"将所选转换成大写",lowercase:"将所选转换成小写",h1:"标题1",h2:"标题2",h3:"标题3",h4:"标题4",h5:"标题5",h6:"标题6","list-ul":"无序列表","list-ol":"有序列表",hr:"横线",link:"链接","reference-link":"引用链接",image:"添加图片",code:"行内代码","preformatted-text":"预格式文本 / 代码块(缩进风格)","code-block":"代码块(多语言风格)",table:"添加表格",datetime:"日期时间",emoji:"Emoji表情","html-entities":"HTML实体字符",pagebreak:"插入分页符","goto-line":"跳转到行",watch:"关闭实时预览",unwatch:"开启实时预览",preview:"全窗口预览HTML(按 Shift + ESC还原)",fullscreen:"全屏(按ESC还原)",clear:"清空",search:"搜索",help:"使用帮助",info:"关于"+r.title},buttons:{enter:"确定",cancel:"取消",close:"关闭"},dialog:{link:{title:"添加链接",url:"链接地址",urlTitle:"链接标题",urlEmpty:"错误:请填写链接地址。"},referenceLink:{title:"添加引用链接",name:"引用名称",url:"链接地址",urlId:"链接ID",urlTitle:"链接标题",nameEmpty:"错误:引用链接的名称不能为空。",idEmpty:"错误:请填写引用链接的ID。",urlEmpty:"错误:请填写引用链接的URL地址。"},image:{title:"添加图片",url:"图片地址",link:"图片链接",alt:"图片描述",uploadButton:"本地上传",imageURLEmpty:"错误:图片地址不能为空。",uploadFileEmpty:"错误:上传的图片不能为空。",formatNotAllowed:"错误:只允许上传图片文件,允许上传的图片文件格式有:"},preformattedText:{title:"添加预格式文本或代码块",emptyAlert:"错误:请填写预格式文本或代码的内容。"},codeBlock:{title:"添加代码块",selectLabel:"代码语言:",selectDefaultText:"请选择代码语言",otherLanguage:"其他语言",unselectedLanguageAlert:"错误:请选择代码所属的语言类型。",codeEmptyAlert:"错误:请填写代码内容。"},htmlEntities:{title:"HTML 实体字符"},help:{title:"使用帮助"}}}},r.classNames={tex:r.classPrefix+"tex"},r.dialogZindex=99999,r.$katex=null,r.$marked=null,r.$CodeMirror=null,r.$prettyPrint=null,r.prototype=r.fn={state:{watching:!1,loaded:!1,preview:!1,fullscreen:!1},init:function(t,i){i=i||{},"object"==typeof t&&(i=t);var a=this.classPrefix=r.classPrefix,n=o=e.extend(!0,r.defaults,i);this.settings=n,t="object"==typeof t?n.id:t;var s=this.editor=e("#"+t);this.id=t,this.lang=n.lang;var l=this.classNames={textarea:{html:a+"html-textarea",markdown:a+"markdown-textarea"}};n.pluginPath=""===n.pluginPath?n.path+"../plugins/":n.pluginPath,this.state.watching=!!n.watch,s.hasClass("editormd")||s.addClass("editormd"),s.css({width:"number"==typeof n.width?n.width+"px":n.width,height:"number"==typeof n.height?n.height+"px":n.height}),n.autoHeight&&s.css("height","auto");var c=this.markdownTextarea=s.children("textarea");c.length<1&&(s.append(""),c=this.markdownTextarea=s.children("textarea")),c.addClass(l.textarea.markdown).attr("placeholder",n.placeholder),void 0!==c.attr("name")&&""!==c.attr("name")||c.attr("name",""!==n.name?n.name:t+"-markdown-doc");var h=[n.readOnly?"":'',n.saveHTMLToTextarea?'':"",'
        ','
        ','
        '].join("\n");return s.append(h).addClass(a+"vertical"),""!==n.theme&&s.addClass(a+"theme-"+n.theme),this.mask=s.children("."+a+"mask"),this.containerMask=s.children("."+a+"container-mask"),""!==n.markdown&&c.val(n.markdown),""!==n.appendMarkdown&&c.val(c.val()+n.appendMarkdown),this.htmlTextarea=s.children("."+l.textarea.html),this.preview=s.children("."+a+"preview"),this.previewContainer=this.preview.children("."+a+"preview-container"),""!==n.previewTheme&&this.preview.addClass(a+"preview-theme-"+n.previewTheme),"function"==typeof define&&define.amd&&("undefined"!=typeof katex&&(r.$katex=katex),n.searchReplace&&!n.readOnly&&(r.loadCSS(n.path+"codemirror/addon/dialog/dialog"),r.loadCSS(n.path+"codemirror/addon/search/matchesonscrollbar"))),"function"==typeof define&&define.amd||!n.autoLoadModules?("undefined"!=typeof CodeMirror&&(r.$CodeMirror=CodeMirror),"undefined"!=typeof marked&&(r.$marked=marked),this.setCodeMirror().setToolbar().loadedDisplay()):this.loadQueues(),this},loadQueues:function(){var e=this,t=o,i=t.path,a=function(){r.isIE8?e.loadedDisplay():t.flowChart||t.sequenceDiagram?r.loadScript(i+"raphael.min",function(){r.loadScript(i+"underscore.min",function(){!t.flowChart&&t.sequenceDiagram?r.loadScript(i+"sequence-diagram.min",function(){e.loadedDisplay()}):t.flowChart&&!t.sequenceDiagram?r.loadScript(i+"flowchart.min",function(){r.loadScript(i+"jquery.flowchart.min",function(){e.loadedDisplay()})}):t.flowChart&&t.sequenceDiagram&&r.loadScript(i+"flowchart.min",function(){r.loadScript(i+"jquery.flowchart.min",function(){r.loadScript(i+"sequence-diagram.min",function(){e.loadedDisplay()})})})})}):e.loadedDisplay()};return t.searchReplace&&!t.readOnly&&(r.loadCSS(i+"codemirror/addon/dialog/dialog"),r.loadCSS(i+"codemirror/addon/search/matchesonscrollbar")),t.codeFold&&r.loadCSS(i+"codemirror/addon/fold/foldgutter"),r.$CodeMirror=CodeMirror,r.loadScript(i+"codemirror/modes.min",function(){r.loadScript(i+"codemirror/addons.min",function(){if(e.setCodeMirror(),"gfm"!==t.mode&&"markdown"!==t.mode)return e.loadedDisplay(),!1;e.setToolbar(),r.loadScript(i+"marked.min",function(){r.$marked=marked,t.previewCodeHighlight?r.loadScript(i+"prettify.min",function(){a()}):a()})})}),this},setTheme:function(e){var t=this.editor,i=o.theme,r=this.classPrefix+"theme-";return t.removeClass(r+i).addClass(r+e),o.theme=e,this},setEditorTheme:function(e){var t=o;return t.editorTheme=e,"default"!==e&&r.loadCSS(t.path+"codemirror/theme/"+t.editorTheme),this.cm.setOption("theme",e),this},setCodeMirrorTheme:function(e){return this.setEditorTheme(e),this},setPreviewTheme:function(e){var t=this.preview,i=o.previewTheme,r=this.classPrefix+"preview-theme-";return t.removeClass(r+i).addClass(r+e),o.previewTheme=e,this},setCodeMirror:function(){var e=o,t=this.editor;"default"!==e.editorTheme&&r.loadCSS(e.path+"codemirror/theme/"+e.editorTheme);var i={mode:e.mode,theme:e.editorTheme,tabSize:e.tabSize,dragDrop:!1,autofocus:e.autoFocus,autoCloseTags:e.autoCloseTags,readOnly:!!e.readOnly&&"nocursor",indentUnit:e.indentUnit,lineNumbers:e.lineNumbers,lineWrapping:e.lineWrapping,extraKeys:{"Ctrl-Q":function(e){e.foldCode(e.getCursor())}},foldGutter:e.codeFold,gutters:["CodeMirror-linenumbers","CodeMirror-foldgutter"],matchBrackets:e.matchBrackets,indentWithTabs:e.indentWithTabs,styleActiveLine:e.styleActiveLine,styleSelectedText:e.styleSelectedText,autoCloseBrackets:e.autoCloseBrackets,showTrailingSpace:e.showTrailingSpace,highlightSelectionMatches:!!e.matchWordHighlight&&{showToken:"onselected"!==e.matchWordHighlight&&/\w/}};return this.codeEditor=this.cm=r.$CodeMirror.fromTextArea(this.markdownTextarea[0],i),this.codeMirror=this.cmElement=t.children(".CodeMirror"),""!==e.value&&this.cm.setValue(e.value),this.codeMirror.css({fontSize:e.fontSize,width:e.watch?"50%":"100%"}),e.autoHeight&&(this.codeMirror.css("height","auto"),this.cm.setOption("viewportMargin",1/0)),e.lineNumbers||this.codeMirror.find(".CodeMirror-gutters").css("border-right","none"),this},getCodeMirrorOption:function(e){return this.cm.getOption(e)},setCodeMirrorOption:function(e,t){return this.cm.setOption(e,t),this},addKeyMap:function(e,t){return this.cm.addKeyMap(e,t),this},removeKeyMap:function(e){return this.cm.removeKeyMap(e),this},gotoLine:function(t){var i=o;if(!i.gotoLine)return this;var r=this.cm,a=(this.editor,r.lineCount()),n=this.preview;if("string"==typeof t&&("last"===t&&(t=a),"first"===t&&(t=1)),"number"!=typeof t)return alert("Error: The line number must be an integer."),this;if((t=parseInt(t)-1)>a)return alert("Error: The line number range 1-"+a),this;r.setCursor({line:t,ch:0});var s=r.getScrollInfo().clientHeight,l=r.charCoords({line:t,ch:0},"local");if(r.scrollTo(null,(l.top+l.bottom-s)/2),i.watch){var c=this.codeMirror.find(".CodeMirror-scroll")[0],h=e(c).height(),d=c.scrollTop,u=d/c.scrollHeight;0===d?n.scrollTop(0):d+h>=c.scrollHeight-16?n.scrollTop(n[0].scrollHeight):n.scrollTop(n[0].scrollHeight*u)}return r.focus(),this},extend:function(){return void 0!==arguments[1]&&("function"==typeof arguments[1]&&(arguments[1]=e.proxy(arguments[1],this)),this[arguments[0]]=arguments[1]),"object"==typeof arguments[0]&&void 0===arguments[0].length&&e.extend(!0,this,arguments[0]),this},set:function(t,i){return void 0!==i&&"function"==typeof i&&(i=e.proxy(i,this)),this[t]=i,this},config:function(t,i){var r=o;return"object"==typeof t&&(r=e.extend(!0,r,t)),"string"==typeof t&&(r[t]=i),o=r,this.recreate(),this},on:function(t,i){var r=o;return void 0!==r["on"+t]&&(r["on"+t]=e.proxy(i,this)),this},off:function(e){var t=o;return void 0!==t["on"+e]&&(t["on"+e]=function(){}),this},showToolbar:function(t){var i=o;return i.readOnly?this:(i.toolbar&&(this.toolbar.length<1||""===this.toolbar.find("."+this.classPrefix+"menu").html())&&this.setToolbar(),i.toolbar=!0,this.toolbar.show(),this.resize(),e.proxy(t||function(){},this)(),this)},hideToolbar:function(t){return o.toolbar=!1,this.toolbar.hide(),this.resize(),e.proxy(t||function(){},this)(),this},setToolbarAutoFixed:function(t){var i=this.state,r=this.editor,a=this.toolbar,n=o;void 0!==t&&(n.toolbarAutoFixed=t);return!i.fullscreen&&!i.preview&&n.toolbar&&n.toolbarAutoFixed&&e(window).bind("scroll",function(){var t=e(window),i=t.scrollTop();if(!n.toolbarAutoFixed)return!1;i-r.offset().top>10&&i
          ';t.append(n),a=this.toolbar=t.children("."+i+"toolbar")}if(!e.toolbar)return a.hide(),this;a.show();for(var s="function"==typeof e.toolbarIcons?e.toolbarIcons(this):"string"==typeof e.toolbarIcons?r.toolbarModes[e.toolbarIcons]:e.toolbarIcons,l=a.find("."+this.classPrefix+"menu"),c="",h=!1,d=0,u=s.length;d|';else{var p=/h(\d)/.test(f),m=f;"watch"!==f||e.watch||(m="unwatch");var g=e.lang.toolbar[m],w=e.toolbarIconTexts[m],v=e.toolbarIconsClass[m];g=void 0===g?"":g,w=void 0===w?"":w,v=void 0===v?"":v;var k=h?'
        • ':"
        • ";void 0!==e.toolbarCustomIcons[f]&&"function"!=typeof e.toolbarCustomIcons[f]?k+=e.toolbarCustomIcons[f]:(k+='',k+=''+(p?f.toUpperCase():""===v?w:"")+"",k+=""),k+="
        • ",c=h?k+c:c+k}}return l.html(c),l.find('[title="Lowercase"]').attr("title",e.lang.toolbar.lowercase),l.find('[title="ucwords"]').attr("title",e.lang.toolbar.ucwords),this.setToolbarHandler(),this.setToolbarAutoFixed(),this},dialogLockScreen:function(){return e.proxy(r.dialogLockScreen,this)(),this},dialogShowMask:function(t){return e.proxy(r.dialogShowMask,this)(t),this},getToolbarHandles:function(e){var t=this.toolbarHandlers=r.toolbarHandlers;return e&&void 0!==toolbarIconHandlers[e]?t[e]:t},setToolbarHandler:function(){var t=this,i=o;if(!i.toolbar||i.readOnly)return this;var a=this.toolbar,n=this.cm,s=this.classPrefix,l=this.toolbarIcons=a.find("."+s+"menu > li > a"),c=this.getToolbarHandles();return l.bind(r.mouseOrTouch("click","touchend"),function(o){var r=e(this).children(".fa"),a=r.attr("name"),s=n.getCursor(),l=n.getSelection();if(""!==a)return t.activeIcon=r,void 0!==c[a]?e.proxy(c[a],t)(n):void 0!==i.toolbarHandlers[a]&&e.proxy(i.toolbarHandlers[a],t)(n,r,s,l),"link"!==a&&"reference-link"!==a&&"image"!==a&&"code-block"!==a&&"preformatted-text"!==a&&"watch"!==a&&"preview"!==a&&"search"!==a&&"fullscreen"!==a&&"info"!==a&&n.focus(),!1}),this},createDialog:function(t){return e.proxy(r.createDialog,this)(t)},createInfoDialog:function(){var e=this,t=this.editor,i=this.classPrefix,o=['
          ','
          ','

          '+r.title+"v"+r.version+"

          ","

          "+this.lang.description+"

          ",'

          '+r.homePage+'

          ','

          Copyright © 2015 Pandao, The MIT License.

          ',"
          ",'',"
          "].join("\n");t.append(o);var a=this.infoDialog=t.children("."+i+"dialog-info");return a.find("."+i+"dialog-close").bind(r.mouseOrTouch("click","touchend"),function(){e.hideInfoDialog()}),a.css("border",r.isIE8?"1px solid #ddd":"").css("z-index",r.dialogZindex).show(),this.infoDialogPosition(),this},infoDialogPosition:function(){var t=this.infoDialog,i=function(){t.css({top:(e(window).height()-t.height())/2+"px",left:(e(window).width()-t.width())/2+"px"})};return i(),e(window).resize(i),this},showInfoDialog:function(){e("html,body").css("overflow-x","hidden");var t=this.editor,i=o,a=this.infoDialog=t.children("."+this.classPrefix+"dialog-info");return a.length<1&&this.createInfoDialog(),this.lockScreen(!0),this.mask.css({opacity:i.dialogMaskOpacity,backgroundColor:i.dialogMaskBgColor}).show(),a.css("z-index",r.dialogZindex).show(),this.infoDialogPosition(),this},hideInfoDialog:function(){return e("html,body").css("overflow-x",""),this.infoDialog.hide(),this.mask.hide(),this.lockScreen(!1),this},lockScreen:function(e){return r.lockScreen(e),this.resize(),this},recreate:function(){var e=this.editor,t=o;return this.codeMirror.remove(),this.setCodeMirror(),t.readOnly||(e.find(".editormd-dialog").length>0&&e.find(".editormd-dialog").remove(),t.toolbar&&(this.getToolbarHandles(),this.setToolbar())),this.loadedDisplay(!0),this},previewCodeHighlight:function(){var e=o,t=this.previewContainer;return e.previewCodeHighlight&&(t.find("pre").addClass("prettyprint linenums"),"undefined"!=typeof prettyPrint&&prettyPrint()),this},katexRender:function(){return null===t?this:(this.previewContainer.find("."+r.classNames.tex).each(function(){var t=e(this);r.$katex.render(t.text(),t[0]),t.find(".katex").css("font-size","1.0em")}),this)},flowChartAndSequenceDiagramRender:function(){var t=o,a=this.previewContainer;if(r.isIE8)return this;if(t.flowChart){if(null===i)return this;a.find(".flowchart").flowChart()}t.sequenceDiagram&&a.find(".sequence-diagram").sequenceDiagram({theme:"simple"});var n=this.preview,s=this.codeMirror.find(".CodeMirror-scroll"),l=s.height(),c=s.scrollTop(),h=c/s[0].scrollHeight,d=0;n.find(".markdown-toc-list").each(function(){d+=e(this).height()});var u=n.find(".editormd-toc-menu").height();return u=u||0,0===c?n.scrollTop(0):c+l>=s[0].scrollHeight-16?n.scrollTop(n[0].scrollHeight):n.scrollTop((n[0].scrollHeight+d+u)*h),this},registerKeyMaps:function(t){var i=this,a=this.cm,n=o,s=r.toolbarHandlers,l=n.disabledKeyMaps;if(t=t||null){for(var c in t)if(e.inArray(c,l)<0){t[c],a.addKeyMap(t)}}else{for(var h in r.keyMaps){var d=r.keyMaps[h],u="string"==typeof d?e.proxy(s[d],i):e.proxy(d,i);if(e.inArray(h,["F9","F10","F11"])<0&&e.inArray(h,l)<0){var f={};f[h]=u,a.addKeyMap(f)}}e(window).keydown(function(t){if(e.inArray({120:"F9",121:"F10",122:"F11"}[t.keyCode],l)<0)switch(t.keyCode){case 120:return e.proxy(s.watch,i)(),!1;case 121:return e.proxy(s.preview,i)(),!1;case 122:return e.proxy(s.fullscreen,i)(),!1}})}return this},bindScrollEvent:function(){var t=this,i=this.preview,a=o,n=this.codeMirror,s=r.mouseOrTouch;if(!a.syncScrolling)return this;var l=function(){n.find(".CodeMirror-scroll").bind(s("scroll","touchmove"),function(o){var r=e(this).height(),n=e(this).scrollTop(),s=n/e(this)[0].scrollHeight,l=0;i.find(".markdown-toc-list").each(function(){l+=e(this).height()});var c=i.find(".editormd-toc-menu").height();c=c||0,0===n?i.scrollTop(0):n+r>=e(this)[0].scrollHeight-16?i.scrollTop(i[0].scrollHeight):i.scrollTop((i[0].scrollHeight+l+c)*s),e.proxy(a.onscroll,t)(o)})},c=function(){n.find(".CodeMirror-scroll").unbind(s("scroll","touchmove"))},h=function(){i.bind(s("scroll","touchmove"),function(i){var o=e(this).height(),r=e(this).scrollTop(),s=r/e(this)[0].scrollHeight,l=n.find(".CodeMirror-scroll");0===r?l.scrollTop(0):r+o>=e(this)[0].scrollHeight?l.scrollTop(l[0].scrollHeight):l.scrollTop(l[0].scrollHeight*s),e.proxy(a.onpreviewscroll,t)(i)})},d=function(){i.unbind(s("scroll","touchmove"))};return n.bind({mouseover:l,mouseout:c,touchstart:l,touchend:c}),"single"===a.syncScrolling?this:(i.bind({mouseover:h,mouseout:d,touchstart:h,touchend:d}),this)},bindChangeEvent:function(){var e=this,i=this.cm,r=o;return r.syncScrolling?(i.on("change",function(i,o){r.watch&&e.previewContainer.css("padding",r.autoHeight?"20px 20px 50px 40px":"20px"),t=setTimeout(function(){clearTimeout(t),e.save(),t=null},r.delay)}),this):this},loadedDisplay:function(t){t=t||!1;var i=this,r=this.editor,a=this.preview,n=o;return this.containerMask.hide(),this.save(),n.watch&&a.show(),r.data("oldWidth",r.width()).data("oldHeight",r.height()),this.resize(),this.registerKeyMaps(),e(window).resize(function(){i.resize()}),this.bindScrollEvent().bindChangeEvent(),t||(n.imageUploadURL&&initEditormdPasteUpload(this,n.imageUploadURL),e.proxy(n.onload,this)()),this.state.loaded=!0,this},width:function(e){return this.editor.css("width","number"==typeof e?e+"px":e),this.resize(),this},height:function(e){return this.editor.css("height","number"==typeof e?e+"px":e),this.resize(),this},resize:function(t,i){t=t||null,i=i||null;var r=this.state,a=this.editor,n=this.preview,s=this.toolbar,l=o,c=this.codeMirror;if(t&&a.css("width","number"==typeof t?t+"px":t),!l.autoHeight||r.fullscreen||r.preview?(i&&a.css("height","number"==typeof i?i+"px":i),r.fullscreen&&a.height(e(window).height()),l.toolbar&&!l.readOnly?c.css("margin-top",s.height()+1).height(a.height()-s.height()):c.css("margin-top",0).height(a.height())):(a.css("height","auto"),c.css("height","auto")),l.watch)if(c.width(a.width()/2),n.width(r.preview?a.width():a.width()/2),this.previewContainer.css("padding",l.autoHeight?"20px 20px 50px 40px":"20px"),l.toolbar&&!l.readOnly?n.css("top",s.height()+1):n.css("top",0),!l.autoHeight||r.fullscreen||r.preview){var h=l.toolbar&&!l.readOnly?a.height()-s.height():a.height();n.height(h)}else n.height("");else c.width(a.width()),n.hide();return r.loaded&&e.proxy(l.onresize,this)(),this},save:function(){if(null===t)return this;var a=this,n=this.state,s=o,l=this.cm,c=l.getValue(),h=this.previewContainer;if("gfm"!==s.mode&&"markdown"!==s.mode)return this.markdownTextarea.val(c),this;var d=r.$marked,u=this.markdownToC=[],f=this.markedRendererOptions={toc:s.toc,tocm:s.tocm,tocStartLevel:s.tocStartLevel,pageBreak:s.pageBreak,taskList:s.taskList,emoji:s.emoji,tex:s.tex,atLink:s.atLink,emailLink:s.emailLink,flowChart:s.flowChart,sequenceDiagram:s.sequenceDiagram,previewCodeHighlight:s.previewCodeHighlight},p=this.markedOptions={renderer:r.markedRenderer(u,f),gfm:!0,tables:!0,breaks:!0,pedantic:!1,sanitize:!s.htmlDecode,smartLists:!0,smartypants:!0};d.setOptions(p);var m=r.$marked(c,p);if(m=r.filterHTMLTags(m,s.htmlDecode),this.markdownTextarea.text(c),l.save(),s.saveHTMLToTextarea&&this.htmlTextarea.text(m),s.watch||!s.watch&&n.preview){if(h.html(m),this.previewCodeHighlight(),s.toc){var g=""===s.tocContainer?h:e(s.tocContainer),w=g.find("."+this.classPrefix+"toc-menu");g.attr("previewContainer",""===s.tocContainer?"true":"false"),""!==s.tocContainer&&w.length>0&&w.remove(),r.markdownToCRenderer(u,g,s.tocDropdown,s.tocStartLevel),(s.tocDropdown||g.find("."+this.classPrefix+"toc-menu").length>0)&&r.tocDropdownMenu(g,""!==s.tocTitle?s.tocTitle:this.lang.tocTitle),""!==s.tocContainer&&h.find(".markdown-toc").css("border","none")}s.tex&&(!r.kaTeXLoaded&&s.autoLoadModules?r.loadKaTeX(function(){r.$katex=katex,r.kaTeXLoaded=!0,a.katexRender()}):(r.$katex=katex,this.katexRender())),(s.flowChart||s.sequenceDiagram)&&(i=setTimeout(function(){clearTimeout(i),a.flowChartAndSequenceDiagramRender(),i=null},10)),n.loaded&&e.proxy(s.onchange,this)()}return this},focus:function(){return this.cm.focus(),this},setCursor:function(e){return this.cm.setCursor(e),this},getCursor:function(){return this.cm.getCursor()},setSelection:function(e,t){return this.cm.setSelection(e,t),this},getSelection:function(){return this.cm.getSelection()},setSelections:function(e){return this.cm.setSelections(e),this},getSelections:function(){return this.cm.getSelections()},replaceSelection:function(e){return this.cm.replaceSelection(e),this},insertValue:function(e){return this.replaceSelection(e),this},appendMarkdown:function(e){var t=this.cm;return t.setValue(t.getValue()+e),this},setMarkdown:function(e){return this.cm.setValue(e||o.markdown),this},getMarkdown:function(){return this.cm.getValue()},getValue:function(){return this.cm.getValue()},setValue:function(e){return this.cm.setValue(e),this},clear:function(){return this.cm.setValue(""),this},getHTML:function(){return o.saveHTMLToTextarea?this.htmlTextarea.val():(alert("Error: settings.saveHTMLToTextarea == false"),!1)},getTextareaSavedHTML:function(){return this.getHTML()},getPreviewedHTML:function(){return o.watch?this.previewContainer.html():(alert("Error: settings.watch == false"),!1)},watch:function(i){var r=o;if(e.inArray(r.mode,["gfm","markdown"])<0)return this;if(this.state.watching=r.watch=!0,this.preview.show(),this.toolbar){var a=r.toolbarIconsClass.watch,n=r.toolbarIconsClass.unwatch,s=this.toolbar.find(".fa[name=watch]");s.parent().attr("title",r.lang.toolbar.watch),s.removeClass(n).addClass(a)}return this.codeMirror.css("border-right","1px solid #ddd").width(this.editor.width()/2),t=0,this.save().resize(),r.onwatch||(r.onwatch=i||function(){}),e.proxy(r.onwatch,this)(),this},unwatch:function(t){var i=o;if(this.state.watching=i.watch=!1,this.preview.hide(),this.toolbar){var r=i.toolbarIconsClass.watch,a=i.toolbarIconsClass.unwatch,n=this.toolbar.find(".fa[name=watch]");n.parent().attr("title",i.lang.toolbar.unwatch),n.removeClass(r).addClass(a)}return this.codeMirror.css("border-right","none").width(this.editor.width()),this.resize(),i.onunwatch||(i.onunwatch=t||function(){}),e.proxy(i.onunwatch,this)(),this},show:function(t){t=t||function(){};var i=this;return this.editor.show(0,function(){e.proxy(t,i)()}),this},hide:function(t){t=t||function(){};var i=this;return this.editor.hide(0,function(){e.proxy(t,i)()}),this},previewing:function(){var t=this,i=this.editor,a=this.preview,n=this.toolbar,s=o,l=this.codeMirror,c=this.previewContainer;if(e.inArray(s.mode,["gfm","markdown"])<0)return this;s.toolbar&&n&&(n.toggle(),n.find(".fa[name=preview]").toggleClass("active")),l.toggle();var h=function(e){e.shiftKey&&27===e.keyCode&&t.previewed()};"none"===l.css("display")?(this.state.preview=!0,this.state.fullscreen&&a.css("background","#fff"),i.find("."+this.classPrefix+"preview-close-btn").show().bind(r.mouseOrTouch("click","touchend"),function(){t.previewed()}),s.watch?c.css("padding",""):this.save(),c.addClass(this.classPrefix+"preview-active"),a.show().css({position:"",top:0,width:i.width(),height:s.autoHeight&&!this.state.fullscreen?"auto":i.height()}),this.state.loaded&&e.proxy(s.onpreviewing,this)(),e(window).bind("keyup",h)):(e(window).unbind("keyup",h),this.previewed())},previewed:function(){var t=this.editor,i=this.preview,a=this.toolbar,n=o,s=this.previewContainer,l=t.find("."+this.classPrefix+"preview-close-btn");return this.state.preview=!1,this.codeMirror.show(),n.toolbar&&a.show(),i[n.watch?"show":"hide"](),l.hide().unbind(r.mouseOrTouch("click","touchend")),s.removeClass(this.classPrefix+"preview-active"),n.watch&&s.css("padding","20px"),i.css({background:null,position:"absolute",width:t.width()/2,height:n.autoHeight&&!this.state.fullscreen?"auto":t.height()-a.height(),top:n.toolbar?a.height():0}),this.state.loaded&&e.proxy(n.onpreviewed,this)(),this},fullscreen:function(){var t=this,i=this.state,r=this.editor,a=(this.preview,this.toolbar),n=o,s=this.classPrefix+"fullscreen";a&&a.find(".fa[name=fullscreen]").parent().toggleClass("active");var l=function(e){e.shiftKey||27!==e.keyCode||i.fullscreen&&t.fullscreenExit()};return r.hasClass(s)?(e(window).unbind("keyup",l),this.fullscreenExit()):(i.fullscreen=!0,e("html,body").css("overflow","hidden"),r.css({width:e(window).width(),height:e(window).height()}).addClass(s),this.resize(),e.proxy(n.onfullscreen,this)(),e(window).bind("keyup",l)),this},fullscreenExit:function(){var t=this.editor,i=o,r=this.toolbar,a=this.classPrefix+"fullscreen";return this.state.fullscreen=!1,r&&r.find(".fa[name=fullscreen]").parent().removeClass("active"),e("html,body").css("overflow",""),t.css({width:t.data("oldWidth"),height:t.data("oldHeight")}).removeClass(a),this.resize(),e.proxy(i.onfullscreenExit,this)(),this},executePlugin:function(t,i){var a=this,n=this.cm;return i=o.pluginPath+i,"function"==typeof define?void 0===this[t]?(alert("Error: "+t+" plugin is not found, you are not load this plugin."),this):(this[t](n),this):(e.inArray(i,r.loadFiles.plugin)<0?r.loadPlugin(i,function(){r.loadPlugins[t]=a[t],a[t](n)}):e.proxy(r.loadPlugins[t],this)(n),this)},search:function(e){var t=o;return t.searchReplace?(t.readOnly||this.cm.execCommand(e||"find"),this):(alert("Error: settings.searchReplace == false"),this)},searchReplace:function(){return this.search("replace"),this},searchReplaceAll:function(){return this.search("replaceAll"),this}},r.fn.init.prototype=r.fn,r.dialogLockScreen=function(){(o||{dialogLockScreen:!0}).dialogLockScreen&&(e("html,body").css("overflow","hidden"),this.resize())},r.dialogShowMask=function(t){var i=this.editor,r=o||{dialogShowMask:!0};t.css({top:(e(window).height()-t.height())/2+"px",left:(e(window).width()-t.width())/2+"px"}),r.dialogShowMask&&i.children("."+this.classPrefix+"mask").css("z-index",parseInt(t.css("z-index"))-1).show()},r.toolbarHandlers={undo:function(){this.cm.undo()},redo:function(){this.cm.redo()},bold:function(){var e=this.cm,t=e.getCursor(),i=e.getSelection();e.replaceSelection("**"+i+"**"),""===i&&e.setCursor(t.line,t.ch+2)},del:function(){var e=this.cm,t=e.getCursor(),i=e.getSelection();e.replaceSelection("~~"+i+"~~"),""===i&&e.setCursor(t.line,t.ch+2)},italic:function(){var e=this.cm,t=e.getCursor(),i=e.getSelection();e.replaceSelection("*"+i+"*"),""===i&&e.setCursor(t.line,t.ch+1)},quote:function(){var e=this.cm,t=e.getCursor(),i=e.getSelection();0!==t.ch?(e.setCursor(t.line,0),e.replaceSelection("> "+i),e.setCursor(t.line,t.ch+2)):e.replaceSelection("> "+i)},ucfirst:function(){var e=this.cm,t=e.getSelection(),i=e.listSelections();e.replaceSelection(r.firstUpperCase(t)),e.setSelections(i)},ucwords:function(){var e=this.cm,t=e.getSelection(),i=e.listSelections();e.replaceSelection(r.wordsFirstUpperCase(t)),e.setSelections(i)},uppercase:function(){var e=this.cm,t=e.getSelection(),i=e.listSelections();e.replaceSelection(t.toUpperCase()),e.setSelections(i)},lowercase:function(){var e=this.cm,t=(e.getCursor(),e.getSelection()),i=e.listSelections();e.replaceSelection(t.toLowerCase()),e.setSelections(i)},h1:function(){var e=this.cm,t=e.getCursor(),i=e.getSelection();0!==t.ch?(e.setCursor(t.line,0),e.replaceSelection("# "+i),e.setCursor(t.line,t.ch+2)):e.replaceSelection("# "+i)},h2:function(){var e=this.cm,t=e.getCursor(),i=e.getSelection();0!==t.ch?(e.setCursor(t.line,0),e.replaceSelection("## "+i),e.setCursor(t.line,t.ch+3)):e.replaceSelection("## "+i)},h3:function(){var e=this.cm,t=e.getCursor(),i=e.getSelection();0!==t.ch?(e.setCursor(t.line,0),e.replaceSelection("### "+i),e.setCursor(t.line,t.ch+4)):e.replaceSelection("### "+i)},h4:function(){var e=this.cm,t=e.getCursor(),i=e.getSelection();0!==t.ch?(e.setCursor(t.line,0),e.replaceSelection("#### "+i),e.setCursor(t.line,t.ch+5)):e.replaceSelection("#### "+i)},h5:function(){var e=this.cm,t=e.getCursor(),i=e.getSelection();0!==t.ch?(e.setCursor(t.line,0),e.replaceSelection("##### "+i),e.setCursor(t.line,t.ch+6)):e.replaceSelection("##### "+i)},h6:function(){var e=this.cm,t=e.getCursor(),i=e.getSelection();0!==t.ch?(e.setCursor(t.line,0),e.replaceSelection("###### "+i),e.setCursor(t.line,t.ch+7)):e.replaceSelection("###### "+i)},"list-ul":function(){var e=this.cm,t=(e.getCursor(),e.getSelection());if(""===t)e.replaceSelection("- "+t);else{for(var i=t.split("\n"),o=0,r=i.length;o'}else{var l=e.match(m),c=e.match(f);if(l)for(var h=0,d=l.length;h'}else{if(!c){var g="+1"===o?"plus1":o;return g="moon"===(g="black_large_square"===g?"black_square":g)?"waxing_gibbous_moon":g,':'+o+':'}for(var w=0,v=c.length;w'}}}});return e},s.atLink=function(t){return c.test(t)?(o.atLink&&(t=(t=t.replace(d,function(e,t,i,o){return e.replace(/@/g,"_#_@_#_")})).replace(c,function(e,t){return''+e+""}).replace(/_#_@_#_/g,"@")),o.emailLink&&(t=t.replace(u,function(t,i,o,r,a){return!i&&e.inArray(a,"jpg|jpeg|png|gif|webp|ico|icon|pdf".split("|"))<0?''+t+"":t})),t):t},s.link=function(e,t,i){if(this.options.sanitize){try{var o=decodeURIComponent(unescape(e)).replace(/[^\w:]/g,"").toLowerCase()}catch(e){return""}if(0===o.indexOf("javascript:"))return""}var r=''+i.replace(/@/g,"@")+""):(t&&(r+=' title="'+t+'"'),r+=">"+i+"")},s.heading=function(e,i,o){var r=e,n=/\s*\]*)\>(.*)\<\/a\>\s*/;if(n.test(e)){for(var s=[],l=0,c=(e=e.split(/\]+)\>([^\>]*)\<\/a\>/)).length;l';return u+='',u+='',u+=n?this.atLink(this.emoji(r)):this.atLink(this.emoji(e)),u+=""},s.pageBreak=function(e){return g.test(e)&&o.pageBreak&&(e='
          '),e},s.em=function(e, capInput){return e&&-1!=e.indexOf("$$") || (capInput && capInput.indexOf('$$') != -1) ?"_"+e+"_":""+e+""},s.paragraph=function(e){var t=/\$\$(.*)\$\$/g.test(e),i=/^\$\$(.*)\$\$$/.test(e),a=i?' class="'+r.classNames.tex+'"':"",n=o.tocm?/^(\[TOC\]|\[TOCM\])$/.test(e):/^\[TOC\]$/.test(e),s=/^\[TOCM\]$/.test(e),l='
          '+(e=!i&&t?e.replace(/(\$\$([^\$]*)\$\$)+/g,function(e,t){return''+t.replace(/\$/g,"")+""}):i?e.replace(/\$/g,""):e)+"
          ";return n?s?'
          '+l+"

          ":l:g.test(e)?this.pageBreak(e):""+this.atLink(this.emoji(e))+"

          \n"},s.code=function(e,t,i){return"seq"===t||"sequence"===t?'
          '+e+"
          ":"flow"===t?'
          '+e+"
          ":"math"===t||"latex"===t||"katex"===t?'

          '+e+"

          ":n.Renderer.prototype.code.apply(this,arguments)},s.tablecell=function(e,t){var i=t.header?"th":"td";return(t.align?"<"+i+' style="text-align:'+t.align+'">':"<"+i+">")+this.atLink(this.emoji(e))+"\n"},s.listitem=function(e){return o.taskList&&/^\s*\[[x\s]\]\s*/.test(e)?(e=e.replace(/^\s*\[\s\]\s*/,' ').replace(/^\s*\[x\]\s*/,' '),'
        • '+this.atLink(this.emoji(e))+"
        • "):"
        • "+this.atLink(this.emoji(e))+"
        • "},s},r.markdownToCRenderer=function(e,t,i,o){var r="",a=0,n=this.classPrefix;o=o||1;for(var s=0,l=e.length;sa?"":h"):"
      • ",r+='
      • '+c+"
          ",a=h)}var d=t.find(".markdown-toc");if(d.length<1&&"false"===t.attr("previewContainer")){var u='
          ';u=i?'
          '+u+"
          ":u,t.html(u),d=t.find(".markdown-toc")}return i&&d.wrap('

          '),d.html('
            ').children(".markdown-toc-list").html(r.replace(/\r?\n?\\<\/ul\>/g,"")),d},r.tocDropdownMenu=function(t,i){i=i||"Table of Contents";var o=400,r=t.find("."+this.classPrefix+"toc-menu");return r.each(function(){var t=e(this),r=t.children(".markdown-toc"),a='',n=''+a+i+"",s=r.children("ul"),l=s.find("li");r.append(n),l.first().before("
          • "+i+" "+a+"

          • "),t.mouseover(function(){s.show(),l.each(function(){var t=e(this),i=t.children("ul");if(""===i.html()&&i.remove(),i.length>0&&""!==i.html()){var r=t.children("a").first();r.children(".fa").length<1&&r.append(e(a).css({float:"right",paddingTop:"4px"}))}t.mouseover(function(){i.css("z-index",o).show(),o+=1}).mouseleave(function(){i.hide()})})}).mouseleave(function(){s.hide()})}),r},r.filterHTMLTags=function(t,i){if("string"!=typeof t&&(t=new String(t)),"string"!=typeof i)return t;for(var o=i.split("|"),r=o[0].split(","),a=o[1],n=0,s=r.length;n]*)>([^>]*)","igm"),"")}if(void 0!==a){var c=/\<(\w+)\s*([^\>]*)\>([^\>]*)\<\/(\w+)\>/gi;t="*"===a?t.replace(c,function(e,t,i,o,r){return"<"+t+">"+o+""}):"on*"===a?t.replace(c,function(t,i,o,r,a){var n=e("<"+i+">"+r+""),s=e(t)[0].attributes,l={};e.each(s,function(e,t){'"'!==t.nodeName&&(l[t.nodeName]=t.nodeValue)}),e.each(l,function(e){0===e.indexOf("on")&&delete l[e]}),n.attr(l);var c=void 0!==n[1]?e(n[1]).text():"";return n[0].outerHTML+c}):t.replace(c,function(t,i,o,r){var n=a.split(","),s=e(t);return s.html(r),e.each(n,function(e){s.attr(n[e],null)}),s[0].outerHTML})}return t},r.markdownToHTML=function(t,i){r.$marked=marked;var o=e("#"+t),a=o.settings=e.extend(!0,{gfm:!0,toc:!0,tocm:!1,tocStartLevel:1,tocTitle:"目录",tocDropdown:!1,tocContainer:"",markdown:"",markdownSourceCode:!1,htmlDecode:!1,autoLoadKaTeX:!0,pageBreak:!0,atLink:!0,emailLink:!0,tex:!1,taskList:!1,emoji:!1,flowChart:!1,sequenceDiagram:!1,previewCodeHighlight:!0},i||{}),n=o.find("textarea");n.length<1&&(o.append(""),n=o.find("textarea"));var s=""===a.markdown?n.val():a.markdown,l=[],c={toc:a.toc,tocm:a.tocm,tocStartLevel:a.tocStartLevel,taskList:a.taskList,emoji:a.emoji,tex:a.tex,pageBreak:a.pageBreak,atLink:a.atLink,emailLink:a.emailLink,flowChart:a.flowChart,sequenceDiagram:a.sequenceDiagram,previewCodeHighlight:a.previewCodeHighlight},h={renderer:r.markedRenderer(l,c),gfm:a.gfm,tables:!0,breaks:!0,pedantic:!1,sanitize:!a.htmlDecode,smartLists:!0,smartypants:!0};s=new String(s);var d=marked(s,h);d=r.filterHTMLTags(d,a.htmlDecode),a.markdownSourceCode?n.text(s):n.remove(),o.addClass("markdown-body "+this.classPrefix+"html-preview").append(d);var u=""!==a.tocContainer?e(a.tocContainer):o;if(""!==a.tocContainer&&u.attr("previewContainer",!1),a.toc&&(o.tocContainer=this.markdownToCRenderer(l,u,a.tocDropdown,a.tocStartLevel),(a.tocDropdown||o.find("."+this.classPrefix+"toc-menu").length>0)&&this.tocDropdownMenu(o,a.tocTitle),""!==a.tocContainer&&o.find(".editormd-toc-menu, .editormd-markdown-toc").remove()),a.previewCodeHighlight&&(o.find("pre").addClass("prettyprint linenums"),prettyPrint()),r.isIE8||(a.flowChart&&o.find(".flowchart").flowChart(),a.sequenceDiagram&&o.find(".sequence-diagram").sequenceDiagram({theme:"simple"})),a.tex){var f=function(){o.find("."+r.classNames.tex).each(function(){var t=e(this);katex.render(t.text(),t[0]),t.find(".katex").css("font-size","1.0em")})};!a.autoLoadKaTeX||r.$katex||r.kaTeXLoaded?f():this.loadKaTeX(function(){r.$katex=katex,r.kaTeXLoaded=!0,f()})}return o.getMarkdown=function(){return n.val()},o},r.themes=["default","dark"],r.previewThemes=["default","dark"],r.editorThemes=["default","3024-day","3024-night","ambiance","ambiance-mobile","base16-dark","base16-light","blackboard","cobalt","eclipse","elegant","erlang-dark","lesser-dark","mbo","mdn-like","midnight","monokai","neat","neo","night","paraiso-dark","paraiso-light","pastel-on-dark","rubyblue","solarized","the-matrix","tomorrow-night-eighties","twilight","vibrant-ink","xq-dark","xq-light"],r.loadPlugins={},r.loadFiles={js:[],css:[],plugin:[]},r.loadPlugin=function(e,t,i){t=t||function(){},this.loadScript(e,function(){r.loadFiles.plugin.push(e),t()},i)},r.loadCSS=function(e,t,i){i=i||"head",t=t||function(){};var o=document.createElement("link");o.type="text/css",o.rel="stylesheet",o.onload=o.onreadystatechange=function(){r.loadFiles.css.push(e),t()},o.href=e+".css","head"===i?document.getElementsByTagName("head")[0].appendChild(o):document.body.appendChild(o)},r.isIE="Microsoft Internet Explorer"==navigator.appName,r.isIE8=r.isIE&&"8."==navigator.appVersion.match(/8./i),r.loadScript=function(e,t,i){i=i||"head",t=t||function(){};var o=null;(o=document.createElement("script")).id=e.replace(/[\./]+/g,"-"),o.type="text/javascript",o.src=e+".js",r.isIE8?o.onreadystatechange=function(){o.readyState&&("loaded"!==o.readyState&&"complete"!==o.readyState||(o.onreadystatechange=null,r.loadFiles.js.push(e),t()))}:o.onload=function(){r.loadFiles.js.push(e),t()},"head"===i?document.getElementsByTagName("head")[0].appendChild(o):document.body.appendChild(o)},r.katexURL={css:"/katex/katex.min",js:"/katex/katex.min"},r.kaTeXLoaded=!1,r.loadKaTeX=function(e){r.loadCSS(r.katexURL.css,function(){r.loadScript(r.katexURL.js,e||function(){})})},r.lockScreen=function(t){e("html,body").css("overflow",t?"hidden":"")},r.createDialog=function(t){t=e.extend(!0,{name:"",width:420,height:240,title:"",drag:!0,closed:!0,content:"",mask:!0,maskStyle:{backgroundColor:"#fff",opacity:.1},lockScreen:!0,footer:!0,buttons:!1},t);var i=this,o=this.editor,a=r.classPrefix,n=(new Date).getTime(),s=""===t.name?a+"dialog-"+n:t.name,l=r.mouseOrTouch,c='
            ';""!==t.title&&(c+='
            ",c+=''+t.title+"",c+="
            "),t.closed&&(c+=''),c+='
            '+t.content,(t.footer||"string"==typeof t.footer)&&(c+='"),c+="
            ",c+='
            ',c+='
            ',c+="
            ",o.append(c);var h=o.find("."+s);h.lockScreen=function(o){return t.lockScreen&&(e("html,body").css("overflow",o?"hidden":""),i.resize()),h},h.showMask=function(){return t.mask&&o.find("."+a+"mask").css(t.maskStyle).css("z-index",r.dialogZindex-1).show(),h},h.hideMask=function(){return t.mask&&o.find("."+a+"mask").hide(),h},h.loading=function(e){return h.find("."+a+"dialog-mask")[e?"show":"hide"](),h},h.lockScreen(!0).showMask(),h.show().css({zIndex:r.dialogZindex,border:r.isIE8?"1px solid #ddd":"",width:"number"==typeof t.width?t.width+"px":t.width,height:"number"==typeof t.height?t.height+"px":t.height});var d=function(){h.css({top:(e(window).height()-h.height())/2+"px",left:(e(window).width()-h.width())/2+"px"})};if(d(),e(window).resize(d),h.children("."+a+"dialog-close").bind(l("click","touchend"),function(){h.hide().lockScreen(!1).hideMask()}),"object"==typeof t.buttons){var u=h.footer=h.find("."+a+"dialog-footer");for(var f in t.buttons){var p=t.buttons[f],m=a+f+"-btn";u.append('"),p[1]=e.proxy(p[1],h),u.children("."+m).bind(l("click","touchend"),p[1])}}if(""!==t.title&&t.drag){var g,w,v=h.children("."+a+"dialog-header");t.mask||v.bind(l("click","touchend"),function(){r.dialogZindex+=2,h.css("z-index",r.dialogZindex)}),v.mousedown(function(e){e=e||window.event,g=e.clientX-parseInt(h[0].style.left),w=e.clientY-parseInt(h[0].style.top),document.onmousemove=x});var k=function(e){e.removeClass(a+"user-unselect").off("selectstart")},b=function(e){e.addClass(a+"user-unselect").on("selectstart",function(e){return!1})},x=function(t){t=t||window.event;var i,o,r=parseInt(h[0].style.left),a=parseInt(h[0].style.top);r>=0?r+h.width()<=e(window).width()?i=t.clientX-g:(i=e(window).width()-h.width(),document.onmousemove=null):(i=0,document.onmousemove=null),a>=0?o=t.clientY-w:(o=0,document.onmousemove=null),document.onselectstart=function(){return!1},b(e("body")),b(h),h[0].style.left=i+"px",h[0].style.top=o+"px"};document.onmouseup=function(){k(e("body")),k(h),document.onselectstart=null,document.onmousemove=null},v.touchDraggable=function(){var t=null;this.bind("touchstart",function(i){var o=i.originalEvent,r=e(this).parent().position();t={x:o.changedTouches[0].pageX-r.left,y:o.changedTouches[0].pageY-r.top}}).bind("touchmove",function(i){i.preventDefault();var o=i.originalEvent;e(this).parent().css({top:o.changedTouches[0].pageY-t.y,left:o.changedTouches[0].pageX-t.x})})},v.touchDraggable()}return r.dialogZindex+=2,e("body").removeAttr("style"),h},r.mouseOrTouch=function(e,t){t=t||"touchend";var i=e=e||"click";try{document.createEvent("TouchEvent"),i=t}catch(e){}return i},r.dateFormat=function(e){e=e||"";var t=function(e){return e<10?"0"+e:e},i=new Date,o=i.getFullYear(),r=o.toString().slice(2,4),a=t(i.getMonth()+1),n=t(i.getDate()),s=i.getDay(),l=t(i.getHours()),c=t(i.getMinutes()),h=t(i.getSeconds()),d=t(i.getMilliseconds()),u="",f=r+"-"+a+"-"+n,p=o+"-"+a+"-"+n,m=l+":"+c+":"+h;switch(e){case"UNIX Time":u=i.getTime();break;case"UTC":u=i.toUTCString();break;case"yy":u=r;break;case"year":case"yyyy":u=o;break;case"month":case"mm":u=a;break;case"cn-week-day":case"cn-wd":u="星期"+["日","一","二","三","四","五","六"][s];break;case"week-day":case"wd":u=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"][s];break;case"day":case"dd":u=n;break;case"hour":case"hh":u=l;break;case"min":case"ii":u=c;break;case"second":case"ss":u=h;break;case"ms":u=d;break;case"yy-mm-dd":u=f;break;case"yyyy-mm-dd":u=p;break;case"yyyy-mm-dd h:i:s ms":case"full + ms":u=p+" "+m+" "+d;break;case"full":case"yyyy-mm-dd h:i:s":default:u=p+" "+m}return u},r}}),window._whenPasterDoUpload=function(e,t,i){var o,r,a,n=e.clipboardData,s=0;if(n){if(!(o=n.items))return;for(r=o[0],a=n.types||[];s Date: Tue, 10 Sep 2019 17:00:11 +0800 Subject: [PATCH 7/9] =?UTF-8?q?=E6=8A=A5=E9=94=99=E8=B0=83=E6=95=B4?= =?UTF-8?q?=EF=BC=8C=E9=A2=98=E5=BA=93=E6=9D=83=E9=99=90=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tpm/challengesnew/TPMchallengesnew.js | 16 ++++++++-------- .../src/modules/user/usersInfo/InfosBanner.js | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/public/react/src/modules/tpm/challengesnew/TPMchallengesnew.js b/public/react/src/modules/tpm/challengesnew/TPMchallengesnew.js index cc3d335bb..2905699e7 100644 --- a/public/react/src/modules/tpm/challengesnew/TPMchallengesnew.js +++ b/public/react/src/modules/tpm/challengesnew/TPMchallengesnew.js @@ -408,13 +408,13 @@ export default class TPMchallengesnew extends Component { } = this.state; let options; - options = optionsums.map((d, k) => { - return ( - - ) - }) - - console.log(this.state.shixunExec_timeType ) + if(optionsums!=undefined){ + options = optionsums.map((d, k) => { + return ( + + ) + }) + } return ( @@ -565,7 +565,7 @@ export default class TPMchallengesnew extends Component {
            { - shixunsskillvaluelist.length === 0 ? "" : shixunsskillvaluelist.map((itme, key) => { + shixunsskillvaluelist===undefined?"":shixunsskillvaluelist.length === 0 ? "" : shixunsskillvaluelist.map((itme, key) => { return (
          • {itme} this.delshixunsskilllist(key)}>× diff --git a/public/react/src/modules/user/usersInfo/InfosBanner.js b/public/react/src/modules/user/usersInfo/InfosBanner.js index 4e6492c7f..5e79a9b2b 100644 --- a/public/react/src/modules/user/usersInfo/InfosBanner.js +++ b/public/react/src/modules/user/usersInfo/InfosBanner.js @@ -124,7 +124,7 @@ class InfosBanner extends Component{
          • } {/*自己的主页且不是学生显示题库按钮*/} - {(is_current && current_user) + {(is_current && current_user&& current_user.is_teacher ) &&
          • this.setState({moduleName: 'topics'})} From 2d3d1efeaac179058d9e7a3e82dd45d41d966510 Mon Sep 17 00:00:00 2001 From: hjm <63528605@qq.com> Date: Tue, 10 Sep 2019 17:01:03 +0800 Subject: [PATCH 8/9] path --- public/react/src/App.js | 2 +- public/react/src/common/util/ShareUtil.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/public/react/src/App.js b/public/react/src/App.js index 194d8f22f..1a4aedc05 100644 --- a/public/react/src/App.js +++ b/public/react/src/App.js @@ -326,7 +326,7 @@ class App extends Component { }); wx.ready(function () { console.log('wx is ready') - configShareForIndex() + configShareForIndex('/') }); wx.error(function (res) { console.log('wx is error') diff --git a/public/react/src/common/util/ShareUtil.js b/public/react/src/common/util/ShareUtil.js index 845297899..24fffbf15 100644 --- a/public/react/src/common/util/ShareUtil.js +++ b/public/react/src/common/util/ShareUtil.js @@ -19,12 +19,12 @@ function share(shareData) { 单个课程和实训 获取课程/实训的简介 该课程或者实训展示的缩略图 */ -export function configShareForIndex () { +export function configShareForIndex (path) { if (!wx) return; var shareData = { title: 'EduCoder - 首页', desc: 'Educoder是一个面向计算机类的互联网IT教育和实战平台,提供企业级工程实训,以实现工程化专业教学的自动化和智能化。高校和企业人员可以在此开展计算机实践性教学活动,将传统的知识传授和时兴的工程实战一体化。', - link: host, + link: host + (path || ''), imgUrl: window.__testImageUrl || host + '/react/build/images/share_logo_icon.jpg' }; From 51ff15554d764058981b9ad165b5fffb121bef85 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Tue, 10 Sep 2019 17:01:15 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E8=AF=BE=E5=A0=82=E7=9A=84=E5=9C=A8?= =?UTF-8?q?=E7=BA=BF=E5=AD=A6=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/course_stages.js | 2 + app/assets/stylesheets/course_stages.scss | 3 + app/controllers/course_stages_controller.rb | 105 ++++++++++++++++++ app/controllers/courses_controller.rb | 4 +- app/helpers/course_stages_helper.rb | 2 + app/helpers/courses_helper.rb | 8 +- app/models/course.rb | 16 +++ app/views/course_stages/edit.json.jbuilder | 11 ++ .../courses/online_learning.json.jbuilder | 4 +- config/routes.rb | 7 ++ .../course_stages_controller_spec.rb | 5 + spec/helpers/course_stages_helper_spec.rb | 15 +++ 12 files changed, 174 insertions(+), 8 deletions(-) create mode 100644 app/assets/javascripts/course_stages.js create mode 100644 app/assets/stylesheets/course_stages.scss create mode 100644 app/controllers/course_stages_controller.rb create mode 100644 app/helpers/course_stages_helper.rb create mode 100644 app/views/course_stages/edit.json.jbuilder create mode 100644 spec/controllers/course_stages_controller_spec.rb create mode 100644 spec/helpers/course_stages_helper_spec.rb diff --git a/app/assets/javascripts/course_stages.js b/app/assets/javascripts/course_stages.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/course_stages.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/course_stages.scss b/app/assets/stylesheets/course_stages.scss new file mode 100644 index 000000000..faa60b4b0 --- /dev/null +++ b/app/assets/stylesheets/course_stages.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the course_stages controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/course_stages_controller.rb b/app/controllers/course_stages_controller.rb new file mode 100644 index 000000000..92e44a336 --- /dev/null +++ b/app/controllers/course_stages_controller.rb @@ -0,0 +1,105 @@ +class CourseStagesController < ApplicationController + before_action :require_login + before_action :find_course, only: [:create] + before_action :find_course_stage, only: [:update, :destroy, :edit, :up_position, :down_position] + before_action :user_course_identity, :teacher_allowed + + def create + ActiveRecord::Base.transaction do + begin + @stage = CourseStage.new(stage_params) + @stage.course_id = @course.id + @stage.position = @course.course_stages.count + 1 + @stage.save! + unless params[:shixun_id].blank? + shixuns = Shixun.where(id: params[:shixun_id]).order("field(id, #{params[:shixun_id].join(",")})") + shixuns.each do |shixun| + CourseStageShixun.create!(course_stage_id: @stage.id, course_id: @course.id, shixun_id: shixun.id, position: @stage.course_stage_shixuns.count + 1) + end + end + normal_status("创建成功") + rescue Exception => e + uid_logger_error(e.message) + tip_exception(e.message) + raise ActiveRecord::Rollback + end + end + end + + def edit + + end + + def update + ActiveRecord::Base.transaction do + begin + @stage.update_attributes!(stage_params) + @stage.course_stage_shixuns.destroy_all + unless params[:shixun_id].blank? + params[:shixun_id].each do |shixun_id| + shixun = Shixun.where(id: shixun_id).first + @stage.course_stage_shixuns.create!(course_id: @course.id, shixun_id: shixun.id, position: @stage.course_stage_shixuns.count + 1) if shixun.present? + end + end + normal_status("更新成功") + rescue Exception => e + uid_logger_error(e.message) + tip_exception(e.message) + raise ActiveRecord::Rollback + end + end + end + + def destroy + ActiveRecord::Base.transaction do + @course.course_stages.where("position > ?", @stage.position).update_all("position = position - 1") + @stage.destroy! + normal_status("删除成功") + end + end + + def up_position + ActiveRecord::Base.transaction do + begin + position = @stage.position + tip_exception("第一章不能向上移动") if @stage.position == 1 + pre_stage = @course.course_stages.where(position: position - 1).first + pre_stage.update_attributes(position: position) + @stage.update_attributes(position: position - 1) + normal_status("更新成功") + rescue Exception => e + uid_logger("stage up failed: #{e.message}") + raise ActiveRecord::Rollback + end + end + end + + def down_position + ActiveRecord::Base.transaction do + begin + position = @stage.position + rails "最后一章不能向下移动" if @stage.position == @course.course_stages.count + next_stage = @course.course_stages.where(position: position + 1).first + next_stage.update_attributes(position: position) + @stage.update_attributes(position: position + 1) + normal_status("更新成功") + rescue Exception => e + uid_logger("stage up failed: #{e.message}") + raise ActiveRecord::Rollback + end + end + end + + private + + def find_course_stage + @stage = CourseStage.find_by!(id: params[:id]) + @course = @stage.course + end + + def stage_params + tip_exception("章节名称不能为空") if params[:name].blank? + params.permit(:name, :description) + end + +end diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index c12b80da8..fc16c050d 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -267,9 +267,9 @@ class CoursesController < ApplicationController def online_learning @subject = @course.subject - @stages = @subject&.stages + @stages = @course.course_stages @user = current_user - @start_learning = @user_course_identity == Course::STUDENT && @subject&.learning?(current_user.id) + @start_learning = @user_course_identity == Course::STUDENT && @course.learning?(current_user.id) end def search_course_list diff --git a/app/helpers/course_stages_helper.rb b/app/helpers/course_stages_helper.rb new file mode 100644 index 000000000..7ebb68d9a --- /dev/null +++ b/app/helpers/course_stages_helper.rb @@ -0,0 +1,2 @@ +module CourseStagesHelper +end diff --git a/app/helpers/courses_helper.rb b/app/helpers/courses_helper.rb index cdb3225d6..6f6c76d04 100644 --- a/app/helpers/courses_helper.rb +++ b/app/helpers/courses_helper.rb @@ -269,10 +269,10 @@ module CoursesHelper group_info end - def last_subject_shixun user_id, subject - myshixun = Myshixun.where(user_id: user_id, shixun_id: subject&.shixuns).order("updated_at desc").first + def last_subject_shixun user_id, course + myshixun = Myshixun.where(user_id: user_id, shixun_id: course.shixuns).order("updated_at desc").first return "" unless myshixun - stage_shixun = subject&.stage_shixuns.where(shixun_id: myshixun.shixun_id).take - progress = stage_shixun&.stage&.position.to_s + "-" + stage_shixun&.position.to_s + " " + myshixun.shixun&.name + stage_shixun = course.course_stage_shixuns.where(shixun_id: myshixun.shixun_id).take + progress = stage_shixun&.course_stage&.position.to_s + "-" + stage_shixun&.position.to_s + " " + myshixun.shixun&.name end end diff --git a/app/models/course.rb b/app/models/course.rb index 2722c3b24..c66c597d4 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -70,6 +70,11 @@ class Course < ApplicationRecord has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy has_many :tidings, as: :container, dependent: :destroy + # 开放课堂 + has_many :course_stages, -> { order("course_stages.position ASC") }, dependent: :destroy + has_many :course_stage_shixuns, dependent: :destroy + has_many :shixuns, through: :course_stage_shixuns + # 老版的members弃用 现用course_members has_many :members @@ -344,6 +349,17 @@ class Course < ApplicationRecord end end + def learning? user_id + Myshixun.where(user_id: user_id, shixun_id: shixuns).exists? + end + + def my_subject_progress + my_challenge_count = Game.joins(:challenge).where(user_id: User.current.id, status: 2, challenges: {shixun_id: shixuns.published_closed}). + pluck(:challenge_id).uniq.size + course_challeng_count = course.shixuns.pluck(:challenges_count).sum + count = course_challeng_count == 0 ? 0 : ((my_challenge_count.to_f / course_challeng_count).round(2) * 100).to_i + end + private #创建课程后,给该用户发送消息 diff --git a/app/views/course_stages/edit.json.jbuilder b/app/views/course_stages/edit.json.jbuilder new file mode 100644 index 000000000..f76efb15f --- /dev/null +++ b/app/views/course_stages/edit.json.jbuilder @@ -0,0 +1,11 @@ +json.stage_id @stage.id +json.stage_name @stage.name +json.stage_description @stage.description +json.delete_path "/course_stages/#{@stage.id}" +json.shixuns_list do + json.array! @stage.shixuns.each do |shixun| + json.shixun_identifier shixun.identifier + json.shixun_name shixun.name + json.shixun_id shixun.id + end +end \ No newline at end of file diff --git a/app/views/courses/online_learning.json.jbuilder b/app/views/courses/online_learning.json.jbuilder index bec8ff301..9c87743ee 100644 --- a/app/views/courses/online_learning.json.jbuilder +++ b/app/views/courses/online_learning.json.jbuilder @@ -2,10 +2,10 @@ json.stages @stages do |stage| json.partial! 'stages/stage', locals: {stage: stage, user:@user, subject:@subject} end -json.description @subject&.description +# json.description @subject&.description json.start_learning @start_learning -json.learned @start_learning ? @subject&.my_subject_progress : 0 +json.learned @start_learning ? @course.my_subject_progress : 0 json.last_shixun @start_learning ? last_subject_shixun(@user.id, @subject) : "" \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 5cf74c29a..9e6b031be 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -371,6 +371,13 @@ Rails.application.routes.draw do get 'search_slim' end + resources :course_stages, shallow: true do + member do + post :up_position + post :down_position + end + end + resources :polls, only:[:index,:new,:create] do collection do post :publish # 立即发布 diff --git a/spec/controllers/course_stages_controller_spec.rb b/spec/controllers/course_stages_controller_spec.rb new file mode 100644 index 000000000..e63a2b6a4 --- /dev/null +++ b/spec/controllers/course_stages_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe CourseStagesController, type: :controller do + +end diff --git a/spec/helpers/course_stages_helper_spec.rb b/spec/helpers/course_stages_helper_spec.rb new file mode 100644 index 000000000..bb1081a10 --- /dev/null +++ b/spec/helpers/course_stages_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the CourseStagesHelper. For example: +# +# describe CourseStagesHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe CourseStagesHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end