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