Commit e0ac84f4 authored by Van's avatar Van

🎨 #12744

parent cf40c6ef
......@@ -266,7 +266,6 @@ blogSubtitle1Label=Blog Subtitle:
blogHost1Label=<a href="https://github.com/b3log/solo/issues/12716" target="_blank">Blog Domain</a>:
submmitCommentLabel=Commit Comment
saveLabel=Save
autoSaveLabel=Auto Save
tagLabel=Tag
tagsLabel=Tags
indexLabel=Index
......
......@@ -266,7 +266,6 @@ blogSubtitle1Label=\u535A\u5BA2\u5B50\u6807\u9898\uFF1A
blogHost1Label=<a href="https://github.com/b3log/solo/issues/12716" target="_blank">\u535A\u5BA2\u57DF\u540D</a>\uFF1A
submmitCommentLabel=\u63D0\u4EA4\u8BC4\u8BBA
saveLabel=\u4FDD\u5B58
autoSaveLabel=\u81EA\u52A8\u4FDD\u5B58
tagLabel=\u6807\u7B7E
tagsLabel=\u6807\u7B7E
indexLabel=\u9996\u9875
......
......@@ -98,7 +98,6 @@
Label.visitorUserLabel = "${visitorUserLabel}"
Label.categoryTooLongLabel = "${categoryTooLongLabel}"
Label.descriptionLabel = "${descriptionLabel}"
Label.autoSaveLabel = "${autoSaveLabel}"
Label.previewLabel = '${previewLabel}'
admin.init()
</script>
\ No newline at end of file
......@@ -35,9 +35,9 @@ Util.htmlDecode = function (code) {
*/
Util.proessURL = function (url) {
if (!/^\w+:\/\//.test(url)) {
url = "http://" + url;
url = 'http://' + url
}
return url;
return url
}
var Admin = function () {
......@@ -133,37 +133,14 @@ $.extend(Admin.prototype, {
return
}
if (tab !== 'article') {
admin.article.clearDraftTimer()
} else if (tab === 'article') {
admin.article.autoSaveDraftTimer = setInterval(function () {
admin.article._autoSaveToDraft()
}, admin.article.AUTOSAVETIME)
}
// 离开编辑器时进行提示
try {
// 除更新、发布、取消发布文章,编辑器中无内容外,离开编辑器需进行提示。
if (tab !== 'article' && admin.article.isConfirm &&
admin.editors.articleEditor.getContent().replace(/\s/g, '') !== ''
&& admin.article.content !== admin.editors.articleEditor.getContent()) {
if (!confirm(Label.editorLeaveLabel)) {
window.location.hash = '#article/article'
return
}
}
// 不离开编辑器,hash 需变为 "#article/article",此时不需要做任何处理。
if (tab === 'article' && admin.article.isConfirm &&
admin.editors.articleEditor.getContent().replace(/\s/g, '') !== ''
&& admin.article.content !== admin.editors.articleEditor.getContent()) {
return
}
} catch (e) {
var $articleContent = $('#articleContent')
if ($articleContent.length > 0) {
if (admin.editors.articleEditor.getContent) {
// 除更新、发布、取消发布文章,编辑器中无内容外,离开编辑器需进行提示。
if (tab !== 'article' && admin.article.isConfirm &&
$articleContent.val().replace(/\s/g, '') !== ''
&& admin.article.content !== $articleContent.val()) {
admin.editors.articleEditor.getContent().replace(/\s/g, '') !== ''
&& admin.article.content !==
admin.editors.articleEditor.getContent()) {
if (!confirm(Label.editorLeaveLabel)) {
window.location.hash = '#article/article'
return
......@@ -171,11 +148,14 @@ $.extend(Admin.prototype, {
}
// 不离开编辑器,hash 需变为 "#article/article",此时不需要做任何处理。
if (tab === 'article' && admin.article.isConfirm &&
$articleContent.val().replace(/\s/g, '') !== ''
&& admin.article.content !== $articleContent.val()) {
admin.editors.articleEditor.getContent().replace(/\s/g, '') !== ''
&& admin.article.content !==
admin.editors.articleEditor.getContent()) {
return
}
}
} catch (e) {
console.log(e)
}
// clear article
......@@ -252,6 +232,15 @@ $.extend(Admin.prototype, {
}
}, 6000)
$('#loadMsg').text('')
window.onbeforeunload = (event) => {
if (window.location.hash === '#article/article') {
if (event) {
event.returnValue = Label.editorLeaveLabel
}
return Label.editorLeaveLabel
}
}
},
/**
* @description tools and article collapse
......
......@@ -30,10 +30,6 @@ admin.article = {
isArticle: undefined,
},
content: '',
// 自动保存草稿定时器
autoSaveDraftTimer: '',
// 自动保存间隔
AUTOSAVETIME: 1000 * 60,
/**
* @description 获取文章并把值塞入发布文章页面
* @param {String} id 文章 id
......@@ -133,9 +129,8 @@ admin.article = {
/**
* @@description 添加文章
* @param {Boolean} articleStatus 0:已发布,1:草稿
* @param {Boolean} isAuto 是否为自动保存
*/
add: function (articleStatus, isAuto) {
add: function (articleStatus) {
if (admin.article.validate()) {
var that = this
that._addDisabled()
......@@ -180,20 +175,14 @@ admin.article = {
type: 'POST',
cache: false,
data: JSON.stringify(requestJSONObject),
success: function (result, textStatus) {
if (isAuto) {
$('#tipMsg').text(Label.autoSaveLabel)
admin.article.status.id = result.oId
return
}
success: function (result) {
$('#tipMsg').text(result.msg)
if (!result.sc) {
return
}
admin.article.status.id = undefined
if (articleStatus === 0) {
admin.article.status.id = undefined
admin.selectTab('article/article-list')
} else {
admin.selectTab('article/draft-list')
......@@ -211,9 +200,8 @@ admin.article = {
/**
* @description 更新文章
* @param {Boolean} articleStatus 0:已发布,1:草稿
* @param {Boolean} isAuto 是否为自动保存
*/
update: function (articleStatus, isAuto) {
update: function (articleStatus) {
if (admin.article.validate()) {
var that = this
that._addDisabled()
......@@ -258,11 +246,6 @@ admin.article = {
cache: false,
data: JSON.stringify(requestJSONObject),
success: function (result, textStatus) {
if (isAuto) {
$('#tipMsg').text(Label.autoSaveLabel)
return
}
$('#tipMsg').text(result.msg)
if (!result.sc) {
return
......@@ -445,11 +428,6 @@ admin.article = {
resize: true,
})
admin.article.clearDraftTimer()
admin.article.autoSaveDraftTimer = setInterval(function () {
admin.article._autoSaveToDraft()
}, admin.article.AUTOSAVETIME)
// thumbnail
$('#articleThumbnailBtn').click(function () {
$.ajax({// Gets all tags
......@@ -469,32 +447,6 @@ admin.article = {
})
}).click()
},
/**
* @description 自动保存草稿件
*/
_autoSaveToDraft: function () {
if ($('#title').val().replace(/\s/g, '') === '' ||
admin.editors.articleEditor.getContent().replace(/\s/g, '') === '') {
return
}
if (admin.article.status.id) {
if (!admin.article.status.isArticle) {
admin.article.update(1, true)
}
} else {
admin.article.add(1, true)
admin.article.status.isArticle = false
}
},
/**
* @description 关闭定时器
*/
clearDraftTimer: function () {
if (admin.article.autoSaveDraftTimer !== '') {
window.clearInterval(admin.article.autoSaveDraftTimer)
admin.article.autoSaveDraftTimer = ''
}
},
/**
* @description 验证发布文章字段的合法性
*/
......@@ -513,9 +465,8 @@ admin.article = {
},
/**
* @description 取消发布
* @param {Boolean} isAuto 是否为自动保存
*/
unPublish: function (isAuto) {
unPublish: function () {
var that = this
that._addDisabled()
$.ajax({
......@@ -524,11 +475,6 @@ admin.article = {
type: 'PUT',
cache: false,
success: function (result, textStatus) {
if (isAuto) {
$('#tipMsg').text(Label.autoSaveLabel)
return
}
$('#tipMsg').text(result.msg)
if (!result.sc) {
return
......
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