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
10 KiB

10 years ago
  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.is.legacy()&&(q.useLegacy=!0),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){var c=q.useLegacy?p.legacyPushPage:p.pushPage;b=a.isFunction(b)?b:function(){},p.is.closed()?(q.overlay&&(p.error(u.overlay),q.transition="overlay"),"overlay"!==q.transition&&p.hideAll(),c(function(){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){var c=q.useLegacy?p.legacyPullPage:p.pullPage;b=a.isFunction(b)?b:function(){},p.is.visible()&&(p.debug("Hiding sidebar",b),c(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=p.get.transition(),f="safe"==e?y:"overlay"==e?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()})},f.on(o,function(b){b.target==f[0]&&(f.off(o),p.remove.inward(),p.bind.clickaway(),p.set.active(),a.proxy(c,E)())}),p.verbose("Adding context push state",y),"overlay"===e?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=p.get.transition(),e="safe"==d?y:"overlay"==d?x:B;c=a.isFunction(c)?c:function(){},p.verbose("Removing context push state",p.get.direction()),p.unbind.clickaway(),e.on(o,function(d){d.target==e[0]&&(e.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()})},legacyPushPage