MediaWiki:Gadget-ImageAnnotator.js: Difference between revisions
Content deleted Content added
m Avoid jquery dependency for this; Some non-WMF wikis also run this, and may not have jquery. Also replace the protocol with the one of the current document instead of removing it to avoid spurious problems possible on IE7. |
V2.3a |
||
Line 2:
/*
THIS IS ImageAnnotator VERSION 2.
Image annotations. Draw rectangles onto image thumbnail displayed on image description
Line 45:
if (result != 0) return result;
return a.model.id - b.model.id; // Just to make sure the order is complete
};▼
}▼
};
Line 357 ⟶ 345:
if (edit_page.isFake && (typeof (edit_page.dispose) == 'function'))
edit_page.dispose ();
var revision_id =
if (!revision_id) {
failureFunc (request, new Error ('Revision ID not found. Please reload the page.'));
Line 791 ⟶ 779:
return;
}
var revision_id =
if (!revision_id) {
if (doc.isFake && (typeof (doc.dispose) == 'function')) doc.dispose ();
Line 1,457 ⟶ 1,445:
// Double check.
if (!
)▼
)▼
{▼
return;▼
var self = IA;
Line 1,485 ⟶ 1,466:
// We'll include self.haveAjax later on once more, to catch the !ajaxQueried case.
self.may_edit = wgNamespaceNumber >= 0 && wgArticleId > 0 && self.haveAjax && config.editingEnabled ();
function namespaceCheck (list)
Line 1,685 ⟶ 1,666:
var stylepath = window.stylepath || '/skin';
// Use this to temporarily display an image off-screen to get its dimensions
var testImgDiv =
{ display: 'none', position: 'absolute', width: '300px'
, overflow: 'hidden', overflowX: 'hidden', left: '-10000px'
document.body.insertBefore (testImgDiv, document.body.firstChild);
function img_check (img, is_other)
{
var w = img.clientWidth; // Don't use offsetWidth, thumbnails may have a boundary...▼
var
// Don't do anything on extremely small previews. We need some minimum extent to be able to place
// rectangles after all...
if (
// For non-thumbnail images, the size limit is larger.
if (is_other && (
▲ var w = img.clientWidth; // Don't use offsetWidth, thumbnails may have a boundary...
var h = img.clientHeight;
// 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 = "";
testImgDiv.appendChild (copied);
testImgDiv.style.display = "";
w = copied.clientWidth;
h = copied.clientHeight;
testImgDiv.style.display = 'none';
LAPI.DOM.removeNode (copied);
▲ }
// Quit if the image wasn't loaded properly for some reason:
if (
▲ || h != parseInt (img.getAttribute ('height'), 10))
▲ return null;
// Exclude system images
if (img.src.contains (stylepath)) return null;
Line 1,719 ⟶ 1,721:
up = up.parentNode;
}
return
}
Line 1,750 ⟶ 1,752:
}
if (!img) return null;
if (!
// Conditionally exclude shared images.
if ( scope != document
Line 1,784 ⟶ 1,786:
}
}
if (name.search (/\.(jpe?g|png|gif|svg)$/i) < 0) return null;
// Finally check for wpImageAnnotatorControl
var icon_only = false;
Line 1,806 ⟶ 1,808:
,isThumbnail: is_thumb
,isOther : is_other
,thumb : {width:
,iconOnly : icon_only
,noCaption : no_caption
Line 1,837 ⟶ 1,839:
setup_images (self.other_images);
}
// Remove the test div
LAPI.DOM.removeNode (testImgDiv);
if (self.imgs.length == 0) return;
Line 2,572 ⟶ 2,577:
var inlineNameEnd = '</span>';
var noteStart = '<div id="image_annotation_note_';
var noteControlRE = /<div\s*class="(wpImageAnnotatorInlinedRules|image_annotation_colors")(\S|\s)*?\/div>/g;
// Our parse request returns the full html of the description pages' contents, including any
Line 2,581 ⟶ 2,587:
// First, get rid of HTML comments and scripts
html = html.replace(/<\!--(.|\s)*?--\>/g, "").replace(/<script(.|\s)*?\/script>/g, "");
var i =
// Now collect pages
while (idx < l && i >= idx) {
if (i < idx) break;▼
var j = html.indexOf (inlineNameEnd, i+blockStart.length);
if (j <
result += html.substring (i, j+inlineNameEnd.length);
idx = j+inlineNameEnd.length;
// Now collect all image image notes for that page
var note_begin = 0, next_block =
// Do we have image note control or color templates?
noteControlRE.lastIndex = j;
var m = noteControlRE.exec (html);
if (!m || next_block >= idx && m.index > next_block) break;
result += m[0];
j = m.index + m[0].length;
// Collect notes
for (;;) {
note_begin = html.indexOf (noteStart, idx);
// Check whether next wrapper comes first
if (note_begin < idx || (next_block >= idx && note_begin > next_block)) break;
Line 2,619 ⟶ 2,632:
} // end loop collecting notes
result += '</div>'; // Close the wrapper
i = next_block;
} // end loop collecting pages
return result;
Line 3,186 ⟶ 3,200:
};
▲ // Start it. Bypass caches; but allow for 4 hours client-side caching. Small file.
▲ IA.getScript (
▲ wgScript + '?title=MediaWiki:ImageAnnotatorConfig.js&action=raw&ctype=text/javascript'
▲ + '&dummy=' + Math.floor ((new Date()).getTime () / (14400 * 1000)) // 4 hours
▲ , true // No local caching!
})(); // end local scope
|