<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://painwiki.com/wiki/index.php?action=history&amp;feed=atom&amp;title=MediaWiki%3AImageMapHighlight.js</id>
	<title>MediaWiki:ImageMapHighlight.js - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://painwiki.com/wiki/index.php?action=history&amp;feed=atom&amp;title=MediaWiki%3AImageMapHighlight.js"/>
	<link rel="alternate" type="text/html" href="https://painwiki.com/wiki/index.php?title=MediaWiki:ImageMapHighlight.js&amp;action=history"/>
	<updated>2026-11-22T08:23:53Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.3</generator>
	<entry>
		<id>https://painwiki.com/wiki/index.php?title=MediaWiki:ImageMapHighlight.js&amp;diff=516&amp;oldid=prev</id>
		<title>Yatreyu: Created page with &quot;/**  * ImageMapHighlight for Standalone MediaWiki installations  * Bypasses Fandom i18n hooks to ensure it runs universally.  */ mw.hook(&#039;wikipage.content&#039;).add(function($content) {          // Only run if there is at least one highlighter div and the browser supports canvas     if (!$(&#039;.imageMapHighlighter&#039;).length || !window.CanvasRenderingContext2D) return;      window.imagemap = window.imagemap || {};      var artifactClass = &#039;imageMapHighlighterArtifact&#039;,         de...&quot;</title>
		<link rel="alternate" type="text/html" href="https://painwiki.com/wiki/index.php?title=MediaWiki:ImageMapHighlight.js&amp;diff=516&amp;oldid=prev"/>
		<updated>2026-06-14T22:23:25Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&lt;span class=&quot;autocomment&quot;&gt;*  * ImageMapHighlight for Standalone MediaWiki installations  * Bypasses Fandom i18n hooks to ensure it runs universally.: &lt;/span&gt; mw.hook(&amp;#039;wikipage.content&amp;#039;).add(function($content) {          // Only run if there is at least one highlighter div and the browser supports canvas     if (!$(&amp;#039;.imageMapHighlighter&amp;#039;).length || !window.CanvasRenderingContext2D) return;      window.imagemap = window.imagemap || {};      var artifactClass = &amp;#039;imageMapHighlighterArtifact&amp;#039;,         de...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;/**&lt;br /&gt;
 * ImageMapHighlight for Standalone MediaWiki installations&lt;br /&gt;
 * Bypasses Fandom i18n hooks to ensure it runs universally.&lt;br /&gt;
 */&lt;br /&gt;
mw.hook(&amp;#039;wikipage.content&amp;#039;).add(function($content) {&lt;br /&gt;
    &lt;br /&gt;
    // Only run if there is at least one highlighter div and the browser supports canvas&lt;br /&gt;
    if (!$(&amp;#039;.imageMapHighlighter&amp;#039;).length || !window.CanvasRenderingContext2D) return;&lt;br /&gt;
&lt;br /&gt;
    window.imagemap = window.imagemap || {};&lt;br /&gt;
&lt;br /&gt;
    var artifactClass = &amp;#039;imageMapHighlighterArtifact&amp;#039;,&lt;br /&gt;
        defaultAreaHighlight = {&lt;br /&gt;
            fillStyle: window.imagemap.hightlightfill || &amp;#039;rgba(0, 0, 0, 0.35)&amp;#039;,&lt;br /&gt;
            strokeStyle: window.imagemap.hightlightcolor || &amp;#039;#FFC500&amp;#039;,&lt;br /&gt;
            lineJoin: &amp;#039;round&amp;#039;,&lt;br /&gt;
            lineWidth: window.imagemap.hightlightstrokewidth || 2&lt;br /&gt;
        };&lt;br /&gt;
&lt;br /&gt;
    // Convert ImageMap area(s) to highlights on the canvas&lt;br /&gt;
    function drawMarker(context, areas) {&lt;br /&gt;
        function drawPoly(coords) {&lt;br /&gt;
            context.moveTo(coords.shift(), coords.shift());&lt;br /&gt;
            while (coords.length)&lt;br /&gt;
                context.lineTo(coords.shift(), coords.shift());&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        for (var i in areas) {&lt;br /&gt;
            var coords = areas[i].coords.split(&amp;#039;,&amp;#039;);&lt;br /&gt;
            context.beginPath();&lt;br /&gt;
            switch (areas[i].shape) {&lt;br /&gt;
                case &amp;#039;rect&amp;#039;: drawPoly([coords[0], coords[1], coords[0], coords[3], coords[2], coords[3], coords[2], coords[1]]); break;&lt;br /&gt;
                case &amp;#039;circle&amp;#039;: context.arc(coords[0], coords[1], coords[2], 0, Math.PI * 2); break;&lt;br /&gt;
                case &amp;#039;poly&amp;#039;: drawPoly(coords); break;&lt;br /&gt;
            }&lt;br /&gt;
            context.closePath();&lt;br /&gt;
            context.stroke();&lt;br /&gt;
            context.fill();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // Add highlighting on hover&lt;br /&gt;
    function mouseAction(e) {&lt;br /&gt;
        var $this = $(this),&lt;br /&gt;
            activate = e.type == &amp;#039;mouseover&amp;#039;,&lt;br /&gt;
            caption = $this.text(),&lt;br /&gt;
            ol = $this.parent(),&lt;br /&gt;
            context = ol.data(&amp;#039;context&amp;#039;),&lt;br /&gt;
            areaHighlight = ol.data(&amp;#039;area-highlight&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
        $this.toggleClass(&amp;#039;liHighlighting&amp;#039;, activate);&lt;br /&gt;
        context.clearRect(0, 0, context.canvas.width, context.canvas.height);&lt;br /&gt;
&lt;br /&gt;
        ol.find(&amp;#039;li&amp;#039;).each(function() {&lt;br /&gt;
            var $li = $(this);&lt;br /&gt;
            var licap = $li.text();&lt;br /&gt;
            if (activate &amp;amp;&amp;amp; licap === caption) {&lt;br /&gt;
                $.extend(context, areaHighlight || defaultAreaHighlight);&lt;br /&gt;
                drawMarker(context, $li.data(&amp;#039;areas&amp;#039;));&lt;br /&gt;
            }&lt;br /&gt;
        });&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // Add highlighting to an ImageMap&lt;br /&gt;
    function handleOneMap() {&lt;br /&gt;
        var img = $(this),&lt;br /&gt;
            w = img.width(),&lt;br /&gt;
            h = img.height(),&lt;br /&gt;
            dims = { position: &amp;#039;absolute&amp;#039;, width: w + &amp;#039;px&amp;#039;, height: h + &amp;#039;px&amp;#039;, border: 0, top: 0, left: 0 },&lt;br /&gt;
            parentMarker = img.closest(&amp;#039;.imageMapHighlighter&amp;#039;),&lt;br /&gt;
            liClasses = parentMarker.data(&amp;#039;list-classes&amp;#039;),&lt;br /&gt;
            map = img.siblings(&amp;#039;map:first&amp;#039;),&lt;br /&gt;
            defaultLink = false;&lt;br /&gt;
&lt;br /&gt;
        if (!map.length) {&lt;br /&gt;
            map = img.parent().siblings(&amp;#039;map:first&amp;#039;);&lt;br /&gt;
            defaultLink = true;&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        if (!$(&amp;#039;area&amp;#039;, map).length) return;&lt;br /&gt;
        img.addClass(&amp;#039;highlighted&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
        $(img).closest(&amp;#039;div.noresize&amp;#039;).css({ height: &amp;#039;&amp;#039;, width: &amp;#039;&amp;#039; });&lt;br /&gt;
&lt;br /&gt;
        var jcanvas = $(&amp;#039;&amp;lt;canvas&amp;gt;&amp;#039;, { &amp;#039;class&amp;#039;: artifactClass })&lt;br /&gt;
            .css(dims)&lt;br /&gt;
            .attr({ width: w, height: h });&lt;br /&gt;
        var bgimg = $(&amp;#039;&amp;lt;img&amp;gt;&amp;#039;, { &amp;#039;class&amp;#039;: artifactClass, src: img.attr(&amp;#039;src&amp;#039;) })&lt;br /&gt;
            .css(dims)&lt;br /&gt;
            .prop(&amp;#039;alt&amp;#039;, &amp;#039;&amp;#039;).prop(&amp;#039;ariaHidden&amp;#039;, true);&lt;br /&gt;
&lt;br /&gt;
        var areaHighlight = $.extend({}, defaultAreaHighlight, {&lt;br /&gt;
            fillStyle: parentMarker.data(&amp;#039;fill&amp;#039;) || parentMarker.css(&amp;#039;--imagemaphighlight-fill&amp;#039;),&lt;br /&gt;
            strokeStyle: parentMarker.data(&amp;#039;stroke&amp;#039;) || parentMarker.css(&amp;#039;--imagemaphighlight-stroke&amp;#039;),&lt;br /&gt;
            lineWidth: parentMarker.data(&amp;#039;line-width&amp;#039;) || parentMarker.css(&amp;#039;--imagemaphighlight-stroke-width&amp;#039;)&lt;br /&gt;
        });&lt;br /&gt;
&lt;br /&gt;
        var context = $.extend(jcanvas[0].getContext(&amp;#039;2d&amp;#039;), areaHighlight);&lt;br /&gt;
&lt;br /&gt;
        var div = $(&amp;#039;&amp;lt;div&amp;gt;&amp;#039;).css({ position: &amp;#039;relative&amp;#039;, width: w + &amp;#039;px&amp;#039;, height: h + &amp;#039;px&amp;#039; });&lt;br /&gt;
        (defaultLink ? img.parent() : img).before(div);&lt;br /&gt;
        div.append(bgimg).append(jcanvas).append(defaultLink ? img.parent() : img);&lt;br /&gt;
        img.fadeTo(1, 0);&lt;br /&gt;
&lt;br /&gt;
        var ol = $(&amp;#039;&amp;lt;ol&amp;gt;&amp;#039;, { &amp;#039;class&amp;#039;: artifactClass })&lt;br /&gt;
            .css({ maxWidth: w + &amp;#039;px&amp;#039; })&lt;br /&gt;
            .data(&amp;#039;area-highlight&amp;#039;, areaHighlight)&lt;br /&gt;
            .data(&amp;#039;context&amp;#039;, context);&lt;br /&gt;
&lt;br /&gt;
        // Simple visibility check for legend toggle&lt;br /&gt;
        if ([0, false, &amp;#039;no&amp;#039;].includes(parentMarker.data(&amp;#039;legend&amp;#039;))) {&lt;br /&gt;
            ol.css(&amp;#039;display&amp;#039;, &amp;#039;none&amp;#039;);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        var figure = parentMarker.find(&amp;#039;figure&amp;#039;);&lt;br /&gt;
        var figcaption = figure.children(&amp;#039;figcaption&amp;#039;);&lt;br /&gt;
        figcaption.addClass(&amp;#039;imageMapHighlighterLegend&amp;#039;);&lt;br /&gt;
        figcaption.empty().append(ol);&lt;br /&gt;
&lt;br /&gt;
        var lis = {};&lt;br /&gt;
        var someli;&lt;br /&gt;
        $(&amp;#039;area&amp;#039;, map).each(function() {&lt;br /&gt;
            var text = this.title;&lt;br /&gt;
            var li = lis[text];&lt;br /&gt;
            if (!li) {&lt;br /&gt;
                var href = this.href;&lt;br /&gt;
                lis[text] = li = $(&amp;#039;&amp;lt;li&amp;gt;&amp;#039;, { &amp;#039;class&amp;#039;: artifactClass })&lt;br /&gt;
                    .append($(&amp;#039;&amp;lt;a&amp;gt;&amp;#039;, { href: href }).html(mw.html.escape(this.title)))&lt;br /&gt;
                    .on(&amp;#039;mouseover mouseout&amp;#039;, mouseAction)&lt;br /&gt;
                    .data(&amp;#039;areas&amp;#039;, [])&lt;br /&gt;
                    .addClass(liClasses &amp;amp;&amp;amp; (liClasses[text] || liClasses[&amp;#039;default&amp;#039;]))&lt;br /&gt;
                    .appendTo(ol);&lt;br /&gt;
            }&lt;br /&gt;
            li.data(&amp;#039;areas&amp;#039;).push(this);&lt;br /&gt;
            someli = li;&lt;br /&gt;
            $(this).on(&amp;#039;mouseover mouseout&amp;#039;, function(e) {&lt;br /&gt;
                li.trigger(e.type);&lt;br /&gt;
            });&lt;br /&gt;
        });&lt;br /&gt;
        if (someli) someli.trigger(&amp;#039;mouseout&amp;#039;);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // Process maps found on load or dynamic injection&lt;br /&gt;
    var selector = &amp;#039;.imageMapHighlighter img[usemap]:not(.highlighted)&amp;#039;;&lt;br /&gt;
    $content.find(selector).each(handleOneMap);&lt;br /&gt;
});&lt;/div&gt;</summary>
		<author><name>Yatreyu</name></author>
	</entry>
</feed>