/vendor/assets/templates/public/js/jetmenu.js

https://github.com/mikajery/Booking-Drive · JavaScript · 126 lines · 112 code · 14 blank · 0 comment · 19 complexity · 1246d8807dc84047114939ad5472f029 MD5 · raw file

  1. jQuery.fn.jetmenu = function(options){
  2. var settings = {
  3. indicator :true // indicator that indicates a submenu
  4. ,speed :300 // submenu speed
  5. ,hideClickOut :true // hide submenus when click outside menu
  6. }
  7. $.extend( settings, options );
  8. var menu = $(".jetmenu");
  9. var lastScreenWidth = window.innerWidth;
  10. if(settings.indicator == true){
  11. $(menu).find("a").each(function(){
  12. if($(this).siblings(".dropdown, .megamenu").length > 0){
  13. $(this).append("<span class='indicator'>+</span>");
  14. }
  15. });
  16. }
  17. $(menu).prepend("<li class='showhide'><span class='title'>MENU</span><span class='icon'><em></em><em></em><em></em><em></em></span></li>");
  18. screenSize();
  19. $(window).resize(function() {
  20. if(lastScreenWidth <= 768 && window.innerWidth > 768){
  21. unbindEvents();
  22. hideCollapse();
  23. bindHover();
  24. }
  25. if(lastScreenWidth > 768 && window.innerWidth <= 768){
  26. unbindEvents();
  27. showCollapse();
  28. bindClick();
  29. }
  30. lastScreenWidth = window.innerWidth;
  31. });
  32. function screenSize(){
  33. if(window.innerWidth <= 768){
  34. showCollapse();
  35. bindClick();
  36. }
  37. else{
  38. hideCollapse();
  39. bindHover();
  40. }
  41. }
  42. function bindHover(){
  43. if (navigator.userAgent.match(/Mobi/i) || window.navigator.msMaxTouchPoints > 0){
  44. $(menu).find("a").on("click touchstart", function(e){
  45. e.stopPropagation();
  46. e.preventDefault();
  47. window.location.href = $(this).attr("href");
  48. $(this).parent("li").siblings("li").find(".dropdown, .megamenu").stop(true, true).fadeOut(settings.speed);
  49. if($(this).siblings(".dropdown, .megamenu").css("display") == "none"){
  50. $(this).siblings(".dropdown, .megamenu").stop(true, true).fadeIn(settings.speed);
  51. }
  52. else{
  53. $(this).siblings(".dropdown, .megamenu").stop(true, true).fadeOut(settings.speed);
  54. $(this).siblings(".dropdown").find(".dropdown").stop(true, true).fadeOut(settings.speed);
  55. }
  56. });
  57. if(settings.hideClickOut == true){
  58. $(document).bind("click.menu touchstart.menu", function(ev){
  59. if($(ev.target).closest(menu).length == 0){
  60. $(menu).find(".dropdown, .megamenu").fadeOut(settings.speed);
  61. }
  62. });
  63. }
  64. }
  65. else{
  66. $(menu).find("li").bind("mouseenter", function(){
  67. $(this).children(".dropdown, .megamenu").stop(true, true).fadeIn(settings.speed);
  68. }).bind("mouseleave", function(){
  69. $(this).children(".dropdown, .megamenu").stop(true, true).fadeOut(settings.speed);
  70. });
  71. }
  72. }
  73. function bindClick(){
  74. $(menu).find("li:not(.showhide)").each(function(){
  75. if($(this).children(".dropdown, .megamenu").length > 0){
  76. $(this).children("a").bind("click", function(){
  77. if($(this).siblings(".dropdown, .megamenu").hasClass("menu-visible")){
  78. $(this).siblings(".dropdown, .megamenu").slideUp(settings.speed);
  79. $(this).siblings(".dropdown, .megamenu").removeClass("menu-visible");
  80. }
  81. else{
  82. $(this).siblings(".dropdown, .megamenu").slideDown(settings.speed);
  83. $(this).siblings(".dropdown, .megamenu").addClass("menu-visible");
  84. firstItemClick = 1;
  85. }
  86. });
  87. }
  88. });
  89. }
  90. function showCollapse(){
  91. $(menu).children("li:not(.showhide)").hide(0);
  92. $(menu).children("li.showhide").show(0);
  93. $(menu).children("li.showhide").bind("click", function(){
  94. if($(menu).children("li").is(":hidden")){
  95. $(menu).children("li").slideDown(settings.speed);
  96. }
  97. else{
  98. $(menu).children("li:not(.showhide)").slideUp(settings.speed);
  99. $(menu).children("li.showhide").show(0);
  100. }
  101. });
  102. }
  103. function hideCollapse(){
  104. $(menu).children("li").show(0);
  105. $(menu).children("li.showhide").hide(0);
  106. }
  107. function unbindEvents(){
  108. $(menu).find("li, a").unbind();
  109. $(document).unbind("click.menu touchstart.menu");
  110. $(menu).find(".dropdown, .megamenu").hide(0);
  111. }
  112. }