123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- function smf_DraftAutoSave(oOptions)
- {
- this.opt = oOptions;
- this.bInDraftMode = false;
- this.sCurDraftId = '';
- this.oCurDraftDiv = null;
- this.interval_id = null;
- this.oDraftHandle = window;
- this.sLastSaved = '';
- this.bPM = this.opt.bPM ? true : false;
- this.sCheckDraft = '';
-
- setTimeout('addLoadEvent(' + this.opt.sSelf + '.init())', 4000);
- }
- 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 = window.setInterval(this.opt.sSelf + '.draft' + (this.bPM ? 'PM' : '') + 'Save();', this.opt.iFreq);
-
- var instanceRef = this;
- this.oDraftHandle.onblur = function (oEvent) {return instanceRef.draftBlur(oEvent, true);};
- this.oDraftHandle.onfocus = function (oEvent) {return 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, source)
- {
- 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, source)
- {
- 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 ()
- {
- var sPostdata = $('#' + this.opt.sSceditorID).data("sceditor").getText(true);
-
- if (isEmptyText(sPostdata) || smf_formSubmitted || this.sCheckDraft == sPostdata)
- return false;
-
- if (this.bInDraftMode)
- this.draftCancel();
-
- document.getElementById('throbber').style.display = '';
- this.bInDraftMode = true;
-
- var aSections = [
- 'topic=' + parseInt(document.forms.postmodify.elements['topic'].value),
- 'id_draft=' + (('id_draft' in document.forms.postmodify.elements) ? parseInt(document.forms.postmodify.elements['id_draft'].value) : 0),
- 'subject=' + escape(document.forms.postmodify['subject'].value.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,
- ];
-
- if (this.opt.sType == 'post')
- {
- if (document.getElementById('check_lock') && document.getElementById('check_lock').checked)
- aSections[aSections.length] = 'lock=1';
- if (document.getElementById('check_sticky') && document.getElementById('check_sticky').checked)
- aSections[aSections.length] = 'sticky=1';
- }
-
- 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 ()
- {
- var sPostdata = $('#' + this.opt.sSceditorID).data("sceditor").getText();
-
- if (isEmptyText(sPostdata) || smf_formSubmitted || this.sCheckDraft == sPostdata)
- return false;
-
- if (this.bInDraftMode)
- this.draftCancel();
-
- document.getElementById('throbber').style.display = '';
- this.bInDraftMode = true;
-
- var aTo = this.draftGetRecipient('recipient_to[]');
- var aBcc = this.draftGetRecipient('recipient_bcc[]');
-
- var aSections = [
- 'replied_to=' + parseInt(document.forms.postmodify.elements['replied_to'].value),
- 'id_pm_draft=' + (('id_pm_draft' in document.forms.postmodify.elements) ? parseInt(document.forms.postmodify.elements['id_pm_draft'].value) : 0),
- 'subject=' + escape(document.forms.postmodify['subject'].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',
- smf_session_var + '=' + smf_session_id,
- ];
-
- if (this.opt.sType == 'post')
- aSections[aSections.length] = 'message_mode=' + parseInt(document.forms.postmodify.elements['message_mode'].value);
-
- sendXMLDocument.call(this, smf_prepareScriptUrl(smf_scripturl) + "action=pm;sa=send2;xml", aSections.join("&"), this.onDraftDone);
-
- this.sCheckDraft = sPostdata;
- }
- smf_DraftAutoSave.prototype.onDraftDone = function (XMLDoc)
- {
-
- if (!XMLDoc || !XMLDoc.getElementsByTagName('draft'))
- return this.draftCancel();
-
- this.sCurDraftId = XMLDoc.getElementsByTagName('draft')[0].getAttribute('id');
- this.sLastSaved = XMLDoc.getElementsByTagName('draft')[0].childNodes[0].nodeValue;
-
- document.getElementById(this.opt.sLastID).value = this.sCurDraftId;
- oCurDraftDiv = document.getElementById(this.opt.sLastNote);
- setInnerHTML(oCurDraftDiv, this.sLastSaved);
-
- if (this.opt.sType == 'post')
- document.getElementById('draft_section').style.display = 'none';
-
- this.bInDraftMode = false;
- document.getElementById('throbber').style.display = 'none';
- }
- smf_DraftAutoSave.prototype.draftGetRecipient = function (sField)
- {
- var oRecipient = document.forms.postmodify.elements[sField];
- var aRecipient = []
- if (typeof(oRecipient) != 'undefined')
- {
-
- if ('value' in oRecipient)
- aRecipient.push(parseInt(oRecipient.value));
- else
- {
-
- for (var i = 0, n = oRecipient.length; i < n; i++)
- aRecipient.push(parseInt(oRecipient[i].value));
- }
- }
- return aRecipient;
- }
- smf_DraftAutoSave.prototype.draftCancel = function ()
- {
-
-
- this.bInDraftMode = false;
- document.getElementById('throbber').style.display = 'none';
- }
|