mirror of
https://github.com/typecho/typecho.git
synced 2025-03-20 01:49:40 +01:00
搞定自动保存
This commit is contained in:
parent
177d426913
commit
caac2ea4b2
@ -2119,6 +2119,8 @@ ul.typecho-list-notable li .loading {
|
||||
}
|
||||
#ui-datepicker-div .ui-datepicker-close { float: right; }
|
||||
|
||||
.ui-effects-transfer { border: 2px dotted #ccc; }
|
||||
|
||||
|
||||
/*
|
||||
* Jquery Tokeninput
|
||||
|
1508
admin/javascript/jquery-ui.js
vendored
1508
admin/javascript/jquery-ui.js
vendored
File diff suppressed because it is too large
Load Diff
@ -186,9 +186,9 @@ $.TokenList = function (input, url_or_data, settings) {
|
||||
|
||||
// Create a new text input an attach keyup events
|
||||
var input_box = $("<input type=\"text\" autocomplete=\"off\">")
|
||||
// .css({
|
||||
// outline: "none"
|
||||
// })
|
||||
.css({
|
||||
outline: "none"
|
||||
})
|
||||
.attr("id", settings.idPrefix + input.id)
|
||||
.focus(function () {
|
||||
if (settings.tokenLimit === null || settings.tokenLimit !== token_count) {
|
||||
|
@ -885,3 +885,112 @@ $.fn.extend({
|
||||
|
||||
})(jQuery);
|
||||
|
||||
/*
|
||||
* jQuery plugin: fieldSelection - v0.1.1 - last change: 2006-12-16
|
||||
* (c) 2006 Alex Brem <alex@0xab.cd> - http://blog.0xab.cd
|
||||
*/
|
||||
|
||||
jQuery.fn.extend({
|
||||
getSelection: function () {
|
||||
|
||||
var e = this.get(0);
|
||||
if (!e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
/* mozilla / dom 3.0 */
|
||||
('selectionStart' in e && function() {
|
||||
var l = e.selectionEnd - e.selectionStart;
|
||||
return { start: e.selectionStart, end: e.selectionEnd, length: l, text: e.value.substr(e.selectionStart, l) };
|
||||
}) ||
|
||||
|
||||
/* other */
|
||||
(window.getSelection() && function () {
|
||||
var selection = window.getSelection(), range = selection.getRangeAt(0);
|
||||
|
||||
return { start: range.startOffset, end: range.endOffset, length: range.endOffset - range.startOffset, text: range.toString()};
|
||||
|
||||
}) ||
|
||||
|
||||
/* exploder */
|
||||
(document.selection && function() {
|
||||
|
||||
e.focus();
|
||||
|
||||
var r = document.selection.createRange();
|
||||
if (r === null) {
|
||||
return { start: 0, end: e.value.length, length: 0 }
|
||||
}
|
||||
|
||||
var re = e.createTextRange();
|
||||
var rc = re.duplicate();
|
||||
re.moveToBookmark(r.getBookmark());
|
||||
rc.setEndPoint('EndToStart', re);
|
||||
|
||||
return { start: rc.text.length, end: rc.text.length + r.text.length, length: r.text.length, text: r.text };
|
||||
}) ||
|
||||
|
||||
/* browser not supported */
|
||||
function() { return null; }
|
||||
|
||||
)();
|
||||
},
|
||||
|
||||
setSelection: function (start, end) {
|
||||
var e = this.get(0);
|
||||
if (!e) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($.browser.opera && $.browser.version >= 9.5 && len == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (e.setSelectionRange) {
|
||||
e.focus();
|
||||
e.setSelectionRange(start, end);
|
||||
} else if (e.createTextRange) {
|
||||
var range = e.createTextRange();
|
||||
range.collapse(true);
|
||||
range.moveEnd('character', end);
|
||||
range.moveStart('character', start);
|
||||
range.select();
|
||||
}
|
||||
},
|
||||
|
||||
replaceSelection: function () {
|
||||
|
||||
var e = this.get(0);
|
||||
if (!e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var text = arguments[0] || '';
|
||||
|
||||
return (
|
||||
|
||||
/* mozilla / dom 3.0 */
|
||||
('selectionStart' in e && function() {
|
||||
e.value = e.value.substr(0, e.selectionStart) + text + e.value.substr(e.selectionEnd, e.value.length);
|
||||
return this;
|
||||
}) ||
|
||||
|
||||
/* exploder */
|
||||
(document.selection && function() {
|
||||
e.focus();
|
||||
document.selection.createRange().text = text;
|
||||
return this;
|
||||
}) ||
|
||||
|
||||
/* browser not supported */
|
||||
function() {
|
||||
e.value += text;
|
||||
return jQuery(e);
|
||||
}
|
||||
|
||||
)();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -77,6 +77,7 @@ $(document).ready(function() {
|
||||
t.width($('.token-input-list').outerWidth() - offset);
|
||||
});
|
||||
|
||||
// 缩略名自适应宽度
|
||||
var slug = $('#slug'), sw = slug.width();
|
||||
|
||||
if (slug.val().length > 0) {
|
||||
@ -93,6 +94,52 @@ $(document).ready(function() {
|
||||
}
|
||||
}).width();
|
||||
|
||||
// 自动保存
|
||||
<?php if ($options->autoSave): ?>
|
||||
var savedData = null, locked = false,
|
||||
form = $('form[name=write_post],form[name=write_page]'),
|
||||
formAction = form.attr('action'),
|
||||
idInput = $('input[name=cid]'),
|
||||
autoSave = $('#auto-save-message'),
|
||||
autoSaveOnce = !!idInput.val(),
|
||||
lastSaveTime = null;
|
||||
|
||||
function autoSaveListener () {
|
||||
setInterval(function () {
|
||||
var data = form.serialize();
|
||||
|
||||
if (savedData != data) {
|
||||
savedData = data;
|
||||
locked = true;
|
||||
|
||||
autoSave.text('<?php _e('正在保存'); ?>');
|
||||
$.post(formAction + '?do=save', data, function (o) {
|
||||
lastSaveTime = o.time;
|
||||
idInput.val(o.cid);
|
||||
autoSave.text('<?php _e('内容已经保存'); ?>' + ' (' + o.time + ')').effect('highlight', '#AACB36', 1000);
|
||||
locked = false;
|
||||
});
|
||||
}
|
||||
}, 10000);
|
||||
}
|
||||
|
||||
if (autoSaveOnce) {
|
||||
savedData = form.serialize();
|
||||
autoSaveListener();
|
||||
}
|
||||
|
||||
$('#text').bind('input propertychange', function () {
|
||||
if (!locked) {
|
||||
autoSave.text('<?php _e('内容尚未保存'); ?>' + (lastSaveTime ? ' (<?php _e('上次保存时间'); ?>: ' + lastSaveTime + ')' : ''));
|
||||
}
|
||||
|
||||
if (!autoSaveOnce) {
|
||||
autoSaveOnce = true;
|
||||
autoSaveListener();
|
||||
}
|
||||
});
|
||||
<?php endif; ?>
|
||||
|
||||
// 高级选项控制
|
||||
$('#advance-panel-btn').click(function() {
|
||||
$('#advance-panel').toggle();
|
||||
|
@ -51,7 +51,7 @@ Typecho_Widget::widget('Widget_Contents_Post_Edit')->to($post);
|
||||
<?php Typecho_Plugin::factory('admin/write-post.php')->content($post); ?>
|
||||
<p class="submit">
|
||||
<span class="left">
|
||||
<span id="auto-save-message">保存于 1 分钟前</span>
|
||||
<span id="auto-save-message"></span>
|
||||
</span>
|
||||
|
||||
<span class="right">
|
||||
|
@ -91,9 +91,9 @@ class Widget_Contents_Page_Edit extends Widget_Contents_Post_Edit implements Wid
|
||||
if ($this->request->isAjax()) {
|
||||
$created = new Typecho_Date($this->options->gmtTime);
|
||||
$this->response->throwJson(array(
|
||||
'success' => 1,
|
||||
'message' => _t('文章保存于 %s', $created->format('H:i A')),
|
||||
'cid' => $this->cid
|
||||
'success' => 1,
|
||||
'time' => $created->format('H:i:s A'),
|
||||
'cid' => $this->cid
|
||||
));
|
||||
} else {
|
||||
/** 设置提示信息 */
|
||||
|
@ -588,9 +588,9 @@ class Widget_Contents_Post_Edit extends Widget_Abstract_Contents implements Widg
|
||||
if ($this->request->isAjax()) {
|
||||
$created = new Typecho_Date($this->options->gmtTime);
|
||||
$this->response->throwJson(array(
|
||||
'success' => 1,
|
||||
'message' => _t('文章保存于 %s', $created->format('H:i A')),
|
||||
'cid' => $this->cid
|
||||
'success' => 1,
|
||||
'time' => $created->format('H:i:s A'),
|
||||
'cid' => $this->cid
|
||||
));
|
||||
} else {
|
||||
/** 设置提示信息 */
|
||||
|
Loading…
x
Reference in New Issue
Block a user