Guest User

Untitled

a guest
Mar 7th, 2017
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. /*
  2. * rwdImageMaps jQuery plugin v1.5
  3. *
  4. * Allows image maps to be used in a responsive design by recalculating the area coordinates to match the actual image size on load and window.resize
  5. *
  6. * Copyright (c) 2013 Matt Stow
  7. * https://github.com/stowball/jQuery-rwdImageMaps
  8. * http://mattstow.com
  9. * Licensed under the MIT license
  10. */
  11. ;
  12. (function(a) {
  13. a.fn.rwdImageMaps = function() {
  14. var c = this;
  15. var b = function() {
  16. c.each(function() {
  17. if (typeof(a(this).attr("usemap")) == "undefined") {
  18. return
  19. }
  20. var e = this,
  21. d = a(e);
  22. a("<img />").load(function() {
  23. var g = "width",
  24. m = "height",
  25. n = d.attr(g),
  26. j = d.attr(m);
  27. if (!n || !j) {
  28. var o = new Image();
  29. o.src = d.attr("src");
  30. if (!n) {
  31. n = o.width
  32. }
  33. if (!j) {
  34. j = o.height
  35. }
  36. }
  37. var f = d.width() / 100,
  38. k = d.height() / 100,
  39. i = d.attr("usemap").replace("#", ""),
  40. l = "coords";
  41. a('map[name="' + i + '"]').find("area").each(function() {
  42. var r = a(this);
  43. if (!r.data(l)) {
  44. r.data(l, r.attr(l))
  45. }
  46. var q = r.data(l).split(","),
  47. p = new Array(q.length);
  48. for (var h = 0; h < p.length; ++h) {
  49. if (h % 2 === 0) {
  50. p[h] = parseInt(((q[h] / n) * 100) * f)
  51. } else {
  52. p[h] = parseInt(((q[h] / j) * 100) * k)
  53. }
  54. }
  55. r.attr(l, p.toString())
  56. })
  57. }).attr("src", d.attr("src"))
  58. })
  59. };
  60. a(window).resize(b).trigger("resize");
  61. return this
  62. }
  63. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment