1/** 2 * @file 3 * Utility functions to handle the mmenus. 4 */ 5 6function mmenu_enabled_callback() { 7 return window.innerWidth <= 480; 8} 9 10(function ($) { 11 Drupal.mmenu = Drupal.mmenu || {}; 12 Drupal.mmenu.settings = Drupal.mmenu.settings || {}; 13 14 Drupal.mmenu.resetDragOpen = function () { 15 Drupal.mmenu.settings = Drupal.settings.mmenu; 16 for (var key in Drupal.mmenu.settings) { 17 var mmenu = Drupal.mmenu.settings[key]; 18 19 // To check if we need to enable/disable the mmenu. 20 var flag = true; 21 if (typeof mmenu.enabled_callback !== 'undefined') { 22 if (mmenu.enabled_callback.js) { 23 for (var i in mmenu.enabled_callback.js) { 24 // Function we want to run. 25 var callbackString = mmenu.enabled_callback.js[i]; 26 // Finds object. 27 var callback = window[callbackString]; 28 // Is object a function? 29 if (typeof callback === "function") { 30 flag = callback(); 31 if (!flag) { 32 break; 33 } 34 } 35 } 36 } 37 } 38 39 // Updates the dragOpen threshold value to enable/disable drag to open event. 40 var _menu = $("#" + mmenu.name).data("mmenu"); 41 if (typeof _menu !== 'undefined') { 42 if (!_menu.opts.dragOpen.oriThreshold) { 43 _menu.opts.dragOpen.oriThreshold = _menu.opts.dragOpen.threshold; 44 } 45 _menu.opts.dragOpen.threshold = flag ? _menu.opts.dragOpen.oriThreshold : 1000000000; 46 } 47 } 48 } 49 50 Drupal.behaviors.mmenu = { 51 attach: function (context, settings) { 52 Drupal.mmenu.resetDragOpen(); 53 $(window).on('resize', function () { 54 Drupal.mmenu.resetDragOpen(); 55 }); 56 57 for (var key in Drupal.mmenu.settings) { 58 var mmenu = Drupal.mmenu.settings[key]; 59 var $mmenu = $('#' + mmenu.name); 60 61 // Initializes single mmenu. 62 $mmenu.mmenu( 63 mmenu.options, 64 mmenu.configurations 65 ); 66 67 // Handles clickOpen event. 68 if (mmenu.options.clickOpen) { 69 if (mmenu.options.clickOpen.open && mmenu.options.clickOpen.selector) { 70 $(mmenu.options.clickOpen.selector).bind('click', {name: mmenu.name}, function (e) { 71 e.preventDefault(); 72 $('#' + e.data.name).trigger('open.mm'); 73 }); 74 } 75 } 76 } 77 78 // In order to support the special_menu_items and menu_firstchild modules. 79 // Opens the next level menu if click the <nolink> and <firstchild> links. 80 $('.mmenu-mm-subopen').click(function() { 81 $(this).siblings('a.mm-subopen').trigger('click'); 82 }); 83 } 84 }; 85 86})(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.