1/* 2 * jQuery Superclick Menu Plugin - v1.1.0 3 * Copyright (c) 2014 Joel Birch 4 * 5 * Dual licensed under the MIT and GPL licenses: 6 * http://www.opensource.org/licenses/mit-license.php 7 * http://www.gnu.org/licenses/gpl.html 8 */ 9 10;(function ($) { 11 "use strict"; 12 13 var methods = (function () { 14 // private properties and methods go here 15 var c = { 16 bcClass: 'sf-breadcrumb', 17 menuClass: 'sf-js-enabled', 18 anchorClass: 'sf-with-ul', 19 menuArrowClass: 'sf-arrows' 20 }, 21 outerClick = (function () { 22 $(window).load(function () { 23 $('body').children().on('click.superclick', function () { 24 var $allMenus = $('.sf-js-enabled'); 25 $allMenus.superclick('reset'); 26 }); 27 }); 28 })(), 29 toggleMenuClasses = function ($menu, o) { 30 var classes = c.menuClass; 31 if (o.cssArrows) { 32 classes += ' ' + c.menuArrowClass; 33 } 34 $menu.toggleClass(classes); 35 }, 36 setPathToCurrent = function ($menu, o) { 37 return $menu.find('li.' + o.pathClass).slice(0, o.pathLevels) 38 .addClass(o.activeClass + ' ' + c.bcClass) 39 .filter(function () { 40 return ($(this).children(o.popUpSelector).hide().show().length); 41 }).removeClass(o.pathClass); 42 }, 43 toggleAnchorClass = function ($li) { 44 $li.children('a').toggleClass(c.anchorClass); 45 }, 46 toggleTouchAction = function ($menu) { 47 var touchAction = $menu.css('ms-touch-action'); 48 touchAction = (touchAction === 'pan-y') ? 'auto' : 'pan-y'; 49 $menu.css('ms-touch-action', touchAction); 50 }, 51 clickHandler = function (e) { 52 var $this = $(this), 53 $popUp = $this.siblings(e.data.popUpSelector), 54 func; 55 56 if ($popUp.length) { 57 func = ($popUp.is(':hidden')) ? over : out; 58 $.proxy(func, $this.parent('li'))(); 59 return false; 60 } 61 }, 62 over = function () { 63 var $this = $(this), 64 o = getOptions($this); 65 $this.siblings().superclick('hide').end().superclick('show'); 66 }, 67 out = function () { 68 var $this = $(this), 69 o = getOptions($this); 70 $.proxy(close, $this, o)(); 71 }, 72 close = function (o) { 73 o.retainPath = ($.inArray(this[0], o.$path) > -1); 74 this.superclick('hide'); 75 76 if (!this.parents('.' + o.activeClass).length) { 77 o.onIdle.call(getMenu(this)); 78 if (o.$path.length) { 79 $.proxy(over, o.$path)(); 80 } 81 } 82 }, 83 getMenu = function ($el) { 84 return $el.closest('.' + c.menuClass); 85 }, 86 getOptions = function ($el) { 87 return getMenu($el).data('sf-options'); 88 }; 89 90 return { 91 // public methods 92 hide: function (instant) { 93 if (this.length) { 94 var $this = this, 95 o = getOptions($this); 96 if (!o) { 97 return this; 98 } 99 var not = (o.retainPath === true) ? o.$path : '', 100 $popUp = $this.find('li.' + o.activeClass).add(this).not(not).removeClass(o.activeClass).children(o.popUpSelector), 101 speed = o.speedOut; 102 103 if (instant) { 104 $popUp.show(); 105 speed = 0; 106 } 107 o.retainPath = false; 108 o.onBeforeHide.call($popUp); 109 $popUp.stop(true, true).animate(o.animationOut, speed, function () { 110 var $this = $(this); 111 o.onHide.call($this); 112 }); 113 } 114 return this; 115 }, 116 show: function () { 117 var o = getOptions(this); 118 if (!o) { 119 return this; 120 } 121 var $this = this.addClass(o.activeClass), 122 $popUp = $this.children(o.popUpSelector); 123 124 o.onBeforeShow.call($popUp); 125 $popUp.stop(true, true).animate(o.animation, o.speed, function () { 126 o.onShow.call($popUp); 127 }); 128 return this; 129 }, 130 destroy: function () { 131 return this.each(function () { 132 var $this = $(this), 133 o = $this.data('sf-options'), 134 $hasPopUp; 135 if (!o) { 136 return false; 137 } 138 $hasPopUp = $this.find(o.popUpSelector).parent('li'); 139 toggleMenuClasses($this, o); 140 toggleAnchorClass($hasPopUp); 141 toggleTouchAction($this); 142 // remove event handlers 143 $this.off('.superclick'); 144 // clear animation's inline display style 145 $hasPopUp.children(o.popUpSelector).attr('style', function (i, style) { 146 return style.replace(/display[^;]+;?/g, ''); 147 }); 148 // reset 'current' path classes 149 o.$path.removeClass(o.activeClass + ' ' + c.bcClass).addClass(o.pathClass); 150 $this.find('.' + o.activeClass).removeClass(o.activeClass); 151 o.onDestroy.call($this); 152 $this.removeData('sf-options'); 153 }); 154 }, 155 reset: function () { 156 return this.each(function () { 157 var $menu = $(this), 158 o = getOptions($menu), 159 $openLis = $($menu.find('.' + o.activeClass).toArray().reverse()); 160 $openLis.children('a').trigger('click'); 161 }); 162 }, 163 init: function (op) { 164 return this.each(function () { 165 var $this = $(this); 166 if ($this.data('sf-options')) { 167 return false;
168 } 169 var o = $.extend({}, $.fn.superclick.defaults, op), 170 $hasPopUp = $this.find(o.popUpSelector).parent('li'); 171 o.$path = setPathToCurrent($this, o); 172 173 $this.data('sf-options', o); 174 175 toggleMenuClasses($this, o); 176 toggleAnchorClass($hasPopUp); 177 toggleTouchAction($this); 178 $this.on('click.superclick', 'a', o, clickHandler); 179 180 $hasPopUp.not('.' + c.bcClass).superclick('hide', true); 181 182 o.onInit.call(this); 183 }); 184 } 185 }; 186 })(); 187 188 $.fn.superclick = function (method, args) { 189 if (methods[method]) { 190 return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); 191 } 192 else if (typeof method === 'object' || ! method) { 193 return methods.init.apply(this, arguments); 194 } 195 else { 196 return $.error('Method ' + method + ' does not exist on jQuery.fn.superclick'); 197 } 198 }; 199 200 $.fn.superclick.defaults = { 201 popUpSelector: 'ul,.sf-mega', // within menu context 202 activeClass: 'sfHover', // keep 'hover' in classname for compatibility reasons 203 pathClass: 'overrideThisToUse', 204 pathLevels: 1, 205 animation: {opacity: 'show'}, 206 animationOut: {opacity: 'hide'}, 207 speed: 'normal', 208 speedOut: 'fast', 209 cssArrows: true, 210 onInit: $.noop, 211 onBeforeShow: $.noop, 212 onShow: $.noop, 213 onBeforeHide: $.noop, 214 onHide: $.noop, 215 onIdle: $.noop, 216 onDestroy: $.noop 217 }; 218 219})(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.