/*----------------------------- swipe_menu -----------------------------*/ (function($){ var defaults = { eleMenuContents:{}, eleOpenTrigger:{}, eleCloseTrigger:{}, maxWinSize:900, slideSpeed:300, //callback funcOpenStartCallback:function(){}, funcOpenEndCallback:function(){}, funcCloseStartCallback:function(){}, funcCloseEndCallback:function(){} }; $.fn.swipeMenu = function(options){ var el = this, lenEl = el.length; if(lenEl === 0)return this; if(lenEl > 1){ el.each(function(){$(this).swipeMenu(options)}); return this; } var configs = {}, cssWidthElChild, posTouch, flagExecuteDirection = 0, flagExecute = true, funcInit = function(){ configs = $.extend({}, defaults, options); if(!configs.eleOpenTrigger[0]) return false; configs.eleOpenTrigger.on({ 'click':function(){ el.funcOpenInit(); } }); configs.eleCloseTrigger.on({ 'click':function(){ el.funcCloseExecute(); } }); el.on({ 'touchstart':function(e){ posTouch = e.originalEvent.changedTouches[0].screenX; flagExecuteDirection = 0; }, 'touchmove':function(e){ if(posTouch - e.originalEvent.changedTouches[0].screenX > 70){ flagExecuteDirection = -1; }else if(posTouch - e.originalEvent.changedTouches[0].screenX < -70){ flagExecuteDirection = 1; }else{ flagExecuteDirection = 0; } if(posTouch - e.originalEvent.changedTouches[0].screenX <= 0) configs.eleMenuContents.css({'right':posTouch - e.originalEvent.changedTouches[0].screenX}); }, 'touchend':function(e){ switch(flagExecuteDirection){ case 1: el.funcCloseExecute(); break; case 0: el.funcOpenExecute(); break; } } }); }, funcCustomEvents = function(){ el.on({ 'swipeMenu.open':function(e, args){ el.funcOpenInit(); }, 'swipeMenu.close':function(e, args){ el.funcCloseExecute(); } }); }; el.funcOpenInit = function(){ if(flagExecute === false) return false; flagExecute = false; cssWidthElChild = parseInt(configs.eleMenuContents.width()); configs.eleMenuContents.css({ 'right':(cssWidthElChild * -1) + 'px' }); $('body').css({ 'overflow':'hidden' }); el.show(); el.funcOpenExecute(function(){ flagExecute = true; }); }, el.funcOpenExecute = function(callback){ configs.eleMenuContents .stop() .show() .animate( { 'right':'0' }, configs.slideSpeed, function(){ if(typeof callback === 'function') callback(); } ); }, el.funcCloseExecute = function(){ if(flagExecute === false) return false; flagExecute = false; configs.eleMenuContents .stop() .animate( { 'right':(cssWidthElChild * -1) + 'px' }, configs.slideSpeed, function(){ configs.eleMenuContents.hide(); el.hide(); $('body').css({ 'overflow':'visible' }); flagExecute = true; } ); }; funcInit(); }; })(jQuery); /*----------------------------- /swipe_menu -----------------------------*/