搞定自动保存

This commit is contained in:
joyqi
2013-10-16 01:37:33 +08:00
parent 177d426913
commit caac2ea4b2
8 changed files with 974 additions and 712 deletions
+47
View File
@@ -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();