1/* Source and licensing information for the line(s) below can be found at https://www.cancham.org/libraries/drupal-superfish/sftouchscreen.js. */ 2/* 3 * sf-Touchscreen v1.3b - Provides touchscreen compatibility for the jQuery Superfish plugin. 4 * 5 * Developer's note: 6 * Built as a part of the Superfish project for Drupal (http://drupal.org/project/superfish) 7 * Found any bug? have any cool ideas? contact me right away! http://drupal.org/user/619294/contact 8 * 9 * jQuery version: 1.7 or higher. 10 * 11 * Dual licensed under the MIT and GPL licenses: 12 * http://www.opensource.org/licenses/mit-license.php 13 * http://www.gnu.org/licenses/gpl.html 14 */ 15 16(function($){ 17 $.fn.sftouchscreen = function(options){ 18 options = $.extend({ 19 mode: 'inactive', 20 breakpoint: 768, 21 breakpointUnit: 'px', 22 useragent: '', 23 behaviour: 2, 24 disableHover: false 25 }, options); 26 27 function activate(menu){ 28 const eventHandler = (('ontouchstart' in window) || (window.DocumentTouch && document instanceof DocumentTouch)) ? ['click touchstart','mouseup touchend'] : ['click','mouseup']; 29 // Select hyperlinks from parent menu items. 30 menu.find('li:has(ul)').children('a,span.nolink').each(function(){ 31 const $item = $(this), 32 parent = $item.closest('li'); 33 if (options.disableHover){ 34 parent.off('mouseenter mouseleave'); 35 } 36 if (options.behaviour === 2){ 37 if (parent.children('a.menuparent,span.nolink.menuparent').length > 0 && parent.children('ul').children('.sf-clone-parent').length === 0){ 38 // Cloning the hyperlink of the parent menu item. 39 let cloneLink = parent.children('a.menuparent').clone(); 40 // Wrapping the hyerplinks in <li>. 41 cloneLink = $('<li class="sf-clone-parent" />').html(cloneLink); 42 // Removing unnecessary stuff. 43 cloneLink.find('.sf-sub-indicator').remove(); 44 // Adding a helper class and attaching them to the sub-menus. 45 parent.children('ul').addClass('sf-has-clone-parent').prepend(cloneLink); 46 } 47 } 48 // No .toggle() here as it's not possible to reset it. 49 $item.on(eventHandler[0], function(event){ 50 // Already clicked? 51 if ($item.hasClass('sf-clicked')){ 52 // Depending on the preferred behaviour, either proceed to the URL. 53 if (options.behaviour === 0){ 54 url = $item.attr('href'); 55 if (typeof(url) != 'undefined'){ 56 window.location = url; 57 } 58 } 59 // or collapse the sub-menu. 60 else if (options.behaviour === 1 || options.behaviour === 2){ 61 event.preventDefault(); 62 $item.removeClass('sf-clicked'); 63 parent.hideSuperfishUl().find('a,span.nolink').removeClass('sf-clicked'); 64 } 65 } 66 // Prevent the default action otherwise. 67 else { 68 event.preventDefault(); 69 $item.addClass('sf-clicked'); 70 parent.showSuperfishUl().siblings('li:has(ul)').hideSuperfishUl().find('.sf-clicked').removeClass('sf-clicked'); 71 } 72 }); 73 }); 74 75 $(document).on(eventHandler[1], function(event){ 76 if (menu.not(event.target) && menu.has(event.target).length === 0){ 77 menu.find('.sf-clicked').removeClass('sf-clicked'); 78 menu.find('li:has(ul)').hideSuperfishUl(); 79 } 80 }); 81 } 82 // Return original object to support chaining. 83 // This is not necessary actually because of the way the module uses these plugins. 84 for (let b = 0; b < this.length; b++) { 85 const menu = $(this).eq(b), 86 mode = options.mode; 87 // The rest is crystal clear, isn't it? :) 88 if (mode === 'always_active'){ 89 activate(menu); 90 } 91 else if (mode === 'window_width'){ 92 const breakpoint = (options.breakpointUnit === 'em') ? (options.breakpoint * parseFloat($('body').css('font-size'))) : options.breakpoint; 93 const windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; 94 let timer; 95 if ((typeof Modernizr === 'undefined' || typeof Modernizr.mq !== 'function') && windowWidth < breakpoint){ 96 activate(menu); 97 } 98 else if (typeof Modernizr !== 'undefined' && typeof Modernizr.mq === 'function' && Modernizr.mq('(max-width:' + (breakpoint - 1) + 'px)')) { 99 activate(menu); 100 } 101 $(window).resize(function(){ 102 clearTimeout(timer); 103 timer = setTimeout(function(){ 104 const windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; 105 if ((typeof Modernizr === 'undefined' || typeof Modernizr.mq !== 'function') && windowWidth < breakpoint){ 106 activate(menu); 107 } 108 else if (typeof Modernizr !== 'undefined' && typeof Modernizr.mq === 'function' && Modernizr.mq('(max-width:' + (breakpoint - 1) + 'px)')) { 109 activate(menu); 110 } 111 }, 50); 112 }); 113 } 114 else if (mode === 'useragent_custom'){ 115 if (options.useragent != ''){ 116 const ua = RegExp(options.useragent, 'i'); 117 if (navigator.userAgent.match(ua)){ 118 activate(menu); 119 } 120 } 121 } 122 else if (mode === 'useragent_predefined' && navigator.userAgent.match(/(android|bb\d+|meego)|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i)){ 123 activate(menu); 124 } 125 } 126 return this; 127 } 128})(jQuery); 129 130/* Source and licensing information for the above line(s) can be found at https://www.canch
130am.org/libraries/drupal-superfish/sftouchscreen.js. */
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.