diff --git a/Themes/default/MessageIndex.template.php b/Themes/default/MessageIndex.template.php index c4c42d8b0e..cc29d3631a 100644 --- a/Themes/default/MessageIndex.template.php +++ b/Themes/default/MessageIndex.template.php @@ -202,12 +202,11 @@ function template_main() ', $topic['is_posted_in'] ? '' : '', ' -
@@ -348,10 +347,12 @@ function template_main() // Show breadcrumbs at the bottom too. theme_linktree(); + echo ' + '; + });'; // Javascript for inline editing. echo ' - '; diff --git a/Themes/default/scripts/topic.js b/Themes/default/scripts/topic.js index 290e16e0f0..9dc076a510 100755 --- a/Themes/default/scripts/topic.js +++ b/Themes/default/scripts/topic.js @@ -9,27 +9,33 @@ function QuickModifyTopic(oOptions) this.oCurSubjectDiv = null; this.oTopicModHandle = document; this.bInEditMode = false; - this.bMouseOnDiv = false; - this.init(); -} + this.aTextFields = ['subject']; + this.oSourceElments = {}; -// Used to initialise the object event handlers -QuickModifyTopic.prototype.init = function () -{ - // Detect and act on keypress - this.oTopicModHandle.onkeydown = this.modify_topic_keypress.bind(this); + const oElement = document.getElementById(oOptions.sTopicContainer); + for (const el of oElement.children) + { + if (el.children[1].dataset.msgId) + el.children[1].addEventListener( + 'dblclick', + this.modify_topic.bind(this, el.children[1].dataset.msgId) + ); + } // Used to detect when we've stopped editing. - this.oTopicModHandle.onclick = this.modify_topic_click.bind(this); -}; + this.oTopicModHandle.addEventListener('click', function (oEvent) + { + if (this.bInEditMode && oEvent.target.tagName != 'INPUT') + this.modify_topic_save(smf_session_id, smf_session_var); + }.bind(this)); +} // called from the double click in the div QuickModifyTopic.prototype.modify_topic = function (topic_id, first_msg_id) { - // already editing if (this.bInEditMode) { - // Same message then just return, otherwise drop out of this edit. + // same message then just return, otherwise drop out of this edit. if (this.iCurTopicId == topic_id) return; else @@ -37,12 +43,27 @@ QuickModifyTopic.prototype.modify_topic = function (topic_id, first_msg_id) } this.bInEditMode = true; - this.bMouseOnDiv = true; this.iCurTopicId = topic_id; - // Get the topics current subject - ajax_indicator(true); - sendXMLDocument.call(this, smf_prepareScriptUrl(smf_scripturl) + "action=quotefast;quote=" + first_msg_id + ";modify;xml", '', this.onDocReceived_modify_topic); + this.sCurMessageId = 'msg_' + first_msg_id; + this.oCurSubjectDiv = document.getElementById('msg_' + first_msg_id); + var oInput = document.createElement('input'); + oInput.type = 'text'; + oInput.name = 'subject'; + oInput.value = this.oCurSubjectDiv.textContent; + oInput.size = '60'; + oInput.style.width = '99%'; + oInput.maxlength = '80'; + oInput.onkeydown = this.modify_topic_keypress.bind(this); + this.oCurSubjectDiv.after(oInput); + oInput.focus(); + + if (this.opt.funcOnAfterCreate) { + this.opt.funcOnAfterCreate.call(this); + } + + // Here we hide any other things they want hidden on edit. + this.set_hidden_topic_areas('none'); } // callback function from the modify_topic ajax call @@ -55,11 +76,6 @@ QuickModifyTopic.prototype.onDocReceived_modify_topic = function (XMLDoc) return true; } - this.sCurMessageId = XMLDoc.getElementsByTagName("message")[0].getAttribute("id"); - this.oCurSubjectDiv = document.getElementById('msg_' + this.sCurMessageId.substr(4)); - this.sBuffSubject = getInnerHTML(this.oCurSubjectDiv); - - // Here we hide any other things they want hidden on edit. this.set_hidden_topic_areas('none'); // Show we are in edit mode and allow the edit @@ -70,7 +86,10 @@ QuickModifyTopic.prototype.onDocReceived_modify_topic = function (XMLDoc) // Cancel out of an edit and return things to back to what they were QuickModifyTopic.prototype.modify_topic_cancel = function () { - setInnerHTML(this.oCurSubjectDiv, this.sBuffSubject); + for (var i of this.aTextFields) + if (i in document.forms.quickModForm) + document.forms.quickModForm[i].remove(); + this.set_hidden_topic_areas(''); this.bInEditMode = false; @@ -87,36 +106,20 @@ QuickModifyTopic.prototype.set_hidden_topic_areas = function (set_style) } } -// For templating, shown that an inline edit is being made. -QuickModifyTopic.prototype.modify_topic_show_edit = function (subject) -{ - // Just template the subject. - setInnerHTML(this.oCurSubjectDiv, ''); - - // attach mouse over and out events to this new div - this.oCurSubjectDiv.instanceRef = this; - this.oCurSubjectDiv.onmouseout = function (oEvent) {return this.instanceRef.modify_topic_mouseout(oEvent);}; - this.oCurSubjectDiv.onmouseover = function (oEvent) {return this.instanceRef.modify_topic_mouseover(oEvent);}; -} - -// Yup that's right, save it +// Yup thats right, save it QuickModifyTopic.prototype.modify_topic_save = function (cur_session_id, cur_session_var) { if (!this.bInEditMode) return true; - // Add backwards compatibility with old themes. - if (typeof(cur_session_var) == 'undefined') - cur_session_var = 'sesc'; - - var i, x = new Array(); - x[x.length] = 'subject=' + document.forms.quickModForm['subject'].value.php_to8bit().php_urlencode(); - x[x.length] = 'topic=' + parseInt(document.forms.quickModForm.elements['topic'].value); - x[x.length] = 'msg=' + parseInt(document.forms.quickModForm.elements['msg'].value); + let x = []; + for (var i of this.aTextFields) + if (i in document.forms.quickModForm) + x.push(i + '=' + document.forms.quickModForm[i].value.php_to8bit().php_urlencode()); // send in the call to save the updated topic subject ajax_indicator(true); - sendXMLDocument.call(this, smf_prepareScriptUrl(smf_scripturl) + "action=jsmodify;topic=" + parseInt(document.forms.quickModForm.elements['topic'].value) + ";" + cur_session_var + "=" + cur_session_id + ";xml", x.join("&"), this.modify_topic_done); + sendXMLDocument.call(this, smf_prepareScriptUrl(smf_scripturl) + "action=jsmodify;topic=" + this.iCurTopicId + ";" + cur_session_var + "=" + cur_session_id + ";xml", x.join("&"), this.modify_topic_done); return false; } @@ -134,17 +137,27 @@ QuickModifyTopic.prototype.modify_topic_done = function (XMLDoc) } var message = XMLDoc.getElementsByTagName("smf")[0].getElementsByTagName("message")[0]; - var subject = message.getElementsByTagName("subject")[0]; + var subject = message.getElementsByTagName("subject")[0].childNodes[0].nodeValue; var error = message.getElementsByTagName("error")[0]; // No subject or other error? + if (!subject || error) return false; - this.modify_topic_hide_edit(subject.childNodes[0].nodeValue); + setInnerHTML(this.oCurSubjectDiv, '' + subject + '<' +'/a>') this.set_hidden_topic_areas(''); this.bInEditMode = false; + for (var i of this.aTextFields) + { + if (this.oSourceElments[i]) + setInnerHTML(this.oSourceElments[i], message.getElementsByTagName(i)[0].childNodes[0].nodeValue); + + if (i in document.forms.quickModForm) + document.forms.quickModForm[i].remove(); + } + // redo tips if they are on since we just pulled the rug out on this one if ($.isFunction($.fn.SMFtooltip)) $('.preview').SMFtooltip().smf_tooltip_off; @@ -152,13 +165,6 @@ QuickModifyTopic.prototype.modify_topic_done = function (XMLDoc) return false; } -// Done with the edit, put in new subject and link. -QuickModifyTopic.prototype.modify_topic_hide_edit = function (subject) -{ - // Re-template the subject! - setInnerHTML(this.oCurSubjectDiv, '' + subject + '<' +'/a>'); -} - // keypress event ... like enter or escape QuickModifyTopic.prototype.modify_topic_keypress = function (oEvent) { @@ -183,25 +189,6 @@ QuickModifyTopic.prototype.modify_topic_keypress = function (oEvent) } } -// A click event to signal the finish of the edit -QuickModifyTopic.prototype.modify_topic_click = function (oEvent) -{ - if (this.bInEditMode && !this.bMouseOnDiv) - this.modify_topic_save(smf_session_id, smf_session_var); -} - -// Moved out of the editing div -QuickModifyTopic.prototype.modify_topic_mouseout = function (oEvent) -{ - this.bMouseOnDiv = false; -} - -// Moved back over the editing div -QuickModifyTopic.prototype.modify_topic_mouseover = function (oEvent) -{ - this.bMouseOnDiv = true; -} - // *** QuickReply object. function QuickReply(oOptions) { @@ -517,9 +504,10 @@ function InTopicModeration(oOptions) this.opt = oOptions; this.bButtonsShown = false; this.iNumSelected = 0; - this.oRemoveButton = null; - this.oRestoreButton = null; - this.oSplitButton = null; + + // Add backwards compatibility with old themes. + if (typeof(this.opt.sSessionVar) == 'undefined') + this.opt.sSessionVar = 'sesc'; this.init(); }