Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1. /**
  2. * Main Navigation
  3. *
  4. * @package WP Day Spa
  5. * @subpackage JavaScript
  6. */
  7.  
  8. (function(d) {
  9. var c = d.document,
  10. b = c.documentElement;
  11.  
  12. function h(j, i) {
  13. for (var k in i) {
  14. if (i.hasOwnProperty(k)) {
  15. j[k] = i[k]
  16. }
  17. }
  18. return j
  19. }
  20.  
  21. function a() {
  22. var i = b.clientHeight,
  23. j = d.innerHeight;
  24. if (i < j) {
  25. return j
  26. } else {
  27. return i
  28. }
  29. }
  30.  
  31. function f(i) {
  32. return i.getBoundingClientRect()
  33. }
  34.  
  35. function e(k, j) {
  36. if (k.type != "mouseout" && k.type != "mouseover") {
  37. return false
  38. }
  39. var i = k.relatedTarget ? k.relatedTarget : k.type == "mouseout" ? k.toElement : k.fromElement;
  40. while (i && i != j) {
  41. i = i.parentNode
  42. }
  43. return (i != j)
  44. }
  45.  
  46. function g(j, i) {
  47. this.el = j;
  48. this.options = h(this.defaults, i);
  49. this._init()
  50. }
  51. g.prototype = {
  52. defaults: {
  53. delayMenu: 100
  54. },
  55. _init: function() {
  56. this.touch = Modernizr.touch;
  57. this.menuItems = c.querySelectorAll("#" + this.el.id + " > li");
  58. this._initEvents()
  59. },
  60. _initEvents: function() {
  61. var i = this;
  62. Array.prototype.slice.call(this.menuItems).forEach(function(l, k) {
  63. var j = l.querySelector("a");
  64. if (i.touch) {
  65. j.addEventListener("click", function(m) {
  66. i._handleClick(this, m)
  67. })
  68. } else {
  69. l.addEventListener("mouseover", function(m) {
  70. if (e(m, this)) {
  71. i._openMenu(this)
  72. }
  73. });
  74. l.addEventListener("mouseout", function(m) {
  75. if (e(m, this)) {
  76. i._closeMenu(this)
  77. }
  78. })
  79. }
  80. })
  81. },
  82. _openMenu: function(j) {
  83. var i = this;
  84. clearTimeout(this.omtimeout);
  85. this.omtimeout = setTimeout(function() {
  86. var k = j.querySelector("ul.sub-menu");
  87. if (k) {
  88. j.className = "cbp-tm-show";
  89. if (i._positionMenu(j) === "top") {
  90. j.className += " cbp-tm-show-above"
  91. } else {
  92. j.className += " cbp-tm-show-below"
  93. }
  94. }
  95. }, this.touch ? 0 : this.options.delayMenu)
  96. },
  97. _closeMenu: function(j) {
  98. clearTimeout(this.omtimeout);
  99. var i = j.querySelector("ul.sub-menu");
  100. if (i) {
  101. j.className = j.className.replace(new RegExp("(^|\\s+)cbp-tm-show(\\s+|$)"), " ");
  102. j.className = j.className.replace(new RegExp("(^|\\s+)cbp-tm-show-below(\\s+|$)"), " ");
  103. j.className = j.className.replace(new RegExp("(^|\\s+)cbp-tm-show-above(\\s+|$)"), " ")
  104. }
  105. },
  106. _handleClick: function(l, n) {
  107. var m = l.parentNode,
  108. i = Array.prototype.slice.call(this.menuItems),
  109. k = m.querySelector("ul.sub-menu");
  110. if (typeof this.current !== "undefined" && i.indexOf(m) !== this.current) {
  111. this._closeMenu(this.el.children[this.current]);
  112. this.el.children[this.current].querySelector("ul.sub-menu").setAttribute("data-open", "false")
  113. }
  114. if (k) {
  115. n.preventDefault();
  116. var j = k.getAttribute("data-open");
  117. if (j === "true") {
  118. this._closeMenu(m);
  119. k.setAttribute("data-open", "false")
  120. } else {
  121. this._openMenu(m);
  122. this.current = i.indexOf(m);
  123. k.setAttribute("data-open", "true")
  124. }
  125. }
  126. },
  127. _positionMenu: function(j) {
  128. var m = a(),
  129. k = f(j),
  130. i = k.top,
  131. l = m - i - j.offsetHeight;
  132. return (l <= i ? "top" : "bottom")
  133. }
  134. };
  135. d.cbpTooltipMenu = g
  136. })(window);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement