PageSourceSearch

https://adherents.april.org//javascript/utils.js

js april.org collected 2026-09-24 08:51:32 UTC 3,976 bytes, 170 lines download raw bytes

1// -*- c-mode -*- 
2
3function select_all ( classname, ref ) {
4  for ( var i = 0; i < document.getElementsByTagName('input').length; i++ ) {
5    if ( document.getElementsByTagName('input')[i].className == classname )
6      {
7	document.getElementsByTagName('input')[i].checked = ref.checked;
8      }
9  }
10}
11
12
13function showhidestuff(boxid) {
14   box = document.getElementById(boxid);
15   switch (box.style.visibility) {
16      case '': box.style.visibility='visible'; break
17      case 'hidden': box.style.visibility='visible'; break
18      case 'visible': box.style.visibility='hidden'; break
19   }
20   switch (box.style.display) {
21      case '': box.style.display='block'; break
22      case 'none': box.style.display='block'; break
23      case 'block': box.style.display='none'; break
24   }
25}
26
27function hidestuff ( boxid ) {
28  box = document.getElementById ( boxid );
29  box.style.display='none'; 
30  box.style.visibility='hidden';
31}
32
33
34function showstuff ( boxid ) {
35  box = document.getElementById ( boxid );
36  box.style.display='block'; 
37  box.style.visibility='visible';
38}
39
40
41function submit_form ()
42{
43  // Be sure that *all* form elements are not disabled so that they
44  // are submited as well.
45  for ( var i = 0 ; i < document.search_form.length ; i ++ )
46    {
47      document.search_form.elements [ i ] . disabled = false;
48    }
49
50  $("form[name='search_form']").append('<input type="hidden" name="dont_do_it" value="1">');
51
52  // Submit form to be sure all elements are up to date.
53  document.search_form.submit();
54}
55
56
57
58var active;
59var last_color;
60function change_color ( objectid )
61{
62    object = document.getElementById ( objectid );
63    if ( object )
64    {
65	if ( active ) 
66	{
67	    active.style.background = last_color;
68	    active.style.border = '0px';
69	}
70	active = object;
71	last_color = object.style.background;
72	object.style.background = '#fce94f';
73	object.style.border = '1px solid #c4a000;';
74  }
75}
76
77
78
79function insert_at_cursor ( fieldid, value )
80{
81    field = document.getElementById ( fieldid );
82
83    if ( document.selection ) {
84	field.focus();
85
86	sel = document.selection.createRange();
87	sel.text = value;
88    }
89
90    else if ( field.selectionStart || field.selectionStart == '0' )
91    {
92	var startPos = field.selectionStart;
93	var endPos = field.selectionEnd;
94	field.value = field.value.substring ( 0, startPos ) 
95	    + '{$' + value + '}' + field.value.substring ( endPos, field.value.length );
96    } 
97    else
98    {
99	field.value += value;
100    }
101
102    field.focus();
103} 
104
105
106function makepassword(inputid,generate) {
107    input = document.getElementById(inputid);
108    if ( ! generate )
109	value = input.value;
110    else
111    {
112	value = 1e6 * Math.random();
113	value = value.toString ();
114    }
115    input.value = SHA1(value);
116    if ( input.disabled )
117	input.disabled = 0;
118}
119
120
121function getCookie(cname) {
122    var name = cname + "=";
123    var decodedCookie = decodeURIComponent(document.cookie);
124    var ca = decodedCookie.split(';');
125    for(var i = 0; i <ca.length; i++) {
126	var c = ca[i];
127	while (c.charAt(0) == ' ') {
128	    c = c.substring(1);
129	}
130	if (c.indexOf(name) == 0) {
131	    return c.substring(name.length, c.length);
132	}
133    }
134    return "";
135} 
136
137
138function ptab_onclick ( i )
139{
140    SetCookie ( 'ptab', i );
141}
142
143
144function SetCookie (name, value)
145{
146    var aujourdhui = new Date() ;
147    var expdate = new Date() ;
148    expdate.setTime( aujourdhui.getTime() + ( 365*24*60*60*1000 ) )
149    document.cookie = name + "=" + value + ";expires=" + expdate.toGMTString() ;
150}
151
152
153
154
155function secondsToString(seconds)
156{
157    var numhours = Math.floor(((seconds % 31536000) % 86400) / 3600);
158    var numminutes = Math.floor((((seconds % 31536000) % 86400) % 3600) / 60);
159    var numseconds = (((seconds % 31536000) % 86400) % 3600) % 60;
160    return ( numhours ? numhours + " heure" + ( numhours>1?'s ':' ')  : '' ) +
161	( numminutes ? numminutes + " minute" + (numminutes>1?'s ':' ') :  '' ) +
162	numseconds + " seconde" + ( numseconds>1?'s':'');
163}
164
165
166
167
168/* Local Variables: */
169/* c-basic-offset: 4 */
170/* End: */

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.