Setting up the repo.
[wakaba-kareha.git] / kareha.js
blobe63819be7f19c2fe820a7c2ddcaf00df8411d997
1 function require_script_version(v)
3         if(v!="3.a") alert("The board has been upgraded. You need to force a reload in your browser to complete the update.\nThis is usually done by holding down Shift and pressing the reload button.");
8 function show(id)
10         var style=document.getElementById(id).style;
11         if(style.display) style.display="";
12         else style.display="none";
15 function insert(text,thread)
17         var textarea=document.getElementById("postform"+thread).comment;
18         if(textarea)
19         {
20                 if(textarea.createTextRange && textarea.caretPos) // IE
21                 {
22                         var caretPos=textarea.caretPos;
23                         caretPos.text=caretPos.text.charAt(caretPos.text.length-1)==" "?text+" ":text;
24                 }
25                 else if(textarea.setSelectionRange) // Firefox
26                 {
27                         var start=textarea.selectionStart;
28                         var end=textarea.selectionEnd;
29                         textarea.value=textarea.value.substr(0,start)+text+textarea.value.substr(end);
30                         textarea.setSelectionRange(start+text.length,start+text.length);
31                 }
32                 else
33                 {
34                         textarea.value+=text+" ";
35                 }
36                 textarea.focus();
37         }
40 function w_insert(text,link)
42         if(document.body.className=="mainpage") document.location=link+"#i"+text;
43         else insert(text,"");
46 function size_field(id,rows) { document.getElementById(id).comment.setAttribute("rows",rows); }
50 function delete_post(thread,post,file)
52         if(confirm("Are you sure you want to delete reply "+post+"?"))
53         {
54                 var fileonly=false;
55                 var script=document.forms[0].action;
56                 var password=document.forms[0].password.value;
58                 if(file) fileonly=confirm("Leave the reply text and delete the only file?");
60                 document.location=script
61                 +"?task=delete"
62                 +"&delete="+thread+","+post
63                 +"&password="+password
64                 +"&fileonly="+(fileonly?"1":"0");
65         }
68 function preview_post(formid,thread)
70         var form=document.getElementById(formid);
71         var preview=document.getElementById("preview"+thread);
73         if(!form||!preview) return;
75         preview.style.display="";
76         preview.innerHTML="<em>Loading...</em>";
78         var text;
79         text="task=preview";
80         text+="&comment="+encodeURIComponent(form.comment.value);
81         text+="&markup="+encodeURIComponent(form.markup.value);
82         if(thread) text+="&thread="+thread;
84         var xmlhttp=get_xmlhttp();
85         xmlhttp.open("POST",self);
86         xmlhttp.onreadystatechange=function() {
87                 if(xmlhttp.readyState==4) preview.innerHTML=xmlhttp.responseText;
88         }
89         if(is_ie()||xmlhttp.setRequestHeader) xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
90         xmlhttp.send(text);
93 function get_xmlhttp()
95         var xmlhttp;
96         try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
97         catch(e1)
98         {
99                 try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
100                 catch(e1) { xmlhttp=null; }
101         }
103         if(!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp=new XMLHttpRequest();
105         return(xmlhttp);
108 function is_ie()
110         return(document.all&&!document.opera);
115 function set_new_inputs(id)
117         var el=document.getElementById(id);
119         if(!el||!el.link) return;
121         if(!el.field_a.value) el.field_a.value=get_cookie("name");
122         if(!el.field_b.value) el.field_b.value=get_cookie("link");
123         if(!el.password.value) el.password.value=get_password("password");
124         if(el.markup&&!el.comment.value) el.markup.value=get_cookie("markup");
125         select_markup(el.markup);
128 function set_delpass(id)
130         with(document.getElementById(id)) password.value=get_cookie("password");
133 function make_password()
135         var chars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
136         var pass='';
138         for(var i=0;i<8;i++)
139         {
140                 var rnd=Math.floor(Math.random()*chars.length);
141                 pass+=chars.substring(rnd,rnd+1);
142         }
144         return(pass);
147 function get_password(name)
149         var pass=get_cookie(name);
150         if(pass) return pass;
151         return make_password();
154 function select_markup(sel)
156         if(!window.markup_descriptions) return;
158         var el=sel;
159         while(el=el.nextSibling) if(el.nodeName.toLowerCase()=="small") break;
161         if(el) el.innerHTML=markup_descriptions[sel.value];
166 function get_cookie(name)
168         with(document.cookie)
169         {
170                 var regexp=new RegExp("(^|;\\s+)"+name+"=(.*?)(;|$)");
171                 var hit=regexp.exec(document.cookie);
172                 if(hit&&hit.length>2) return unescape(hit[2]);
173                 else return '';
174         }
177 function set_cookie(name,value,days)
179         if(days)
180         {
181                 var date=new Date();
182                 date.setTime(date.getTime()+(days*24*60*60*1000));
183                 var expires="; expires="+date.toGMTString();
184         }
185         else expires="";
186         document.cookie=name+"="+value+expires+"; path=/";
189 function set_stylesheet(styletitle)
191         var links=document.getElementsByTagName("link");
192         var found=false;
193         for(var i=0;i<links.length;i++)
194         {
195                 var rel=links[i].getAttribute("rel");
196                 var title=links[i].getAttribute("title");
197                 if(rel.indexOf("style")!=-1&&title)
198                 {
199                         links[i].disabled=true; // IE needs this to work. IE needs to die.
200                         if(styletitle==title) { links[i].disabled=false; found=true; }
201                 }
202         }
203         if(!found) set_preferred_stylesheet();
206 function set_preferred_stylesheet()
208         var links=document.getElementsByTagName("link");
209         for(var i=0;i<links.length;i++)
210         {
211                 var rel=links[i].getAttribute("rel");
212                 var title=links[i].getAttribute("title");
213                 if(rel.indexOf("style")!=-1&&title) links[i].disabled=(rel.indexOf("alt")!=-1);
214         }
217 function get_active_stylesheet()
219         var links=document.getElementsByTagName("link");
220         for(var i=0;i<links.length;i++)
221         {
222                 var rel=links[i].getAttribute("rel");
223                 var title=links[i].getAttribute("title");
224                 if(rel.indexOf("style")!=-1&&title&&!links[i].disabled) return title;
225         }
228 function get_preferred_stylesheet()
230         var links=document.getElementsByTagName("link");
231         for(var i=0;i<links.length;i++)
232         {
233                 var rel=links[i].getAttribute("rel");
234                 var title=links[i].getAttribute("title");
235                 if(rel.indexOf("style")!=-1&&rel.indexOf("alt")==-1&&title) return title;
236         }
237         return null;
242 window.onunload=function(e)
244         if(style_cookie)
245         {
246                 var title=get_active_stylesheet();
247                 set_cookie(style_cookie,title,365);
248         }
251 window.onload=function(e)
253         if(match=/#i(.+)/.exec(document.location.toString()))
254         if(!document.getElementById("postform").comment.value)
255         insert(unescape(match[1]),"");
258 if(style_cookie)
260         var cookie=get_cookie(style_cookie);
261         var title=cookie?cookie:get_preferred_stylesheet();
262         set_stylesheet(title);
265 var captcha_key=make_password();