User:PC-XT/Advisor.js: Difference between revisions

Content deleted Content added
m summary: no ; after section
maintenance: more info TypeError: Cannot read property 'parentNode' of null
 
(12 intermediate revisions by 3 users not shown)
Line 1:
//<nowiki>
// See http://en.wikipedia.org/wiki/User:Cameltrader/Advisor.js/Description
// for details and installation instructions.
Line 22 ⟶ 23:
// Initialise static variables used within this function
var _static = arguments.callee; // this is the Function we are in. It will be used as a poor man's function-local static scope.
ta.focus();
ta.setSelectionRange(start, end);
if(ct.noscroll)return;
if (ta.setSelectionRange) {
// Guess the vertical scroll offset by creating a
Line 41 ⟶ 45:
hta.style.width = ta.clientWidth + 'px';
hta.style.height = ta.clientHeight + 'px';
hta.value = _static.NEWLINES.substring(0, ta.rows) + ta.value.substring(0, start/*+(end-start)/2*/);
var yOffset = hta.scrollHeight;
hta.style.display = 'none';
//if(yOffset>ta.scrollTop||yOffset<=ta.scrollTop-ta.clientHeight) {
ta.focus();
if (yOffset -=> Math.floor(ta.clientHeight) / 2);{
ta.setSelectionRange(start, end);
if ta.scrollTop = (yOffset >- Math.floor(ta.clientHeight) {/ 2);
// Opera does not support setting the scrollTop property
yOffset -= Math.floor(ta.clientHeight / 2);
if (ta.scrollTop != yOffset;) {
// todo: Warn the user or apply a workaround
// Opera does not support setting the scrollTop property
}
if (ta.scrollTop != yOffset) {
} else {
// todo: Warn the user or apply a workaround
if ( ta.scrollTop != yOffset) {0;
}
//} else {
ta.scrollTop = 0;
}
} else {
// IE incorrectly counts '\r\n' as a signle character
Line 120 ⟶ 123:
// It is convenient to embed in a help popup.
ct.hlink = function (toWhat, text) {
var wgServer = windowmw.config.get('wgServer') || 'http://en.wikipedia.org';
var wgArticlePath = windowmw.config.get('wgArticlePath') || '/wiki/$1';
var url = (wgServer + wgArticlePath).replace('$1', toWhat);
return '<a href="' + url + '" target="_blank">' + (text || toWhat) + '</a>';
Line 250 ⟶ 253:
var e = document.getElementById('editform');
while (true) {
var p = e && e.previousSibling;
if ( (p == null) || ((p.nodeType == 1) && (p.id != 'toolbar')) ) {
break;
Line 256 ⟶ 259:
e = p;
}
if(e) {
e.parentNode.insertBefore(ct.eSuggestions, e);
} else {
return;
}
ct.eAddToSummary = document.createElement('DIV');
ct.eAddToSummary.style.border = 'dashed #ccc 1px';
Line 368 ⟶ 375:
}
// Warn about scanning a talk page
ifvar ((window.wgCanonicalNamespace != nullmw.config.get('wgCanonicalNamespace');
&& if /(\b|_)talk$/i.test(window.wgCanonicalNamespace != null)
&& /(\b|_)talk$/i.test(wgCanonicalNamespace)
&& !ct.isTalkPageScanConfirmed) {
ct.eSuggestions.appendChild(document.createTextNode(
Line 514 ⟶ 522:
return;
}
var editform = document.getElementById('editform');,
var suggestion = ct.suggestions[k];
st=editform.wpTextbox1.scrollTop,
var suggestion = ct.suggestions[k];
if (suggestion.replacement == null) { // the issue is not automatically fixable
return;
Line 527 ⟶ 537:
suggestion.start + suggestion.replacement.length
);
if(ct.noscroll)editform.wpTextbox1.scrollTop=st; //to help automatic scrolling do its job better
// Propose an edit summary unless it's a new section
var editform = document.getElementById('editform');
if (!editform['wpSection'] || (editform['wpSection'].value != 'new')) {
if (ct.appliedSuggestions[suggestion.name] == null) {
Line 551 ⟶ 561:
// Cut off the leading ``, '' and add ``formatting: '' and ``using Advisor.js''
s = ct._(
'formatting: $1 (using [[User:Cameltrader#PC-XT/Advisor.js|Advisor.js]])',
s.substring(2)
);
Line 603 ⟶ 613:
// * name---this is what appears at the top of the page
// * description---used as a tooltip for the name of the suggestion
 
// The rules are stored in an array:
ct.rules = ct.rules||[]; // : Function[]
// and are grouped into categories.
 
// The set of rules to apply depends on the content language. Different
Line 610 ⟶ 624:
// Wikipedia.
 
if (!windowct.noDefaultRules && (!mw.config.get('wgContentLanguage') || (windowmw.config.get('wgContentLanguage') === 'en'))) { // switch to turn off default rules for replacement by custom ones // from this line on, a level of indent is spared
 
// The rules are stored in an array:
ct.rules = ct.rules||[]; // : Function[]
// and are grouped into categories.
 
// === Linking rules ===
Line 1,132 ⟶ 1,142:
ct.rules.push(function (s) {
var exceptions = {};
var wgTitle = windowmw.config.get('wgTitle') || '';
if (exceptions[wgTitle]) {
return [];
Line 1,177 ⟶ 1,187:
 
ct.rules.push(function (s) {
var wgTitle = windowmw.config.get('wgTitle') || '';
var reTitle = /^(a|the) (.*)$/i;
if (!reTitle.test(wgTitle) || (s.indexOf('DEFAULTSORT') !== -1)) {
Line 1,428 ⟶ 1,438:
end: m.end,
name: 'ISBN',
replacement: m[1]+" {{Please check ISBN|"+m[1]+"}}",
description: 'Should be either 10 or 13 digits long',
help: 'ISBN numbers should be either 10 or 13 digits long. '
Line 1,441 ⟶ 1,452:
end: m.end,
name: 'ISBN',
replacement: "{{Please check ISBN|"+m[1]+"}}",
description: 'Improper usage of X as a digit',
help: "``<tt>X</tt>'' can only be used in 10-digit ISBN numbers "
Line 1,466 ⟶ 1,478:
end: m.end,
name: 'ISBN',
replacement: "{{Please check ISBN|"+m[1]+"}}",
description: 'Bad ISBN checksum',
help: 'Bad ISBN checksum for<br/><tt>' + m[1] + '</tt><br/>'
Line 1,473 ⟶ 1,486:
});
 
} // end if (windowmw.config.get('wgContentLanguage') === 'en') // end of default rules
//</nowiki>