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