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