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