'use strict';var _createClass=function(){function defineProperties(target,props){for(var i=0;i');this._anchors=this._menu.find('a');this._slider=this._menu.find('.slider:first');this._level=0;this._isOpen=false;this._isAnimating=false;this._hasMenu=this._anchors.length>0;this._lastAction=null;this._setupEventHandlers();this._setupMenu();if(this._hasMenu)this._setupSubmenus();} _createClass(SlideMenu,[{key:'toggle',value:function toggle(){var open=arguments.length>0&&arguments[0]!==undefined?arguments[0]:null;var animate=arguments.length>1&&arguments[1]!==undefined?arguments[1]:true;var offset=void 0;if(open===null){if(this._isOpen){this.close();}else{this.open();} return;}else if(open){offset=0;this._isOpen=true;}else{offset=this.options.position==='left'?'-100%':'100%';this._isOpen=false;} this._triggerEvent();if(animate)this._triggerAnimation(this._menu,offset);else{this._pauseAnimations(this._triggerAnimation.bind(this,this._menu,offset));this._isAnimating=false;}}},{key:'open',value:function open(){var animate=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;this._lastAction='open';this.toggle(true,animate);}},{key:'close',value:function close(){var animate=arguments.length>0&&arguments[0]!==undefined?arguments[0]:true;this._lastAction='close';this.toggle(false,animate);}},{key:'back',value:function back(){this._lastAction='back';this._navigate(null,-1);}},{key:'navigateTo',value:function navigateTo(target){var _this=this;target=this._menu.find($(target)).first();if(!target.length)return false;var parents=target.parents('ul');var level=parents.length-1;if(level===0)return false;this._pauseAnimations(function(){_this._level=level;parents.show().first().addClass('active');_this._triggerAnimation(_this._slider,-_this._level*100);});}},{key:'_setupEventHandlers',value:function _setupEventHandlers(){var _this2=this;if(this._hasMenu){this._anchors.click(function(event){var anchor=$(event.target).is('a')?$(event.target):$(event.target).parents('a:first');_this2._navigate(anchor);});} $(this._menu.add(this._slider)).on('transitionend msTransitionEnd',function(){_this2._isAnimating=false;_this2._triggerEvent(true);});$(document).keydown(function(e){switch(e.which){case _this2.options.keycodeClose:_this2.close();break;case _this2.options.keycodeOpen:_this2.open();break;default:return;} e.preventDefault();});this._menu.on('sm.back-after',function(){var lastActiveUl='ul '+'.active '.repeat(_this2._level+1);_this2._menu.find(lastActiveUl).removeClass('active').hide();});}},{key:'_triggerEvent',value:function _triggerEvent(){var afterAnimation=arguments.length>0&&arguments[0]!==undefined?arguments[0]:false;var eventName='sm.'+this._lastAction;if(afterAnimation)eventName+='-after';this._menu.trigger(eventName);}},{key:'_navigate',value:function _navigate(anchor){var dir=arguments.length>1&&arguments[1]!==undefined?arguments[1]:1;if(this._isAnimating){return;} var offset=(this._level+dir)*-100;if(dir>0){if(!anchor.next('ul').length)return;anchor.next('ul').addClass('active').show();}else if(this._level===0){return;} this._lastAction=dir>0?'forward':'back';this._level=this._level+dir;this._triggerAnimation(this._slider,offset);}},{key:'_triggerAnimation',value:function _triggerAnimation(elem,offset){this._triggerEvent();if(!(String(offset).indexOf('%')!==-1))offset+='%';elem.css('transform','translateX('+offset+')');this._isAnimating=true;}},{key:'_setupMenu',value:function _setupMenu(){var _this3=this;this._pauseAnimations(function(){switch(_this3.options.position){case'left':_this3._menu.css({left:0,right:'auto',transform:'translateX(-100%)'});break;default:_this3._menu.css({left:'auto',right:0});break;} _this3._menu.show();});}},{key:'_pauseAnimations',value:function _pauseAnimations(work){this._menu.addClass('no-transition');work();this._menu[0].offsetHeight;this._menu.removeClass('no-transition');}},{key:'_setupSubmenus',value:function _setupSubmenus(){var _this4=this;this._anchors.each(function(i,anchor){anchor=$(anchor);if(anchor.next('ul').length){anchor.click(function(ev){ev.preventDefault();});var anchorTitle=anchor.text();anchor.html(_this4.options.submenuLinkBefore+anchorTitle+_this4.options.submenuLinkAfter);if(_this4.options.showBackLink){var backLink=$(''+anchorTitle+'');backLink.html(_this4.options.backLinkBefore+backLink.text()+_this4.options.backLinkAfter);anchor.next('ul').prepend($('
  • ').append(backLink));}}});}}]);return SlideMenu;}();$('body').on('click','.slide-menu-control',function(e){var menu=void 0;var target=$(this).data('target');if(!target||target==='this'){menu=$(this).parents('.slide-menu:first');}else{menu=$('#'+target);} if(!menu.length)return;var instance=menu.data(PLUGIN_NAME);var action=$(this).data('action');if(instance&&typeof instance[action]==='function'){instance[action]();} return false;});$.fn[PLUGIN_NAME]=function(options){if(!$(this).length){console.warn('Slide Menu: Unable to find menu DOM element. Maybe a typo?');return;} options=$.extend({},DEFAULT_OPTIONS,options);options.elem=$(this);var instance=new SlideMenu(options);$(this).data(PLUGIN_NAME,instance);return instance;};})(jQuery);