1(function ($) { 2 3 'use strict'; 4 5 Drupal.behaviors.responsive_menu = { 6 attach: function (context, settings) { 7 8 $('body', context).once('responsive-menu', function() { 9 10 if (typeof($.mmenu) != 'undefined') { 11 12 // Get the position and theme options from Drupal settings. 13 var position = Drupal.settings.responsive_menu.position; 14 var theme = Drupal.settings.responsive_menu.theme; 15 16 // Set up the off canvas menu. 17 $('#off-canvas').mmenu({ 18 extensions: [theme, 'effect-slide-menu'], 19 offCanvas: { 20 zposition: 'next', 21 position: position 22 } 23 }, { 24 clone: false 25 }); 26 } 27 28 // Apply the superfish library to the menu. 29 if ($.fn.superfish) { 30 // Get the superfish settings. 31 var superfishDelay = Drupal.settings.responsive_menu.superfish.delay, 32 superfishSpeed = Drupal.settings.responsive_menu.superfish.speed, 33 superfishSpeedOut = Drupal.settings.responsive_menu.superfish.speedOut; 34 // Attach superfish to the responsive menu. 35 $('#horizontal-menu').superfish({ 36 delay: parseInt(superfishDelay, 10), 37 speed: parseInt(superfishSpeed, 10), 38 speedOut: parseInt(superfishSpeedOut, 10) 39 }).addClass('sf-menu'); 40 } 41 42 // Add the Hammer config if needed. 43 if (typeof(Hammer) != 'undefined') { 44 45 var mc = new Hammer($('body').get(0), { 46 cssProps: { 47 userSelect: true 48 }, 49 // Reset the touchAction to auto as this allows pinch zooming. 50 // mmenu handles the scrolling once open. 51 touchAction: 'auto' 52 }); 53 mc.get('swipe').set({ 54 velocity: 0.3, 55 threshold: 5 56 }); 57 58 mc.on("swipeleft swiperight", function(e) { 59 // Only do something if we're below our breakpoint. The simplest 60 // method is to check whether the horizontal desktop sized 61 // responsive menu is hidden. 62 if ($('.responsive-menu-block-wrapper').is(':hidden')) { 63 hammerswipe(mc, e); 64 } 65 }); 66 67 } 68 69 }); 70 } 71 }; 72 73 /** 74 * Opens or closes the mmenu based on swipe direction. 75 * 76 * @param mc 77 * Hammer object instance. 78 * @param e 79 * Swipe event. 80 */ 81 function hammerswipe(mc, e) { 82 var position = Drupal.settings.responsive_menu.position; 83 var api = $('#off-canvas').data('mmenu'), 84 $html = $('html'); 85 86 if (e.type == 'swiperight') { 87 if (position == 'right' && $html.hasClass('mm-opened')) { 88 // Close the menu. 89 api.close(); 90 } 91 if (position == 'left' && !$html.hasClass('mm-opened')) { 92 // Open the menu. 93 api.open(); 94 } 95 } 96 97 if (e.type == 'swipeleft') { 98 if (position == 'right' && !$html.hasClass('mm-opened')) { 99 // Open the menu. 100 api.open(); 101 } 102 if (position == 'left' && $html.hasClass('mm-opened')) { 103 // Close the menu. 104 api.close(); 105 } 106 } 107 } 108 109})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.