Guest User

map highlighting library for jquery

a guest
Sep 30th, 2017
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*map highlight library for jquery, functions in Twine SugarCube 2.19*/
  2.  
  3. !function (a, b) {
  4.     "function" == typeof define && define.amd ? define(["jquery"], b) : b(a.jQuery)
  5. }
  6. (window, function (a) {
  7.     var b,
  8.     c,
  9.     d,
  10.     e,
  11.     f,
  12.     g,
  13.     h,
  14.     i,
  15.     j,
  16.     k,
  17.     l;
  18.     if (c = !!document.createElement("canvas").getContext, b = function () {
  19.         var a = document.createElement("div");
  20.         a.innerHTML = '<v:shape id="vml_flag1" adj="1" />';
  21.         var b = a.firstChild;
  22.         return b.style.behavior = "url(#default#VML)",
  23.         !b || "object" == typeof b.adj
  24.     }
  25.         (), !c && !b)
  26.         return void(a.fn.maphilight = function () {
  27.             return this
  28.         });
  29.     if (c) {
  30.         i = function (a) {
  31.             return Math.max(0, Math.min(parseInt(a, 16), 255))
  32.         },
  33.         j = function (a, b) {
  34.             return "rgba(" + i(a.substr(0, 2)) + "," + i(a.substr(2, 2)) + "," + i(a.substr(4, 2)) + "," + b + ")"
  35.         },
  36.         d = function (b) {
  37.             var c = a('<canvas style="width:' + a(b).width() + "px;height:" + a(b).height() + 'px;"></canvas>').get(0);
  38.             return c.getContext("2d").clearRect(0, 0, a(b).width(), a(b).height()),
  39.             c
  40.         };
  41.         var m = function (a, b, c, d, e) {
  42.             if (d = d || 0, e = e || 0, a.beginPath(), "rect" == b)
  43.                 a.rect(c[0] + d, c[1] + e, c[2] - c[0], c[3] - c[1]);
  44.             else if ("poly" == b) {
  45.                 a.moveTo(c[0] + d, c[1] + e);
  46.                 for (var f = 2; f < c.length; f += 2)
  47.                     a.lineTo(c[f] + d, c[f + 1] + e)
  48.             } else
  49.                 "circ" == b && a.arc(c[0] + d, c[1] + e, c[2], 0, 2 * Math.PI, !1);
  50.             a.closePath()
  51.         };
  52.         e = function (b, c, d, e, f) {
  53.             var h = b.getContext("2d");
  54.             if (e.shadow) {
  55.                 h.save(),
  56.                 "inside" == e.shadowPosition && (m(h, c, d), h.clip());
  57.                 var i = 100 * b.width,
  58.                 k = 100 * b.height;
  59.                 m(h, c, d, i, k),
  60.                 h.shadowOffsetX = e.shadowX - i,
  61.                 h.shadowOffsetY = e.shadowY - k,
  62.                 h.shadowBlur = e.shadowRadius,
  63.                 h.shadowColor = j(e.shadowColor, e.shadowOpacity);
  64.                 var l = e.shadowFrom;
  65.                 l || (l = "outside" == e.shadowPosition ? "fill" : "stroke"),
  66.                 "stroke" == l ? (h.strokeStyle = "rgba(0,0,0,1)", h.stroke()) : "fill" == l && (h.fillStyle = "rgba(0,0,0,1)", h.fill()),
  67.                 h.restore(),
  68.                 "outside" == e.shadowPosition && (h.save(), m(h, c, d), h.globalCompositeOperation = "destination-out", h.fillStyle = "rgba(0,0,0,1);", h.fill(), h.restore())
  69.             }
  70.             h.save(),
  71.             m(h, c, d),
  72.             e.fill && (h.fillStyle = j(e.fillColor, e.fillOpacity), h.fill()),
  73.             e.stroke && (h.strokeStyle = j(e.strokeColor, e.strokeOpacity), h.lineWidth = e.strokeWidth, h.stroke()),
  74.             h.restore(),
  75.             e.fade && a(b).css("opacity", 0).animate({
  76.                 opacity: 1
  77.             }, 100)
  78.         },
  79.         f = function (a) {
  80.             a.getContext("2d").clearRect(0, 0, a.width, a.height)
  81.         }
  82.     } else
  83.         d = function (b) {
  84.             return a('<var style="zoom:1;overflow:hidden;display:block;width:' + b.width + "px;height:" + b.height + 'px;"></var>').get(0)
  85.         },
  86.     e = function (b, c, d, e, f) {
  87.         var g,
  88.         h,
  89.         i,
  90.         j;
  91.         for (var k in d)
  92.             d[k] = parseInt(d[k], 10);
  93.         g = '<v:fill color="#' + e.fillColor + '" opacity="' + (e.fill ? e.fillOpacity : 0) + '" />',
  94.         h = e.stroke ? 'strokeweight="' + e.strokeWidth + '" stroked="t" strokecolor="#' + e.strokeColor + '"' : 'stroked="f"',
  95.         i = '<v:stroke opacity="' + e.strokeOpacity + '"/>',
  96.         "rect" == c ? j = a('<v:rect name="' + f + '" filled="t" ' + h + ' style="zoom:1;margin:0;padding:0;display:block;position:absolute;left:' + d[0] + "px;top:" + d[1] + "px;width:" + (d[2] - d[0]) + "px;height:" + (d[3] - d[1]) + 'px;"></v:rect>') : "poly" == c ? j = a('<v:shape name="' + f + '" filled="t" ' + h + ' coordorigin="0,0" coordsize="' + b.width + "," + b.height + '" path="m ' + d[0] + "," + d[1] + " l " + d.join(",") + ' x e" style="zoom:1;margin:0;padding:0;display:block;position:absolute;top:0px;left:0px;width:' + b.width + "px;height:" + b.height + 'px;"></v:shape>') : "circ" == c && (j = a('<v:oval name="' + f + '" filled="t" ' + h + ' style="zoom:1;margin:0;padding:0;display:block;position:absolute;left:' + (d[0] - d[2]) + "px;top:" + (d[1] - d[2]) + "px;width:" + 2 * d[2] + "px;height:" + 2 * d[2] + 'px;"></v:oval>')),
  97.         j.get(0).innerHTML = g + i,
  98.         a(b).append(j)
  99.     },
  100.     f = function (b) {
  101.         var c = a("<div>" + b.innerHTML + "</div>");
  102.         c.children("[name=highlighted]").remove(),
  103.         b.innerHTML = c.html()
  104.     };
  105.     g = function (a) {
  106.         var b,
  107.         c = a.getAttribute("coords").split(",");
  108.         for (b = 0; b < c.length; b++)
  109.             c[b] = parseFloat(c[b]);
  110.         return [a.getAttribute("shape").toLowerCase().substr(0, 4), c]
  111.     },
  112.     l = function (b, c) {
  113.         var d = a(b);
  114.         return a.extend({}, c, !!a.metadata && d.metadata(), d.data("maphilight"))
  115.     },
  116.     k = function (a) {
  117.         return !!a.complete && ("undefined" == typeof a.naturalWidth || 0 !== a.naturalWidth)
  118.     },
  119.     h = {
  120.         position: "absolute",
  121.         left: 0,
  122.         top: 0,
  123.         padding: 0,
  124.         border: 0
  125.     };
  126.     var n = !1;
  127.     a.fn.maphilight = function (i) {
  128.         return i = a.extend({}, a.fn.maphilight.defaults, i),
  129.         c || n || (a(window).ready(function () {
  130.                 document.namespaces.add("v", "urn:schemas-microsoft-com:vml");
  131.                 var b = document.createStyleSheet(),
  132.                 c = ["shape", "rect", "oval", "circ", "fill", "stroke", "imagedata", "group", "textbox"];
  133.                 a.each(c, function () {
  134.                     b.addRule("v\\:" + this, "behavior: url(#default#VML); antialias:true")
  135.                 })
  136.             }), n = !0),
  137.         this.each(function () {
  138.             var j,
  139.             m,
  140.             n,
  141.             o,
  142.             p,
  143.             q,
  144.             s;
  145.             if (j = a(this), !k(this))
  146.                 return window.setTimeout(function () {
  147.                     j.maphilight(i)
  148.                 }, 200);
  149.             if (n = a.extend({}, i, !!a.metadata && j.metadata(), j.data("maphilight")), s = j.get(0).getAttribute("usemap"), s && (o = a('map[name="' + s.substr(1) + '"]'), j.is('img,input[type="image"]') && s && o.length > 0)) {
  150.                 if (j.hasClass("maphilighted")) {
  151.                     var t = j.parent();
  152.                     j.insertBefore(t),
  153.                     t.remove(),
  154.                     a(o).unbind(".maphilight")
  155.                 }
  156.                 m = a("<div></div>").css({
  157.                         display: "block",
  158.                         backgroundImage: 'url("' + this.src + '")',
  159.                         backgroundSize: "contain",
  160.                         position: "relative",
  161.                         padding: 0,
  162.                         width: this.width,
  163.                         height: this.height
  164.                     }),
  165.                 n.wrapClass && (n.wrapClass === !0 ? m.addClass(a(this).attr("class")) : m.addClass(n.wrapClass)),
  166.                 j.before(m).css("opacity", 0).css(h).remove(),
  167.                 b && j.css("filter", "Alpha(opacity=0)"),
  168.                 m.append(j),
  169.                 p = d(this),
  170.                 a(p).css(h),
  171.                 p.height = this.height,
  172.                 p.width = this.width,
  173.                 a(o).bind("alwaysOn.maphilight", function () {
  174.                     q && f(q),
  175.                     c || a(p).empty(),
  176.                     a(o).find("area[coords]").each(function () {
  177.                         var b,
  178.                         f;
  179.                         f = l(this, n),
  180.                         f.alwaysOn && (!q && c && (q = d(j[0]), a(q).css(h), q.width = j[0].width, q.height = j[0].height, j.before(q)), f.fade = f.alwaysOnFade, b = g(this), c ? e(q, b[0], b[1], f, "") : e(p, b[0], b[1], f, ""))
  181.                     })
  182.                 }).trigger("alwaysOn.maphilight").bind("mouseover.maphilight, focus.maphilight", function (b) {
  183.                     var d,
  184.                     f,
  185.                     h = b.target;
  186.                     if (f = l(h, n), !f.neverOn && !f.alwaysOn) {
  187.                         if (d = g(h), e(p, d[0], d[1], f, "highlighted"), f.groupBy) {
  188.                             var i;
  189.                             i = /^[a-zA-Z][\-a-zA-Z]+$/.test(f.groupBy) ? o.find("area[" + f.groupBy + '="' + a(h).attr(f.groupBy) + '"]') : o.find(f.groupBy);
  190.                             var j = h;
  191.                             i.each(function () {
  192.                                 if (this != j) {
  193.                                     var a = l(this, n);
  194.                                     if (!a.neverOn && !a.alwaysOn) {
  195.                                         var b = g(this);
  196.                                         e(p, b[0], b[1], a, "highlighted")
  197.                                     }
  198.                                 }
  199.                             })
  200.                         }
  201.                         c || a(p).append("<v:rect></v:rect>")
  202.                     }
  203.                 }).bind("mouseout.maphilight, blur.maphilight", function (a) {
  204.                     f(p)
  205.                 }),
  206.                 j.before(p),
  207.                 j.addClass("maphilighted")
  208.             }
  209.         })
  210.     },
  211.     a.fn.maphilight.defaults = {
  212.         fill: !0,
  213.         fillColor: "000000",
  214.         fillOpacity: .2,
  215.         stroke: !0,
  216.         strokeColor: "ff0000",
  217.         strokeOpacity: 1,
  218.         strokeWidth: 1,
  219.         fade: !0,
  220.         alwaysOn: !1,
  221.         neverOn: !1,
  222.         groupBy: !1,
  223.         wrapClass: !0,
  224.         shadow: !1,
  225.         shadowX: 0,
  226.         shadowY: 0,
  227.         shadowRadius: 6,
  228.         shadowColor: "000000",
  229.         shadowOpacity: .8,
  230.         shadowPosition: "outside",
  231.         shadowFrom: !1
  232.     }
  233. });
Advertisement
Add Comment
Please, Sign In to add comment