You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

0 lines
8.3 KiB

  1. !function(a,b,c,d){"use strict";a.fn.sidebar=function(e){var f,g=a(this),h=(a("head"),g.selector||""),i=(new Date).getTime(),j=[],k=arguments[0],l="string"==typeof k,m=[].slice.call(arguments,1),n=b.requestAnimationFrame||b.mozRequestAnimationFrame||b.webkitRequestAnimationFrame||b.msRequestAnimationFrame||function(a){setTimeout(a,0)};return g.each(function(){var g,o,p,q=a.isPlainObject(e)?a.extend(!0,{},a.fn.sidebar.settings,e):a.extend({},a.fn.sidebar.settings),r=q.selector,s=q.className,t=q.namespace,u=q.error,v="."+t,w="module-"+t,x=a(this),y=a(q.context),z=a("style[title="+t+"]"),A=y.children(r.sidebar),B=y.children(r.pusher),C=B.children(r.page),D=B.find(r.fixed),E=this,F=x.data(w);p={initialize:function(){p.debug("Initializing sidebar",x),o=p.get.transitionEvent(),p.setup.context(),n(p.setup.layout),p.instantiate()},instantiate:function(){p.verbose("Storing instance of module",p),F=p,x.data(w,p)},destroy:function(){p.verbose("Destroying previous module for",x),x.off(v).removeData(w)},event:{clickaway:function(b){0===x.find(b.target).size()&&0===a(b.target).filter(x).size()&&(p.verbose("User clicked on dimmed page"),p.hide())},scroll:function(b){0===x.find(b.target).size()&&0===a(b.target).filter(x).size()&&b.preventDefault()}},bind:{clickaway:function(){q.scrollLock&&a(b).on("DOMMouseScroll"+v,p.event.scroll),y.on("click"+v,p.event.clickaway).on("touchend"+v,p.event.clickaway)}},unbind:{clickaway:function(){y.off(v),q.scrollLock&&a(b).off("DOMMouseScroll"+v)}},refresh:function(){p.verbose("Refreshing selector cache"),y=a(q.context),z=a("style[title="+t+"]"),A=y.children(r.sidebar),B=y.children(r.pusher),C=B.children(r.page),D=B.find(r.fixed)},repaint:function(){p.verbose("Forcing repaint event");y[0].offsetWidth},setup:{layout:function(){0===y.find(r.pusher).size()&&(p.debug("Adding wrapper element for sidebar"),B=a('<div class="pusher" />'),C=a('<div class="page" />'),B.append(C),y.children().not(r.omitted).not(A).wrapAll(B)),x.prevAll(C)[0]!==C[0]&&(p.debug("Moved sidebar to correct parent element"),x.detach().prependTo(y)),p.refresh()},context:function(){p.verbose("Adding pusshable class to wrapper"),y.addClass(s.pushable)}},attachEvents:function(b,c){var d=a(b);c=a.isFunction(p[c])?p[c]:p.toggle,d.size()>0?(p.debug("Attaching sidebar events to element",b,c),d.off(v).on("click"+v,c)):p.error(u.notFound)},show:function(b){b=a.isFunction(b)?b:function(){},p.debug("Showing sidebar",b),p.is.closed()?(q.overlay&&(q.transition="overlay"),"overlay"!==q.transition&&p.hideAll(),p.pushPage(function(){p.set.active(),a.proxy(b,E)(),a.proxy(q.onShow,E)()}),a.proxy(q.onChange,E)(),a.proxy(q.onVisible,E)()):p.debug("Sidebar is already visible")},hide:function(b){b=a.isFunction(b)?b:function(){},p.debug("Hiding sidebar",b),p.is.visible()&&(p.pullPage(function(){a.proxy(b,E)(),a.proxy(q.onHidden,E)()}),a.proxy(q.onChange,E)(),a.proxy(q.onHide,E)())},hideAll:function(){var a=A.find("."+s.visible);a.sidebar("hide")},toggle:function(){p.verbose("Determining toggled direction"),p.is.closed()?p.show():p.hide()},pushPage:function(c){var d,e="safe"==q.transition?y:"overlay"==q.transition?x:B;c=a.isFunction(c)?c:function(){},d=function(){p.set.visible(),p.set.transition(),p.set.direction(),n(function(){p.set.inward(),p.set.pushed()})},e.on(o,function(b){b.target==e[0]&&(e.off(o),p.remove.inward(),p.bind.clickaway(),a.proxy(c,E)())}),p.verbose("Adding context push state",y),"overlay"===q.transition?n(d):(p.is.mobile()&&(x.scrollTop(0),g=a(b).scrollTop(),b.scrollTo(0,0)),p.remove.allVisible(),n(d))},pullPage:function(c){var d="safe"==q.transition?y:"overlay"==q.transition?x:B;c=a.isFunction(c)?c:function(){},p.verbose("Removing context push state",p.get.direction()),p.unbind.clickaway(),d.on(o,function(e){e.target==d[0]&&(d.off(o),p.remove.transition(),p.remove.direction(),p.remove.outward(),p.remove.visible(),p.is.mobile()&&q.returnScroll&&b.scrollTo(0,g),a.proxy(c,E)())}),n(function(){p.set.outward(),p.remove.active(),p.remove.pushed()})},set:{active:function(){y.addClass(s.active)},direction:function(a){a=a||p.get.direction(),y.addCl