|
@@ -9,7 +9,10 @@ function smf_DraftAutoSave(oOptions)
|
|
|
this.oDraftHandle = window;
|
|
|
this.sLastSaved = '';
|
|
|
this.bPM = this.opt.bPM ? true : false;
|
|
|
- addLoadEvent(this.opt.sSelf + '.init();');
|
|
|
+ this.sCheckDraft = '';
|
|
|
+
|
|
|
+
|
|
|
+ setTimeout('addLoadEvent(' + this.opt.sSelf + '.init())', 4000);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -17,41 +20,66 @@ smf_DraftAutoSave.prototype.init = function ()
|
|
|
{
|
|
|
if (this.opt.iFreq > 0)
|
|
|
{
|
|
|
+
|
|
|
+ var oIframe = document.getElementsByTagName('iframe')[0];
|
|
|
+ var oIframeWindow = oIframe.contentWindow || oIframe.contentDocument;
|
|
|
|
|
|
- this.interval_id = setInterval(this.opt.sSelf + '.draft' + (this.bPM ? 'PM' : '') + 'Save();', this.opt.iFreq);
|
|
|
+ this.interval_id = window.setInterval(this.opt.sSelf + '.draft' + (this.bPM ? 'PM' : '') + 'Save();', this.opt.iFreq);
|
|
|
|
|
|
|
|
|
this.oDraftHandle.instanceRef = this;
|
|
|
- this.oDraftHandle.onblur = function (oEvent) {return this.instanceRef.draftBlur(oEvent);};
|
|
|
- this.oDraftHandle.onfocus = function (oEvent) {return this.instanceRef.draftFocus(oEvent);};
|
|
|
+ this.oDraftHandle.onblur = function (oEvent) {return this.instanceRef.draftBlur(oEvent, true);};
|
|
|
+ this.oDraftHandle.onfocus = function (oEvent) {return this.instanceRef.draftFocus(oEvent, true);};
|
|
|
+
|
|
|
+
|
|
|
+ if (oIframeWindow.document)
|
|
|
+ {
|
|
|
+ var oIframeDoc = oIframeWindow.document;
|
|
|
+
|
|
|
+ oIframeDoc.body.onblur = function (oEvent) {return parent.oDraftAutoSave.draftBlur(oEvent, false);};
|
|
|
+ oIframeDoc.body.onfocus = function (oEvent) {return parent.oDraftAutoSave.draftFocus(oEvent, false);};
|
|
|
+ };
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
-smf_DraftAutoSave.prototype.draftBlur = function(oEvent)
|
|
|
+smf_DraftAutoSave.prototype.draftBlur = function(oEvent, source)
|
|
|
{
|
|
|
-
|
|
|
- if (this.bPM)
|
|
|
- this.draftPMSave();
|
|
|
- else
|
|
|
- this.draftSave();
|
|
|
- clearInterval(this.interval_id);
|
|
|
- this.interval_id = 0;
|
|
|
+ if ($('#' + this.opt.sSceditorID).data("sceditor").inSourceMode() == source)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (this.bPM)
|
|
|
+ this.draftPMSave();
|
|
|
+ else
|
|
|
+ this.draftSave();
|
|
|
+
|
|
|
+ if (this.interval_id != "")
|
|
|
+ window.clearInterval(this.interval_id);
|
|
|
+ this.interval_id = "";
|
|
|
+ }
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
|
|
|
-smf_DraftAutoSave.prototype.draftFocus = function(oEvent)
|
|
|
+smf_DraftAutoSave.prototype.draftFocus = function(oEvent, source)
|
|
|
{
|
|
|
- this.interval_id = setInterval(this.opt.sSelf + '.draft' + (this.bPM ? 'PM' : '') + 'Save();', this.opt.iFreq);
|
|
|
+ if ($('#' + this.opt.sSceditorID).data("sceditor").inSourceMode() == source)
|
|
|
+ {
|
|
|
+ if (this.interval_id == "")
|
|
|
+ this.interval_id = window.setInterval(this.opt.sSelf + '.draft' + (this.bPM ? 'PM' : '') + 'Save();', this.opt.iFreq);
|
|
|
+ }
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
|
|
|
smf_DraftAutoSave.prototype.draftSave = function ()
|
|
|
{
|
|
|
-
|
|
|
- if (isEmptyText($('#' + this.opt.sSceditorID).data("sceditor").getText()) || smf_formSubmitted)
|
|
|
+ var sPostdata = $('#' + this.opt.sSceditorID).data("sceditor").getText();
|
|
|
+
|
|
|
+
|
|
|
+ if (isEmptyText(sPostdata) || smf_formSubmitted || this.sCheckDraft.localeCompare(sPostdata) == 0)
|
|
|
return false;
|
|
|
-
|
|
|
+
|
|
|
|
|
|
if (this.bInDraftMode)
|
|
|
this.draftCancel();
|
|
@@ -65,7 +93,7 @@ smf_DraftAutoSave.prototype.draftSave = function ()
|
|
|
'topic=' + parseInt(document.forms.postmodify.elements['topic'].value),
|
|
|
'id_draft=' + parseInt(document.forms.postmodify.elements['id_draft'].value),
|
|
|
'subject=' + escape(document.forms.postmodify['subject'].value.replace(/&#/g, "&#").php_to8bit()).replace(/\+/g, "%2B"),
|
|
|
- 'message=' + escape($('#' + this.opt.sSceditorID).data("sceditor").getText().replace(/&#/g, "&#").php_to8bit()).replace(/\+/g, "%2B"),
|
|
|
+ 'message=' + escape(sPostdata.replace(/&#/g, "&#").php_to8bit()).replace(/\+/g, "%2B"),
|
|
|
'icon=' + escape(document.forms.postmodify['icon'].value.replace(/&#/g, "&#").php_to8bit()).replace(/\+/g, "%2B"),
|
|
|
'save_draft=true',
|
|
|
smf_session_var + '=' + smf_session_id,
|
|
@@ -81,17 +109,22 @@ smf_DraftAutoSave.prototype.draftSave = function ()
|
|
|
}
|
|
|
|
|
|
|
|
|
- aSections[aSections.length] = 'message_mode=' + $("#message").data("sceditor").inSourceMode();
|
|
|
+ aSections[aSections.length] = 'message_mode=' + $('#' + this.opt.sSceditorID).data("sceditor").inSourceMode();
|
|
|
|
|
|
|
|
|
sendXMLDocument.call(this, smf_prepareScriptUrl(smf_scripturl) + "action=post2;board=" + this.opt.iBoard + ";xml", aSections.join("&"), this.onDraftDone);
|
|
|
+
|
|
|
+
|
|
|
+ this.sCheckDraft = sPostdata;
|
|
|
}
|
|
|
|
|
|
|
|
|
smf_DraftAutoSave.prototype.draftPMSave = function ()
|
|
|
{
|
|
|
-
|
|
|
- if (isEmptyText(document.forms.postmodify['message']))
|
|
|
+ var sPostdata = $('#' + this.opt.sSceditorID).data("sceditor").getText();
|
|
|
+
|
|
|
+
|
|
|
+ if (isEmptyText(sPostdata) || smf_formSubmitted || this.sCheckDraft.localeCompare(sPostdata) == 0)
|
|
|
return false;
|
|
|
|
|
|
|
|
@@ -111,7 +144,7 @@ smf_DraftAutoSave.prototype.draftPMSave = function ()
|
|
|
'replied_to=' + parseInt(document.forms.postmodify.elements['replied_to'].value),
|
|
|
'id_pm_draft=' + parseInt(document.forms.postmodify.elements['id_pm_draft'].value),
|
|
|
'subject=' + escape(document.forms.postmodify['subject'].value.replace(/&#/g, "&#").php_to8bit()).replace(/\+/g, "%2B"),
|
|
|
- 'message=' + escape(document.forms.postmodify['message'].value.replace(/&#/g, "&#").php_to8bit()).replace(/\+/g, "%2B"),
|
|
|
+ 'message=' + escape(sPostdata.replace(/&#/g, "&#").php_to8bit()).replace(/\+/g, "%2B"),
|
|
|
'recipient_to=' + aTo,
|
|
|
'recipient_bcc=' + aBcc,
|
|
|
'save_draft=true',
|
|
@@ -128,6 +161,9 @@ smf_DraftAutoSave.prototype.draftPMSave = function ()
|
|
|
|
|
|
|
|
|
sendXMLDocument.call(this, smf_prepareScriptUrl(smf_scripturl) + "action=pm;sa=send2;xml", aSections.join("&"), this.onDraftDone);
|
|
|
+
|
|
|
+
|
|
|
+ this.sCheckDraft = sPostdata;
|
|
|
}
|
|
|
|
|
|
|