MediaWiki:Gadget-ImageAnnotator.js: Difference between revisions
Content deleted Content added
Fix 2.x bug: failure undefined |
more clean up and type coercion guards |
||
Line 153:
this.view.style
);
this.view.style.zIndex
try {
this.view.style.border = '1px solid ' + this.viewer.outer_border;
Line 336:
}
var char_before = 0;
var char_after
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)
span.start = span.start - 1;
pagetext = pagetext.substring(0, span.start) + pagetext.substring(span.end);
Line 395:
if (this.tooltip) this.tooltip.hide_now();
if (this.model && this.model.id > 0 && this.viewer) this.viewer.deregister(this);
this.model
this.view
this.content = null;
this.tooltip = null;
this.viewer
},
Line 517:
editNote: function (note) {
var same_note = (note === this.note);
this.note = note;
this.viewer = this.note.viewer;
var cover
cover.style.cursor = 'auto';
IA.show_cover();
Line 576:
// Set the position relative to the note's view.
var view_pos = LAPI.Pos.position(this.note.view);
var origin
this.tooltip.options.fixed_offset.x =
view_pos.x - origin.x + this.tooltip.options.mouse_offset.x;
Line 636:
}
return;
} else if (data === this.note.model.wiki) {
// Text unchanged
this.hide_editor();
Line 781:
// TODO: Actually, the edit got through here, so calling failureFunc on
// inconsistencies isn't quite right. Should we reload the page?
var id
var doc
if (!doc) return;
var html = LAPI.$ (id, doc);
Line 896:
Object.merge(descriptor, this);
this.annotations = [];
this.max_id
this.main_div
this.msg
this.may_edit
this.setup_done
this.tip
this.icon
this.factors = {
dx : this.full_img.width / this.thumb.width,
Line 926:
var $fullname;
if (this.isThumbnail || this.scope === document || this.may_edit || !IA.haveAjax) {
this.imgName
this.realName = '';
} else {
$fullname = $(this.scope).find('.wpImageAnnotatorFullName');
this.realName = $fullname.length ? $fullname.text() : '';
this.imgName
}
Line 1,030:
// Set colors
var colors = IA.getRawItem('colors', this.scope);
this.outer_border
this.inner_border = colors && IA.getItem('
this.active_border =
colors && IA.getItem('active', colors) || IA.active_border;
Line 1,040 ⟶ 1,038:
var id = annotations[i].id;
if (id && /^image_annotation_note_(\d+)$/.test(id)) {
id = parseInt
} else
id = null;
Line 1,048 ⟶ 1,046:
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; })
) {
try {
Line 1,101 ⟶ 1,099:
// Set overflow parents, if any
var simple
var checks
: ['overflow', 'overflowX', 'overflowY']
);
Line 1,195 ⟶ 1,193:
}
// 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
) {
node.style.top = '' + view_y + 'px';
Line 1,281 ⟶ 1,279:
for (i = 0; i < this.overflowParents.length && rect.x < rect.r && rect.y < rect.b; i++) {
img_pos
img_pos.r = img_pos.x + this.overflowParents[i].clientWidth;
img_pos.b = img_pos.y + this.overflowParents[i].clientHeight;
Line 1,335 ⟶ 1,333:
deregister: function (note) {
Array.remove(this.annotations, note);
if (note.model.id === this.max_id) this.max_id--;
if (this.annotations.length === 0) this.setDefaultMsg(); //If we removed the last one, clear the msg
},
Line 1,457 ⟶ 1,455:
&& typeof LAPI.Ajax.getRequest !== 'undefined'
) {
self.haveAjax
self.ajaxQueried = true;
} else {
self.haveAjax
self.ajaxQueried = false;
}
Line 1,621 ⟶ 1,619:
) {
// Publish parts of config.
ImageAnnotator.UI
self.outer_border
self.inner_border
self.active_border = config.active_border;
self.new_border
self.wait_for_required_libraries();
}
Line 1,686 ⟶ 1,684:
}
// Quit if the image wasn't loaded properly for some reason:
if (w !== srcW || h !== srcH) return null;
// Exclude system images
if (img.src.contains(conf.stylepath)) return null;
Line 1,703 ⟶ 1,701:
// Exclude any that are within an image note!
var up = img.parentNode.parentNode;
while (up !== document.body) {
if (LAPI.DOM.hasClass(up, IA.annotation_class)) return null;
up = up.parentNode;
Line 1,713 ⟶ 1,711:
var file_div = scope;
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) {
file_div = LAPI.$('file');
} else if (!is_thumb && !is_other) {
Line 1,728 ⟶ 1,726:
if (!file_div) return null;
var img = null;
if (scope === document) {
img = LAPI.WP.getPreviewImage(conf.wgTitle);
// TIFFs may be multi-paged: allow only for single-page TIFFs
Line 1,743 ⟶ 1,741:
if (!dim) return null;
// Conditionally exclude shared images.
if ( scope !== document
&& !self.rules.shared.show
&& ImageAnnotator_config.imageIsFromSharedRepository(img.src)
Line 1,749 ⟶ 1,747:
return null;
var name = null;
if (scope === document) {
name = conf.wgPageName;
} else {
Line 1,853 ⟶ 1,851:
var to_do = names.length;
var done
function check_done (length) {
Line 1,901 ⟶ 1,899:
,height: info.imageinfo[0].height};
self.imgs[i].has_page = (typeof info.missing === 'undefined');
self.imgs[i].isLocal
if (i !== 0 || !self.may_edit || !info.protection || wgNamespaceNumber !== 6) return;
// Care about the protection settings
Line 1,932 ⟶ 1,930:
+ '&titles=&callback=ImageAnnotator.info_callbacks[].callback';
if (template.startsWith('//')) template = document.___location.protocol + template; // Avoid protocol-relative URIs (IE7 bug)
make_calls
function (length, titles) {
var idx = ImageAnnotator.info_callbacks.length;
Line 1,963 ⟶ 1,961:
ImageAnnotator.info_callbacks[idx].script = null;
}
(LAPI.Browser.is_ie ? 1950 : 4000) - template.length
);
} else {
make_calls
function (length, titles) {
LAPI.Ajax.apiGet(
titles: titles, check_done(length);
}
);
}
Line 1,990 ⟶ 1,992:
// Complete the UI object we've gotten from config.
ImageAnnotator.UI.ready
ImageAnnotator.UI.repo
ImageAnnotator.UI.needs_plea = false;
Line 2,045 ⟶ 2,047:
var self = ImageAnnotator.UI;
if (!self.repo) self.setup();
var result
var add_plea = false;
if (self.basic) {
Line 2,125 ⟶ 2,127:
var ui_page = '{{MediaWiki:ImageAnnotatorTexts'
+ (conf.wgUserLanguage !== wgContentLanguage ? '|lang=' + conf.wgUserLanguage : '')
+ '|live=1}}';
Line 2,141 ⟶ 2,143:
function get_ui () {
IA.haveAjax
IA.ajaxQueried = true;
Line 2,203 ⟶ 2,205:
var mouse_pos = LAPI.Pos.mousePosition(evt);
if (!LAPI.Pos.isWithin(self.cover, mouse_pos.x, mouse_pos.y)) return;
var origin
// Make mouse pos relative to cover
mouse_pos.x = mouse_pos.x - origin.x;
Line 2,209 ⟶ 2,211:
if (mouse_pos.x >= self.base_x) {
self.definer.style.width = '' + (mouse_pos.x - self.base_x) + 'px';
self.definer.style.left
} else {
self.definer.style.width = '' + (self.base_x - mouse_pos.x) + 'px';
self.definer.style.left
}
if (mouse_pos.y >= self.base_y) {
self.definer.style.height = '' + (mouse_pos.y - self.base_y) + 'px';
self.definer.style.top
} else {
self.definer.style.height = '' + (self.base_y - mouse_pos.y) + 'px';
self.definer.style.top
}
return LAPI.Evt.kill(evt);
Line 2,279 ⟶ 2,281:
} else {
// We have a div with some extent: remove event capturing and create a new annotation
var new_note = new ImageAnnotation
self.viewers[0].register(new_note);
self.editor.editNote(new_note);
Line 2,295 ⟶ 2,297:
// Set the position, size 1
var mouse_pos = LAPI.Pos.mousePosition(evt);
var origin
self.base_x = mouse_pos.x - origin.x;
self.base_y = mouse_pos.y - origin.y;
Line 2,351 ⟶ 2,353:
self.show_cover();
self.is_tracking = false;
self.is_adding
LAPI.Evt.attach(cover, 'mousedown', start_tracking);
resume ();
Line 2,396 ⟶ 2,398:
else
img_page_name = '';
self.may_edit = (img_page_name.replace(/ /g, '_') === conf.wgTitle.replace(/ /g, '_'));
}
Line 2,455 ⟶ 2,457:
// Get the file description pages of thumbnails. Figure out for which viewers we need to do this.
var cache
var get_local
var get_foreign = [];
Array.forEach(self.viewers, function (viewer, idx) {
Line 2,519 ⟶ 2,521:
}
var divRE
var blockStart
var inlineNameEnd = '</span>';
var noteStart
var noteControlRE = /<div\s*class="(wpImageAnnotatorInlinedRules|image_annotation_colors")(\S|\s)*?\/div>/g;
Line 2,754 ⟶ 2,756:
self.zoom.appendChild(LAPI.make('div', null, { position : 'relative' }));
// Calculate zoom size and source link
var zoom_width
var zoom_height = Math.floor(self.viewers[0].thumb.height * self.zoom_factor);
// For SVGs, always use a scaled PNG for the zoom.
Line 2,761 ⟶ 2,763:
// well get the full image instead of a scaled version.
self.zoom_factor = Math.min(self.viewers[0].factors.dx, self.viewers[0].factors.dy);
zoom_width
zoom_height
}
// Construct the initial zoomed image. We need to clone; if we create a completely
Line 2,821 ⟶ 2,823:
if (!self.zoom) return;
var mouse_pos = LAPI.Pos.mousePosition(evt);
var origin
if (!LAPI.Pos.isWithin(self.cover, mouse_pos.x, mouse_pos.y)) {
IA.hide_zoom();
Line 2,829 ⟶ 2,831:
var dy = mouse_pos.y - origin.y;
// dx, dy is the offset within the preview image. Align the zoom image accordingly.
var top
var left = - dx * self.zoom_factor + 100;
self.zoom.firstChild.firstChild.style.top
self.zoom.firstChild.firstChild.style.left = '' + left + 'px';
self.zoom.style.top
// Horizontally keep it in view.
var x = (self.is_rtl ? mouse_pos.x - 10 : mouse_pos.x + 10);
Line 2,844 ⟶ 2,846:
if (x < 0) x = 0;
} else {
var off
var view = LAPI.Pos.viewport();
if (x + self.zoom.offsetWidth > off.x + view.x) x = off.x + view.x - self.zoom.offsetWidth;
Line 2,932 ⟶ 2,934:
Object.merge(
{border: '3px solid green', top: '-3px', left: '-3px'}, self.border.style);
self.cover.style.zIndex
if (LAPI.Browser.is_ie) {
shim = LAPI.make('iframe', {frameBorder: 0, tabIndex: -1}, pos);
shim.style.filter
// Unfortunately, IE6/SP2 has a "security setting" called "Binary and script
// behaviors". If that is disabled, filters don't work, and our iframe would
Line 2,943 ⟶ 2,945:
var imgZ = self.viewers[0].img.style.zIndex;
if (isNaN (imgZ)) imgZ = 10; // Arbitrary, positive, > 1, < 500
shim.style.zIndex
self.ieFix = shim;
// And now the bgImage div...
Line 2,963 ⟶ 2,965:
shim.style.zIndex = self.cover.style.zIndex - 1;
LAPI.Evt.attach(shim, 'mousemove',
function (evt) { return LAPI.Evt.kill(evt || window.event); });
LAPI.Evt.attach(shim, 'mousedown',
function (evt) { return LAPI.Evt.kill(evt || window.event); });
LAPI.Evt.attach(shim, 'mouseup',
function (evt) { return LAPI.Evt.kill(evt || window.event); });
shim.style.cursor = 'default';
self.eventFix = shim;
Line 3,004 ⟶ 3,006:
getRawItem: function (what, scope) {
var node = null;
if (!scope || scope === document) {
node = LAPI.$ ('image_annotation_' + what);
} else {
Line 3,055 ⟶ 3,057:
for (var i = 0; i < self.note_delim.length; i++) {
var start = self.note_delim[i].content_start.replace('$1', note.model.id);
var end
var j = code.indexOf(start);
var k = code.indexOf(end);
|