PageSourceSearch

https://prorum.com//qa-content/qa-page.js?1.7.0

js prorum.com collected 2026-09-26 11:18:21 UTC 5,751 bytes, 239 lines download raw bytes

1/*
2	Question2Answer by Gideon Greenspan and contributors
3
4	http://www.question2answer.org/
5
6
7	File: qa-content/qa-page.js
8	Version: See define()s at top of qa-include/qa-base.php
9	Description: Common Javascript including voting, notices and favorites
10
11
12	This program is free software; you can redistribute it and/or
13	modify it under the terms of the GNU General Public License
14	as published by the Free Software Foundation; either version 2
15	of the License, or (at your option) any later version.
16
17	This program is distributed in the hope that it will be useful,
18	but WITHOUT ANY WARRANTY; without even the implied warranty of
19	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20	GNU General Public License for more details.
21
22	More about this license: http://www.question2answer.org/license.php
23*/
24
25function qa_switch_div_visibility(theDiv)
26{
27       if (theDiv.style.display==="block") {
28           theDiv.style.display="none";
29       } else {
30           theDiv.style.display="block";       
31       } 
32}
33
34
35function qa_reveal(elem, type, callback)
36{
37	if (elem)
38		$(elem).slideDown(400, callback);
39}
40
41function qa_conceal(elem, type, callback)
42{
43	if (elem)
44		$(elem).slideUp(400);
45}
46
47function qa_set_inner_html(elem, type, html)
48{
49	if (elem)
50		elem.innerHTML=html;
51}
52
53function qa_set_outer_html(elem, type, html)
54{
55	if (elem) {
56		var e=document.createElement('div');
57		e.innerHTML=html;
58		elem.parentNode.replaceChild(e.firstChild, elem);
59	}
60}
61
62function qa_show_waiting_after(elem, inside)
63{
64	if (elem && !elem.qa_waiting_shown) {
65		var w=document.getElementById('qa-waiting-template');
66
67		if (w) {
68			var c=w.cloneNode(true);
69			c.id=null;
70
71			if (inside)
72				elem.insertBefore(c, null);
73			else
74				elem.parentNode.insertBefore(c, elem.nextSibling);
75
76			elem.qa_waiting_shown=c;
77		}
78	}
79}
80
81function qa_hide_waiting(elem)
82{
83	var c=elem.qa_waiting_shown;
84
85	if (c) {
86		c.parentNode.removeChild(c);
87		elem.qa_waiting_shown=null;
88	}
89}
90
91
92function qa_listmania_add_q(questionID)
93{
94    
95     returnMessageSpan = document.getElementById("listmaniaSpan".concat(questionID)); 
96     returnMessageSpan.innerHTML = "";
97     comboBox = document.getElementById("listmaniaCombo".concat(questionID));  
98
99
100     listmaniaSpinner = document.getElementById("listmaniaSpinner".concat(questionID));
101     listmaniaSpinner.style = "visibility:visible";
102
103     listID = comboBox.value;
104
105     if (!listID) {
106        returnMessageSpan.innerHTML = "Escolha um caderno";
107             listmaniaSpinner.style = "visibility:hidden";
108        return false;
109     }    
110
111	qa_ajax_post('listmania_contains', {questionID:questionID, listID:listID},
112		function(lines) {
113			if (lines[0]=='1') {				
114				returnMessageSpan.innerHTML = "Caderno já contem esta pergunta";
115				     listmaniaSpinner.style = "visibility:hidden";
116				return false;
117			} else if (lines[0]=='0') {				
118				returnMessageSpan.innerHTML = "Adicionando pergunta ao caderno...";
119				
120				qa_ajax_post('listmania_add', {questionID:questionID, listID:listID},
121					function(lines) {
122						if (lines[0]=='1') {				
123							returnMessageSpan.innerHTML = "Pergunta adicionada ao caderno";
124							     listmaniaSpinner.style = "visibility:hidden";			
125						} else
126							qa_ajax_error();
127					}
128				);  
129											
130			} else
131				qa_ajax_error();
132		}
133	);
134          
135        
136          
137     listmaniaSpinner.style = "visibility:hidden";       
138     return false;
139}
140
141
142
143function qa_vote_click(elem)
144{
145	var ens=elem.name.split('_');
146	var postid=ens[1];
147	var vote=parseInt(ens[2]);
148	var code=elem.form.elements.code.value;
149	var anchor=ens[3];
150
151	qa_ajax_post('vote', {postid:postid, vote:vote, code:code},
152		function(lines) {
153			if (lines[0]=='1') {
154				qa_set_inner_html(document.getElementById('voting_'+postid), 'voting', lines.slice(1).join("\n"));
155
156			} else if (lines[0]=='0') {
157				var mess=document.getElementById('errorbox');
158
159				if (!mess) {
160					var mess=document.createElement('div');
161					mess.id='errorbox';
162					mess.className='qa-error';
163					mess.innerHTML=lines[1];
164					mess.style.display='none';
165				}
166
167				var postelem=document.getElementById(anchor);
168				var e=postelem.parentNode.insertBefore(mess, postelem);
169				qa_reveal(e);
170
171			} else
172				qa_ajax_error();
173		}
174	);
175
176	return false;
177}
178
179function qa_notice_click(elem)
180{
181	var ens=elem.name.split('_');
182	var code=elem.form.elements.code.value;
183
184	qa_ajax_post('notice', {noticeid:ens[1], code:code},
185		function(lines) {
186			if (lines[0]=='1')
187				qa_conceal(document.getElementById('notice_'+ens[1]), 'notice');
188			else if (lines[0]=='0')
189				alert(lines[1]);
190			else
191				qa_ajax_error();
192		}
193	);
194
195	return false;
196}
197
198function qa_favorite_click(elem)
199{
200	var ens=elem.name.split('_');
201	var code=elem.form.elements.code.value;
202
203	qa_ajax_post('favorite', {entitytype:ens[1], entityid:ens[2], favorite:parseInt(ens[3]), code:code},
204		function (lines) {
205			if (lines[0]=='1')
206				qa_set_inner_html(document.getElementById('favoriting'), 'favoriting', lines.slice(1).join("\n"));
207			else if (lines[0]=='0') {
208				alert(lines[1]);
209				qa_hide_waiting(elem);
210			} else
211				qa_ajax_error();
212		}
213	);
214
215	qa_show_waiting_after(elem, false);
216
217	return false;
218}
219
220function qa_ajax_post(operation, params, callback)
221{
222	jQuery.extend(params, {qa:'ajax', qa_operation:operation, qa_root:'qa_root', qa_request:qa_request});
223
224	jQuery.post(qa_root, params, function(response) {
225		var header='QA_AJAX_RESPONSE';
226		var headerpos=response.indexOf(header);
227
228		if (headerpos>=0)
229			callback(response.substr(headerpos+header.length).replace(/^\s+/, '').split("\n"));
230		else
231			callback([]);
232
233	}, 'text').fail(function(jqXHR) { if (jqXHR.readyState>0) callback([]) });
234}
235
236function qa_ajax_error()
237{
238	alert('Unexpected response from server - please try again or switch off Javascript.');
239}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.