From cbf111179b8d0fbb5bb539b2e576f67a422e55ad Mon Sep 17 00:00:00 2001 From: cxt Date: Fri, 21 Jul 2017 10:03:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E8=AE=AD=E6=96=B0=E5=BB=BA=E3=80=81?= =?UTF-8?q?=E9=A2=84=E5=A4=87=E7=9F=A5=E8=AF=86=E3=80=81=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E7=9A=84markdown=E8=87=AA=E5=8A=A8=E4=BF=9D?= =?UTF-8?q?=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/shixuns/_form.html.erb | 136 +++------------------- app/views/shixuns/_settings_edit.html.erb | 2 + app/views/shixuns/_settings_show.html.erb | 10 ++ app/views/shixuns/propaedeutics.html.erb | 13 ++- public/javascripts/edu/application.js | 52 +++++++++ 5 files changed, 91 insertions(+), 122 deletions(-) diff --git a/app/views/shixuns/_form.html.erb b/app/views/shixuns/_form.html.erb index ef93c6a78..fbc030f94 100644 --- a/app/views/shixuns/_form.html.erb +++ b/app/views/shixuns/_form.html.erb @@ -139,6 +139,8 @@ } window.onload = function(){ + console.log(shixun_editormd); + $("#shixun_introduction [type=\"latex\"]").bind("click", function(){ shixun_editormd.cm.replaceSelection("```latex"); shixun_editormd.cm.replaceSelection("\n"); @@ -175,8 +177,8 @@ }; $(function(){ -// md_elocalStorage($("textarea[name='shixun[description]']"),"shixun_in_<%#= User.current.id %>","in"); -// md_elocalStorage($("textarea[name='shixun[propaedeutics]']"),"shixun_pr_<%#= User.current.id %>","pr"); + md_elocalStorage(shixun_editormd,"shixun_in_<%= User.current.id %>","in"); + md_elocalStorage(shixun_propaedeutics,"shixun_pr_<%= User.current.id %>","pr"); //$("textarea[name='shixun[description]']").md_elocalStorage(); // 防止刷新页面后适用课程的下拉列表为空 @@ -259,123 +261,15 @@ $(".lesson_checkbox").html(""); } }); -// var editor_in; -// var editor_pr; -// function md_elocalStorage(editor,mdu,id){ -// if (window.sessionStorage){ -// if(id=="in"){ -// editor_in = editor; -// } else{ -// editor_pr = editor; -// } -// var oc = window.sessionStorage.getItem('content'+mdu); -// if(oc !== null ){ -// var h = '您上次有已保存的数据,是否恢复 ? / 不恢复'; -// $("#e_tips_"+id).html(h); -// } -// setInterval(function() { -// d = new Date(); -// var h = d.getHours(); -// var m = d.getMinutes(); -// var s = d.getSeconds(); -// h = h < 10 ? '0' + h : h; -// m = m < 10 ? '0' + m : m; -// s = s < 10 ? '0' + s : s; -// if(editor.val().trim() != ""){ -// md_add_data("content",mdu,editor.val()); -// var id1 = "#e_tip_"+id; -// var id2 = "#e_tips_"+id; -// $(id1).html(" 数据已于 " + h + ':' + m + ':' + s +" 保存 "); -// $(id2).html(""); -// } -// },10000); -// -// }else{ -// $('.ke-edit').after('您的浏览器不支持localStorage.无法开启自动保存草稿服务,请升级浏览器!'); -// } -// } -// function md_add_data(k,mdu,d){ -// console.log(d); -// window.sessionStorage.setItem(k+mdu,d); -// } -// function md_rec_data(k,mdu,id){ -// if(window.sessionStorage.getItem(k+mdu) !== null){ -// if(id == "in"){ -// editor_in.val(window.sessionStorage.getItem(k+mdu)); -// } else{ -// editor_pr.val(window.sessionStorage.getItem(k+mdu)); -// } -// if(id == "pr"){ -// console.log(shixun_propaedeutics); -// /* --------------------------------- 预备知识 -------------------------------------- */ -// var shixun_propaedeutics = editormd("shixun_propaedeutics", { -// width : "89.7%", -// height : 300, -// syncScrolling : "single", -// //你的lib目录的路径,我这边用JSP做测试的 -// path : "/editormd/lib/", -// tex : true, -// toolbarIcons : function() { -// // Or return editormd.toolbarModes[name]; // full, simple, mini -// // Using "||" set icons align right. -// return ["bold", "italic", "|", "list-ul", "list-ol", "|", "code", "code-block", "|", "testIcon", "testIcon1", '|', "image", "table", '|', "watch", "clear" ] -// }, -// toolbarCustomIcons : { -// testIcon : "
", -// testIcon1 : "
" -// }, -// //这个配置在simple.html中并没有,但是为了能够提交表单,使用这个配置可以让构造出来的HTML代码直接在第二个隐藏的textarea域中,方便post提交表单。 -// saveHTMLToTextarea : true, -// autoFocus: false, -// // 用于增加自定义工具栏的功能,可以直接插入HTML标签,不使用默认的元素创建图标 -// dialogMaskOpacity : 0.6, -// placeholder: "请输入完成当前任务依赖的知识点或者其它相关信息", -// imageUpload : true, -// imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"], -// imageUploadURL : "<%= upload_with_markdown_path(:container_id => @shixun.id, :container_type => @shixun.class) %>" //url -// }); -// shixun_propaedeutics.getHTML(); -// } else{ -// var shixun_editormd = editormd("shixun_introduction", { -// width : "89.7%", -// height : 300, -// syncScrolling : "single", -// //你的lib目录的路径,我这边用JSP做测试的 -// path : "/editormd/lib/", -// tex : true, -// toolbarIcons : function() { -// // Or return editormd.toolbarModes[name]; // full, simple, mini -// // Using "||" set icons align right. -// return ["bold", "italic", "|", "list-ul", "list-ol", "|", "code", "code-block", "|", "testIcon", "testIcon1", '|', "image", "table", '|', "watch", "clear" ] -// }, -// -// toolbarCustomIcons : { -// testIcon : "
", -// testIcon1 : "
" -// }, -// //这个配置在simple.html中并没有,但是为了能够提交表单,使用这个配置可以让构造出来的HTML代码直接在第二个隐藏的textarea域中,方便post提交表单。 -// saveHTMLToTextarea : true, -// autoFocus: false, -// // 用于增加自定义工具栏的功能,可以直接插入HTML标签,不使用默认的元素创建图标 -// dialogMaskOpacity : 0.6, -// placeholder: "请输入完成当前任务依赖的知识点或者其它相关信息", -// imageUpload : true, -// imageFormats : ["jpg", "jpeg", "gif", "png", "bmp", "webp", "JPG", "JPEG", "GIF", "PNG", "BMP", "WEBP"], -// imageUploadURL : "<%= upload_with_markdown_path(:container_id => @shixun.id, :container_type => @shixun.class) %>" //url -// }); -// shixun_editormd.getHTML(); -// } -// md_clear_data(k,mdu,id); -// } -// } -// function md_clear_data(k,mdu,id){ -// window.sessionStorage.removeItem(k+mdu); -// var id1 = "#e_tip_"+id; -// var id2 = "#e_tips_"+id; -// if(k == 'content'){ -// $(id2).html(""); -// }else{ -// $(id1).html(""); -// } -// } + + function md_rec_data(k,mdu,id){ + if(window.sessionStorage.getItem(k+mdu) !== null){ + if(id == "in"){ + shixun_editormd.setValue(window.sessionStorage.getItem(k+mdu)); + } else{ + shixun_propaedeutics.setValue(window.sessionStorage.getItem(k+mdu)); + } + md_clear_data(k,mdu,id); + } + } \ No newline at end of file diff --git a/app/views/shixuns/_settings_edit.html.erb b/app/views/shixuns/_settings_edit.html.erb index 42930ea95..682c3bb28 100644 --- a/app/views/shixuns/_settings_edit.html.erb +++ b/app/views/shixuns/_settings_edit.html.erb @@ -11,6 +11,8 @@
+

+