Commit e0ac84f4 authored by Van's avatar Van

🎨 #12744

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