Commit 38b3d8ef authored by Van's avatar Van

🎨 #12720

parent b4b2236a
...@@ -17,9 +17,6 @@ ...@@ -17,9 +17,6 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
--> -->
<script src="${staticServePath}/js/lib/compress/pjax.min.js"></script>
<script src="${staticServePath}/js/common${miniPostfix}.js?${staticResourceVersion}"></script>
<script src="${staticServePath}/skins/${skinDirName}/js/common${miniPostfix}.js?${staticResourceVersion}"></script>
<script> <script>
var Label = { var Label = {
"servePath": "${servePath}", "servePath": "${servePath}",
......
...@@ -37,16 +37,7 @@ ...@@ -37,16 +37,7 @@
</div> </div>
</#if> </#if>
<script type="text/javascript"> <script type="text/javascript">
if (!window.Page) { Util.addScript('${staticServePath}/js/page${miniPostfix}.js?${staticResourceVersion}', 'soloPageScript')
var xhrObj = new XMLHttpRequest()
xhrObj.open('GET', '${staticServePath}/js/page${miniPostfix}.js?${staticResourceVersion}', false)
xhrObj.setRequestHeader('Accept', 'text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01')
xhrObj.send('')
var scriptElement = document.createElement('script')
scriptElement.type = 'text/javascript'
scriptElement.text = xhrObj.responseText
document.getElementsByTagName('head')[0].appendChild(scriptElement)
}
var page = new Page({ var page = new Page({
"commentContentCannotEmptyLabel": "${commentContentCannotEmptyLabel}", "commentContentCannotEmptyLabel": "${commentContentCannotEmptyLabel}",
"oId": "${oId}", "oId": "${oId}",
......
...@@ -103,6 +103,11 @@ var Util = { ...@@ -103,6 +103,11 @@ var Util = {
window.open(this.src) window.open(this.src)
}) })
}, },
/**
* 异步添加 css
* @param url css 文件访问地址
* @param id css 文件标示
*/
addStyle: function (url, id) { addStyle: function (url, id) {
if (!document.getElementById(id)) { if (!document.getElementById(id)) {
var styleElement = document.createElement('link') var styleElement = document.createElement('link')
...@@ -113,6 +118,25 @@ var Util = { ...@@ -113,6 +118,25 @@ var Util = {
document.getElementsByTagName('head')[0].appendChild(styleElement) document.getElementsByTagName('head')[0].appendChild(styleElement)
} }
}, },
/**
* 异步添加 js
* @param url js 文件访问地址
* @param id js 文件标示
*/
addScript: function (url, id) {
if (!document.getElementById(id)) {
var xhrObj = new XMLHttpRequest()
xhrObj.open('GET', url, false)
xhrObj.setRequestHeader('Accept',
'text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01')
xhrObj.send('')
var scriptElement = document.createElement('script')
scriptElement.id = id
scriptElement.type = 'text/javascript'
scriptElement.text = xhrObj.responseText
document.getElementsByTagName('head')[0].appendChild(scriptElement)
}
},
/* /*
* @description 解析语法高亮 * @description 解析语法高亮
*/ */
...@@ -141,23 +165,19 @@ var Util = { ...@@ -141,23 +165,19 @@ var Util = {
} }
}, },
/** /**
* 按需加载 MathJax 及图标 * 按需加载数学公式、代码复制、图标
* @returns {undefined} * @returns {undefined}
*/ */
parseMarkdown: function () { parseMarkdown: function () {
if (!window.Vditor) { var text = $('.vditor-reset').text()
var xhrObj = new XMLHttpRequest() if ($('.vditor-reset pre > code').length === 0 ||
xhrObj.open('GET', Label.staticServePath + !(text.split('$').length > 2 ||
'/js/lib/vditor-1.1.10/index.min.js', false) (text.split('\\(').length > 1 && text.split('\\)').length > 1))) {
xhrObj.setRequestHeader('Accept', return
'text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, */*; q=0.01')
xhrObj.send('')
var scriptElement = document.createElement('script')
scriptElement.type = 'text/javascript'
scriptElement.text = xhrObj.responseText
document.getElementsByTagName('head')[0].appendChild(scriptElement)
} }
Util.addScript(Label.staticServePath + '/js/lib/vditor-1.1.10/index.min.js', 'vditorScript')
Vditor.mermaidRender(document.body) Vditor.mermaidRender(document.body)
Vditor.mathRender(document.body) Vditor.mathRender(document.body)
Vditor.codeRender(document.body, Label.langLabel) Vditor.codeRender(document.body, Label.langLabel)
......
...@@ -65,6 +65,7 @@ $.extend(Page.prototype, { ...@@ -65,6 +65,7 @@ $.extend(Page.prototype, {
if (typeof vditor === 'undefined') { if (typeof vditor === 'undefined') {
var that = this var that = this
Util.addScript(Label.staticServePath + '/js/lib/vditor-1.1.10/index.min.js', 'vditorScript')
window.vditor = new Vditor('soloEditorComment', { window.vditor = new Vditor('soloEditorComment', {
placeholder: that.tips.commentContentCannotEmptyLabel, placeholder: that.tips.commentContentCannotEmptyLabel,
height: 180, height: 180,
......
Subproject commit 1605dceed8fe66f27f266881e237957248d23fb7 Subproject commit 8c9b13c393450bd679876182c350de5fd7bd8d2c
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment