Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0a9efac

Browse files
author
xuxinhua
committed
代码
1 parent 31cb12a commit 0a9efac

File tree

2 files changed

+76
-8
lines changed

2 files changed

+76
-8
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
(function(){
2+
SG.Projects = function() {}
3+
SG.Projects.prototype = new SG.Publisher();
4+
SG.Projects.prototype.parseDesc = function(){
5+
var markdownString = $('.project .desc').text();
6+
// 配置 marked 语法高亮
7+
marked = SG.markSetting();
8+
9+
var contentHtml = marked(markdownString);
10+
contentHtml = SG.replaceCodeChar(contentHtml);
11+
12+
$('.project .desc').html(contentHtml);
13+
}
14+
15+
jQuery(document).ready(function($) {
16+
var IS_PREVIEW = false;
17+
$('.desc .preview').on('click', function(){
18+
// console.log(hljs.listLanguages());
19+
if (IS_PREVIEW) {
20+
$('.preview-div').hide();
21+
$('#desc').show();
22+
IS_PREVIEW = false;
23+
} else {
24+
var markdownString = $('#desc').val();
25+
// 配置 marked 语法高亮
26+
marked.setOptions({
27+
highlight: function (code) {
28+
code = code.replace(/"/g, '"');
29+
code = code.replace(/&lt;/g, '<');
30+
code = code.replace(/&gt;/g, '>');
31+
return hljs.highlightAuto(code).value;
32+
}
33+
});
34+
35+
$('#desc').hide();
36+
$('.preview-div').html(marked(markdownString)).show();
37+
IS_PREVIEW = true;
38+
}
39+
});
40+
41+
// 发布项目
42+
$('#submit').on('click', function(evt){
43+
evt.preventDefault();
44+
var validator = $('.validate-form').validate();
45+
if (!validator.form()) {
46+
return false;
47+
}
48+
49+
var projects = new SG.Projects()
50+
projects.publish(this);
51+
});
52+
53+
$(document).keypress(function(evt){
54+
if (evt.ctrlKey && (evt.which == 10 || evt.which == 13)) {
55+
$('#submit').click();
56+
}
57+
});
58+
});
59+
}).call(this)

websites/code/studygolang/template/codes/new.html

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@
1919
<div class="form-group form-group-sm">
2020
<label class="col-sm-2 control-label" for="title"><abbr>*</abbr>标题</label>
2121
<div class="col-sm-9">
22-
<input class="form-control required" type="text" id="title" name="title" placeholder="标题" value="{{.code.Title}}">
22+
<input class="form-control required" type="text" id="title" name="title" placeholder="一句话概述代码的用途" value="{{.code.Title}}">
2323
</div>
2424
</div>
2525
<div class="form-group form-group-sm">
26-
<label class="col-sm-2 control-label" for="remark">代码说明</label>
26+
<label class="col-sm-2 control-label" for="remark">简单介绍</label>
2727
<div class="col-sm-9">
2828
<textarea class="form-control need-autogrow" id="desc" name="desc" rows="5">{{.code.Remark}}</textarea>
29+
<span class="help-block">例如代码出处、适用的平台、所依赖的项目等等(可选)</span>
2930
</div>
3031
</div>
3132
<div class="form-group form-group-sm">
@@ -52,11 +53,19 @@
5253
</div>
5354
<div class="col-lg-3 col-md-4 col-sm-5">
5455
<div class="row box_white sidebar">
55-
<script type="text/javascript">
56-
var cpro_id="u1996895";
57-
(window["cproStyleApi"] = window["cproStyleApi"] || {})[cpro_id]={at:"3",rsi0:"291",rsi1:"291",pat:"6",tn:"baiduCustNativeAD",rss1:"#FFFFFF",conBW:"0",adp:"1",ptt:"0",titFF:"%E5%BE%AE%E8%BD%AF%E9%9B%85%E9%BB%91",titFS:"14",rss2:"#000000",titSU:"0",ptbg:"90",piw:"0",pih:"0",ptp:"0"}
58-
</script>
59-
<script src="http://cpro.baidustatic.com/cpro/ui/c.js" type="text/javascript"></script>
56+
<div class="top">
57+
<h3 class="title"><i class="glyphicon glyphicon-list-alt"></i>&nbsp;分享代码提示</h3>
58+
</div>
59+
<div class="sb-content">
60+
<span class="help-block">
61+
<ul>
62+
<li>第一次分享代码之前,请先参考别人的作品</li>
63+
<li>请先搜索一下是否已有人发布同样代码</li>
64+
<li>代码将在下一步输入,而不是“简单介绍”</li>
65+
<li>标签应尽可能短,不要包含其他标点符号</li>
66+
</ul>
67+
</span>
68+
</div>
6069
</div>
6170

6271
<div class="row box_white sidebar">
@@ -94,7 +103,7 @@
94103
<script type="text/javascript" src="/static/js/libs/jquery.validate.msg.cn.js"></script>
95104
<script type="text/javascript" src="/static/js/libs/marked.min.js"></script>
96105
<script type="text/javascript" src="/static/js/libs/highlight.min.js"></script>
97-
<script type="text/javascript" src="/static/js/projects.js?v=1.0"></script>
106+
<script type="text/javascript" src="/static/js/codes.js"></script>
98107
<script type="text/javascript">
99108
// 需要加载的侧边栏
100109
SG.SIDE_BARS = [

0 commit comments

Comments
 (0)