'wcf.bbcode.quote.title.clickToSet': '{lang}wcf.bbcode.quote.title.clickToSet{/lang}',
'wcf.bbcode.quote.title.javascript': '{lang}wcf.bbcode.quote.title.javascript{/lang}',
'wcf.global.noSelection': '{lang}wcf.global.noSelection{/lang}',
+ 'wcf.message.autosave.prompt': '{lang}wcf.message.autosave.prompt{/lang}',
+ 'wcf.message.autosave.prompt.confirm': '{lang}wcf.message.autosave.prompt.confirm{/lang}',
+ 'wcf.message.autosave.prompt.discard': '{lang}wcf.message.autosave.prompt.discard{/lang}',
'wcf.message.autosave.restored': '{lang}wcf.message.autosave.restored{/lang}',
'wcf.message.autosave.restored.confirm': '{lang}wcf.message.autosave.restored.confirm{/lang}',
'wcf.message.autosave.restored.revert': '{lang}wcf.message.autosave.restored.revert{/lang}',
{include file='wysiwygToolbar'}
var $autosave = $textarea.data('autosave');
+ var $autosaveLastEditTime = ($autosave && $textarea.data('autosaveLastEditTime')) ? (parseInt($textarea.data('autosaveLastEditTime')) || 0) : 0;
+ var $autosavePrompt = ($autosave && $textarea.data('autosavePrompt')) ? true : false;
var $config = {
autosave: false,
buttons: $buttons,
autosave: {
active: ($autosave) ? true : false,
key: ($autosave) ? '{@$__wcf->getAutosavePrefix()}_' + $autosave : '',
+ lastEditTime: $autosaveLastEditTime,
prefix: '{@$__wcf->getAutosavePrefix()}',
+ prompt: $autosavePrompt,
saveOnInit: {if !$errorField|empty}true{else}false{/if}
},
originalValue: $textarea.val()
return false;
}
+ if ($options.lastEditTime && ($options.lastEditTime * 1000) > $text.timestamp) {
+ // stored message is older than last edit time, consider it tainted and discard
+ this.wutil.autosavePurge();
+
+ return false;
+ }
+
+ if ($options.prompt) {
+ this.wutil.autosaveShowNotice('prompt', $text);
+
+ return false;
+ }
+
if (this.wutil.inWysiwygMode()) {
this.wutil.setOption('woltlab.originalValue', $text.content);
}
}
this.wutil.autosaveShowNotice('restored', { timestamp: $text.timestamp });
- WCF.DOMNodeInsertedHandler.execute();
return true;
},
if ($autosaveNotice === null) {
$autosaveNotice = $('<div class="redactorAutosaveNotice"><span class="redactorAutosaveMessage" /></div>');
$autosaveNotice.appendTo(this.$box);
- $autosaveNotice.on('transitionend webkitTransitionEnd', (function(event) {
- if (event.originalEvent.propertyName !== 'opacity') {
+
+ var $resetNotice = (function(event) {
+ if (event !== null && event.originalEvent.propertyName !== 'opacity') {
return;
}
- if ($autosaveNotice.hasClass('open')) {
+ if ($autosaveNotice.hasClass('open') && event !== null) {
if ($autosaveNotice.data('callbackOpen')) {
$autosaveNotice.data('callbackOpen')();
}
$autosaveNotice.removeData('callbackClose');
$autosaveNotice.removeData('callbackOpen');
- $autosaveNotice.removeClass('redactorAutosaveNoticeRestore');
+ $autosaveNotice.removeClass('redactorAutosaveNoticeIcons');
$autosaveNotice.empty();
$('<span class="redactorAutosaveMessage" />').appendTo($autosaveNotice);
}
- }).bind(this));
+ }).bind(this);
+
+ $autosaveNotice.on('transitionend webkitTransitionEnd', $resetNotice);
}
var $message = '';
switch (type) {
+ case 'prompt':
+ $('<span class="icon icon16 fa-info blue jsTooltip" title="' + WCF.Language.get('wcf.message.autosave.restored.version', { date: new Date(data.timestamp).toLocaleString() }) + '"></span>').prependTo($autosaveNotice);
+ var $accept = $('<span class="icon icon16 fa-check green pointer jsTooltip" title="' + WCF.Language.get('wcf.message.autosave.prompt.confirm') + '"></span>').appendTo($autosaveNotice);
+ var $discard = $('<span class="icon icon16 fa-times red pointer jsTooltip" title="' + WCF.Language.get('wcf.message.autosave.prompt.discard') + '"></span>').appendTo($autosaveNotice);
+ console.debug(data);
+ $accept.click((function() {
+ this.wutil.replaceText(data.content);
+
+ $resetNotice(null);
+
+ this.wutil.autosaveShowNotice('restored', data);
+ }).bind(this));
+
+ $discard.click((function() {
+ this.wutil.autosavePurge();
+
+ $autosaveNotice.removeClass('open');
+ }).bind(this));
+
+ $message = WCF.Language.get('wcf.message.autosave.prompt');
+ $autosaveNotice.addClass('redactorAutosaveNoticeIcons');
+
+ var $uuid = '';
+ $uuid = WCF.System.Event.addListener('com.woltlab.wcf.redactor', 'keydown_' + this.$textarea.wcfIdentify(), (function(data) {
+ WCF.System.Event.removeListener('com.woltlab.wcf.redactor', 'keydown_' + this.$textarea.wcfIdentify(), $uuid);
+
+ setTimeout(function() { $autosaveNotice.removeClass('open'); }, 3000);
+ }).bind(this));
+ break;
+
case 'restored':
$('<span class="icon icon16 fa-info blue jsTooltip" title="' + WCF.Language.get('wcf.message.autosave.restored.version', { date: new Date(data.timestamp).toLocaleString() }) + '"></span>').prependTo($autosaveNotice);
var $accept = $('<span class="icon icon16 fa-check green pointer jsTooltip" title="' + WCF.Language.get('wcf.message.autosave.restored.confirm') + '"></span>').appendTo($autosaveNotice);
}).bind(this));
$message = WCF.Language.get('wcf.message.autosave.restored');
-
- $autosaveNotice.addClass('redactorAutosaveNoticeRestore');
+ $autosaveNotice.addClass('redactorAutosaveNoticeIcons');
var $uuid = '';
$uuid = WCF.System.Event.addListener('com.woltlab.wcf.redactor', 'keydown_' + this.$textarea.wcfIdentify(), (function(data) {
$autosaveNotice.children('span.redactorAutosaveMessage').text($message);
$autosaveNotice.addClass('open');
+
+ if (type !== 'saved') {
+ WCF.DOMNodeInsertedHandler.execute();
+ }
},
/**