MediaWiki talk:Common.js/Archive 4: Difference between revisions

Content deleted Content added
Shadowbot3 (talk | contribs)
m Automated archival of 2 sections from MediaWiki talk:Common.js
Shadowbot3 (talk | contribs)
m Automated archival of 1 sections from MediaWiki talk:Common.js
Line 110:
 
:As Ruud just said, there is no need for a fallback, since the edit tools already do not work (and cannot work) without Javascript. --[[User:CesarB|cesarb]] 14:06, 8 March 2007 (UTC)
<span id="63299025922" />
== Placing the cursor after the section name ==
 
A long time ago, [[User_talk:Quarl/Archive_2006-02#User:Quarl.2Fauto_summary.js|Quarl and I discussed]] some user scripts and made a little snippet of code that, when you press ''tab'' to go to the Summary field, puts your cursor after the section name, so you can just start typing. It's a tremendously helpful little tweak, and now that I've removed Quarl's code from my monobook.js, I miss it. :-) It would be a good thing to implement site-wide, though. This was my version, though I think he improved on it in his Power Tools scripts:
 
<pre>
/* When the summary box is clicked, select only the part *after* the section title/place the cursor after the auto summary */
 
addOnloadHook(function () {
if (document.getElementById('wpSummary')) {
summary = document.getElementById('wpSummary');
function selectSummary() {
section = summary.value.match(/(?:\/\*(?:.*)\*\/)?\s*(?:«(?:.*)»)? ?/);
if (section) {
sectlen = section[0].length;
end = summary.textLength;
summary.setSelectionRange(sectlen,end);
}
}
summary.onclick = selectSummary;
}
});
</pre>
 
I don't know enough about JavaScript to follow his code, but I think this is equivalent:
 
<pre>
// auto focus
$autosummary._focusSummaryEvent = function(event) {
var sumField = document.editform.wpSummary;
if (sumField.value.match(/^(?:\/\*.*?\*\/)?\s*(?:«(?:.*)»)? ?/)) {
var n = RegExp.lastMatch.length;
var m = sumField.value.length;
// apparently you can't setSelectionRange in an onFocus handler, but
// you can set a timer to do it 0 seconds from now.
setTimeout(function() { sumField.setSelectionRange(n, m) }, 0);
}
}
</pre>
 
Found on http://www.cubewano.org/wpt/scripts/COMBINED.js
 
— [[User:Omegatron|Omegatron]] 00:13, 2 March 2007 (UTC)
:Please check that code on multiple browsers; I think I remember something about selection code being different on IE and FireFox. --[[User:ais523|ais523]] 11:21, 9 March 2007 ([[User:ais523|U]][[User talk:ais523|T]][[Special:Contributions/Ais523|C]])
 
:: I don't know enough to check it for compatibility with all browsers and situations. I'm just proposing that someone with the knowledge include it site-wide. — [[User:Omegatron|Omegatron]] 03:59, 10 March 2007 (UTC)
:::Your version is a syntax error in IE6. Code shouldn't be added to the site-wide JS unless it works on ''all'' browsers! --[[User:ais523|ais523]] 14:45, 12 March 2007 ([[User:ais523|U]][[User talk:ais523|T]][[Special:Contributions/Ais523|C]])