MediaWiki:Gadget-ImageAnnotator.js: Difference between revisions
Content deleted Content added
Remove redundant " || null" from namespaceCheck calls. Falsey values are fine, and the function in question checks for falseyness not null |
Stricten a few comparisions |
||
Line 323:
if (span.start > 0) char_before = pagetext.charCodeAt(span.start - 1);
if (span.end < pagetext.length) char_after = pagetext.charCodeAt(span.end);
if ( String.fromCharCode(char_before) === '\n'
&& String.fromCharCode(char_after) === '\n')
span.start = span.start - 1;
pagetext = pagetext.substring(0, span.start) + pagetext.substring(span.end);
Line 592:
IA.is_editing = false;
this.tooltip.hide_now(evt);
if (evt && evt.type === 'keydown' && !this.saving) {
// ESC pressed on new note before a save attempt
this.cancel();
Line 912:
var name = this.realName;
var $fullname;
if (this.isThumbnail || this.scope === document || this.may_edit || !IA.haveAjax) {
this.imgName = this.realName;
this.realName = '';
Line 948:
LAPI.DOM.insertAfter(breaker, floater);
// Remove spurious br tag.
if (breaker.nextSibling && breaker.nextSibling.nodeName.toLowerCase() === 'br')
LAPI.DOM.removeNode(breaker.nextSibling);
} else if (this.isOther || isEnabledImage) {
Line 984:
// Guard against misconfigurations
if ( this.icon
&& this.icon.nodeName.toLowerCase() === 'a'
&& this.icon.firstChild.nodeName.toLowerCase() === 'img'
) {
// Make sure we use the right protocol:
Line 1,097:
Array.any(checks, function (t) {
var o = curStyle[t];
return (o && o !== 'visible') ? o : null;
});
if (overflow) {
Line 1,486:
self.rules.thumbs.show = false;
}
if (wgNamespaceNumber === 6)
self.rules.shared.show = true;
else if ( !config.sharedImagesEnabled()
Line 1,587:
// Guard against other scripts adding aribtrary numbers of divs (dshuf for instance!)
var is_other = true;
while (up && up.nodeName.toLowerCase() === 'div' && is_other) {
up = up.parentNode;
if (up) is_other = (' ' + up.className + ' ').indexOf(' gallerybox ') < 0;
Line 1,601:
self.thumbs = document.getElementsByClassName('thumbinner');
}
if ( wgNamespaceNumber === 6
|| (self.imgs_with_notes.length)
|| (self.thumbs.length)
Line 1,617:
wait_for_required_libraries : function () {
if (typeof Tooltip === 'undefined' || typeof LAPI === 'undefined') {
if (IA.install_attempts++ < IA.max_install_attempts) {
setTimeout(IA.wait_for_required_libraries, 500); // 0.5 sec.
Line 1,637:
LAPI.DOM.hasClass(document.body, 'rtl')
|| ( LAPI.DOM.currentStyle // Paranoia: added recently, not everyone might have it
&& LAPI.DOM.currentStyle(document.body, 'direction') === 'rtl'
)
;
Line 1,661:
// If the image is currently hidden, its clientWidth and clientHeight are not set. Try
// harder to get the true width and height:
if ((!w || !h) && img.style.display !== 'none') {
var copied = img.cloneNode(true);
copied.style.display = '';
Line 1,676:
if (img.src.contains(conf.stylepath)) return null;
// Only if within a link
if (img.parentNode.nodeName.toLowerCase() !== 'a') return null;
if (is_other) {
// Only if the img-within-link construction is within some element that may contain a div!
Line 1,700:
var is_thumb =
scope != document
&& scope.nodeName.toLowerCase() === 'div'
&& LAPI.DOM.hasClass(scope, 'thumbinner')
;
var is_other = scope.nodeName.toLowerCase() === 'img';
if (is_other && self.imgs.length && scope == self.imgs[0]) return null;
if (scope == document) {
Line 1,709:
} else if (!is_thumb && !is_other) {
file_div = scope.getElementsByClassName('wpImageAnnotatorFile');
if (!file_div || file_div.length !== 1) return null;
file_div = file_div[0];
}
Line 1,790:
}
if (wgNamespaceNumber === 6) {
setup_images ([document]);
self.may_edit = self.may_edit && (self.imgs.length === 1);
setup_images (self.imgs_with_notes);
} else {
setup_images (self.imgs_with_notes);
self.may_edit = self.may_edit && (self.imgs.length === 1);
}
Line 1,814:
// need them. This has in particular a benefit if we do have to query for the file sizes below.
if (self.imgs.length === 1 && self.imgs[0].scope == document && !self.haveAjax) {
// Try to get the full size without Ajax.
self.imgs[0].full_img = LAPI.WP.fullImageSizeFromPage();
Line 1,888:
,height: info.imageinfo[0].height};
self.imgs[i].has_page = (typeof info.missing === 'undefined');
self.imgs[i].isLocal = !info.imagerepository || info.imagerepository === 'local';
if (i != 0 || !self.may_edit || !info.protection || wgNamespaceNumber !== 6) return;
// Care about the protection settings
var protection = Array.any(info.protection, function (e) {
return (e.type === 'edit' ? e : null);
});
self.may_edit =
Line 2,045:
if (wgServer.contains('/commons') && add_plea && !no_plea) {
// Add a translation plea.
if (result.nodeName.toLowerCase() === 'div') {
result.appendChild(self.get_plea());
} else {
Line 2,198:
self.may_edit = (!sharedUpload || sharedUpload.length === 0);
}
if (self.may_edit && wgNamespaceNumber !== 6) {
// Only allow edits if the stored page name matches the current one.
var img_page_name = self.imgs[0].scope.getElementsByClassName('wpImageAnnotatorPageName');
Line 2,483:
// in the result, which would make us load the full images, which is desastrous if there are
// many thumbs to large images on the page.
if (done === 5) break;
}
return {text: text, n: done};
Line 2,857:
}
}
if ( msg.childNodes.length === 1
&& msg.firstChild.nodeName.toLowerCase() === 'a'
&& !LAPI.DOM.hasClass(msg.firstChild, 'image')
) {
Line 2,867:
// link.
tgt = msg.lastChild;
if (tgt.nodeName.toLowerCase() !== 'a')
tgt = wgServer + wgArticlePath.replace('$1', 'Help:Gadget-ImageAnnotator');
else
|