Chris@76
|
1 var smf_topic, smf_start, smf_show_modify, quickReplyCollapsed, buff_message;
|
Chris@76
|
2 var cur_msg_id, cur_msg_div, buff_subject, cur_subject_div, in_edit_mode = 0;
|
Chris@76
|
3
|
Chris@76
|
4 function doQuote(messageid, cur_session_id)
|
Chris@76
|
5 {
|
Chris@76
|
6 if (quickReplyCollapsed)
|
Chris@76
|
7 window.location.href = smf_scripturl + "?action=post;quote=" + messageid + ";topic=" + smf_topic + "." + smf_start + ";sesc=" + cur_session_id;
|
Chris@76
|
8 else
|
Chris@76
|
9 {
|
Chris@76
|
10 if (window.XMLHttpRequest)
|
Chris@76
|
11 {
|
Chris@76
|
12 if (typeof window.ajax_indicator == "function")
|
Chris@76
|
13 ajax_indicator(true);
|
Chris@76
|
14 getXMLDocument(smf_scripturl + "?action=quotefast;quote=" + messageid + ";sesc=" + cur_session_id + ";xml", onDocReceived);
|
Chris@76
|
15 }
|
Chris@76
|
16 else
|
Chris@76
|
17 reqWin(smf_scripturl + "?action=quotefast;quote=" + messageid + ";sesc=" + cur_session_id, 240, 90);
|
Chris@76
|
18
|
Chris@76
|
19 if (navigator.appName == "Microsoft Internet Explorer")
|
Chris@76
|
20 window.location.hash = "quickreply";
|
Chris@76
|
21 else
|
Chris@76
|
22 window.location.hash = "#quickreply";
|
Chris@76
|
23 }
|
Chris@76
|
24 }
|
Chris@76
|
25
|
Chris@76
|
26 function onDocReceived(XMLDoc)
|
Chris@76
|
27 {
|
Chris@76
|
28 var text = "";
|
Chris@76
|
29 for (var i = 0; i < XMLDoc.getElementsByTagName("quote")[0].childNodes.length; i++)
|
Chris@76
|
30 text += XMLDoc.getElementsByTagName("quote")[0].childNodes[i].nodeValue;
|
Chris@76
|
31
|
Chris@76
|
32 replaceText(text, document.forms.postmodify.message);
|
Chris@76
|
33 if (typeof window.ajax_indicator == "function")
|
Chris@76
|
34 ajax_indicator(false);
|
Chris@76
|
35 }
|
Chris@76
|
36
|
Chris@76
|
37
|
Chris@76
|
38 function modify_msg(msg_id, cur_session_id)
|
Chris@76
|
39 {
|
Chris@76
|
40 if (!window.XMLHttpRequest)
|
Chris@76
|
41 return;
|
Chris@76
|
42 if (typeof(window.opera) != "undefined")
|
Chris@76
|
43 {
|
Chris@76
|
44 var test = new XMLHttpRequest();
|
Chris@76
|
45 if (typeof(test.setRequestHeader) != "function")
|
Chris@76
|
46 return;
|
Chris@76
|
47 }
|
Chris@76
|
48 if (in_edit_mode == 1)
|
Chris@76
|
49 modify_cancel();
|
Chris@76
|
50 in_edit_mode = 1;
|
Chris@76
|
51 if (typeof window.ajax_indicator == "function")
|
Chris@76
|
52 ajax_indicator(true);
|
Chris@76
|
53 getXMLDocument(smf_scripturl + '?action=quotefast;quote=' + msg_id + ';sesc=' + cur_session_id + ';modify;xml', onDocReceived_modify);
|
Chris@76
|
54 }
|
Chris@76
|
55
|
Chris@76
|
56 function onDocReceived_modify(XMLDoc)
|
Chris@76
|
57 {
|
Chris@76
|
58 var text = "";
|
Chris@76
|
59 var subject = "";
|
Chris@76
|
60
|
Chris@76
|
61 // Grab the message ID.
|
Chris@76
|
62 cur_msg_id = XMLDoc.getElementsByTagName("message")[0].getAttribute("id");
|
Chris@76
|
63
|
Chris@76
|
64 // Replace the body part.
|
Chris@76
|
65 for (var i = 0; i < XMLDoc.getElementsByTagName("message")[0].childNodes.length; i++)
|
Chris@76
|
66 text += XMLDoc.getElementsByTagName("message")[0].childNodes[i].nodeValue;
|
Chris@76
|
67 cur_msg_div = document.getElementById(cur_msg_id);
|
Chris@76
|
68 buff_message = getInnerHTML(cur_msg_div);
|
Chris@76
|
69
|
Chris@76
|
70 // Actually create the content, with a bodge for dissapearing dollar signs.
|
Chris@76
|
71 text = text.replace(/\$/g,"{&dollarfix;$}");
|
Chris@76
|
72 text = smf_template_body_edit.replace(/%body%/, text).replace(/%msg_id%/g, cur_msg_id.substr(4));
|
Chris@76
|
73 text = text.replace(/\{&dollarfix;\$\}/g,"$");
|
Chris@76
|
74 setInnerHTML(cur_msg_div, text);
|
Chris@76
|
75
|
Chris@76
|
76 // Replace the subject part.
|
Chris@76
|
77 cur_subject_div = document.getElementById('subject_' + cur_msg_id.substr(4));
|
Chris@76
|
78 buff_subject = getInnerHTML(cur_subject_div);
|
Chris@76
|
79
|
Chris@76
|
80 subject = XMLDoc.getElementsByTagName("subject")[0].childNodes[0].nodeValue;
|
Chris@76
|
81 subject = subject.replace(/\$/g,"{&dollarfix;$}");
|
Chris@76
|
82 subject = smf_template_subject_edit.replace(/%subject%/, subject);
|
Chris@76
|
83 subject = subject.replace(/\{&dollarfix;\$\}/g,"$");
|
Chris@76
|
84 setInnerHTML(cur_subject_div, subject);
|
Chris@76
|
85 if (typeof window.ajax_indicator == "function")
|
Chris@76
|
86 ajax_indicator(false);
|
Chris@76
|
87 }
|
Chris@76
|
88
|
Chris@76
|
89 function modify_cancel()
|
Chris@76
|
90 {
|
Chris@76
|
91 // Roll back the HTML to its original state.
|
Chris@76
|
92 setInnerHTML(cur_msg_div, buff_message);
|
Chris@76
|
93 setInnerHTML(cur_subject_div, buff_subject);
|
Chris@76
|
94
|
Chris@76
|
95 // No longer in edit mode, that's right.
|
Chris@76
|
96 in_edit_mode = 0;
|
Chris@76
|
97
|
Chris@76
|
98 return false;
|
Chris@76
|
99 }
|
Chris@76
|
100
|
Chris@76
|
101 function modify_save(cur_session_id)
|
Chris@76
|
102 {
|
Chris@76
|
103 if (!in_edit_mode)
|
Chris@76
|
104 return true;
|
Chris@76
|
105
|
Chris@76
|
106 var i, x = new Array();
|
Chris@76
|
107 x[x.length] = 'subject=' + escape(textToEntities(document.forms.quickModForm['subject'].value.replace(/&#/g, "&#"))).replace(/\+/g, "%2B");
|
Chris@76
|
108 x[x.length] = 'message=' + escape(textToEntities(document.forms.quickModForm['message'].value.replace(/&#/g, "&#"))).replace(/\+/g, "%2B");
|
Chris@76
|
109 x[x.length] = 'topic=' + parseInt(document.forms.quickModForm.elements['topic'].value);
|
Chris@76
|
110 x[x.length] = 'msg=' + parseInt(document.forms.quickModForm.elements['msg'].value);
|
Chris@76
|
111
|
Chris@76
|
112 if (typeof window.ajax_indicator == "function")
|
Chris@76
|
113 ajax_indicator(true);
|
Chris@76
|
114
|
Chris@76
|
115 sendXMLDocument(smf_scripturl + "?action=jsmodify;topic=" + smf_topic + ";sesc=" + cur_session_id + ";xml", x.join("&"), modify_done);
|
Chris@76
|
116
|
Chris@76
|
117 return false;
|
Chris@76
|
118 }
|
Chris@76
|
119
|
Chris@76
|
120 function modify_done(XMLDoc)
|
Chris@76
|
121 {
|
Chris@76
|
122 if (!XMLDoc)
|
Chris@76
|
123 {
|
Chris@76
|
124 modify_cancel();
|
Chris@76
|
125 return;
|
Chris@76
|
126 }
|
Chris@76
|
127
|
Chris@76
|
128 var message = XMLDoc.getElementsByTagName("smf")[0].getElementsByTagName("message")[0];
|
Chris@76
|
129 var body = message.getElementsByTagName("body")[0];
|
Chris@76
|
130 var error = message.getElementsByTagName("error")[0];
|
Chris@76
|
131
|
Chris@76
|
132 if (body)
|
Chris@76
|
133 {
|
Chris@76
|
134 // Show new body.
|
Chris@76
|
135 var bodyText = "";
|
Chris@76
|
136 for (i = 0; i < body.childNodes.length; i++)
|
Chris@76
|
137 bodyText += body.childNodes[i].nodeValue;
|
Chris@76
|
138
|
Chris@76
|
139 bodyText = bodyText.replace(/\$/g,"{&dollarfix;$}");
|
Chris@76
|
140 bodyText = smf_template_body_normal.replace(/%body%/, bodyText);
|
Chris@76
|
141 bodyText = bodyText.replace(/\{&dollarfix;\$\}/g,"$");
|
Chris@76
|
142 setInnerHTML(cur_msg_div, bodyText);
|
Chris@76
|
143 buff_message = bodyText;
|
Chris@76
|
144
|
Chris@76
|
145 // Show new subject.
|
Chris@76
|
146 var subject = message.getElementsByTagName("subject")[0];
|
Chris@76
|
147 var subject_text = subject.childNodes[0].nodeValue;
|
Chris@76
|
148 subject_text = subject_text.replace(/\$/g,"{&dollarfix;$}");
|
Chris@76
|
149 var subject_html = smf_template_subject_normal.replace(/%msg_id%/g, cur_msg_id.substr(4)).replace(/%subject%/, subject_text);
|
Chris@76
|
150 subject_html = subject_html.replace(/\{&dollarfix;\$\}/g,"$");
|
Chris@76
|
151 setInnerHTML(cur_subject_div, subject_html);
|
Chris@76
|
152 buff_subject = subject_html;
|
Chris@76
|
153
|
Chris@76
|
154 // If this is the first message, also update the topic subject.
|
Chris@76
|
155 if (subject.getAttribute("is_first") == 1)
|
Chris@76
|
156 {
|
Chris@76
|
157 var subject_top = smf_template_top_subject.replace(/%subject%/, subject_text);
|
Chris@76
|
158 subject_top = subject_top.replace(/\{&dollarfix;\$\}/g,"$");
|
Chris@76
|
159 setInnerHTML(document.getElementById("top_subject"), subject_top);
|
Chris@76
|
160 }
|
Chris@76
|
161
|
Chris@76
|
162 // Show this message as "modified on x by y".
|
Chris@76
|
163 if (smf_show_modify)
|
Chris@76
|
164 {
|
Chris@76
|
165 var cur_modify_div = document.getElementById('modified_' + cur_msg_id.substr(4));
|
Chris@76
|
166 setInnerHTML(cur_modify_div, message.getElementsByTagName("modified")[0].childNodes[0].nodeValue);
|
Chris@76
|
167 }
|
Chris@76
|
168 }
|
Chris@76
|
169 else if (error)
|
Chris@76
|
170 {
|
Chris@76
|
171 setInnerHTML(document.getElementById("error_box"), error.childNodes[0].nodeValue);
|
Chris@76
|
172 document.forms.quickModForm.message.style.border = error.getAttribute("in_body") == "1" ? "1px solid red" : "";
|
Chris@76
|
173 document.forms.quickModForm.subject.style.border = error.getAttribute("in_subject") == "1" ? "1px solid red" : "";
|
Chris@76
|
174 }
|
Chris@76
|
175
|
Chris@76
|
176 if (typeof window.ajax_indicator == "function")
|
Chris@76
|
177 ajax_indicator(false);
|
Chris@76
|
178 }
|
Chris@76
|
179
|
Chris@76
|
180 function showModifyButtons()
|
Chris@76
|
181 {
|
Chris@76
|
182 var numImages = document.images.length;
|
Chris@76
|
183 for (var i = 0; i < numImages; i++)
|
Chris@76
|
184 if (document.images[i].id.substr(0, 14) == 'modify_button_')
|
Chris@76
|
185 document.images[i].style.display = '';
|
Chris@76
|
186 }
|
Chris@76
|
187
|
Chris@76
|
188 function expandThumb(thumbID)
|
Chris@76
|
189 {
|
Chris@76
|
190 var img = document.getElementById('thumb_' + thumbID);
|
Chris@76
|
191 var link = document.getElementById('link_' + thumbID);
|
Chris@76
|
192 var tmp = img.src;
|
Chris@76
|
193 img.src = link.href;
|
Chris@76
|
194 link.href = tmp;
|
Chris@76
|
195 img.style.width = '';
|
Chris@76
|
196 img.style.height = '';
|
Chris@76
|
197 return false;
|
Chris@76
|
198 }
|
Chris@76
|
199
|
Chris@76
|
200 function swapQuickReply()
|
Chris@76
|
201 {
|
Chris@76
|
202 document.getElementById("quickReplyExpand").src = smf_images_url + "/" + (quickReplyCollapsed ? "collapse.gif" : "expand.gif");
|
Chris@76
|
203 document.getElementById("quickReplyOptions").style.display = quickReplyCollapsed ? "" : "none";
|
Chris@76
|
204
|
Chris@76
|
205 quickReplyCollapsed = !quickReplyCollapsed;
|
Chris@76
|
206 }
|