https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=User%3AJava7837%2FSearchBox.js User:Java7837/SearchBox.js - Revision history 2025-06-09T18:08:13Z Revision history for this page on the wiki MediaWiki 1.45.0-wmf.4 https://en.wikipedia.org/w/index.php?title=User:Java7837/SearchBox.js&diff=1005263405&oldid=prev Ladsgroup: Maintenance: Replacing addOnloadHook with native jQuery (mw:ResourceLoader/Migration_guide_(users)#addOnloadHook - phab:T130879) 2021-02-06T20:38:01Z <p>Maintenance: Replacing addOnloadHook with native jQuery (<a href="https://www.mediawiki.org/wiki/ResourceLoader/Migration_guide_(users)#addOnloadHook" class="extiw" title="mw:ResourceLoader/Migration guide (users)">mw:ResourceLoader/Migration_guide_(users)#addOnloadHook</a> - <a href="https://phabricator.wikimedia.org/T130879" class="extiw" title="phab:T130879">phab:T130879</a>)</p> <table style="background-color: #fff; color: #202122;" data-mw="interface"> <col class="diff-marker" /> <col class="diff-content" /> <col class="diff-marker" /> <col class="diff-content" /> <tr class="diff-title" lang="en"> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td> <td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 20:38, 6 February 2021</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 302:</td> <td colspan="2" class="diff-lineno">Line 302:</td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> + '&amp;action=raw&amp;ctype=text/css&amp;dontcountme=s"&gt;');</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> + '&amp;action=raw&amp;ctype=text/css&amp;dontcountme=s"&gt;');</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td> </tr> <tr> <td class="diff-marker" data-marker="−"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div><del style="font-weight: bold; text-decoration: none;">addOnloadHook</del>(srInit);</div></td> <td class="diff-marker" data-marker="+"></td> <td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div><ins style="font-weight: bold; text-decoration: none;">$</ins>(srInit);</div></td> </tr> <tr> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>//&lt;/nowiki&gt;&lt;/pre&gt;</div></td> <td class="diff-marker"></td> <td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div>//&lt;/nowiki&gt;&lt;/pre&gt;</div></td> </tr> </table> Ladsgroup https://en.wikipedia.org/w/index.php?title=User:Java7837/SearchBox.js&diff=121306650&oldid=prev Java7837: ←Created page with '// Search box for Mediawiki // (c) 2006 User:Zocky, released under GPL //<pre><nowiki> var sr$t; var sr$f; var sr$s; var sr$r; var sr$w; var sr$i; var sr$re; v...' 2007-04-09T00:38:10Z <p><a href="/wiki/Wikipedia:AES" class="mw-redirect" title="Wikipedia:AES">←</a>Created page with &#039;// Search box for Mediawiki // (c) 2006 <a href="/wiki/User:Zocky" title="User:Zocky">User:Zocky</a>, released under GPL //&lt;pre&gt;&lt;nowiki&gt; var sr$t; var sr$f; var sr$s; var sr$r; var sr$w; var sr$i; var sr$re; v...&#039;</p> <p><b>New page</b></p><div>// Search box for Mediawiki<br /> // (c) 2006 [[User:Zocky]], released under GPL<br /> //&lt;pre&gt;&lt;nowiki&gt;<br /> <br /> var sr$t;<br /> var sr$f;<br /> var sr$s;<br /> var sr$r;<br /> var sr$w;<br /> var sr$i;<br /> var sr$re;<br /> var sr$mc;<br /> <br /> function $e(id) {return document.getElementById(id)}<br /> <br /> function srBack()<br /> {<br /> if (sr$s.value==&#039;&#039;) {sr$t.focus(); return }<br /> <br /> if (sr$re.checked) {<br /> var searchString = sr$s.value;<br /> } else {<br /> searchString=sr$s.value.replace(/([\[\]\{\}\|\.\*\?\(\)\$\^\\])/g,&#039;\\$1&#039;);<br /> }<br /> <br /> searchString=&quot;(&quot;+searchString+&quot;)(?![\\s\\S]*&quot;+searchString+&quot;)&quot;;<br /> if (sr$mc.checked)<br /> var re=new RegExp(searchString);<br /> else<br /> var re=new RegExp(searchString,&quot;i&quot;);<br /> <br /> var res = re.exec (sr$t.value.substring(0,sr$t.selectionStart));<br /> if (!res) {<br /> var res = re.exec (sr$t.value)<br /> }<br /> <br /> if (res)<br /> {<br /> sr$t.selectionStart=res.index;<br /> sr$t.selectionEnd=res.index+res[1].length;<br /> }<br /> else sr$t.selectionStart=sr$t.selectionEnd;<br /> <br /> srSync();<br /> }<br /> <br /> function srNext()<br /> {<br /> if (sr$s.value==&#039;&#039;) {sr$t.focus(); return }<br /> <br /> if (sr$re.checked) {<br /> var searchString = sr$s.value;<br /> } else {<br /> searchString=sr$s.value.replace(/([\[\]\{\}\|\.\*\?\(\)\$\^\\])/g,&#039;\\$1&#039;);<br /> }<br /> <br /> if (sr$mc.checked)<br /> var re=new RegExp(searchString,&quot;g&quot;);<br /> else<br /> var re=new RegExp(searchString,&quot;gi&quot;);<br /> <br /> re.lastIndex=sr$t.selectionEnd;<br /> var res = re.exec (sr$t.value)<br /> if (!res) {<br /> re.lastIndex=0;<br /> var res = re.exec (sr$t.value)<br /> }<br /> <br /> if (res)<br /> {<br /> sr$t.selectionStart=res.index;<br /> sr$t.selectionEnd=res.index+res[0].length;<br /> }<br /> else sr$t.selectionStart=sr$t.selectionEnd;<br /> srSync();<br /> }<br /> <br /> function srReplace()<br /> {<br /> <br /> var sels=sr$t.selectionStart;<br /> var sele=sr$t.selectionEnd;<br /> var selr=sr$t.value.length-sele;<br /> <br /> if (sr$s.value==&#039;&#039; || sels==sele) {sr$t.focus(); return }<br /> <br /> if (sr$re.checked) {<br /> var searchString = sr$s.value;<br /> var replaceString = sr$r.value;<br /> <br /> } else {<br /> searchString=sr$s.value.replace(/([\[\]\{\}\|\.\*\?\(\)\$\^\\])/g,&#039;\\$1&#039;);<br /> replaceString=sr$r.value.replace(/([\$\\])/g,&#039;\\$1&#039;);<br /> }<br /> <br /> if (sr$mc.checked)<br /> var re=new RegExp(searchString,&quot;g&quot;);<br /> else<br /> var re=new RegExp(searchString,&quot;gi&quot;);<br /> <br /> re.lastIndex=sels;<br /> var res = re.exec (sr$t.value);<br /> var $$=0;<br /> if (res &amp;&amp; res.index==sels &amp;&amp; res[0].length==sele-sels)<br /> {<br /> if (sr$re.checked) {<br /> replaceString=replaceString.replace(/\\\\/g,&#039;&amp;backslash;&#039;).replace(/\\\$/g,&#039;&amp;dollar;&#039;)<br /> var replaceBits=(&quot; &quot;+replaceString).split(/(?=\$\d)/);<br /> replaceString=replaceBits[0].substring(1);<br /> for (var i=1; i&lt;replaceBits.length; i++)<br /> {<br /> $$=replaceBits[i][1]-&#039;0&#039;;<br /> if ($$&lt;res.length)<br /> replaceString += res[$$] + replaceBits[i].substring(2)<br /> else<br /> replaceString += replaceBits[i];<br /> }<br /> replaceString=replaceString.replace (/\\n/,&quot;\n&quot;).replace (/&amp;backslash;/g,&quot;\\&quot;).replace<br /> (/&amp;dollar;/g,&quot;\$&quot;)<br /> <br /> }<br /> sr$t.value= sr$t.value.substring(0,sels) + replaceString + sr$t.value.substring(sele);<br /> }<br /> <br /> sr$t.selectionStart=sels;<br /> sr$t.selectionEnd=sr$t.value.length-selr;<br /> srSync();<br /> }<br /> <br /> <br /> function srReplaceall()<br /> {<br /> if (!sr$s.value) {sr$t.focus(); return }<br /> <br /> var sels=sr$t.selectionStart;<br /> var sele=sr$t.selectionEnd;<br /> var selr=sr$t.value.length-sele;<br /> <br /> var reps;<br /> <br /> if (sr$re.checked) {<br /> var searchString = sr$s.value;<br /> var replaceString = sr$r.value.replace(/\\\\/,&#039;&amp;backslash;&#039;).replace(/\\n/,&#039;\n&#039;).replace(/&amp;backslash;/,&quot;\\&quot;);<br /> } else {<br /> searchString=sr$s.value.replace(/([\[\]\{\}\|\.\*\?\(\)\$\^\\])/g,&#039;\\$1&#039;);<br /> replaceString=sr$r.value.replace(/([\$\\])/g,&#039;\\$1&#039;);<br /> }<br /> <br /> if (sele&gt;sels)<br /> reps=sr$t.value.substring(sels,sele);<br /> else<br /> reps=sr$t.value;<br /> <br /> if (sr$mc.checked)<br /> var re=new RegExp(searchString,&quot;g&quot;);<br /> else<br /> var re=new RegExp(searchString,&quot;gi&quot;);<br /> <br /> var replaceCounter=0;<br /> <br /> var replaceFunc=function(){replaceCounter++;return replaceString};<br /> <br /> reps=reps.replace(re,replaceFunc);<br /> <br /> if (sele&gt;sels)<br /> sr$t.value = sr$t.value.substring(0,sels) + reps + sr$t.value.substring(sele);<br /> else<br /> sr$t.value = reps;<br /> <br /> sr$t.selectionStart=sels;<br /> sr$t.selectionEnd=sele&gt;sels ? sr$t.value.length-selr : sels;<br /> window.status = replaceCounter+&quot; ocurrences of &quot; + searchString + &quot; replaced.&quot;;<br /> srSync();<br /> }<br /> <br /> function srToggleCase()<br /> {<br /> var sels=sr$t.selectionStart;<br /> var sele=sr$t.selectionEnd;<br /> var selr=sr$t.value.length-sele;<br /> var selt=sr$t.value.substring(sels,sele);<br /> <br /> if (sele&gt;sels)<br /> {<br /> if (selt==selt.toUpperCase())<br /> selt=selt.toLowerCase()<br /> else if (selt==selt.toLowerCase() &amp;&amp; sele-sels&gt;1)<br /> selt=selt.substring(0,1).toUpperCase()+selt.substring(1).toLowerCase()<br /> else<br /> selt=selt.toUpperCase();<br /> <br /> sr$t.value = sr$t.value.substring(0,sels) + selt + sr$t.value.substring(sele);<br /> sr$t.selectionStart=sels;<br /> sr$t.selectionEnd=sele&gt;sels ? sr$t.value.length-selr : sels;<br /> }<br /> srSync();<br /> }<br /> <br /> <br /> function srSync()<br /> {<br /> var i;<br /> var allLines=0;<br /> var lineNo=0;<br /> var w=sr$t.cols-5;<br /> <br /> var dummy=sr$t.value.split(&quot;\n&quot;);<br /> for (i=0;i&lt;dummy.length;i++){allLines+=Math.ceil(dummy[i].length/w)}<br /> <br /> var dummy=sr$t.value.substring(0,sr$t.selectionStart).split(&quot;\n&quot;);<br /> for (i=0;i&lt;dummy.length;i++){lineNo+=Math.ceil(dummy[i].length/w)}<br /> <br /> // alert (w+&quot; &quot;+lineNo+&quot;/&quot;+allLines);<br /> <br /> sr$t.scrollTop=sr$t.scrollHeight*(lineNo-10)/allLines;<br /> sr$t.focus();<br /> }<br /> <br /> <br /> function srInit()<br /> {<br /> <br /> if($e(&#039;wpTextbox1&#039;)) {<br /> <br /> var srBoxCode =&#039;&lt;div id=&quot;srForm&quot;&gt;&lt;table id=&quot;srBox&quot; cellpadding=&quot;0&quot; cellspacing=&quot;2&quot;&gt;&#039;<br /> +&#039;&lt;tr&gt;&lt;td valign=&quot;bottom&quot;&gt;&lt;small&gt;&lt;span style=&quot;color:#000000;&quot;&gt;search for:&lt;/span&gt;&lt;/small&gt;&lt;br/&gt;&#039;<br /> +&#039;&lt;input type=&quot;text&quot; id=&quot;srSearch&quot; accesskey=&quot;F&quot; tabindex=&quot;8&quot;&#039;<br /> +&#039;onkeypress=&quot;event.which == 13 &amp;&amp; srNext()&quot;; value=&quot;&quot;/&gt;&lt;/td&gt;&#039;<br /> +&#039;&lt;td valign=&quot;bottom&quot;&gt;&lt;small&gt;&lt;span style=&quot;color:#000000;&quot;&gt;replace with:&lt;/span&gt;&lt;/small&gt;&lt;br/&gt;&lt;input type=&quot;text&quot; id=&quot;srReplace&quot; accesskey=&quot;G&quot; tabindex=&quot;9&quot;&#039;<br /> +&#039;onkeypress=&quot;event.which == 13 &amp;&amp; srNext()&quot;; value=&quot;&quot;/&gt;&lt;/td&gt;&#039;<br /> +&#039;&lt;td valign=&quot;top&quot;&gt;&#039;<br /> +&#039;&lt;input type=&quot;checkbox&quot; id=&quot;srCase&quot; onclick=&quot;sr$t.focus()&quot; tabindex=&quot;10&quot;/&gt;&lt;small&gt;&lt;span style=&quot;color:#000000;&quot;&gt;match case&lt;/span&lt;/small&gt;&#039;<br /> +&#039;&lt;input type=&quot;checkbox&quot; id=&quot;srRegexp&quot; onclick=&quot;sr$t.focus()&quot; tabindex=&quot;11&quot;/&gt;&lt;small&gt;&lt;span style=&quot;color:#000000;&quot;&gt;use regexp&lt;/span&gt;&lt;/small&gt;&lt;br/&gt; &#039;<br /> +&#039;&lt;a href=&quot;javascript:srBack()&quot; onmouseover=&quot;sr$t.focus()&quot; title=&quot;find previous match [alt-2]&quot; accesskey=&quot;2&quot;&gt;&amp;lt;&lt;/a&gt;&amp;nbsp;&#039;<br /> +&#039;&lt;a href=&quot;javascript:srNext()&quot; onmouseover=&quot;sr$t.focus()&quot; title=&quot;find next match [alt-3]&quot; accesskey=&quot;3&quot;&gt;find&amp;nbsp;&amp;nbsp;&amp;gt;&lt;/a&gt;&amp;emsp;&#039;<br /> +&#039;&lt;a href=&quot;javascript:srReplace();srBack()&quot; onmouseover=&quot;sr$t.focus()&quot; title=&quot;replace and find previous match [alt-4]&quot; accesskey=&quot;4&quot;&gt;&amp;lt;&lt;/a&gt;&amp;nbsp;&#039;<br /> +&#039;&lt;a href=&quot;javascript:srReplace()&quot; onmouseover=&quot;sr$t.focus()&quot; title=&quot;replace this match&quot;&gt;replace&lt;/a&gt;&amp;nbsp;&#039;<br /> +&#039;&lt;a href=&quot;javascript:srReplace();srNext()&quot; onmouseover=&quot;sr$t.focus()&quot; title=&quot;replace and find next match [alt-5]&quot; accesskey=&quot;5&quot;&gt;&amp;gt;&lt;/a&gt;&amp;emsp;&#039;<br /> +&#039;&lt;a href=&quot;javascript:srReplaceall()&quot; onmouseover=&quot;sr$t.focus()&quot; title=&quot;replace all matches [alt-7]&quot; accesskey=&quot;7&quot;&gt;replace&amp;nbsp;all&lt;/a&gt;&amp;emsp;&#039;<br /> +&#039;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&#039;<br /> <br /> var ep=$e(&#039;searchInput&#039;);<br /> if (ep) ep.accessKey=&#039;none&#039;;<br /> <br /> sr$t=document.editform.wpTextbox1;<br /> sr$w=sr$t.style.width;<br /> <br /> var sr=document.createElement(&#039;div&#039;);<br /> sr.innerHTML=srBoxCode;<br /> <br /> var im=document.createElement(&#039;span&#039;);<br /> im.innerHTML=&#039;&lt;a id=&quot;SearchIcon&quot; href=&quot;javascript:srShowHide()&quot;&gt;&lt;img style=&quot;cursor: pointer;&quot; title=&quot;Search/Replace&quot; alt=&quot;Search/Replace&quot; src=&quot;/media/wikipedia/en/1/12/Button_find.png&quot; border=&quot;0&quot; height=&quot;22&quot; width=&quot;23&quot;&gt;&lt;/a&gt;&lt;a href=&quot;javascript:srToggleCase()&quot;&gt;&lt;img style=&quot;cursor: pointer;&quot; title=&quot;Toggle case&quot; alt=&quot;Toggle case&quot; src=&quot;/media/wikipedia/en/1/12/Button_case.png&quot; border=&quot;0&quot; height=&quot;22&quot; width=&quot;23&quot;&gt;&lt;/a&gt;&#039;;<br /> <br /> var ep=$e(&#039;toolbar&#039;);<br /> if (ep)<br /> {<br /> ep.appendChild(im)<br /> }<br /> else<br /> {<br /> var ep=$e(&#039;editform&#039;);<br /> ep.parentNode.insertBefore(im,ep);<br /> } <br /> <br /> sr$i=$e(&#039;SearchIcon&#039;);<br /> sr$i.accessKey=&quot;F&quot;;<br /> sr.firstChild.style.display=&#039;none&#039;;<br /> <br /> <br /> var ep=$e(&#039;editform&#039;);<br /> ep.parentNode.insertBefore(sr,ep);<br /> <br /> sr$f=$e(&#039;srForm&#039;);<br /> sr$s=$e(&#039;srSearch&#039;);<br /> sr$r=$e(&#039;srReplace&#039;);<br /> sr$re=$e(&#039;srRegexp&#039;);<br /> sr$mc=$e(&#039;srCase&#039;);<br /> <br /> }<br /> }<br /> <br /> function srShowHide()<br /> {<br /> if (sr$f.style.display==&#039;none&#039;)<br /> {<br /> sr$f.style.display=&#039;block&#039;;<br /> sr$i.accessKey=&quot;none&quot;;<br /> sr$t.style.width=&#039;auto&#039;;<br /> sr$s.focus();<br /> }<br /> else<br /> {<br /> sr$f.style.display=&#039;none&#039;;<br /> sr$t.style.width=sr$w;<br /> sr$i.accessKey=&quot;F&quot;;<br /> }<br /> }<br /> <br /> <br /> document.write(&#039;&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;&#039; <br /> + &#039;http://en.wikipedia.org/w/index.php?title=User:Zocky/SearchBox.css&#039;<br /> + &#039;&amp;action=raw&amp;ctype=text/css&amp;dontcountme=s&quot;&gt;&#039;);<br /> <br /> addOnloadHook(srInit);<br /> //&lt;/nowiki&gt;&lt;/pre&gt;</div> Java7837