MediaWiki:Gadget-ImageAnnotator.js: Difference between revisions

Content deleted Content added
Scope wgNamespaceNumber
mNo edit summary
Line 95:
if (x < 0 || x >= viewer.full_img.width || y < 0 || y >= viewer.full_img.height)
throw new Error('Invalid note: origin invalid on note ' + id);
if ( x + w > viewer.full_img.width + 10
|| y + h > viewer.full_img.height + 10
) {
Line 340:
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;
Line 425:
var editor_width = 50;
// Respect potential user-defined width setting
if ( window.ImageAnnotationEditor_columns
&& !isNaN (window.ImageAnnotationEditor_columns)
&& window.ImageAnnotationEditor_columns >= 30
Line 986:
this.img_div.appendChild(this.img.parentNode);
}
if ( (this.isThumbnail || this.isOther) && !this.may_edit
&& ( onlyIcon
|| this.iconOnly
|| ImageAnnotator_config.inlineImageUsesIndicator
Line 999:
if (this.icon) this.icon = this.icon.firstChild; // Skip the message container span or div
// Guard against misconfigurations
if ( this.icon
&& this.icon.nodeName.toLowerCase() === 'a'
&& this.icon.firstChild.nodeName.toLowerCase() === 'img'
Line 1,046:
var w = IA.getIntItem('full_width_' + id, this.scope);
var h = IA.getIntItem('full_height_' + id, this.scope);
if ( w === this.full_img.width && h === this.full_img.height
&& !Array.exists(this.annotations, function (note) { return note.model.id === id; })
) {
Line 1,083:
}
}
if ( !(this.isThumbnail || this.isOther)
|| !this.noCaption
&& !IA.hideCaptions
Line 1,194:
}
// Now set position and width and height, subtracting cumulated border widths
if ( view_x !== node.offsetLeft || view_y !== node.offsetTop
|| view_w !== node.offsetWidth || view_h !== node.offsetHeight
) {
Line 1,287:
}
 
is_within = !( rect.x >= rect.r || rect.y >= rect.b // Empty rectangle
|| rect.x >= mouse_pos.x || rect.r <= mouse_pos.x
|| rect.y >= mouse_pos.y || rect.b <= mouse_pos.y
);
if (is_within) {
Line 1,297:
for (i = this.annotations.length - 1; i >= 0; i--) {
display = this.annotations[i].view.style.display;
if ( display !== 'none' && display != null
&& LAPI.Pos.isWithin(this.annotations[i].view.firstChild, mouse_pos.x, mouse_pos.y)
) {
Line 1,451:
// Determine whether we have XmlHttp. We try to determine this here to be able to avoid
// doing too much work.
if ( window.XMLHttpRequest
&& typeof LAPI !== 'undefined'
&& typeof LAPI.Ajax !== 'undefined'
Line 1,485:
// but overrideable by per-image rules. If set, it's not overrideable by per-image rules.
//
if ( !self.haveAjax
|| !config.generalImagesEnabled()
|| namespaceCheck(window.ImageAnnotator_no_images)
Line 1,493:
self.rules.shared.show = false;
} else {
if ( !self.haveAjax
|| !config.thumbsEnabled()
|| namespaceCheck(window.ImageAnnotator_no_thumbs)
Line 1,501:
if (conf.wgNamespaceNumber === 6)
self.rules.shared.show = true;
else if ( !config.sharedImagesEnabled()
|| namespaceCheck(window.ImageAnnotator_no_shared)
) {
Line 1,526:
self.rules.shared.show = false;
}
if ( typeof self.rules.inline.show === 'undefined'
&& rules.className.indexOf('wpImageAnnotatorDisplay') >= 0
) {
Line 1,534:
self.rules.thumbs.show = false;
}
if ( typeof self.rules.thumbs.show === 'undefined'
&& rules.className.indexOf('wpImageAnnotatorThumbDisplay') >= 0
) {
Line 1,649:
self.is_rtl =
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,742:
if (!dim) return null;
// Conditionally exclude shared images.
if ( scope !== document
&& !self.rules.shared.show
&& ImageAnnotator_config.imageIsFromSharedRepository(img.src)
Line 1,956:
// script (and call the callback) synchronously before the assignment is done. Clean
// up in that case.
if ( ImageAnnotator.info_callbacks && ImageAnnotator.info_callbacks[idx]
&& ImageAnnotator.info_callbacks[idx].done && ImageAnnotator.info_callbacks[idx].script
) {
Line 2,100:
if (typeof html_text_or_json === 'string')
text = html_text_or_json;
else if ( typeof html_text_or_json !== 'undefined'
&& typeof html_text_or_json.parse !== 'undefined'
&& typeof html_text_or_json.parse.text !== 'undefined'
&& typeof html_text_or_json.parse.text['*'] !== 'undefined'
)
text = html_text_or_json.parse.text['*'];
else
Line 2,333:
cover.style.cursor = 'crosshair';
self.definer =
LAPI.make('div', null, {
border: '1px solid 'div', null+ IA.new_border,
,{ borderdisplay: '1px solid none' + IA.new_border,
,displayposition: 'noneabsolute',
,positiontop: 'absolute0px',
,topleft: '0px',
,leftwidth: '0px',
,widthheight: '0px',
,heightpadding: '0px0',
// IE needs this,padding: '0'even though there are no lines within
,lineHeight: '0px' // IE needs this, even though there are no lines within
,fontSize: '0px' // IE
fontSize: '0px',
,zIndex: cover.style.zIndex - 2 // Below the mouse capture div
// Below }the mouse capture div
,zIndex: cover.style.zIndex - 2 // Below the mouse capture div
});
self.viewers[0].img_div.appendChild(self.definer);
// Enter mouse-tracking mode to define extent of view. Mouse cursor is outside of image,
Line 2,380 ⟶ 2,381:
if (self.may_edit && typeof wgRestrictionEdit !== 'undefined' ) {
self.may_edit =
( (wgRestrictionEdit.length === 0 || wgUserGroups && wgUserGroups.join(' ').contains('sysop'))
|| ( wgRestrictionEdit.length === 1 && wgRestrictionEdit[0] === 'autoconfirmed'
&& wgUserGroups && wgUserGroups.join(' ').contains('confirmed') // confirmed & autoconfirmed
)
Line 2,411 ⟶ 2,412:
 
if (self.may_edit) {
// Respect user override for zoom, if any
 
self.zoom_threshold = ImageAnnotator_config.zoom_threshold;
// Respect user override for zoom, if any
if ( if ( typeof window.ImageAnnotator_zoom_threshold !== 'undefined'
self.zoom_threshold = ImageAnnotator_config.zoom_threshold;
&& !isNaN (window.ImageAnnotator_zoom_threshold >= 0.0)
if ( typeof window.ImageAnnotator_zoom_threshold !== 'undefined'
&& !isNaN (window.ImageAnnotator_zoom_threshold) >= 0.0
&& window.ImageAnnotator_zoom_threshold >= 0.0
) {
// If somebody sets it to a nonsensical high value, that's his or her problem: there won't be any
// zooming.
self.zoom_threshold = window.ImageAnnotator_zoom_threshold;
}
// Adapt zoom threshold for small thumbnails or images with a very lopsided width/height ratio,
// but only if we *can* zoom at least twice
if ( self.viewers[0].full_img.width > 300
&& Math.min(self.viewers[0].factors.dx, self.viewers[0].factors.dy) >= 2.0
) {
if ( self.viewers[0].thumb.width < 400
|| self.viewers[0].thumb.width / self.viewers[0].thumb.height > 2.0
|| self.viewers[0].thumb.height / self.viewers[0].thumb.width > 2.0
) {
// If somebody sets it to a nonsensical high value, that's his or her problem: there won't be any
self.zoom_threshold = 0; // Force zooming
// zooming.
self.zoom_threshold = window.ImageAnnotator_zoom_threshold;
}
// Adapt zoom threshold for small thumbnails or images with a very lopsided width/height ratio,
// but only if we *can* zoom at least twice
if ( if ( self.viewers[0].full_img.width > 300
&& Math.min(self.viewers[0].factors.dx, self.viewers[0].factors.dy) >= 2.0
) {
if ( if ( self.viewers[0].thumb.width < 400
|| self.viewers[0].thumb.width / self.viewers[0].thumb.height > 2.0
|| self.viewers[0].thumb.height / self.viewers[0].thumb.width > 2.0
) {
self.zoom_threshold = 0; // Force zooming
}
}
}
 
self.editor = new ImageAnnotationEditor();
 
self.button_div = LAPI.make('div');
self.viewers[0].main_div.appendChild(self.button_div);
self.add_button =
LAPI.DOM.makeButton(
'ImageAnnotationAddButton'
, ImageAnnotator.UI.get('wpImageAnnotatorAddButtonText', true)
, add_new
);
var add_plea = ImageAnnotator.UI.needs_plea;
self.button_div.appendChild(self.add_button);
self.help_link = self.createHelpLink();
if (self.help_link) {
self.button_div.appendChild(document.createTextNode('\xa0'));
self.button_div.appendChild(self.help_link);
}
if (add_plea && wgServer.contains('/commons'))
self.button_div.appendChild(ImageAnnotator.UI.get_plea());
 
self.button_div = LAPI.make('div');
self.viewers[0].main_div.appendChild(self.button_div);
self.add_button =
LAPI.DOM.makeButton(
'ImageAnnotationAddButton'
, ImageAnnotator.UI.get('wpImageAnnotatorAddButtonText', true)
, add_new
);
var add_plea = ImageAnnotator.UI.needs_plea;
self.button_div.appendChild(self.add_button);
self.help_link = self.createHelpLink();
if (self.help_link) {
self.button_div.appendChild(document.createTextNode('\xa0'));
self.button_div.appendChild(self.help_link);
}
if (add_plea && wgServer.contains('/commons'))
self.button_div.appendChild(ImageAnnotator.UI.get_plea());
} // end if may_edit
 
Line 2,609 ⟶ 2,608:
if (rules && rules.length) {
rules = rules[0];
if ( typeof local_rules.inline.show === 'undefined'
&& LAPI.DOM.hasClass(rules, 'wpImageAnnotatorNoInlineDisplay')
) {
local_rules.inline.show = false;
}
if ( typeof local_rules.inline.icon === 'undefined'
&& LAPI.DOM.hasClass(rules, 'wpImageAnnotatorInlineDisplayIcon')
) {
local_rules.inline.icon = true;
}
if ( typeof local_rules.thumbs.show === 'undefined'
&& LAPI.DOM.hasClass(rules, 'wpImageAnnotatorNoThumbs')
) {
local_rules.thumbs.show = false;
}
if ( typeof local_rules.thumbs.icon === 'undefined'
&& LAPI.DOM.hasClass(rules, 'wpImageAnnotatorThumbDisplayIcon')
) {
Line 2,648 ⟶ 2,647:
if (!self.viewers[v].isThumbnail || local_rules.thumbs.show) {
self.viewers[v].scope = pages[i];
self.viewers[v].setup( self.viewers[v].isThumbnail && local_rules.thumbs.icon
|| self.viewers[v].isOther && local_rules.inline.icon);
}
Line 2,687 ⟶ 2,686:
, true // No local caching!
);
if ( ImageAnnotator.script_callbacks && ImageAnnotator.script_callbacks[idx]
&& ImageAnnotator.script_callbacks[idx].done && ImageAnnotator.script_callbacks[idx].script
) {
Line 2,726 ⟶ 2,725:
show_zoom: function () {
var self = IA;
if ( ( self.viewers[0].factors.dx < self.zoom_threshold
&& self.viewers[0].factors.dy < self.zoom_threshold
)
Line 2,877 ⟶ 2,876:
}
}
if ( msg.childNodes.length === 1
&& msg.firstChild.nodeName.toLowerCase() === 'a'
&& !LAPI.DOM.hasClass(msg.firstChild, 'image')